In the code below I would like servo 1(ch1) and servo 2(ch2) to stop after their movements and then if the switch(ch0) is switched they will move to 6000 and then script stops. Hope that made sense? I’ve tried multiple ways and just can’t see it to get it to work. It keeps looping after if.
1: An issue I’m having is when the switch is turned ON it takes (or the delay is) to long. I would like it to delay for 2 sec. when switch is turned ON and delay for 3 sec when switch is turned OFF. That would give me enough time to remove the key from the switch. It’s a keyed switch as you guessed. Not sure if I need a debounce code for this?
2: Also servo 4 struggles a bit with it’s load and will hum some when moved to position and stationary. If I code the Maestro to stop sending a signal it does go silent so I’m hoping to figure out a way keep it silent for initial start and shutdown subs and somehow try to keep the speed function? I have read the FAQ’s section and understand about the speed and acceleration loss on power up. Just hoping to try and fool it somewhat. Hope that made sense?
3: Reading through the Maestro’s guide I can’t seem to figure out how to properly calculate the actual servo position to number form for code. I just guessed and played quite a while to get it right. For instance let’s say my Min and Max position is 1020-1630. How do I calculate the precise number for the code to work in between those positions only?
4: Forgot to add that when I hit the Apply Settings tab after making adjustments on the Channel Settings page it automatically starts the script. Can I do something to get that to not happen? When I’m testing servos and changing settings I would like it to not start the script.
From your code, it looks like the shutdown subroutine is continuously looping followed by a three second delay, which would explain why it takes longer than you are expecting for the program check the status of your switch. You might try using a state variable to keep track of the switch and determine when it is switched “ON” or “OFF”. You can see an example of a state variable used here.
One way you could have speed and acceleration limits still apply to the movements of a servo once it has been turned off is to first send the servo to the last known position it was in when the Maestro turned it off. The speed and acceleration limits should be applied to subsequent movements.
The units are displayed as microseconds under the “Status” tab of the Maestro Control Center, whereas the units are displayed as quarter-microseconds in the Maestro scripting language. To convert from microseconds to quarter-microseconds, you would need to multiply the microsecond value by 4 (e.g. 1020 * 4 = 4080).
It sounds like you have the “Run script on startup” option enabled. To prevent the script from running whenever you make a change in the Maestro Control Center and clicking on the “Apply Settings” button, you can uncheck the “Run script on startup” box under the “Script” tab of the Maestro Control Center. Remember to enable that option and apply those changes if you are going to use the Maestro as a standalone device (not connected to your computer via USB).
I have everything working and am so excited! I will post pics and a video once I have everything mounted and ready. I do have one other question though. I am still struggling to get my key switch to function just right. This key switch I would like to leave in the ON position once turned. The way the code is below I have to turn ON and then OFF real quick to get my “sub start” to go just once. Otherwise left ON it keeps looping the “sub start”. I would like to be able to leave the switch in the ON position. (I then can remove key so no tampering is done) I’m just so confused on how to get it working right? Probably the most simple thing and I just can’t see it. Thanks for your help!
I looked at your code and noticed that your script doesn’t check for the variable state before calling your start and shutdown subroutines. You would need to add a couple of IF statements to check the status of your state variable before executing the appropriate subroutine. For example, you might try the following code for the BEGIN/REPEAT block:
1 #state variable status
begin
dup #duplicate the state variable value
0 get_position 500 less_than
if #check switch state: ON
if start #if state variable is 1, start subroutine hasn't been executed
drop 0
endif
else #switch state: OFF
0 equals #check if state variable is 0.
if shutdown #if state variable is 0, shutdown subroutine hasn't been executed
drop 1
endif
endif
repeat
Also, I noticed that you have a BEGIN/REPEAT block and a WHILE command in the start subroutine, which seems unnecessary since the subroutine should only execute once whenever called. It would be easier and probably less confusing if you control the number of times a behavior-specific subroutine is called from the main loop instead of in the subroutine.