Servo sequence doesn't work

Hey friends, greetings from Germany. I have a small problem with Pololu.
I’m currently building the animated head of the B1 and have decided to use the Pololu controller. I don’t want much. So I’ve now created 4 scenes.
There are 2 or 3 movements in each scene. At the end of each sequence, all servos return to their starting position. If I now play the scenes individually, everything works.
If I copy all the scenes into the script and start it, the first scene runs and then it stops because of an error. And I don’t know why. Getting that right would be my first step.
And at the end, a switch that plays a sequence every time it’s pressed or something like a timer would be great. So switch it on and the sequences are played randomly, one every 3-5 minutes.

<!--Pololu Maestro servo controller settings file, http://www.pololu.com/catalog/product/1350-->
<UscSettings version="1">
  <NeverSuspend>false</NeverSuspend>
  <SerialMode>UART_FIXED_BAUD_RATE</SerialMode>
  <FixedBaudRate>9600</FixedBaudRate>
  <SerialTimeout>0</SerialTimeout>
  <EnableCrc>false</EnableCrc>
  <SerialDeviceNumber>12</SerialDeviceNumber>
  <SerialMiniSscOffset>0</SerialMiniSscOffset>
  <Channels ServosAvailable="6" ServoPeriod="156">
    <!--Period = 19,968 ms-->
    <!--Channel 0-->
    <Channel name="seite" mode="Servo" min="3200" max="7936" homemode="Off" home="3200" speed="30" acceleration="0" neutral="6000" range="1905" />
    <!--Channel 1-->
    <Channel name="hoch" mode="Servo" min="3968" max="8000" homemode="Off" home="3968" speed="20" acceleration="0" neutral="6000" range="1905" />
    <!--Channel 2-->
    <Channel name="" mode="Servo" min="3968" max="8000" homemode="Off" home="3968" speed="0" acceleration="0" neutral="6000" range="1905" />
    <!--Channel 3-->
    <Channel name="" mode="Servo" min="3968" max="8000" homemode="Off" home="3968" speed="0" acceleration="0" neutral="6000" range="1905" />
    <!--Channel 4-->
    <Channel name="" mode="Servo" min="3968" max="8000" homemode="Off" home="3968" speed="0" acceleration="0" neutral="6000" range="1905" />
    <!--Channel 5-->
    <Channel name="" mode="Servo" min="3968" max="8000" homemode="Off" home="3968" speed="0" acceleration="0" neutral="6000" range="1905" />
  </Channels>
  <Sequences>
    <Sequence name="Kopf bewegen 1">
      <Frame name="Frame 0" duration="500">6000 6000 0 0 0 0</Frame>
      <Frame name="Frame 1" duration="500">6000 6000 0 0 0 0</Frame>
      <Frame name="Frame 2" duration="500">6000 8000 0 0 0 0</Frame>
      <Frame name="Frame 3" duration="500">6000 8000 0 0 0 0</Frame>
      <Frame name="Frame 4" duration="500">8000 8000 0 0 0 0</Frame>
      <Frame name="Frame 5" duration="500">8000 8000 0 0 0 0</Frame>
      <Frame name="Frame 6" duration="500">4946 8000 0 0 0 0</Frame>
      <Frame name="Frame 7" duration="500">4946 8000 0 0 0 0</Frame>
      <Frame name="Frame 8" duration="500">4946 3968 0 0 0 0</Frame>
      <Frame name="Frame 9" duration="500">4946 3968 0 0 0 0</Frame>
      <Frame name="Frame 10" duration="500">6000 6000 0 0 0 0</Frame>
    </Sequence>
    <Sequence name="Kopf bewegen 2">
      <Frame name="Frame 10" duration="500">6000 6000 0 0 0 0</Frame>
      <Frame name="Frame 0" duration="500">3968 3968 0 0 0 0</Frame>
      <Frame name="Frame 2" duration="500">8000 3968 0 0 0 0</Frame>
      <Frame name="Frame 1" duration="500">8000 3968 0 0 0 0</Frame>
      <Frame name="Frame 3" duration="500">8000 3968 0 0 0 0</Frame>
      <Frame name="Frame 4" duration="500">8000 3968 0 0 0 0</Frame>
      <Frame name="Frame 5" duration="500">8000 3968 0 0 0 0</Frame>
      <Frame name="Frame 6" duration="500">8000 3968 0 0 0 0</Frame>
      <Frame name="Frame 7" duration="500">8000 3968 0 0 0 0</Frame>
      <Frame name="Frame 8" duration="500">8000 3968 0 0 0 0</Frame>
      <Frame name="Frame 9" duration="500">8000 3968 0 0 0 0</Frame>
      <Frame name="Frame 11" duration="500">6000 6000 0 0 0 0</Frame>
      <Frame name="Frame 12" duration="500">6000 6000 0 0 0 0</Frame>
    </Sequence>
    <Sequence name="Kopf bewegen 3">
      <Frame name="Frame 10" duration="500">6000 6000 0 0 0 0</Frame>
      <Frame name="Frame 0" duration="500">8000 3968 0 0 0 0</Frame>
      <Frame name="Frame 1" duration="500">8000 6081 0 0 0 0</Frame>
      <Frame name="Frame 2" duration="500">3968 6081 0 0 0 0</Frame>
      <Frame name="Frame 3" duration="500">3968 6081 0 0 0 0</Frame>
      <Frame name="Frame 4" duration="500">3968 6081 0 0 0 0</Frame>
      <Frame name="Frame 5" duration="500">6023 6081 0 0 0 0</Frame>
      <Frame name="Frame 6" duration="500">6023 6081 0 0 0 0</Frame>
      <Frame name="Frame 7" duration="500">6023 6081 0 0 0 0</Frame>
      <Frame name="Frame 8" duration="500">6000 6000 0 0 0 0</Frame>
      <Frame name="Frame 9" duration="500">6000 6000 0 0 0 0</Frame>
      <Frame name="Frame 11" duration="500">6000 6000 0 0 0 0</Frame>
    </Sequence>
  </Sequences>
  <Script ScriptDone="true" />
