User Manual

It is a good idea to try stepping through this script before doing anything further with scripts on the
Maestro. In particular, pay attention to how the command “100” puts the number 100 on the stack,
and the DELAY command consumes that number. In the Maestro scripting language, arguments to
commands always need to be placed on the stack before the commands that use them, which makes
the language seem backwards compared to other languages. It also means that you can arrange your
code in a variety of different ways. For example, this program is equivalent to the one above:
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.
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
1
2
3
4
5
6
# Blinks the red LED once per second.
begin
900 100
led_on delay
led_off delay
repeat
1
2
3
4
5
6
7
8
9
10
11
12
13
# 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
?
?
Pololu Maestro Servo Controller User’s Guide © 2001–2017 Pololu Corporation
6. The Maestro Scripting Language Page 76 of 99