## Support » Pololu Maestro Servo Controller User’s Guide » 6. The Maestro Scripting Language »

# 6.b. Command Reference

The following is the entire list of commands and keywords in the Maestro script language. The “stack effect” column specifies how many numbers are consumed and added to the stack. For example, the PLUS command takes off two numbers and returns one; so it has a stack effect of -2,+1. Commands with special effects will be marked with a *.

#### Keywords

keyword | stack effect | description |
---|---|---|

BEGIN | none | marks the beginning of a loop |

ENDIF | none | ends a conditional block IF…ENDIF |

ELSE | none | begins the alternative block in IF…ELSE…ENDIF |

GOTO label |
none | goes to the label label (define it with label:) |

IF | -1 | enters the conditional block if the argument is true (non-zero) in IF…ENDIF or IF…ELSE…ENDIF |

REPEAT | none | marks the end of a loop |

SUB name |
none | defines a subroutine name |

WHILE | -1 | jumps to the end of a loop if the argument is false (zero) |

#### Control commands

command | stack effect | description |
---|---|---|

QUIT | none | stops the script |

RETURN | none | ends a subroutine |

#### Timing commands

command | stack effect | description |
---|---|---|

DELAY | -1 | delays by the given number of milliseconds |

GET_MS | +1 | gets the current millisecond timer (wraps around from 32767 to -32768) |

#### Stack commands

command | stack effect | description |
---|---|---|

DEPTH | +1 | gets the number of numbers on the stack |

DROP | -1 | removes the top number from the stack |

DUP | +1 | duplicates the top number |

OVER | +1 | duplicates the number directly below the top, copying it onto the top |

PICK | -1,+1 | takes a number n between 0 and 63, then puts the nth number below the top onto the stack (0 PICK is equivalent to DUP) |

SWAP | a,b → b,a | swaps the top two numbers |

ROT | a,b,c → b,c,a | permutes the top three numbers so that the 3rd becomes the top and the others move down one position |

ROLL | -1,* | takes a number n, then permutes the top n+1 numbers so that the n+1th becomes the top and all of the others move down one |

PEEK | -1,+1 | (Mini Maestro 12, 18, and 24 only) takes a number n, then copies the nth value on the stack (measured from the bottom) to the top of the stack |

POKE | -2,+1 | (Mini Maestro 12, 18, and 24 only) takes a number n, then removes the next value from the stack and puts it at the nth location on the stack (measured from the bottom) |

#### Mathematical commands (unary)

These commands take a single argument from the top of the stack, then return a single value as a result. Some of these have equivalents in C (and most other languages), listed in the “C equivalent” column below. We use “false” to mean 0 and “true” to mean any non-zero value. A command returning “true” always returns a 1.

command | C equivalent | description |
---|---|---|

BITWISE_NOT | ~ | inverts all of the bits in its argument |

LOGICAL_NOT | ! | replaces true by false, false by true |

NEGATE | – | replaces x by -x |

POSITIVE | none | true if and only if the argument is greater than zero |

NEGATIVE | none | true if and only if the argument is less than zero |

NONZERO | none | true (1) if and only if the argument is true (non-zero) |

#### Mathematical commands (binary)

These commands take two arguments from the top of the stack, then return a single value as a result. The order of the arguments, when important, is the standard one in mathematics; for example, to compute 1 – 2, you write “1 2 MINUS”. These commands all have equivalents in C (and most other languages), listed in the “C equivalent” column below.

command | C equivalent | description |
---|---|---|

BITWISE_AND | & | applies the boolean AND function to corresponding bits of the arguments |

BITWISE_OR | | | applies the boolean OR function to corresponding bits of the arguments |

BITWISE_XOR | ^ | applies the boolean XOR function to corresponding bits of the arguments |

DIVIDE | / | divides the arguments |

EQUALS | == | true if and only if the arguments are equal |

GREATER_THAN | > | true if and only if the first argument is greater than the second |

LESS_THAN | < | true if and only if the first argument is less than the second |

LOGICAL_AND | && | true if and only if both arguments are true |

LOGICAL_OR | || | true if and only if at least one argument is true |

MAX | none | selects the greater of the two arguments |

MIN | none | selects the lesser of the two arguments |

MINUS | – | subtracts the arguments |

MOD | % | computes the remainder on division of the first argument by the second |

NOT_EQUALS | != | true if and only if the arguments are not equal |

PLUS | + | adds the arguments |

SHIFT_LEFT | << | shifts the binary representation of the second argument to the left by a number of bits given in the second argument (without wrapping) |

SHIFT_RIGHT | >> | shifts the binary representation of the first argument to the right by a number of bits given in the second argument (without wrapping) |

TIMES | * | multiplies the arguments |

#### Servo, LED, and other output commands

command | stack effect | description |
---|---|---|

SPEED | -2 | sets the speed of the channel specified by the top element to the value in the second element (see Section 4.b) |

ACCELERATION | -2 | sets the acceleration of the channel specified by the top element to the value in the second element (see Section 4.b) |

GET_POSITION | -1,+1 | gets the position of the channel specified by the top element |

GET_MOVING_STATE | +1 | true if any servos that are limited by speed or acceleration settings are still moving |

SERVO | -2 | sets the target of the channel specified by the top element to the value in the second element, in units of 0.25 μs |

SERVO_8BIT | -2 | sets the target of the channel specified by the top element to the value in the second element, which should be a value from 0 to 254 (see the Mini SSC command in Section 5.e) |

LED_ON | none | turns the red LED on |

LED_OFF | none | turns the red LED off (assuming no errors bits are set) |

PWM | -2 | (Mini Maestro 12, 18, and 24 only) enables the PWM output channel, with the period specified by the top element and the on time specified by the second element, both in units of 1/48 μs (see Section 4.a for more information about PWM) |

SERIAL_SEND_BYTE | -1 | (Mini Maestro 12, 18, and 24 only) removes the top number from the stack, interprets it as a single byte, and sends that byte to the TTL serial output (TX) |