Micro Maestro Servo off issue

So,
I am helping a friend out with a project,
He needs 2 servos to work in unison to move a single object, being triggered by a single pushbutton.
I have figured out how to program the script, however the servos hum all the time.
I understand that is because they are fighting to hold position.

However, when I turn them off, the speed and acceleration controls no longer function.
I have tried to add the position back to them before the command to move, but they still ignore the speed and acceleration.

It also seems to stop working after a few minutes, and the script must be restarted to get it working again.
I am very new to this device, so thank you for your patience.
I have included the script below, Thank you for your time.

Goto main_loop
Sub button
  5 get_position 500 less_than
  Return

sub wait_for_button_press
  wait_for_button_open_10ms
  wait_for_button_closed_10ms
  return

sub wait_for_button_open_10ms
  get_ms
  Begin
    button
    if
      drop get_ms
    else
      get_ms over minus 10 greater_than
      if drop return endif
    endif
  repeat

sub wait_for_button_closed_10ms
  get_ms
  begin
    button
    if
      get_ms over minus 10 greater_than
      if drop return endif
    endif
  repeat

Sub open
  4090 0 servo
  9920 1 servo
  200 delay
  20 0 speed
  20 1 speed
  2 0 acceleration
  2 1 acceleration
  9900 0 servo 
  4100 1 servo
  20 delay
  0 0 servo
  0 1 servo
  return

sub closed
  9900 0 servo
  4100 1 servo
  200 delay
  20 0 speed
  20 1 speed
  2 0 acceleration
  2 1 acceleration
  20 delay
  4090 0 servo
  9920 1 servo
  20 delay
  0 0 servo
  0 1 servo
  return

begin
  main_loop:
  open 
  frame
  closed 
  frame
repeat

sub frame
  wait_for_button_press 
  return

Hello.

I edited your post above, but in the future, please use some sort of indentation in your code and post it inside [code ] [/code ] tags (without the spaces) to make it more readable.

I fixed up your script:

20 0 speed
20 1 speed
2 0 acceleration
2 1 acceleration

begin
  closed_to_open 
  wait_for_button_press
  open_to_closed
  wait_for_button_press
repeat

sub button
  5 get_position 500 less_than
  Return

sub wait_for_button_press
  wait_for_button_open_10ms
  wait_for_button_closed_10ms
  return

sub wait_for_button_open_10ms
  get_ms
  Begin
    button
    if
      drop get_ms
    else
      get_ms over minus 10 greater_than
      if drop return endif
    endif
  repeat

sub wait_for_button_closed_10ms
  get_ms
  begin
    button
    if
      get_ms over minus 10 greater_than
      if drop return endif
    endif
  repeat

sub open
  9900 0 servo
  4100 1 servo
  return

sub closed
  4090 0 servo
  9920 1 servo
  return

sub off
  0 0 servo
  0 1 servo
  return

sub closed_to_open
  closed
  20 delay
  open
  4000 delay
  off
  return

sub open_to_closed
  open
  20 delay
  closed
  4000 delay
  off
  return

EDIT: The script above has a bug in it, in wait_for_button_closed_10ms. See below.

Your problem was that you were not delaying enough before turning off the servos, so they didn’t actually reach their intended destination. You only delayed for 20 ms before turning them off. I increased that delay to 4000. If you want to delay for the optimal amount of time, you should use get_moving_state to wait until the servos pulses are done changing, then wait a little bit more to ensure that the servos themselves are done moving, and THEN turn off the servos.

I also did some other things to clean up your code, so it can serve as a good example to future people doing the same thing.

I’m not sure why your script would stop working after some time. If that continues to happen, please have the Maestro connected to USB and see if the Maestro Control Center reports any errors when the script stops. Using the Status tab and the Script tab, you should be able to see exactly what your script is doing and debug this.

–David

Thank you greatly for your help,
It does seem to occasionally stop responding after a short break, but then it will suddenly start working again with no prompting.

I will play around with it and see if I can narrow down where the problem lies.
Thanks again for your help,

So,
after doing some troubleshooting.
When the Micro is not working, everything seems correct from the computer’s point of view.

The input shows that it has received signal, And the script is setting in the correct location, But for some reason the script doesn’t move past the following section of the script sub button 5 get_position 500 less_than Return

But after a indeterminate amount of time, it will usually start working again, Or a power reset will also get it working.

Thanks,

During normal operation with the button open, if you are looking at the Script tab, you should see a little pink triangle that jumps around between parts of the “button” subroutine and parts of the “wait_for_button_closed_10ms” subroutine, indicating which part of the code is currently executing. Is that what you see?

When you say “for some reason the script doesn’t move past the following section of the script” I’m not totally sure what you mean. Does the pink triangle still jump around at all, or is it stationary? The next time the problem happens, could you take a screenshot of the Maestro Control Center so we can see all the debugging information that is available?

What do you mean by “The input shows that it has received signal”? The next time the problem happens, please check the Status tab and let me know if the “Position” of channel 5 actually changes as you would expect when you press the button. Also, let me know how your two servo channels look in the status tab (i.e. how do they behave when you press the button).

–David

My apologies, I was unclear earlier.

When it is not working correctly, the triangle is jumping around in the “Sub_Button” and “wait_for_button_closed_10ms” subroutines.
(this is also what it is doing when it is working correctly but not being triggered)

When it is working correctly,
Servo 0 is enabled, and moves from 2375 to 1000
Servo 1 is enabled, and moves from 1075 to 2496

When it it is malfunctioning, you can go to the status tab and watch the input be triggered. But the servos do not Enable or move, nor does the script move from the “Sub_Button” and “wait_for_button_closed_10ms” subroutines.

I will take a screen shot the next time it misbehaves. I will try to get the status screen, as well as the script screen.

Thank you for your time.

Here are the promised photos, taken while it was malfunctioning.
Status with the button being pressed, and the script also while the button is being pressed.




I looked at your script and found the problem. You were missing some critcal lines from the wait_for_button_closed_10ms subroutine. Where did you copy that subroutine from? I am curious because the version in the “Example Scripts” section of the Maestro User’s Guide is correct, and has those lines.

Here is a script that should work better:

20 0 speed
20 1 speed
2 0 acceleration
2 1 acceleration

begin
  closed_to_open 
  wait_for_button_press
  open_to_closed
  wait_for_button_press
repeat

sub button
  5 get_position 5000 less_than
  Return

sub wait_for_button_press
  wait_for_button_open_10ms
  wait_for_button_closed_10ms
  return

sub wait_for_button_open_10ms
  get_ms
  Begin
    button
    if
      drop get_ms
    else
      get_ms over minus 10 greater_than
      if drop return endif
    endif
  repeat

sub wait_for_button_closed_10ms
  get_ms
  begin
    button
    if
      get_ms over minus 10 greater_than
      if drop return endif
    else
      drop get_ms
    endif
  repeat

sub open
  9900 0 servo
  4100 1 servo
  return

sub closed
  4090 0 servo
  9920 1 servo
  return

sub off
  0 0 servo
  0 1 servo
  return

sub closed_to_open
  closed
  20 delay
  open
  4000 delay
  off
  return

sub open_to_closed
  open
  20 delay
  closed
  4000 delay
  off
  return

–David

David,
I appreciate your help greatly!
I assume I missed those lines when I was copying the script.
I apologies for taking up so much of your time.
Thank you for the help!