User Manual

GET_MOVING_STATE returns a 1 as long as there is at least one servo that is limited by a speed or
acceleration setting still moving, so you can use it whenever you want to wait for all motion to stop
before proceeding to the next step of a script.
Using an analog input to control servos
An important feature of the Maestro is that it can be used to read inputs from sensors, switches, or
other devices. As a simple example, suppose we want to use a potentiometer to control the position of
a servo. For this example, connect the potentiometer to form a voltage divider between 5V and 0, with
the center tap connected to channel 1. Configure channel 1 to be an input, and examine the signal
on the Status tab of the Maestro Control Center. You should see the position indicator vary from 0 to
255 μs as you turn the potentiometer from one side to the other. In your script, this range corresponds
to numbers from 0 to 1023. We can scale this number up to approximately the full range of a servo,
then set the servo position to this number, all in a loop:
Alternatively, you might want the servo to go to discrete positions depending on the input value:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# This example uses speed and acceleration to make a smooth
# motion back and forth between 1 and 2 ms.
3 0 acceleration
30 0 speed
begin
4000 0 servo # set servo 0 to 1.00 ms
moving_wait
8000 0 servo # 2.00 ms
moving_wait
repeat
sub moving_wait
begin
get_moving_state
while
# wait until it is no longer moving
repeat
return
1
2
3
4
5
6
# Sets servo 0 to a position based on an analog input.
begin
1 get_position # get the value of the pot, 0-1023
4 times 4000 plus # scale it to 4000-8092, approximately 1-2 ms
0 servo # set servo 0 based to the value
repeat
?
?
Pololu Maestro Servo Controller User’s Guide © 2001–2017 Pololu Corporation
6. The Maestro Scripting Language Page 79 of 99