</UscSettings>

Hello.

If you used the “Sequence” tab to make your scenes, then used the “Copy all Sequences to Script” button, the Maestro Control Center will generate a subroutine for each sequence. This is intended to make it easy to write your own script and call the subroutines when you want them to play. If you play the generated script as-is, it will start at the top and trigger an error at the end of the first subroutine since it uses a RETURN command and the script has nowhere to return to.

As an example, if you want to play your generated subroutines back-to-back in a loop with one second between each, your script would look something like this:

begin
  Kopf_bewegen_1  #call the first subroutine by name
  1000 delay  #wait 1 second
  Kopf_bewegen_2   #call the second subroutine by name
  1000 delay  #wait 1 second
  Kopf_bewegen_3   #call the third subroutine by name
  1000 delay  #wait 1 second
repeat

### Sequence subroutines: ###

#followed by the subroutines generated by your sequences

For using a button to trigger the subroutines or having them play every 3-5 minutes, I recommend looking through the “Example Scripts” section of the Maestro user’s guide, specifically the “Using a button or switch to control servos” and “Using multiple buttons or switches to control servos” examples and the “Long delays” example.

If you try writing a script that does one of those things and have problems, you can post a copy of your script and a description of what it is doing wrong and I would be glad to help troubleshoot it.

Brandon

1 Like

Should I write these lines into the script?

Hello, I finally managed it and the script with the 2 routines is running.
Now there is 1 question left:

  1. What do I have to enter so that there is a 3 minute break between the two SUBs?
### Sequence subroutines: ###

# Kopf bewegen 1
begin
sub Kopf_bewegen_1
  500 5536 5504 0 0 0 0 frame_0..5 # Frame 0
  500 7232 frame_0 # Frame 1
  500 delay # Frame 2
  500 delay # Frame 3
  500 6418 frame_1 # Frame 4
  500 delay # Frame 5
  500 4416 4889 frame_0_1 # Frame 6
  500 delay # Frame 7
  500 5536 frame_0 # Frame 8
  500 delay # Frame 9
  500 5504 frame_1 # Frame 10
  500 delay # Frame 11
