Maestro Errors

Hello Everyone!
I have a Micro Maestro 6 channel servo controller. I would like to use it as the main brain in a small robot. it would be a light/line follower, obstacle avoider depending on what sensor is high. I was working with the obstacle avoider part but i keep having stack overflow/underflow problems. Here is what i have:

0000:                      -- begin
0000: 81                   --  Forward
0001: 2E82                 -- get_position Front_sensor
0003: 07120082280239       -- if Front_sensor less_than 57  
000A: 800B0B0B0B           -- backward drop drop drop drop    
000F: 06130081             -- else Forward
0013: 822902FF             -- endif Front_sensor greater_than 255
0017: 060000               -- repeat
001A:                      -- ### Sequence subroutines: ###
001A:                      -- # Backward
001A:                      -- sub Backward
001A: 0308F401DB130B1BFF0385 --   500 5083 6923 1023 frame_0..2 # Backwards 0
0025: 01F40108             --   500 delay
0029: 05                   --   return
002A:                      -- sub Forward
002A: 0308F40157191316FF0385 --   500 6487 5651 1023 frame_0..2 # Frame 0
0035: 01F40108             --   500 delay # Frame 1
0039: 05                   --   return
003A:                      -- sub Front_Sensor
003A: 0308F40100000000000085 --   500 0 0 0 frame_0..2 # open space
0045: 01F40108             --   500 delay # object detected
0049: 05                   --   return
004A:                      -- # Obstacle Detect
004A:                      -- sub Obstacle_Detect
004A: 0308F401941B6613800F85 --   500 7060 4966 3968 frame_0..2 # Frame 0
0055: 0306F4010000000086   --   500 0 0 frame_0_1 # obstacle detected
005E: 0306F401941B661386   --   500 7060 4966 frame_0_1 # Frame 2
0067: 05                   --   return
0068:                      -- sub Sensors_Bottom
0068: 0308F40100000000000085 --   500 0 0 0 frame_0..2 # Frame 0
0073: 01F40108             --   500 delay # Frame 1
0077: 01F40108             --   500 delay # Frame 2
007B: 05                   --   return
007C:                      -- sub frame_0..2
007C: 02022A               --   2 servo
007F: 02012A               --   1 servo
0082: 02002A               --   0 servo
0085: 05                   --   return
0086:                      -- 
0086:                      -- sub frame_0_1
0086: 02012A               --   1 servo
0089: 02002A               --   0 servo
008C: 05                   --   return
008D:                      -- 

Subroutines:
Hex Decimal Address Name
00  000     001A    BACKWARD
01  001     002A    FORWARD
02  002     003A    FRONT_SENSOR
03  003     004A    OBSTACLE_DETECT
04  004     0068    SENSORS_BOTTOM
05  005     007C    FRAME_0..2
06  006     0086    FRAME_0_1

Hello.

It looks like you are putting 4 values on the stack each time you call “frame_0 . . 2”, but it only uses 3 arguments. This is going to cause an overflow. The first number (500) you place on the stack each time you call your frame looks like it might be intended as a delay, but there is no delay implemented in your frame. This is also occurring when you call “frame_0_1”.

I am a little confused on what you are trying to do with the get_position command and “Front_sensor” subroutine. What is happening in your script right now, is that get_position is being called with no arguments (so it is just using whatever is on the stack before it is called), followed by your “Front_sensor” subroutine.

I see you wrote “if Front_sensor less_than 57”. There are lots of things wrong with this. First of all, your subroutine named Front_Sensor contains no code that actually reads a sensor. All that subroutine does currently is turn off the pulses to three servos, delay, and add a 500 to the stack (which is probably a mistake). Secondly, the overall structure of your if statement looks like it came from a different language. In Maestro scripting, you need to put a boolean on the stack before calling ‘if’. A proper version of that line would look something like: “read_front_sensor 57 less_than if”. It looks like you are also trying to compare Front_sensor to 255 (which again is not done in a valid way), but I do not see what this comparison supposed to be used for. Is there a reason you are checking it? Also, can you explain why you are calling “drop” four times after “backward” subroutine?

I would recommend re-reading the “The Maestro Scripting Langauge” section of the Maestro User’s Guide to make sure you understand the stack and the provided example scripts. Also, you can use the single-stepping abillity of the Maestro Control Center to step through your script one step at a time: this will help you understand what your script is doing to the stack and help you pinpoint any other underflow or overflow issues.

-Brandon

Thank you for your time and analysis! I will have to reread those sections! As you can see, I don’t grasp the concept at all.
As for the operation, I was intending to use an IR sensor to detect when the robot is nearing an object. I am more familiar with an Arduino set up but since I had this unit and its small size I figured I might as well use it(or so was my thought).
The Front sensor comparison was to establish a trigger point when the servos would activate. the drop function served no real function here.