Pololu Robotics & Electronics
Menu
My account Comments or questions? About Pololu Contact Ordering information Distributors

Micro Maestro Help! Button, sequence, reverse sequence


#1

IM using a Micro Maestro 6-Channel.
Hi, Im a total beginner with this and I apologize if Im all over the place Ill try and be concise. IM making an iron man helmet and want to control servos with the micro maestro. Ive figured out basically how to create and run a sequence from the laptop.

Im going to wire a button into channel 0, servo A into channel 1, Servo B into channel 2 (possibly LEDS eyes into channel 3 though it’ll probably be easier to run the lights manually with just a switch on a seperate circuit without the pololu)

The way I see it I could have a few possibilities:
Situation A- Top priority
I would like to have the button begin a sequence (open helmet) and push the button again to reverse the sequence, or reset (to close the helmet) whichever brings it back to the starting position the easiest.
…if that isnt easily doable

Situation B- I dont mind using extra buttons if needed
Same as A except a second button in a spare channel to play a closing sequence. button1 runs open command, button2 runs close

Situation C
Same as A except LED light eyes turn off on open command, and turn back on after close, another button controls lights independently. This would be my most ideal, but it is the most confusing for me to imagine, and most complicated IM sure, so it isnt my top priority

IF anyone in Pololu land could help and paste the most basic script to achieve Situation A or B that I could study, (please assume Im ignorant of programming) and tweak myself with my own actual movement commands I would be forever grateful. And if someone really really patient wants to walk through a possible way to achieve Situation 3 I wouldnt turn that down :).


Pololu Maestro indepedant button press issue
#2

Hello.

Having one button do a sequence of different things (in this case just 2 things) can usually be done easily by using some sort of state variable. Here is an example script that should function the way you described in “Situation A” once you add your servo commands where I have indicated:

1  #Sets an initial state (open)
begin

    0 get_position
    500 greater_than  #Check if button is pushed
    if
          
        dup
        if  #If helmet is open, run frame to close it

            close_helmet #Run the close_helmet subroutine
            drop  #Change the state to 0
            0

        else  #If helmet is closed, run frame to open it

            open_helmet #Run the open_helmet subroutine	            
            drop #Change the state to 1
            1

        endif

    endif

repeat


sub close_helmet #This is the subroutine to close the helmet
            #Add your servo commands to close the helmet here
    500 delay
return

sub open_helmet #This is the subroutine to open the helmet
            #Add your servo commands to open the helmet here
    500 delay
return

As for “Situation C”, you could try adding in commands in the “close_helmet” and “open_helmet” subroutines that control your LEDs. Once you get that working, you could try adding a second button that uses the “get_position” command to check the state of the LED, and changes it independently of the first button. If you have trouble with any of that, please let me know.

-Brandon


Script switch issue
Model railroad turnout script
Help writeing animatronic code
#3

Thanks so much for the help. I did a little test run with two junk sub routines and it kept looping forever. Im totally new to this code, but I just applied a little thought and quickly noticed, that the button was going from 0-256 when open or closed. SO I changed the first line you gave me to less than 1 just to see what would happen. Now it runs one command with one press and the other command with a second press. As far as I can tell I just have to plug in the real positions and I’ll be done. Thanks so much again. Ill let you know if something else comes up. Let me know if you notice a flaw in my logic above.

Another Question(s).
IF I were to run a second button to do somethng else separately how could I let the program know the difference between the two buttons? A different strength resistor? a different range signal change to look for?
Also could you show me a basic on/ off command for LEd please. Thanks again :slight_smile:

**EDIT**
Ive only actually tested it by checking “run script on startup” in the script part of the program. I havent downloaded it to the Pololu yet. While Testing I noticed the Stack window on the side, it goes up to 31, and after 31 routines(basically it is filling up when I press the button) there is an error and I have to manually restart the device. Will this happen after downloading the commands to the Pololu as well? or is it just a part of the script program that Im misreading? I understand there is only so much memory in the chip, but im repeating the same two commands, I didnt think it would matter how often I press the button (maybe it doesnt??) is there a way to avoid this error? Like a command that resets upon error?
*DOUBLE EDIT*
I think Ive solved that issue, I had my delay after a frame at the bottom instead of after the actual subroutine for open_helmet. Ive fixed that and now the stack isnt growing at all no matter how often I press the button

1  #Sets an initial state (open)
begin

    0 get_position
    1 less_than  #Check if button is pushed
    if
          
        dup
        if  #If helmet is open, run frame to close it

            close_helmet #Run the close_helmet subroutine
            drop  #Change the state to 0
            0

        else  #If helmet is closed, run frame to open it

            open_helmet #Run the open_helmet subroutine               
            drop #Change the state to 1
            1

        endif

    endif

repeat
### Sequence subroutines: ###

# close_helmet
sub close_helmet
  500 0 0 0 7491 9033 frame_1..5 # Frame 0
  500 4594 frame_4 # Frame 1
500 delay
return
# open_helmet
sub open_helmet
  500 0 0 0 5984 7254 frame_1..5 # Frame 0
  500 6659 frame_5 # Frame 1
  500 6316 frame_4 # Frame 2
  500 5686 frame_5 # Frame 3
  500 6923 frame_4 # Frame 4
  500 5091 frame_5 # Frame 5
  500 7491 frame_4 # Frame 6
  return

