User Manual
If you step through this version program, you will also notice that all five numbers are placed on the
stack in a single step: this is because the compiler can use a single command to put multiple numbers
on the stack. Using a single command for multiple numbers saves space: we are now down to just 26
bytes. Only 12 bytes are used for the 5 frames, for an average of 2.4 bytes per frame. This is probably
compact enough – by duplicating this structure we could fit 420 different positions into the 1024-byte
program memory of the Micro Maestro. However, the code can get even smaller. Consider this script,
which uses 31 frames to make a smooth back-and-forth motion:
In this version of the code, we have rewritten the FRAME subroutine, using the DEPTH command
to automatically load frames from the stack until there are none left. This program uses 34 bytes to
store 31 frames, for an average of just 1.1 bytes per frame. We could store a sequence containing 900
different positions in the memory of the Micro Maestro using this kind of script.
Making smooth sequences with GET_MOVING_STATE
Speed and acceleration settings can be used to make smooth motion sequences with the Maestro.
However, a common problem is that you do not know how much you need to delay between frames
to allow the servo to reach its final position. Here is an example of how to use the built-in function
GET_MOVING_STATE to make a smooth sequence, instead of DELAY:
1
2
3
4
5
6
7
8
9
10
11
12
# Move servo 0 to five different positions, in a loop.
begin
80 70 60 50 40
frame frame frame frame frame
repeat
# loads a frame specified in 25 us units
sub frame
100 times
0 servo
500 delay
return
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# Moves servo in a sine wave between 1 and 2 ms.
begin
60 64 68 71 74 77 79 80 80 79 78 76 73 70 66 62
58 54 50 47 44 42 41 40 40 41 43 46 49 52 56
all_frames
repeat
sub all_frames
begin
depth
while
100 times
0 servo
100 delay
repeat
return
?
?
Pololu Maestro Servo Controller User’s Guide © 2001–2017 Pololu Corporation
6. The Maestro Scripting Language Page 78 of 99










