Remote Robot Command

The remote robot command library aims at building a simple command language for remotely controlling a NxOS-based robot. The command syntax is kept as simple as possible, and commands can be executed from a file, or in the near future streamed through a Bluetooth link.

A command file is a succession of command lines, separated by the new line \n character. Lines starting with a # (sharp) are treated as comments and are not interpreted.

For example, the execution of this file will result in some text being displayed and annoying sounds to be played:

clear
print Hello, world
play 1000 100
wait 150
play 2000 100 sync
print Goodbye
wait 1000
clear

Available commands include:

Command syntax

Move

The move command controls the NXT motors ports. It can control any number of motors at once, with common or per-motor values for speed and duration.

Syntax

move <motors> <speed> <duration>

Parameters

This command takes 3 parameters:

  • The motors parameter is a comma-separated list of motors identifiers. Accepted identifiers are capital letters from A to C included.
  • The speed and duration parameters control respectively the speed (between -100, for full reverse, and 100 for full forward) and the duration of the motors' activation (in ms). They are both comma-separated lists of values, but they do not need to be of the same size as the motors parameter: the missing values will be copied from the last encountered one.

Examples

# Move motor A at 80% for 1 second
move A 80 1000

# Move motor A at 100% for 1 second, and motor B at 100% for 0.5 seconds
move A,B 100 1000,500

# Move all three motors at 100%, 90% and -30% for 1sec, 2secs and 2secs
move A,B,C 100,90,-30 2000,1000

Notes

  • Unknown motor identifiers, out of bounds speeds and negative duration values throw an INVALID_PARAMETER error.

Print

Display a string and move to the next line.

Syntax

print [message ...]

Parameters

This command takes 0 or more parameters. The message parameter can contain spaces, as the result of the command tokenization is joined with spaces at display time.

Examples

# Prints 'Hello, world'
print Hello, world

# Pass a line
print

Clear

Clears the screen.

Syntax

clear

Parameters

This command has no parameters.

Play

Plays a sound at a given frequency.

Syntax

play <freq> <duration> [sync]

Parameters

This command takes 2 or 3 parameters:

  • freq is the frequency in Hertz of the sound to play.
  • duration is the duration in ms.
  • sync is an optional parameter to activate synchronous play mode (blocks until the command is complete).

Examples

# Plays a sound at 2kHz for 1 second and return immediately
play 2000 1000

# Plays a sound at 3.5kHz for 800 ms and wait until the 800 ms have passed
play 3500 800 sync

Notes

Both freq and duration must be positive, non-zero numbers.

Wait

Waits for a given time.

Syntax

wait <duration>

Parameters

This command takes one parameter, duration, the length in milliseconds of the waiting time.

Examples

# Waits for 1.2 seconds and go on
wait 1200

Notes

The duration parameter must be a strictly positive number.

Exec

Executes another command file from the flash file system (branch execution before coming back).

Syntax

exec <filename>

Parameters

This command takes one parameter:

  • filename, the name of the file to read and execute.

Examples

# Executes 'music.cmd'
exec music.cmd

Notes

  • The name of the file must not contain spaces.
  • If an error occurs during the execution of the file, the program's behavior is yet to be defined.