Newbie problems with code - Micro Maestro 6

Hello all!

I’m new here and I got my first MAestro 6 servo controller board yesterday. I want to solve a problem with an RC-remote, but I can’t get it to work…
I get an error in the script, but I don’t know why? Maybe someone can help me.

I want to solve a porbably easy task:

After dipping a switch on the remote, servo 0 should go to a given position slowly and back to its origin.
After that servo 1 should go even slower to a given position and back to it’s origin.
That’s all.

I want to be able to trigger this sequenze every time I push the switch. Thats all.
I already got a working sequenze by saving frames, but since I want to use the input port 2 as a trigger, I had to adapt the code and now I’m stuck.

Could somebody please look into it, what’s going wrong?



3200 6272 frame_00

begin 
2 get_position 100 less_than 
if  
frame_00
else  
frame_11  
endif 
repeat 

sub frame_00
	1 servo
	0 servo
	delay
return


sub frame_11
	50 0 speed
  	4096 0 servo
	250  delay
  	3200 0 servo
	250 delay
	25 1 speed
	3584 1 servo
	1300 delay
	6272 1 servo
	1300 delay
return

By the way:
Yes, i have the RC switch hooked up between the Maestro 6 and the receiver. The red led on the RC switch turns red when the switch is triggered on the RC transmitter, and ist blinking slowly when the switch is not triggered. So the hardware seems fine, but the error has to be somewhere in the code.

I’m getting error 0x0040, “Stack overflow/Underflow” at the end of frame_00…

Hello.

What you are trying to do is certainly possible. However, the code you posted has some mistakes. For example, when the subroutine frame_00 is called in the loop, there are no position values on the stack for the servo commands to use. There is also no delay value given for the delay command in frame_00. I recommend reading The Maestro Scripting Language section of the Maestro’s user’s guide. In particular the “Using a button or switch to control servos” example in the Example Scripts section might be helpful.

  • Grant

Sorry, I don’t quite understand the stack issue, but my english is not too good either.

I worked with the example scripts, but I’m not sure what to do now? Can somebody point me on the errors in my script?
I know it’s not funny to help clueless people, but it’s all greek to me…

You could change some of the code from the example “Using a button or switch to control servos” to move the second servo. These changes should all occur in the main_loop and sub frame. I have posted a modified version of the example code that moves two servos through a sequence of positions after a button is pressed. This should be good starting point for you to look at.

[code]goto main_loop # Run the main loop when the script starts (see below).

This subroutine returns 1 if the button is pressed, 0 otherwise.

To convert the input value (0-1023) to a digital value (0 or 1) representing

the state of the button, we make a comparison to an arbitrary threshold (500).

This subroutine puts a logical value of 1 or a 0 on the stack, depending

on whether the button is pressed or not.

sub button
0 get_position 500 less_than
return

This subroutine uses the BUTTON subroutine above to wait for a button press,

including a small delay to eliminate noise or bounces on the input.

sub wait_for_button_press
wait_for_button_open_10ms
wait_for_button_closed_10ms
return

Wait for the button to be NOT pressed for at least 10 ms.

sub wait_for_button_open_10ms
get_ms # put the current time on the stack
begin
# reset the time on the stack if it is pressed
button
if
drop get_ms
else
get_ms over minus 10 greater_than
if drop return endif
endif
repeat

Wait for the button to be pressed for at least 10 ms.

sub wait_for_button_closed_10ms
get_ms
begin
# reset the time on the stack if it is not pressed
button
if
get_ms over minus 10 greater_than
if drop return endif
else
drop get_ms
endif
repeat

An example of how to use wait_for_button_press is shown below:

Uses WAIT_FOR_BUTTON_PRESS to allow a user to step through

a sequence of positions on servo 1.

main_loop:
begin
wait_for_button_press
4000 4000 frame
500 delay
5000 5000 frame
500 delay
6000 6000 frame
500 delay
7000 7000 frame
500 delay
8000 8000 frame
repeat

sub frame
1 servo 2 servo
return[/code]

- Grant

Hello. I had trouble getting a switch to work a did my research on the forums and nothing worked. I made a change of code that worked and wanted to post it to help others. The problem was the 10ms in the wait for button to not be pressed. The following are the changes to the code:

goto main_loop    # Run the main loop when the script starts (see below).

# This subroutine returns 1 if the button is pressed, 0 otherwise.
# To convert the input value (0-1023) to a digital value (0 or 1) representing
# the state of the button, we make a comparison to an arbitrary threshold (500).
# This subroutine puts a logical value of 1 or a 0 on the stack, depending
# on whether the button is pressed or not.
sub button
  0 get_position 200 less_than
  return

# This subroutine uses the BUTTON subroutine above to wait for a button press,
# including a small delay to eliminate noise or bounces on the input.
sub wait_for_button_press
  wait_for_button_open_10ms
  wait_for_button_closed_10ms
  return

# Wait for the button to be NOT pressed for at least 10 ms.
sub wait_for_button_open_10ms
  get_ms # put the current time on the stack
  begin
    # reset the time on the stack if it is pressed
    button
    if
      drop get_ms
    else
      get_ms over minus 100 greater_than
      if drop return endif
    endif
  repeat

# Wait for the button to be pressed for at least 10 ms.
sub wait_for_button_closed_10ms
  get_ms
  begin
    # reset the time on the stack if it is not pressed
    button
    if
      get_ms over minus 100 greater_than
      if drop return endif
    else
      drop get_ms
    endif
  repeat

# An example of how to use wait_for_button_press is shown below:

# Uses WAIT_FOR_BUTTON_PRESS to allow a user to step through
# a sequence of positions on servo 1.
main_loop:
begin
  wait_for_button_press
  4000 4000 frame
  500 delay
  5000 5000 frame
  500 delay
  6000 6000 frame
  500 delay
  7000 7000 frame
  500 delay
  8000 8000 frame
repeat

sub frame
  1 servo 2 servo
  return

Hello.

I am glad you were able to get your code working. Thanks for sharing it.

- Grant