Recently I have bought my first maestro servo controller and i would really like to make a script that will execute a servo sequence after button press has been released. I have started with the example scripts from the user guide just to see what each command does and how everything works. But every time i think i figured something an error shows and forces more questions. Ive looked through whole forum on related topics but couldnt find right fix. Down below is what I have started with. It is also giving me overflow error.
sub button
1 get_position 500 less_than
sub wait_for_button_press
wait_for_button_open_10ms
wait_for_button_closed_10ms
return
sub wait_for_button_open_10ms
begin
button
if
drop get_ms
else
get_ms over minus 10 greater_than
if drop return endif
endif
goto main_loop
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
main_loop:
begin
4000 frame
5000 frame
6000 frame
7000 frame
8000 frame
repeat
sub frame
wait_for_button_press
5 servo
return
quit
I know that this is not the code that i need but like i said i wanted to see how script affects maestro.
On my maestro switch is on 1 and servo is on 5. All i wanted is to move to servo in position after set time delay.
I also wanted to ask if 2c 7.4V 350mah lipo battery would be sufficient to run maestro and one micro 7g servo with next to none load on servo.
Thank you so much for your time and i hope to hear from you soon
There are some major problems with the way your script is structured. For example, when it starts, it goes right into a subroutine, which then has another subroutine declared inside of it. Also, you are using a goto command inside of a subroutine. Both of those are very likely to cause problems and are best avoided in most cases.
Doing the following 4 things should get the script functioning again without errors, but it is not clear to me if it will do what you want it to:
Add a goto main_loop command to the very start of your script.
Add a return command to the end of your button subroutine (before sub wait_for_button_press).
Start the wait_for_button_open_10ms subroutine with a get_ms (just before begin).
Remove the goto main_loop inside of the wait_for_button_open_10ms subroutine.
You mentioned wanting the servos to move after a timed delay, but you are also using a button, which is controlling when the servos move. If the script doesn’t do what you want it to, and you can explain how you want it to behave, I might be able to give you some more suggestions.
As far as the battery, that 7.4V LiPo, 350mAh battery will probably be fine, as long as your servo is okay with operating at that voltage, which can be upwards of 8.4V when fully charged (most servos are rated for a nominal 4.8-6V battery).
I have figured everything out in a meanwhile. Thank you for your time and help. The structure was bad because i was deleting lines trying to get the results. Anyway i figured how the subroutines work and ive used them and now everything works as intended.
Thank you once again. This great little product of yours has opened a lot of opportunities for me and i am definitely getting quite few more
I will add a script just in case someone needs something like this.
So the script executes servo movements after button release. On my Maestro micro switch is on 1 and servo is on 5 which can be easily seen in the script below.
goto main_loop
sub button
1 get_position 200 greater_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 delay_seconds
begin dup while
1 minus 1000 delay
repeat
drop return
main_loop:
begin
4000 frame
1 delay_seconds
5000 frame1
2 delay_seconds
6000 frame2
3 delay_seconds
7000 frame3
4 delay_seconds
8000 frame4
repeat
sub frame
wait_for_button_press
5 servo
return
sub frame1
5 servo
return
sub frame2
5 servo
return
sub frame3
5 servo
return
sub frame4
5 servo
I cannot vouch for that particular regulator, but according to the claims on that page it should be okay for your input voltage and handle enough current to drive a servo.