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:
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).
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):
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?