Choreography of servos

Hello. I’m looking for script for my Pololu Maestro 24 ch to drive my servos like in this video -one rotates after another - https://www.youtube.com/watch?v=X0apeZULiKc . What command do I need to use for that application ? Any idea or ready script ? I’d be glad for any help.

Hello.

Did you read through the “Command Reference” and “Example Scripts” sections in the Maestro user’s guide that I pointed you to when you emailed us? Have you tried writing your own script as I suggested? If so, can you post it here and describe what it does incorrectly?

Brandon

Hi Brandon. Thanks you for your reply. I read “Example Scripts” and tried some scripts just to learn this language.
Today I found one script with I want to work with. It’s look like that :

0 begin dup 15001 less_than while       # We loop from time=0 to time=15000, where "time" is a variable on the top of the stack.
  dup 2 divide 0 servo                 # Servo0 target = Time/2.
  dup 1 servo     
  dup 2 servo
  dup 3 servo 
 dup 4 servo
                                             # Servo1 target = Time.
  10 plus  80 delay                  # Increment "time" and delay.  This means that "time" has units of 8 ms.

repeat

I think this is the good way for a script that I’m looking for.
I need only find a way to delay between servos rotation

If you have any suggestion , please write a comment

Thank you for posting what you have so far. Have you tried running that script? It does not look like it will do the same kind of motion as what is shown in the video you linked to. Also, it looks like for a large majority of that script, it is trying to send the servos to positions outside of the allowed range (and well outside of the standard 1-2ms pulse width range).

If you want to move the servos one at a time, you can send the servo a target value then add a DELAY command before sending the next servo the target value. For example, this script will alternate between moving the servos on channel 0 and 1 to different positions, with 1 second delays between each movement.

begin
  4000 0 servo    #set servo 0 to 1ms (4000 quarter microseconds)
  1000 delay       #delay for 1 seconds (1000ms)
  4000 1 servo  
  1000 delay
  
  8000 0 servo     #set servo 0 to 2ms (8000 quarter microseconds)
  1000 delay
  8000 1 servo
  1000 delay
repeat

Alternatively, if you have speed or acceleration limits set for your servo channels, you can use the GET_MOVING_STATE command to wait until it has reached its target position before continuing. You can set a speed or acceleration limit for each servo channel in the “Channel Settings” tab of the Maestro Control Center. Here is the same script rewritten to use the “moving_wait” subrouine from our “Making smooth sequences with GET_MOVING_STATE” example:

begin
  4000 0 servo
  moving_wait
  4000 1 servo
  moving_wait
  
  8000 0 servo
  moving_wait
  8000 1 servo
  moving_wait
repeat

sub moving_wait    #the script will stay in this subroutine until all servos have reached their target 
  begin
    get_moving_state  #note this command only works for servos with speed or acceleration limits
  while
    # wait until it is no longer moving
  repeat
return

Note that both of these scripts can be compressed to make a much more efficient script (see the “Compressing the sequence” heading in the “Example Scripts” section of the Maestro User’s Guide for more information about this), but they are probably easier to understand when written out.

Brandon

Hello Brandon
Thank you so much to show me a way to work with scripts . It’s geting easier.
I modyfied your script and I almost done, it is what I want but I now I’m looking for a command to return all servos to position from the beginning. Any suggestion ? I will also try to deal with it.
And this is my script :

 begin
  4000 0 servo    #set servo 0 to 1ms (4000 quarter microseconds)
  1000 delay       #delay for 1 seconds (1000ms)
  4000 1 servo  
  1000 delay

  4000 2 servo  
  1000 delay

  4000 3 servo  
  1000 delay

  4000 4 servo  
  1000 delay

  4000 5 servo  
  1000 delay

  4000 6 servo  
  1000 delay

  4000 7 servo    #set servo 0 to 1ms (4000 quarter microseconds)
  1000 delay       #delay for 1 seconds (1000ms)
  4000 8 servo  
  1000 delay

  4000 9 servo  
  1000 delay

  4000 10 servo  
  1000 delay

  4000 11 servo  
  1000 delay

  4000 12 servo  
  1000 delay

  4000 13 servo  
  1000 delay

