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

Pololu Forum

Mico Maestro push button servo operation help

I need help with the script on my Micro Maestro, I need it to make a servo center when the system is powered up and then move to a pre-set position when a button is pushed and move back to center right after the button is released.
Here is my script, it does not center the servo on power up and there is a delay when releasing the button.
Any help would be appreciated.
Thank you.

 # this loop will listen for button presses.  When a button
# is pressed it runs the corresponding sequence.
begin
  button_a if sequence_a endif
repeat
 
# These subroutines each return 1 if the corresponding
# button is pressed, and return 0 otherwise.
# Currently button_a is assigned to channel 0, 
# button_b is assigned to channel 1, and
# button_c is assigned to channel 2.
# These channels must be configured as Inputs in the
# Channel Settings tab.
sub button_a
  0 get_position 500 less_than
  return
 

# These subroutines each perform an arbitrary sequence
# of servo movements.  You should change these to fit
# your application.
sub sequence_a
  8000 1 servo 1000 delay
1600 1 servo 3000
  return

Hello.

There are a couple things stopping the behavior you want from happening. The first is that the script will only do something if the button is pressed, so it will not move the servo on power up. The second is that your sequence has both of your servo commands in it, so you cannot call one without the other. Also, it has a delay, which it sounds like you do not want.

Since the behavior you want is only involving 1 servo and 1 position (e.g. not a sequence), it would probably be simpler to not use a subroutine to handle setting the servo position

For example, your main BEGIN/REPEAT loop could look like this:

begin
    button_a if 1600 1 servo              #if button_a is pushed, move servo 1 to one side
    else 8000 1 servo endif	#otherwise, move servo 1 to center
repeat

Note that it is generally good practice to do a little button debouncing, which that script currently does not handle. One simple way would be to add a small delay, but a more elegant solution would be to use our subroutines from the “Using a button or switch to control servos” example script in the “Example Scripts” section of the Maestro User’s Guide.

Brandon

Awesome, thank you, I will give this a try.

Hi Bardon,
Thank you for the help.
The servo is not centering on power up and after 10 button pushes the red light comes on and it stops working.

I suspect you might have made a mistake modifying your script. Could you post your settings file here so I can try it? You can save your settings file by selecting the “Save settings file…” option within the “File” drop-down menu in the Maestro Control Center.

Brandon

It is saying “Did not understand Button A”.

Hi Brandon,
It is working now, thank you very much.
Gary

1 Like