As basic script as it gets

Hi Everyone, I have what is a basic question but after reading countless forums I’m not quite sure why I am still having this problem.

I am trying to do a basic setup in my robot using a 6 channel maestro which is connected to an arduino. But honestly the arduino is not even the problem at this time. I have 6 servos connected and I am just trying to create a single sequence that moves 2 servos a couple times. Then I want to output that sequence as a script, upload it to the maestro and run it. In the long run, I will be using restart script on the arduino to trigger this which is important to keep in mind.

In either case, I can get the sequence recorded and when I click play sequence on the sequence tab, it plays nicely, so all is good there. Then I click Copy all sequences to script and I can see it copies over. Now on the script tab, I click Apply settings and it uploads. I then try to test it, by clicking on Run script on the same script tab and it attempts to run through, but then fails with underflow/overflow error. I’ve read it has to do with extra data on the stack and all that, but if my sequence is fine, I’m not quite sure why the script doesnt just work?

I am only trying to get these 2 servos working as of now, but once this does work, I will expand to the others and so on. Ultimately I will have probably 6 sequences. I dont want the script to loop continuously since again I am using restart script in Arduino. I’m apparently missing something here, so any help is greatly appreciated.
Here is the super simple script thus far:


### Sequence subroutines: ###

# Sequence 0
sub Sequence_0
  500 0 0 6257 4646 0 0 frame_0..5 # Frame 0
  500 2960 frame_3 # Frame 1
  500 3992 frame_2 # Frame 2
  return

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

sub frame_3
  3 servo
  delay
  return

sub frame_2
  2 servo
  delay
  return

When you use the “Copy All Sequences To Script” button, the code that is generated puts each sequence into a subroutine. The intention is that you can then write your own script and call the sequence subroutines however you want throughout it. If you try to run the script as-is without adding any extra code, it will error out when it gets to the return command since there is nowhere for it to return to. Please note that the same thing will happen if you try to use the “Restart Script at Subroutine” command from your Arduino. If you only want the sequence to play once and stop, you can add a QUIT command before the RETURN in your Sequence_0 subroutine.

Doing that should be enough to fix the problem you’re having right now, but if you expand to using more than once sequence later and want to test them by running the script first, you can just call the subroutine you want to test at the start of your script (before the generated subroutines).

Brandon

So I added the quit prior to the return and while from my Arduino program I can get sequence 0 to trigger, the other 3 sequences I created wont. Its almost like the restart script only picks up the very first sequence.

Here is my updated script from the Pololu Control center as of now (I have 4 sequences in total):


### Sequence subroutines: ###

# Sequence 0
sub Sequence_0
  500 0 0 4281 3968 0 0 
  0 0 0 0 0 0 frame_0..11 # Frame 0
  500 6453 frame_3 # Frame 1
  500 5064 frame_2 # Frame 2
  500 3968 frame_3 # Frame 3
  500 6081 frame_2 # Frame 4
  500 3968 5298 frame_2_3 # Frame 5
  500 6414 frame_2 # Frame 6
  500 5201 3968 frame_2_3 # Frame 7
  500 6277 frame_3 # Frame 8
  500 6258 5083 frame_2_3 # Frame 9
  500 4790 frame_2 # Frame 10
  quit
  return
# Sequence 1
sub Sequence_1
  500 4868 3968 0 0 0 0 
  0 0 0 0 0 0 frame_0..11 # Frame 0
  500 3968 4026 frame_0_1 # Frame 1
  500 6003 frame_1 # Frame 2
  500 7080 frame_0 # Frame 3
  500 4202 5827 frame_0_1 # Frame 4
  500 4457 frame_1 # Frame 5
  500 4653 frame_0 # Frame 6
  quit
  return
# Sequence 2
sub Sequence_2
  5000 0 0 0 0 8000 0 
  0 0 0 0 0 0 frame_0..11 # Frame 0
  500 3986 frame_4 # Frame 1
  quit
  return
# Sequence 3
sub Sequence_3
  5000 0 0 0 0 0 8000 
  0 0 0 0 0 0 frame_0..11 # Frame 0
  500 2432 frame_5 # Frame 1
  quit
  return

sub frame_0..11
  11 servo
  10 servo
  9 servo
  8 servo
  7 servo
  6 servo
  5 servo
  4 servo
  3 servo
  2 servo
  1 servo
  0 servo
  delay
  return

sub frame_3
  3 servo
  delay
  return

sub frame_2
  2 servo
  delay
  return

sub frame_2_3
  3 servo
  2 servo
  delay
  return

sub frame_0_1
  1 servo
  0 servo
  delay
  return

sub frame_1
  1 servo
  delay
  return

sub frame_0
  0 servo
  delay
  return

sub frame_4
  4 servo
  delay
  return

sub frame_5
  5 servo
  delay
  return

And here is the bits of the Arduino program that really matter:

// Additions for the Pololu Maestro
#include <PololuMaestro.h>
#include <SoftwareSerial.h>
SoftwareSerial maestroSerial (10, 11); // TX pin is 11
MiniMaestro maestrosserial(maestroSerial); 

void setup() {
  maestroSerial.begin(9600);  // software serial start for Maestro board

void loop() {
if (Xbox.getButtonClick(L1, 0)) {
    if (Xbox.getButtonPress(UP, 0)) {
      maestrosserial.restartScript(0);
    }
  }
  if (Xbox.getButtonClick(L1, 0)) {
    if (Xbox.getButtonPress(DOWN, 0)) {
      maestrosserial.restartScript(1);
    }
  }
  if (Xbox.getButtonClick(L1, 0)) {
    if (Xbox.getButtonPress(LEFT, 0)) {
      maestrosserial.restartScript(2);
    }
  }
  if (Xbox.getButtonClick(L1, 0)) {
    if (Xbox.getButtonPress(RIGHT, 0)) {
      maestrosserial.restartScript(3);
    }
  }

As I said, the first sequence (sequence 0) works when triggering the correct above button combo. Although sequences 1, 2 and 3 do not trigger for some reason. My guess is that it has to do with the way the Script is created in the Pololu control center. Really appreciate the help with this!

Your Maestro script looks okay to me, and I was able to load it on a Maestro here and use an Arduino to call each of your 4 subroutine sequences without issue, so I suspect the problem is with your Arduino code or serial communication.

You might try simplifying your Arduino code until you find what is causing the issue, or you could add some print outs to the Serial Monitor when the sketch should be sending data to the Maestro to make sure it is successfully getting to that part of your code. If you continue having problems could you post your complete simplified code and a description of what it is doing when you run it?

Brandon