User Manual
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.
Using the subroutine brings the script down to 31 bytes: 4 per position and 11 bytes of overhead for
the loop and to define FRAME. We can go further: inspecting the compiled code shows that putting
each number on the stack requires 3 bytes: one byte as a command, and two for the two-byte number.
Numbers from 0 to 255 can be loaded onto the stack with just two bytes. Suppose in our application
we do not need the full 0.25 μs resolution of the device, since all of our settings are multiples of 100.
Then we can use smaller numbers to save another byte:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 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–2019 Pololu Corporation
6. The Maestro Scripting Language Page 79 of 102










