Calling function during script triggers error 0x0080

Hi team, I’m testing some simple arduino mega code to call scripts on the miastro 24. I can trigger the script no problem but when I call any function like getScriptStatus or getMovingState or even getError during the script the board goes into error state and gets a stack overflow/underflow error 0x0800.
Please help, is there a problem in my pololu script? or arduino code? Thanks for any help!!
Here is the code starting with pololu:

### Sequence subroutines: ###

#master sequence test script 2 servos
begin
	#Sequence_0
	#Sequence_1
repeat

# Sequence 0
sub Sequence_0
  500 6000 6000 0 0 0 0 
  0 0 0 0 0 0 
  0 0 0 0 0 0 
  0 0 0 0 0 0 frame_0..23 # Frame 0
  500 8000 frame_0 # Frame 1
  500 3968 frame_1 # Frame 2
  500 5944 frame_1 # Frame 3
  500 5846 frame_0 # Frame 4
  500 3968 7921 frame_0_1 # Frame 5
  return
# Sequence 1
sub Sequence_1
  500 3968 7921 0 0 0 0 
  0 0 0 0 0 0 
  0 0 0 0 0 0 
  0 0 0 0 0 0 frame_0..23 # Frame 0
  500 5925 frame_1 # Frame 1
  500 5905 frame_0 # Frame 2
  500 3968 frame_0 # Frame 3
  500 6042 frame_0 # Frame 4
  return
# Sequence 2
sub Sequence_2
  500 8000 3968 0 0 0 0 
  0 0 0 0 0 0 
  0 0 0 0 0 0 
  0 0 0 0 0 0 frame_0..23 # Frame 0
  500 8000 frame_1 # Frame 1
  500 7197 frame_1 # Frame 2
  500 7902 frame_1 # Frame 3
  500 3968 frame_0 # Frame 4
  500 5494 frame_0 # Frame 5
  500 6062 frame_1 # Frame 6
  return

sub frame_0..23
  23 servo
  22 servo
  21 servo
  20 servo
  19 servo
  18 servo
  17 servo
  16 servo
  15 servo
  14 servo
  13 servo
  12 servo
  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_0
  0 servo
  delay
  return

sub frame_1
  1 servo
  delay
  return

sub frame_0_1
  1 servo
  0 servo
  delay
  return

→ Begin Arduino Code

#include <PololuMaestro.h>
#include <SoftwareSerial.h>
SoftwareSerial maestroSerial(19, 18);

MiniMaestro maestro(maestroSerial);

void setup()
{
  maestroSerial.begin(9600);
  Serial.begin(115200);
  Serial.println("Test Maestro");
  maestro.goHome(); 
  Serial.println("went home");
}

void loop()
{
  uint8_t scriptstatus = 0;
  uint8_t servostatus = 0;
  uint8_t errorstate = 0;
  
  Serial.println("start script 0");
  maestro.restartScript(0);
  
  //servostatus = maestro.getMovingState();
  //Serial.print("Servo Status");Serial.println(servostatus);
  scriptstatus = maestro.getScriptStatus();
  errorstate = maestro.getErrors();
   
  
  Serial.print("script Status");Serial.println(scriptstatus);
  Serial.print("error");Serial.println(errorstate);
  delay(4000);

  // Stop the running script.
  maestro.stopScript();
  Serial.println("Stop");

}

I suspect the error is happening because the subroutines you are trying to start from end with RETURN command (and not actually from calling getScriptStatus() or the other functions you mentioned). When you use the Restart Script at Subroutine command (i.e. restartScript() from our Arduino library), the specified script cannot have a RETURN because the script was restarted and does not have any understanding of where to return to.

If you want it to run the subroutine once and stop, you can use a QUIT command instead of RETURN. If you want it to loop until it is told to do something different, you can remove the RETURN command and put the subroutine inside of a BEGIN/REPEAT loop.

If you continue to have trouble after making those adjustments, you can post your updated code and description of the behavior and I would be glad to help further.

Brandon

Thank you very much Brandon! I’ll give this a shot today when I get a minute. This sounds exactly like what I need. I’ll reply with my results.

1 Like

Yep that did it. setting the end of the subroutine to quit allowed me to make the calls. I should do a bit more testing as it seemed I needed to call a subroutine as a seed before calling getScriptStatus to work. but it could have been something else. also, the Mini script I was using was adapted from the one provided in the examples which uses return at the end of the subs but that example didn’t call getScriptStatus or other status functions, only restart and stop. Thanks for the help!

1 Like