sub frame_1..5
  5 servo
  4 servo
  3 servo
  2 servo
  1 servo
  delay
  return

sub frame_4
  4 servo
  delay
  return

sub frame_5
  5 servo
500 delay
return

Can you help me modify my code?
#4

I am glad you figured out the problem with your script and that you were able to get it working.

Connecting and controlling an LED is described in the “Attaching Servos and Peripherals” section of the user’s guide. Please note that you will use the same “Set Target” command you use for controlling servos, to control your LEDs. The LED should be on if you set the target to greater than or equal to 1500us (or 6000 in your script) and off otherwise.

In order to connect a second button that controls the LEDs independently, you would use a separate channel and use the “get_position” command with that channel, as you did with the first button on channel 0.

-Brandon


#5

[quote=“supafreak”]IM using a Micro Maestro 6-Channel.
Hi, Im a total beginner with this and I apologize if Im all over the place Ill try and be concise. IM making an iron man helmet and want to control servos with the micro maestro. Ive figured out basically how to create and run a sequence from the laptop.

Im going to wire a button into channel 0, servo A into channel 1, Servo B into channel 2 (possibly LEDS eyes into channel 3 though it’ll probably be easier to run the lights manually with just a switch on a seperate circuit without the pololu)

The way I see it I could have a few possibilities:
Situation A- Top priority
I would like to have the button begin a sequence (open helmet) and push the button again to reverse the sequence, or reset (to close the helmet) whichever brings it back to the starting position the easiest.
…if that isnt easily doable

Situation B- I dont mind using extra buttons if needed
Same as A except a second button in a spare channel to play a closing sequence. button1 runs open command, button2 runs close

Situation C
Same as A except LED light eyes turn off on open command, and turn back on after close, another button controls lights independently. This would be my most ideal, but it is the most confusing for me to imagine, and most complicated IM sure, so it isnt my top priority

IF anyone in Pololu land could help and paste the most basic script to achieve Situation A or B that I could study, (please assume Im ignorant of programming) and tweak myself with my own actual movement commands I would be forever grateful. And if someone really really patient wants to walk through a possible way to achieve Situation 3 I wouldnt turn that down :).[/quote]

Hey Bud. I actually made a Ironman costume 2 years ago built around the Micro Maestro 6-Channel. I posted all the code and how it was to function in the Projects forum. Good luck. Here is the test I recorded. The switch was a small piece of metal glued to my forefinger and one on the thumb of my glove. I used RCA male and female jacks for easy connecting when I put the suit on.
Testing
facebook.com/photo.php?v=10 … 2570949749

Completed


#6

Sorry to dig up an old thread, but instead of starting a new one I thought I would revive this one…
Anyone perchance have the wiring diagram of how he hooked up the switches?
I’m doing something similar with 4 servos (opening 4 doors), each 2 doors get 1 button. Push to open then push to close again.

So a schematic or fzz file, anything would be appreciated.


#7

Hello.

Information about connecting switches to the Maestro can be found in the “Button or switch” heading of the “Attaching Servos and Peripherals” section of the Maestro user’s guide. Please note that in order to use a switch or button with the Maestro, the channel it is connected to must be configured as an input, which you can do from the “Channel Settings” tab of the Maestro Control Center. If you have any questions about connecting your switches after looking through the section of the guide linked to above, please let me know, and I would be glad to help.

Brandon


#8

Well I made some progress. But nothing happens on button push.

goto main_loop    # Run the main loop when the script starts (see below).
 
# This subroutine returns 1 if the button is pressed, 0 otherwise.
# To convert the input value (0-1023) to a digital value (0 or 1) representing
# the state of the button, we make a comparison to an arbitrary threshold (500).
# This subroutine puts a logical value of 1 or a 0 on the stack, depending
# on whether the button is pressed or not.
sub button
  0 get_position 500 less_than
  return
 
# This subroutine uses the BUTTON subroutine above to wait for a button press,
# including a small delay to eliminate noise or bounces on the input.
sub wait_for_button_press
  wait_for_button_open_10ms
  wait_for_button_closed_10ms
  return
 
# Wait for the button to be NOT pressed for at least 10 ms.
sub wait_for_button_open_10ms
  get_ms # put the current time on the stack
  begin
    # reset the time on the stack if it is pressed
    button
    if
      drop get_ms
    else
      get_ms over minus 10 greater_than
      if drop return endif
    endif
  repeat
 
# Wait for the button to be pressed for at least 10 ms.
sub wait_for_button_closed_10ms
  get_ms
  begin
    # reset the time on the stack if it is not pressed
    button
    if
      get_ms over minus 10 greater_than
      if drop return endif
    else
      drop get_ms
    endif
  repeat`

# Uses WAIT_FOR_BUTTON_PRESS to allow a user to step through
# a sequence of positions on servo 1.
main_loop:
begin
  4000 frame
  5000 frame
  6000 frame
  7000 frame
  8000 frame
repeat
 
sub frame
  wait_for_button_press
  1 servo
  return

Noting happens.


#9

Ogh nevermind, I’m a dolt. Forgot to plug in power for the servo lol

This really is easy thanks to your instructions. I’m just making silly mistakes.

Thank you guys.


#10

I am glad you were able to figure out what your problem was and get it working. Thank you for letting us know.

Brandon