User Manual

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:
This program is 29 bytes long, with 3 bytes used per position and 14 bytes of overhead. Note that
we could get the same efficiency if we used the SERVO_8BIT command, which takes a one-byte
argument from 0 to 254. We can go even smaller by putting all of the numbers together:
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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Move servo 0 to five different positions, in a loop.
begin
40 frame
50 frame
60 frame
70 frame
80 frame
repeat
# loads a frame specified in 25 us units
sub frame
100 times
0 servo
500 delay
return
?
?
Pololu Maestro Servo Controller User’s Guide © 2001–2017 Pololu Corporation
6. The Maestro Scripting Language Page 77 of 99