Rcx ToonTalk extension

The RCX Extension
The goal of the RCX ToonTalk extension is to enable learners to create connected executable models of a phenomenon both in a virtual world (the computer screen) and in the physical one using the LEGO MindStorms kit.
The RCX extension is aimed at providing the basic functionality that TT projects involving RCX can use. Higher level TT software abstractions encapsulate specific project primitives. Such abstractions will be distributed in the form of TT notebooks containing robots that accomplish specific RCX-related tasks.
The communication between the PC and the RCX is implemented using IR devices. The LEGO kit comprises an IR tower that can be connected to an USB or serial port on the PC. The IR tower sends signals covering a narrow cone at a maximum distance of few meters. IR communication is directional (i.e. the IR tower and RCX should “see” each other) and this might cause problems with mobile robots.
From a programming point of view, the RCX extension is a special bird that can fly "outside" of ToonTalk and communicate with the RCX. To execute a command on the RCX, e.g. turn on the motors, boxes that contain commands are given to the bird. If a response is needed, e.g. a sensor reading, then the box will include another bird that will bring back the response, thereby achieving communication from the RCX back to the computer.
The RCX is controlled by a firmware implementing an interpreter that executes low level byte code commands – either from downloaded programs or from direct commands received from a controlling computer. With the RCX extension the user can interactively:
- play a sound;
- control motors;
- set the RCX display to a sensor, message or variable value;
- send a message;
- set sensor type (since the RCX has no plug-and-play support, one must always tell it what kind of sensors is attached to what port);
- get a sensor value;
- set and get a variable;
- store the data log of an experiment on the RCX and upload it to ToonTalk;
Since the RCX computer has very
limited memory and processing power, it’s impossible to enhance the LEGO RCX
firmware with a TT runtime engine. Thus, programming running on the RCX need
to be developed in another programming language. However an RCX program is
composed of independent parallel tasks that can be controlled interactively from
TT. Using this capability, learners can “program” the RCX composing “behaviors”
that are developed by more skillful members of the Weblabs community. (See the "Interacting with an RCX program" tutorial for more info.)
The RCX extension is an Open Source software released (clic here TTRcx1.1.zip to download the source code) under the Mozilla Public License. The ToonTalk RCX software extension is based on, and incorporates source code from, the Not Quite C project.
How to install and upgrade the extension:
Download and copy this file TTRcx.dll to your ToonTalk directory, to install and/or upgrade the RCX extension.
The current version is: 1.1
To check the version of the
currently installed RCX extension, execute the following command:
How to set up and check the IR communication with the RCX:
To enable the connection between TT and the RCX, one must tell the program the port actually used by the IR tower (COM or USB). If everything is working correctly, i.e. the tower is connected to the PC and the RCX is on and oriented tower the tower, one hears a sound from the RCX.
To set up the IR tower use the
following command:
1. Sound
Play sound
Play a built in sound. The second hole in
the box contains the name of the sound. One of “key click”, “beep”, “sweep up”,
“sweep down”, “error”, “fast sweep up”.
2. Motor
On
Turn the specified motor/s on. The second
hole in the box contains the name of the motor: A, B or C. To control more than
one motor, put the motors names in a box.
Off
Turn the specified motor/s off and leave it in brake status. The second hole in the box contains the name of the motor: A, B or C. To control more than one motor, put the motors names in a box.
Float
Turn the specified motor/s off and leave it in neutral status. The second hole in the box contains the name of the motor: A, B or C. To control more than one motor, put the motors names in a box.
Set forward
Set the direction of the specified motor/s forward. The second hole in the box contains the name of the motor: A, B or C. To control more than one motor, put the motors names in a box.
Set backward
Set the direction of the specified motor/s backward. The second hole in the box contains the name of the motor: A, B or C. To control more than one motor, put the motors names in a box.
Reverse direction
Reverse the direction of the specified motor/s. The second hole in the box contains the name of the motor: A, B or C. To control more than one motor, put the motors names in a box.
3. RCX display
Set
Set the RCX display to monitor the
specified sensor, global variable or message. The second hole in the box
contains the word "display". The third the name of the value source, i.e. "sensor" or "var". The fourth contains the source index, an integer in the range [1..3] for sensor and [1..32] for var.
4. Message
Send message
Have the RCX send the specified message.
The second hole in the box contains the message number, an integer in the range [1..255].
5. Sensor
Get
Return the value of the specified sensor.
The second hole in the box contains the word "sensor". The third the sensor index, an integer in the range [1..3]. The fourth hole a bird.
Set
Tell the RCX the sensor type of the
specified sensor. The second hole in the box contains the words "sensor type". The third the sensor index, an integer in the range [1..3]. The fourth hole in the box contains the name of the type.
One of: "raw", "light", "touch", "temperature", "angle".
6. Variable
Get
Return the value of the specified variable.
The second hole in the box contains the word "var". The third the variable index, an integer in the range [1..32]. The fourth hole a bird.
Set
Set the value of the specified variable. The second hole in the box contains the word "var". The third the var index, an integer in the range [1..32]. The fourth hole an integer in the range [-32767 .. +32767].
7. Data log
Get Datalog Size
Return the actual number of currently
logged elements. The second hole in the box contains a bird.
Set Datalog Size
Clear the current data log buffer and allocates room for a new one of the given size. The second hole in the box contains an integer in the range [1 .. 1024].
Get Datalog Element
Return the specified data log element. The second hole in the box contains an integer in the range [1 .. 1024]. The third hole a bird.
Get Datalog Element Verbose
Return a specified data log element. Each element is a pair where the first component is a string describing the source of the log value (e.g., “Sensor1”) and the second component is the integer value. The second hole in the box contains an integer in the range [1 .. 1024]. The third hole a bird.
Set
Store a 3 byte data point in the log. If
there is no more space in the log, the data point is ignored. Only variables and
sensor values can be logged. The second hole in the box
contains the words "datalog element". The third the name of the value source, i.e. "sensor" or "var". The fourth contains the source index, an integer in the range [1..3] for sensor and [1..32] for var.
Get Datalog
Return the whole content of the data log (i.e., all the recorded elements). The second hole in the box contains a bird.
Get Datalog Verbose
Return the whole content of the data log. Each element is a pair where the first component is a string describing the source of the log value (e.g., “Sensor1”) and the second component is the integer value. The second hole in the box contains a bird.
8. Program/Tasks
Download Program
Download a compiled RCX program into the
specified program slot. The
second hole in the box contains the file name. The third hole an integer in the
range [1..5] indicating the program slot; if this parameter is omitted, the
current program slot is used.
Run Program
Run the program in the specified slot. The second hole in the box contains an integer in the range [1..5] indicating the program slot; if this parameter is omitted, the current program slot is used.
Stop Program
Stop the running program. If no program is running, the command has no effect.
Start Task
Start the specified task. The second hole in the box contains an integer in the range [1..9] indicating the task.
Stop Task
Stop the specified task. The second hole in the box contains an integer in the range [1..9] indicating the task.
9. Setup & checking
Get TTRcx Version
Return a string that identifies the
TTRcx.dll version currently installed. The second hole in the box contains a bird.
If this parameter is omitted, Marty will report the version.
Set Tower Port
Define the IR device port and optionally test the communication link by having the RCX play a sound. The second hole in the box contains the name of the port. One of: “USB”, “com1”, “com2”, “com3”. The third hole in the box contains the name of the sound. One of: “key click”, “beep”, “sweep up”, “sweep down”, “error”, “fast sweep up”. This parameter is optional.
Ping
Tests for the presence of the RCX and returns a string message. The second hole in the box contains a bird.
Note that: most commands require a bird parameter to return a completion code to TT – such a code is always a character string, with value “OK” if the command completed successfully, or an error message otherwise. It is possible for these commands to omit the bird parameter: in this case, successful completion of the command is not notified, whereas error messages are passed to Marty. This multiple exception handling policy accounts for two different user perspectives: the direct, interactive usage mode in which the user can deal with failures on the spot; and the programmed mode in which the TT program has to monitor the correct execution of the RCX command and knows how to react to possible exceptions. The above command description takes the viewpoint of the direct/interactive usage perspective.














