A simple servo sequence, Compressing the sequence – Pololu Maestro User Manual
Page 57

led_on delay
led_off delay
repeat
The numbers are placed on the stack at the beginning of the loop, then consumed later on in execution. Pay attention
to the order of the numbers used here: the 900 goes on the stack first, and it is used last.
A simple servo sequence
The following script shows how to direct servo 0 to five different positions in a loop.
# Move servo 0 to five different positions, in a loop.
begin
4000 0 servo # set servo 0 to 1.00 ms
500 delay
5000 0 servo # 1.25 ms
500 delay
6000 0 servo # 1.50 ms
500 delay
7000 0 servo # 1.75 ms
500 delay
8000 0 servo # 2.00 ms
500 delay
repeat
The serial mode must not be set to detect baud rate for this script to work. In detect baud rate mode,
the Maestro does not enable any of the servo outputs until the start byte has been received.
Note that the servo positions are specified in units of 0.25 μs, so a value of 4000 corresponds to 1 ms. The text after
the # is a comment; it does not get programmed on to the device, but it can be useful for making notes about how
the program works. Good comments are essential for complicated programs. It is important to remember the DELAY
commands; without these, the script will not wait at all between servo commands, running the loop hundreds of times
per second.
Compressing the sequence
The program above takes 58 bytes of program space: 11 bytes for each servo position and 3 for the loop. At this rate,
we could store up to 92 servo positions in the 1024-byte memory of the Micro Maestro, or 744 servo positions in the
8192-byte memory of the Mini Maestros. To get the most out of the limited memory, there are a variety of ways to
compress the program. Most important is to make use of subroutines. For example, since we repeat the instructions “0
servo 500 delay” several times, we can move them into a subroutine to save space. At the same time, this simplifies
the code and makes it easier to make future modifications, such as changing the speed of the entire sequence.
# Move servo 0 to five different positions, in a loop.
begin
4000
frame
5000
frame
6000
frame
7000
frame
8000
frame
repeat
sub frame
0 servo
500 delay
return
Pololu Maestro Servo Controller User's Guide
© 2001–2014 Pololu Corporation
6. The Maestro Scripting Language
Page 57 of 73