|
Hello and welcome to my LEGO page!!
I have recently developed a real-time interface
to program Lego RCX 1.x/2.0 in VC++ 6.0 environment. It works by
directly accessing the serial/USB port of the windows operating
systems. The interface is based on the RCX programming
opcodes.
Features:
- Real-time interface written in VC++ to interface directly with
the RCX 1.x/2.0 (without spirit.ocx).
- Works with both the serial-port IR-Tower as well as the new
USB-Tower.
-
Auto-firmware download (downloads the firmware if there is none on
the RCX brick)
- Easy-to-use APIs.
- Provides better control of the motors/sensors/sound.
- Supports debug mode (optional)
How it works:
The Lego Class, lego, contained in
lego.h defines the basic interface. It supports
the APIs for communicating with the RCX brick through a
USB/serial-port IR-Tower. It also contains APIs to provide a good
debugging environment. Some of them are briefly discussed below:
Communication APIs:
|
API Name |
Input Params. |
Description |
Example Usage |
|
open |
None |
Opens the USB/serial port
for communication with the IR Tower. |
lego.open( ) |
|
close |
None |
Closes the USB/serial port
for communication with the RCX brick and de-initializes the Lego
Mindstorms. |
lego.close( ) |
|
DbgOn |
None |
Turns on the Debug Mode of
Lego System |
lego.DbgOn( ) |
|
DbgOff |
None |
Turns off the Debug Mode
of Lego System |
lego.DbgOff( ) |
Functions to Control Sensors:
Data types associated with sensor APIs are defined in the header
file lego.h. Sensors are addressed as
S1, S2,
and S3.
|
API Name |
Input Params |
Description |
Example Usage |
|
SetSensor |
-
SENSOR_NAME
sensor
-
SENSOR_TYPE type
|
Configures
a particular sensor port, on the RCX brick, as a LIGHT, TOUCH,
or ROTATION sensor. |
lego.SetSensor(S2,
TOUCH_SENSOR)
|
|
ReadSensor |
-
SENSOR_NAME name
- int&
sensor_val
|
Provide the means to read sensor
value. A call to this function with appropriate parameters
stores the sensor reading in its second argument , sensor_val. |
lego.ReadSensor(S2,
sensor_val) |
APIs to control Motors:
Motors are named as A,
B and C.
Direction parameter in SetMotorDirection is an enum and can
take two values: FORWARD and
BACKWARD.
|
API Name |
Input Params |
Description |
Example Usage |
|
SetMotorSpeed |
-
MOTOR
motor
- int speed
|
Sets
the speed of a particular motor. The second
argument can
take values from 0 to 7. |
lego.SetMotorSpeed(A,
3) |
|
SetMotorDirection |
-
MOTOR
motor
- DIRECTION
dir
|
Sets the
direction of rotation of a particular motor. |
lego.SetMotorDirection(A,
BACKWARD)
|
|
StartMotor |
MOTOR motor |
Turns on a motor. |
lego.StartMotor(B) |
|
StopMotor |
MOTOR motor |
Turns off a motor. |
leog.StopMotor(C) |
Sound APIs:
|
API Name |
Input Params |
Description |
Example Usage |
|
SetSound |
LEGO_SOUND
sval |
Plays one of the inbuilt Lego
sounds in the RCX brick. |
lego.SetSound(BEEP_BEEP) |
|
SetTone |
-
int freq
-
int dur
|
Plays sound at frequency ?freq?
for the duration ?dur?. The first argument can take
values from 1-20000 (human audible range) and second one takes
values from 1-255. The tone duration, dur, is measured
in 1/100ths of a second. |
lego.SetTone(50, 100) |
Limitations:
-
React Time: The RCX IR-interface runs at
2400bps and average packet size is 16-bytes, which makes each
packet approx 53ms. A basic control logic requires reading a
sensor and then acting on it, say, start the motor-A, which sums
up to a delay of 3x53 = 159ms. Some applications may demand
a better react-time. The Solution: replace IR-based communication
with some sort of FM-transceiver system (currently working on it).
- Unix: Though the interface is written in VC++, it can
be made to work in Unix environment if WIN32 socket calls are
replaced with appropriate Unix utility functions.
Download:
Lego Links:
This website and I
have no affiliation whatsoever with the Lego group. By entering this
site, you agree to not hold me responsible for any damage that may
occur from use of this website. Use this
information at your own risk. |