Hi Guys
Im struggling to set the servo speed in my program.
Servo’s run as per button presses, but runs at full speed,how do I set each servo’s speed in my script?
below is my current working script without speed adjustments:
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
7300 frame_3
1000 frame_2
1000 frame
1000 frame_3
7400 frame_3
10000 frame
10000 frame_2
7200 frame_3
repeat
sub frame
wait_for_button_press
1 servo
return
sub frame_2
wait_for_button_press
2 servo
return
sub frame_3
wait_for_button_press
5 servo
As far as I know Servo motors get as input a PWM signal where a pulse width of 1ms moves it to one extreme, 1.5 ms to the center and 2ms to the other extreme (correct me if I’m wrong on the timings). A software solution may be to iteratively change the position of the motor according to some time difference between main loop iterations. I don’t know what hardware you use but it is very probable you have all the components to do so by hardware and if so, it is more preferable to do it by hardware.
Therefore, I think we will be able to give you a better answer if you will give us more information on your setup:
Look at the section “Making smooth sequences with GET_MOVING_STATE” - they have the following line in the code:
30 0 speed
I read their manual a bit and found out that the first argument is the speed in 0.25 (servo) microseconds per 10 milliseconds and the second argument is the servo channel.
To set servo speed from a script, you can use the speed command. More information on how that command works can be found under the Command Reference section of the Maestro’s user’s guide. You can also find an example showing the use of that command under the “Making smooth sequences with GET_MOVING_STATE” example script, which can be found under the “Example Scripts” section of the user’s guide. (You can finder the user’s guide under the Resources tab of the Maestro’s product page.)
By the way, you can configure the default speed limit applied to each channel at startup in the “Channel Settings” tab of the Maestro Control Center. This is especially appealing if you do not need your servos to change speeds throughout your script. (Be sure to click Apply Settings in the bottom right corner of the Maestro Control Center to save your settings.)