Hello, forgive me if this has asked before but i need help. I really don’t understand the coding aspect of these things. i need help with writing the script for what i need which is as follows.
currently i have the micro 6 controlling 2 servos simultaneously on power up. when i power on the board, it runs a sequence of frames then stops like i want. but i also want the ability to press a momentary button and have the sequence run 2 frames then stop.
so essentially i have an automatic mode on power up and a manual mode on trigger (button press). i have no idea how to do this or even understand the scripting…please help.
my current scrip for the automatic run is as follows;
thank you
### Sequence subroutines: ###
# Sequence 0
sub Sequence_0
700 4664 8000 6000 0 0 2560 frame_0..5 # Load
1000 2048 0 8000 frame_0_1_5 # Retract
700 4664 8000 2560 frame_0_1_5 # Load
1000 2048 0 8000 frame_0_1_5 # Retract
700 4664 8000 2560 frame_0_1_5 # Load
1000 2048 0 8000 frame_0_1_5 # Retract
700 4664 8000 2560 frame_0_1_5 # Load
1000 2048 0 8000 frame_0_1_5 # Retract
700 4664 8000 2560 frame_0_1_5 # Load
1000 2048 0 8000 frame_0_1_5 # Retract
700 4664 8000 2560 frame_0_1_5 # Load
1000 2048 0 8000 frame_0_1_5 # Retract
700 4664 8000 2560 frame_0_1_5 # Load
1000 2048 0 8000 frame_0_1_5 # Retract
700 4664 8000 2560 frame_0_1_5 # Load
1000 2048 0 8000 frame_0_1_5 # Retract
700 4664 8000 2560 frame_0_1_5 # Load
1000 2048 0 8000 frame_0_1_5 # Retract
700 4664 8000 2560 frame_0_1_5 # Load
1000 2048 0 8000 frame_0_1_5 # Retract
700 4664 8000 2560 frame_0_1_5 # Load
1000 3396 frame_0 # Retract Hold
quit
return
sub frame_0..5
5 servo
4 servo
3 servo
2 servo
1 servo
0 servo
delay
return
sub frame_0_1_5
5 servo
1 servo
0 servo
delay
return
sub frame_0
0 servo
delay
return
Hello.
I moved your post to the “Servo controllers and Servos” section of the forum since it is about the Maestro.
It looks like your sequence is basically 2 movements (“Load” and “Retract”) repeated 11 times. Just to clarify, are you saying you want the entire sequence to happen every time the Maestro is powered up, then you want it to wait for a button press that triggers it to run the “Load” and “Retract” movements once each time it is pressed?
Also, have you already connected your button and tested it by monitoring the “Status” tab? If not, please see the details under the “Button or switch” heading of the “Attaching Servos and Peripherals” section of the user’s guide to get started with that.
Brandon
hello! yes that’s exactly right! I’ve been trying to make this happen for hours and just don’t understand the scripting. so when i power on the unit i want the 2 movements to run the full sequence off 11 times, then i want it to hold and wait for a momentary button to be pressed which would trigger just the 2 individual movement then again wait. so i basically have a power on into an automatic function, but i also have a manual function triggered only by the switch. i do have the switch correctly installed on my channel 3 i can see when its open (not pressed) i see a value of 255. then when pressed it drops to 0. so i know the switch is working.
i have my servos on channels 0 and 5, leds on 1 and 2, and the switch on 3. channel 4 is unused. my “automatic” sequence works fine. i then created the 2nd sequence calling it “manual” and then used the "copy all sequences to script function. from there im totally lost…
Probably the quickest way to get the behavior you want would be to add a call to your Sequence_0 at the top of your script, then use a BEGIN/REPEAT loop that looks for the button press. For example:
Sequence_0
begin
#if the button reads low:
3 get_position 500 less_than if
#run the following code:
700 4664 8000 2560 frame_0_1_5 # Load
1000 2048 0 8000 frame_0_1_5 # Retract
#1000 3396 frame_0 # you can uncomment this and remove the line above if you want it to end with "Retract Hold" instead of just "Retract"
endif
#short delay to control loop speed
10 delay
repeat
#the rest of your code can go under this as-is:
### Sequence subroutines: ###
Since there is a lot of repeated code in your script, you could refactor it to make it more elegant and easier to modify if you wanted to as well. For example, you could make a subroutine that runs one cycle of “load” then “retract” and make your Sequence_0 subroutine run a loop that calls the new subroutine 11 times (instead of copy/pasting the same code 11 times). If you try to make that kind of modification and run into problems, you can post what you have so far and I would be happy to help further.
Brandon
outstanding! thank you so much, i was just able to load the new script and it works exactly as i wanted, again thank you so much! ill try to learn more about the scripting to make it more streamline as time goes on but for now it works and im happy! thank you
1 Like
I am glad that worked for you! Thank you for letting us know.
Brandon