repeat

There are a couple of ways to do something like that. If you are just setting a “home” position (i.e. the position you want the servos to start in as soon as the Maestro is powered on), you can set the “On startup or error” setting for each channel in the “Channel Settings” tab to “Go to”, then specify the target value. Alternatively, you could have a subroutine that sends all of the servos to a specific position, which you could call at any point in your script. For example:

sub frame
  4000 0 servo
  4000 1 servo
  4000 2 servo    #and so on for each of the servos
return

Please note that if you want to set many servos to the same position, this can be compressed by looping through the servo channels since all of the other commands are the same each time. This would look something like:

sub frame
14     #the number of servos (e.g. 14 will set servo channels 0-13)
  begin
    dup while
      1 minus dup 4000 swap servo
  repeat
return

Also, if you only want to send them to this starting position one time (e.g. as soon as the script starts and not each time through the loop) you can call this subroutine just before the BEGIN command in your main loop. You might also choose to put a DELAY command after it to allow time for all of the servos to get to their starting positions before continuing on to the rest of your script.

Brandon

Hello Brandon. I really appreciate your help. I tried to update my script and it works with my few servos perfect. I’ve noticed only one strange behaviour. When I use about 14 servos something is getting stuck after few loops It looks that all servos working at the same time and I see on my lab power supply that it takes 2 amper !. So I need to plug off my Maestro. Why does it happend ? This is my code :

begin
  4000 0 servo    
  100 delay       
  4000 1 servo  
  100 delay
  4000 2 servo  
  100 delay
  4000 3 servo  
  100 delay
  4000 4 servo  
  100 delay
  4000 5 servo  
  100 delay

  4000 6 servo  
  100 delay
  4000 7 servo  
  100 delay
  4000 8 servo  
  100 delay
  4000 9 servo  
  100 delay
  4000 10 servo  
  100 delay
  4000 7 servo  
  100 delay

sub frame
  8000 0 servo
100 delay
  8000 1 servo
100 delay
  8000 2 servo 
100 delay
  8000 3 servo
100 delay
  8000 4 servo
100 delay
  8000 5 servo
100 delay
  8000 6 servo
100 delay
  8000 7 servo
100 delay
  8000 8 servo 
100 delay  


repeat

It looks like you might not understand how subroutines work within a Maestro script. The subroutine should be defined outside of your main BEGIN/REPEAT loop, and you can call it from within the loop by using the name of the subroutine. For example, the script below will call the subroutine at the beginning of each loop through the script:

begin
  
  frame  #calling the subroutine will run the code within the subroutine declaration below
	#the script will return to here after it finishes the code in the subroutine

  8000 0 servo
  8000 1 servo
  8000 2 servo

  1000 delay

repeat

sub frame    #the code within your subroutine should go below here
    4000 0 servo
    4000 1 servo
    4000 2 servo    #and so on for each of the servos
    1000 delay
return  #returns to the main begin/repeat loop above

Typically, subroutines can be used to call a series of commands that will need to be called more than once. This allows you to simply call the subroutine instead of copying all of that code over again, which can be more convenient if you need to make changes and also saves on space.

As far as the strange behavior you are describing, it is not clear to me what you mean when you say it gets stuck and looks like all the servos are working at the same time. The 2A current draw you are seeing sounds reasonable for powering 14 servos (especially if they are micro servos). We typically recommend budgeting around 1A per standard servo. If your Maestro script stops running and you need to power cycle to get it to start working again, you might be triggering an error. Does it stay connected to the Maestro Control Center when this happens? If so, can you check the “Errors” tab to see if anything is being displayed?

By the way, it looks like you are sending a target position of 4000 to servo 7 twice (once in order with the other servo channels and once after setting channel 10).

Brandon