Micro Maestro Scripting Basics Question

I’m trying to write a script for my micro maestro with very little programming knowledge. Right now I simply want to know how to use the “and” function. Basically I want:

If servo 2 is less than 6364 and greater than 5568 then do something. Here’s the code I’ve tried:

begin
main_loop:
# Check if in neutral zone and if so go back to main loop
2 get_position
6364 less_than
5568 greater_than
logical_and
if
  goto main_loop
endif
repeat

However every time I try to apply this script I get the 0x0040 error code of Stack overflow/underflow. Can anyone point me in the right direction?

Hello.

It looks like you are really close to having it working correctly. The main thing is that the value you are reading from channel 2 with 2 get_position is being consumed (i.e. used and taken off the stack) when you do the less_than comparison.

To fix it, you can duplicate the measured value by putting a dupcommand after 2 get_position, then, to make sure the greater_than comparison gets the correct values, you will need to add a swap command just before 5568 greater_than. For example:

2 get_position
dup
6364 less_than
swap
5568 greater_than
logical_and
if
  goto main_loop
endif

By the way, if you aren’t already using the “Step Script” button to troubleshoot by stepping through the script one step at a time, I highly recommend using it. It is very helpful to be able to monitor the values on the stack (to the right of the script) when diagnosing problems.

Brandon

Brandon,

Thank you! Thank you! Thank you!

That was exactly what I needed and now my servo is doing exactly what we need!
Really appreciate the help. Have a great day!

1 Like