# Kopf bewegen 2
sub Kopf_bewegen_2
  500 5536 5504 0 0 0 0 frame_0..5 # Frame 0
  500 4032 frame_1 # Frame 1
  500 delay # Frame 2
  500 6853 frame_0 # Frame 3
  500 delay # Frame 4
  500 4136 frame_0 # Frame 5
  500 delay # Frame 6
  500 6518 frame_1 # Frame 7
  500 delay # Frame 8
  500 5536 frame_0 # Frame 9
  500 delay # Frame 10
  500 5504 frame_1 # Frame 11
  500 delay # Frame 12
  return
repeat

sub frame_0..5
  5 servo
  4 servo
  3 servo
  2 servo
  1 servo
  0 servo
  delay
  return

sub frame_0
  0 servo
  delay
  return

sub frame_1
  1 servo
  delay
  return

sub frame_0_1
  1 servo
  0 servo
  delay
  return

The longest delay that can be achieved by the Maestro’s DELAY command directly is approximately 32 seconds, so I recommend using the method in the Long delays example from the “Example Scripts” section of the Maestro user’s guide to delay 3 minutes between calling those subroutines.

For example, you can add the following lines of code to the top of your script (above the ### Sequence subroutines: ### lines) to get that behavior:

begin
  Kopf_bewegen_1
  3 delay_minutes
  Kopf_bewegen_2
  3 delay_minutes
repeat

# delay by a specified number of seconds, up to 65535 s
sub delay_seconds
  begin dup while      # check if the count has reached zero
    1 minus 1000 delay # subtract one and delay 1s
  repeat
  drop return          # remove the 0 from the stack and return
 
# delay by a specified number of minutes, up to 65535 min
sub delay_minutes
  begin dup while
    1 minus 60 delay_seconds # subtract one and delay 1min
  repeat
  drop return                # remove the 0 from the stack and return

Please note that this will endlessly alternate between each subroutine with a 3 minute pause between them. If you want it to stop after playing each of them once, you can add a QUIT command before REPEAT.

Brandon

Sorry, but what should I enter where? I’ve tried a lot of things, but nothing works. What command should I enter where so that it takes a 3-minute break after the first sequence?

You should be able to copy the entirety of the code from my previous post, and paste it at the top of the code from your previous post.

If it makes it easier for you, I combined them below, so you can delete everything you have in your Script tab and copy/paste this code there instead:

begin
  Kopf_bewegen_1
  3 delay_minutes
  Kopf_bewegen_2
  3 delay_minutes
repeat

# delay by a specified number of seconds, up to 65535 s
sub delay_seconds
  begin dup while      # check if the count has reached zero
    1 minus 1000 delay # subtract one and delay 1s
  repeat
  drop return          # remove the 0 from the stack and return
 
# delay by a specified number of minutes, up to 65535 min
sub delay_minutes
  begin dup while
    1 minus 60 delay_seconds # subtract one and delay 1min
  repeat
  drop return                # remove the 0 from the stack and return

### Sequence subroutines: ###

# Kopf bewegen 1
begin
sub Kopf_bewegen_1
  500 5536 5504 0 0 0 0 frame_0..5 # Frame 0
  500 7232 frame_0 # Frame 1
  500 delay # Frame 2
  500 delay # Frame 3
  500 6418 frame_1 # Frame 4
  500 delay # Frame 5
  500 4416 4889 frame_0_1 # Frame 6
  500 delay # Frame 7
  500 5536 frame_0 # Frame 8
  500 delay # Frame 9
  500 5504 frame_1 # Frame 10
  500 delay # Frame 11
# Kopf bewegen 2
sub Kopf_bewegen_2
  500 5536 5504 0 0 0 0 frame_0..5 # Frame 0
  500 4032 frame_1 # Frame 1
  500 delay # Frame 2
  500 6853 frame_0 # Frame 3
  500 delay # Frame 4
  500 4136 frame_0 # Frame 5
  500 delay # Frame 6
  500 6518 frame_1 # Frame 7
  500 delay # Frame 8
  500 5536 frame_0 # Frame 9
  500 delay # Frame 10
  500 5504 frame_1 # Frame 11
  500 delay # Frame 12
  return
repeat

sub frame_0..5
  5 servo
  4 servo
  3 servo
  2 servo
  1 servo
  0 servo
  delay
  return

sub frame_0
  0 servo
  delay
  return

sub frame_1
  1 servo
  delay
  return

sub frame_0_1
  1 servo
  0 servo
  delay
  return

If you try that and have problems with it, please post a copy of your settings file. You can save a copy of your settings file from the “File” drop-down menu of the Maestro Control Center software while the controller is connected.

Brandon

I’ve already done that and the result wasn’t quite right. The whole script runs through and then there’s a 3-minute break and then the whole script runs through again.
But I wanted there to be a 3-minute break between sequence 1 and 2.

begin
  Kopf_bewegen_1
  3 delay_minutes
  Kopf_bewegen_2
  5 delay_minutes
repeat

# delay by a specified number of seconds, up to 65535 s
sub delay_seconds
  begin dup while      # check if the count has reached zero
    1 minus 1000 delay # subtract one and delay 1s
  repeat
  drop return          # remove the 0 from the stack and return
 
# delay by a specified number of minutes, up to 65535 min
sub delay_minutes
  begin dup while
    1 minus 60 delay_seconds # subtract one and delay 1min
  repeat
  drop return                # remove the 0 from the stack and return

### Sequence subroutines: ###

# Kopf bewegen 1
begin
sub Kopf_bewegen_1
  500 5536 5504 0 0 0 0 frame_0..5 # Frame 0
  500 7232 frame_0 # Frame 1
  500 delay # Frame 2
  500 delay # Frame 3
  500 6418 frame_1 # Frame 4
  500 delay # Frame 5
  500 4416 4889 frame_0_1 # Frame 6
  500 delay # Frame 7
  500 5536 frame_0 # Frame 8
  500 delay # Frame 9
  500 5504 frame_1 # Frame 10
  500 delay # Frame 11
  # Kopf bewegen 2
sub Kopf_bewegen_2
  500 5536 5504 0 0 0 0 frame_0..5 # Frame 0
  500 4032 frame_1 # Frame 1
  500 delay # Frame 2
  500 6853 frame_0 # Frame 3
  500 delay # Frame 4
  500 4136 frame_0 # Frame 5
  500 delay # Frame 6
  500 6518 frame_1 # Frame 7
  500 delay # Frame 8
  500 5536 frame_0 # Frame 9
  500 delay # Frame 10
  500 5504 frame_1 # Frame 11
  500 delay # Frame 12
  # Kopf bewegen 3
sub Kopf_bewegen_3
  500 5536 5504 0 0 0 0 frame_0..5 # Frame 0
  500 3938 frame_0 # Frame 1
  500 delay # Frame 2
  500 delay # Frame 3
  500 delay # Frame 4
  500 delay # Frame 5
  500 7083 frame_0 # Frame 6
  500 delay # Frame 7
  500 delay # Frame 8
  500 delay # Frame 9
  500 delay # Frame 10
  500 5536 frame_0 # Frame 11
  500 delay # Frame 12
  return
repeat

sub frame_0..5
  5 servo
  4 servo
  3 servo
  2 servo
  1 servo
  0 servo
  delay
  return

sub frame_0
  0 servo
  delay
  return

sub frame_1
  1 servo
  delay
  return

sub frame_0_1
  1 servo
  0 servo
  delay
  return

And I checked the box “Run script on startup” so that it starts as soon as it gets power. But nothing happens.

It looks like somehow your subroutines had the RETURN command at the end of them removed. Could you try adding a RETURN command at the end of each of them? So, for Kopf_bewegen_1 you should add return between 500 delay # Frame 11 and # Kopf bewegen 2, and for Kopf bewegen 2 you should add return between 500 delay # Frame 12 and # Kopf bewegen 3.

Brandon