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

Pololu Forum

Mini maestro 12 / use button to click through sequences?

Hi there.

i want to play a set of sequence several times using one button

1: 3 servos in a starting position / not moving
button press
2: servos are doing a programmed sequence and stop at programmed point
button press
3: going on with a sequence ending in the starting position

Right now i have the following script:

begin

  6000 2 servo # Ausgangsposition
  moving_wait
  6300 1 servo
  moving_wait
  4000 0 servo 
  moving_wait

  5 get_position     # get the value from button connected to pin 5
  200 less_than   # test if it is pressed
  if  

  200 delay
  8000 0 servo 
  moving_wait
  2000 delay

  7500 1 servo # knopfdruck vor
  moving_wait
  30 delay  
  6380 1 servo
  moving_wait
  1000 delay

  8000 2 servo 
  moving_wait
  1000 delay

  4500 2 servo 
  moving_wait
  1000 delay

  6000 2 servo 
  moving_wait
  800 delay

  4500 2 servo 
  moving_wait
  1000 delay


  7500 1 servo # knopfdruck vor 2
  moving_wait
  20 delay  
  6380 1 servo
  moving_wait
  4000 delay
  
  6000 2 servo 
  moving_wait
  1000 delay

  4000 1 servo # knopfdruck zurĂĽck
  moving_wait
  130 delay  
  6380 1 servo
  moving_wait
  500 delay

  4000 0 servo 
  moving_wait  
   
                              
   begin 5 get_position 200 greater_than while  #  then wait until the button is released
   repeat
  endif

       
repeat
 
sub moving_wait
  begin
    get_moving_state
  while
    # wait until it is no longer moving
  repeat
  return

Hello.

It looks like the first time you check the button, your code is just doing it once and the code following it is all inside the if statement, so it will only run if the button is pressed when the script happens to check for it (instead of waiting for it to be pressed before moving on). Since it sounds like each time you press the button, you want the code to wait until it is pressed to continue, I recommend using the method shown in the wait_for_button_press subroutine from our “Using a button or switch to control servos” example script. You can find that example in the “Example Scripts” section of the Maestro user’s guide.

If you have problems after integrating that into your script, could you post an updated version of your script?

Brandon

Hello Brandon,
thank you for you quick reply.

Yes theoreticaly i need the “wait for button press” script, but how to play sequences instead of frames ?

Right now the button starts only one sequence, without any stops.

To clarify, you can copy the button press subroutines from that example into your script, then call the wait_for_button_press subroutine where ever you want in your script. You do not need to use the entire example script. The structure of your script would then look something like this:

begin

  #send servos to starting positions

    wait_for_button_press

  #start your sequence

    wait_for_button_press

  #finish your sequence

repeat

#define subroutines

Unfortunately, it is hard to give any more specific advice than that, since I cannot tell from your original script where you want the sequence to wait for a button press. If you are still having problems, can you be more specific about what you want the sequence to do compared to what it is doing when you run it now? Also, can you post an updated version of your script?

Brandon

Hey Brandon,

yes ! Perfect ! That is the way i need it. Needed a little hint =)

Thank you !

Thats the script:

5 0 acceleration
50 0 speed
8 1 acceleration
50 1 speed
3 2 acceleration
20 2 speed


goto main_loop   

sub button
  5 get_position 500 less_than
  return
 
sub wait_for_button_press
  wait_for_button_open_10ms
  wait_for_button_closed_10ms
  return
 
sub wait_for_button_open_10ms
  get_ms 
  begin
    
    button
    if
      drop get_ms
    else
      get_ms over minus 10 greater_than
      if drop return endif
    endif
  repeat
 
sub wait_for_button_closed_10ms
  get_ms
  begin
    
    button
    if
      get_ms over minus 10 greater_than
      if drop return endif
    else
      drop get_ms
    endif
  repeat
 
main_loop:
begin

  6000 2 servo 
  moving_wait
  6300 1 servo
  moving_wait
  4000 0 servo 
  moving_wait

wait_for_button_press

  200 delay
  8000 0 servo 
  moving_wait
  2000 delay

  7500 1 servo 
  moving_wait
  30 delay  
  6380 1 servo
  moving_wait
  1000 delay

  8000 2 servo 
  moving_wait
  1000 delay

  4000 2 servo 
  moving_wait
  1000 delay

  6000 2 servo 
  moving_wait
  800 delay

  4000 2 servo 
  moving_wait
  1000 delay


  7500 1 servo   
  moving_wait
  20 delay  
  6380 1 servo
  moving_wait

wait_for_button_press
  
  6000 2 servo 
  moving_wait
  1000 delay

  4000 1 servo 
  moving_wait
  130 delay  
  6380 1 servo
  moving_wait
  500 delay

  4000 0 servo 
  moving_wait  

repeat
 
 sub moving_wait
  begin
    get_moving_state
  while
    
  repeat
  return
1 Like