User Manual

Note that the PLUS command always decreases the size of the stack by one. It is up to you to make
sure that you have enough values on the stack to complete the commands you want to run!
Consider a more complicated example: suppose we want to compute the value of (1 3) × 4, using
the MINUS and MULTIPLY commands. The way to write this computation as a script is “1 3 MINUS 4
TIMES”.
Comments, case, whitespace, and line breaks
All parts of the Maestro script language are case-insensitive, and you may use any kind of whitespace
(spaces, tabs, and newlines) to separate commands. Comments are indicated by the pound sign
“#” everything from the # to the end of the line will be ignored by the compiler. For example, the
computation above may be written as:
with absolutely no effect on the compiled program. We generally use lower-case for commands and
two or four spaces of indentation to indicate control structures and subroutines, but feel free to arrange
your code to suit your personal style.
Control structures
The Maestro script language has several control structures, which allow arbitrarily complicated
programs to be written. Unlike subroutines, there is no limit to the level of nesting of control structures,
since they are all ultimately based on GOTO commands (discussed below) and simple branching. By
far the most useful control structure is the BEGIN…REPEAT infinite loop, an example of which is given
below:
This infinite loop will continue forever. If you want a loop that is bounded in some way, the WHILE
keyword is likely to be useful. WHILE consumes the top number on the stack and jumps to the end of
the loop if and only if it is a zero. For example, suppose we want to repeat this loop exactly 10 times:
1
2
3
1 3 miNUS
4 # this is a comment!
times
1
2
3
4
5
6
7
# move servo 1 back and forth with a period of 1 second
begin
8000 1 servo
500 delay
4000 1 servo
500 delay
repeat
?
?
Pololu Maestro Servo Controller User’s Guide © 2001–2019 Pololu Corporation
6. The Maestro Scripting Language Page 70 of 102