Logo for NXT
Welcome to Logo for NXT
This page contains information about the project of programming NXT in Logo language.
The project is under intensive development, and there are no releases yet. However, the projet is open-source and the latest development version is available in the CVS.
- Implemented in Imagine and Next Byte Codes (NBC)
- Three levels of use:
- Interactive Imagine project with direct GUI controls that allow interfacing with NXT robot over Bluetooth
- Loadable imagine library (nxt.imt) that contains set of procedures for direct control of NXT robot over Bluetooth from your Imagine projects
- Interpreter of Logo running on the NXT that can run logo programs (with restricted syntax), which can communicate with Imagine projects and control the robots motors and sensors.
Motor & Sensor procedures
(motor m cmd [arg]) where cmd is one of: on off brake regulate [speed] sync [ratio] on_rot [number_of_rotations] on_ms [number_of_ms] power [power] rst (readmotor m cmd) where cmd is one of: rotations tacho blocktacho (sensor N) (setsensor N type) where type is one of: raw switch tmp_C tmp_F refl angle light_a light_i db dba lowspeed ls9V
NXT Logo supports the following primitive procedures and operations:
- Arithmetic: add, sub, mul, div, mod, neg
- Logic: and, or, xor, not
- Bitwise: bitand, bitor, bitxor, bitnot
- Lists and words: first, bf, last, bl, item, se, list, word
- Maps & co.: map, apply, foreach, run, remote
- Loops and conditions: repeat, while, foreach, if, ifelse
- Predicates: empty? number? list? word? equal? gt? lt? ge? le? member?
- Variables and procedures: make, let, to, op, stop, erase
- NXT file handling: load, printto, fopen, fwrite, fread, fclose
- Sounds: tone, sound
- Motors, sensors: motor, readmotor, sensor, setsensor, battery
- Other: wait, random, draw, ascii, char, boot, gc, fm
The expressions must be in prefix notation. Variables are used the same way as in Logo - as "name when referring to variable name, and as :name when referring to its value. There are global variables as well as local variables, lexical scoping as usual in Logo.
The (remote expression) operations allow to start evaluating an expression on NXT when started from PC, and vice-versa. This can be used for communication. Of course, one could then easily say, for example:
remote [print "hello]
remote [my_program 123]
or read value of remote variable:
However, one has to keep in mind that BlueTooth communication is slow due to switching of the direction of the transceiver and receiver. Therefore, it is preferable to implement higher-level functions and procedures that can run on NXT brick autonomously. Logo programs have about 30kb of memory available - for storing both the logo programs and data, however, programs can load/erase data and code from NXT files that are stored in the large flash.
Some sample code for Logo for NXT is in the Examples folder.
Detailed syntax is shown in the file syntax.txt.