beautypg.com

The maestro scripting language, A. maestro script language basics, Commands and the stack – Pololu Maestro User Manual

Page 50: Comments, case, whitespace, and line breaks

background image

6. The Maestro Scripting Language

A script is a sequence of commands that is executed by the Maestro. Commands can set servo targets, speeds,
and accelerations, retrieve input values, and perform mathematical computations. Basic control structures – looping
and conditionals – are available for use in making complicated scripts. The Maestro script language is a simple
stack-based language very similar to FORTH, and scripts compile to a compact bytecode in which commands and
subroutine calls each take just a single byte. A basic editor/debugger is available in the Script tab of the Maestro
Control Center application.

6.a. Maestro Script Language Basics
Commands and the stack

A program in the Maestro script language consists of a sequence of commands which act on a stack of values. Values
in the stack are integers from -32768 to +32767. On the Micro Maestro 6-channel servo controller, there is room for
up to 32 values on the stack, while on the Mini Maestro servo controllers there is room for up to 126 values on the
stack. Commands always act on the topmost values of the stack and leave their results on the top of the stack. The
simplest kind of commands are literals, numerical values that are placed directly onto the stack. For example, the
program “-10 20 35 0” puts the values -10, 20, 35, and 0 sequentially onto the stack, so that it looks like this:

value

3

0

2

35

1

20

0

-10

A more complicated command is the PLUS command, which adds the top two numbers, leaving the result on the top
of the stack. Suppose the numbers 1, 2, 4, and 7 are sequentially placed on the stack, and the PLUS command is run.
The following table shows the result:

before after

3

7

2

4

11

1

2

2

0

1

1

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:

Pololu Maestro Servo Controller User's Guide

© 2001–2014 Pololu Corporation

6. The Maestro Scripting Language

Page 50 of 73