24
IR-to-RF Link for the Lego RCX Eric P. Walklet Senior Project - Computer Engineering - 2005 Advisor: Prof. John Spinelli

IR-to-RF Link for the Lego RCX Eric P. Walklet Senior Project - Computer Engineering - 2005 Advisor: Prof. John Spinelli

  • View
    213

  • Download
    0

Embed Size (px)

Citation preview

IR-to-RF Linkfor the Lego RCX

Eric P. WalkletSenior Project - Computer Engineering - 2005

Advisor: Prof. John Spinelli

Presentation Agenda

• Introduction to the RCX• Statement of the Problem• Project Considerations• Block Diagram• Programming the RCX• The IR Circuitry• Crossbow Motes and TinyOS• Communicating Between Unlike Devices• RFRCX – Controlling the RCX with MATLAB• Challenges and Conclusions

IR-to-RF Link for the Lego RCX Slide 2

Introducing the Lego RCX

• Part of the Lego Mindstorms package for many years

• Three motors and three sensors

• Programmed using a proprietary language created by Lego

• Interfaces with a host computer through a 935-nm IR link with a USB tower

IR-to-RF Link for the Lego RCX Slide 3

Purpose of the Project

• To design an interface for the Lego RCX that does not require a line of sight to operate – such as an RF link

• To design a new “programming language” in MATLAB that can allow novice programmers to control the RCX

• Inspired by CSC-030

IR-to-RF Link for the Lego RCX Slide 4

Project Requirements

• Language must control all three motors and read all three sensors, at least

• Language must be simple enough to understand for a student with little programming experience

• Information must travel between MATLAB and the RCX via some type of RF link

• RCX is limited by a one-byte message buffer and an archaic protocol

IR-to-RF Link for the Lego RCX Slide 5

Crossbow Motes

• The building blocks of wireless sensor networks

• Operate at RF frequency of 900 MHz

• Capable of communication through RF or UART

• Ethernet Gateway allows communication with other devices through TCP/IP

• Programmed with nesC

IR-to-RF Link for the Lego RCX Slide 6

Block Diagram

IR-to-RF Link for the Lego RCX Slide 7

MATLAB

User’s PC

MIB600CA

Ethernet Gateway

Mote

Mote

IR RX/TX CircuitryLego RCX

900 MHz RF

935 nm IR

TCP/IP

Making the Most of One Byte

IR-to-RF Link for the Lego RCX Slide 8

From MATLAB to the RCX – Motor Control

From RCX to MATLAB – Sensor Status

100 scaled levels of sensitivity; now limited to 4 scaled levels of sensitivity

8 voltage settings, two directions; now limited to 3 settings in each direction + idle

Motor 1 Motor 2 Motor 3

Sensor 1 Sensor 2 Sensor 3

Even Parity

Even Parity

Odd Parity

Odd Parity

Programming the RCX with LeJOS

• LeJOS is a Java VM that replaces the standard RCX firmware

• Small enough to fit in the 32 kB (!) of memory

• Allows RCX programmers to use a language that they are already familiar with, though there are limitations

• Support for the entire RCX feature set… and beyond

IR-to-RF Link for the Lego RCX Slide 9

What the RCX Accomplishes

• Accepts a one-byte message from the IR receiver

• Uses that message to control the three motors accordingly

• Checks the status of the three sensors• Assembles the status of the three sensors

into a one-byte message• Sends the message back through the IR

transmitter

IR-to-RF Link for the Lego RCX Slide 10

I Can’t Believe It’s Not Java!while(true) // loop indefinitely{// reads in a message from the mote, and converts// it to binaryinBin = integerToBinary(dis.readInt());

// if the parity checks properly, set the motors// accordinglyif (evenParityCheck(inBin) &&

oddParityCheck(inBin)){

setMotors(inBin);}

// assembles a message from the status of the// sensors, and adds parityoutBin = convertBinary(setParity(getSensors()));

// sends the sensor messagedos.writeInt(outBin);dos.flush();}

if(motorNumber==1){

if((chArray[0] == 1) && (chArray[1] == 1)){

return 3; // motor is floating}else if((chArray[0] == 1) && (chArray[1] == 0)){

return 2; // motor is on, forward}else if((chArray[0] == 0) && (chArray[1] == 1)){

return 1; // motor is on, reverse}else return 0; // motor is off

}else if(motorNumber==2){

if((chArray[2] == 1) && (chArray[3] == 1)){

return 3; // motor is floating}else if((chArray[2] == 1) && (chArray[3] == 0)){

return 2; // motor is on, forward}else if((chArray[2] == 0) && (chArray[3] == 1)){

return 1; // motor is on, reverse}else return 0; // motor is off

}else if(motorNumber==3){

if((chArray[4] == 1) && (chArray[5] == 1)){

return 3; // motor is floating}

IR-to-RF Link for the Lego RCX Slide 11

Do You Speak Infrared?

• Need an IR receiver and transmitter to communicate directly with the RCX

• A Sharp GP1UW70QS remote control receiver collects sensor information from the RCX

• A PIC12C508A microcontroller modulates the motor messages at 38 kHz so they can be detected by the RCX, and outputs them through an IR photodiode

IR-to-RF Link for the Lego RCX Slide 12

Circuit Diagram

IR-to-RF Link for the Lego RCX Slide 13

What the IR Detector Sees

What the IR Diode Sends

Mote #2 – The Great Interpreter

• The RCX uses a unique protocol – eight bytes sent for a one-byte message

• Crossbow motes use a variation of HDLC for both radio transmission and UART communication

• The mote that connects to the IR circuit must change the message to a structure the RCX can understand

• Sends translated message to RCX via UART, and sends decoded message to gateway via RF

IR-to-RF Link for the Lego RCX Slide 14

TinyOS and nesC

• TinyOS is a native environment for small devices like the motes

• nesC is a modular language based on C

• Programs are formed by “wiring” interfaces and components to each other

• VERY DIFFICULT AT FIRST

• Each program requires a configuration and a module to operate

IR-to-RF Link for the Lego RCX Slide 15

A Look at the Configuration

configuration UARTRCXPacket{ provides { interface StdControl as Control; interface BareSendMsg as Send; interface ReceiveMsg as Receive; }}implementation{ components RCXPacket as Packet, UART;

Control = Packet.Control; Send = Packet.Send; Receive = Packet.Receive; Packet.ByteControl -> UART; Packet.ByteComm -> UART;}

/* Command to transfer an RCX-compatible packet */ command result_t sendRCXPacket(TOS_MsgPtr msg) { uint8_t* rcx_packet; result_t rval; // form RCX-compatible frame rcx_packet[0] = (uint8_t)(PACKET_HEADER); rcx_packet[1] = (uint8_t)(0xFF PACKET_HEADER); rcx_packet[2] = (uint8_t)(OPCODE_MESSAGE); rcx_packet[3] = (uint8_t)(0xFF -

OPCODE_MESSAGE);rcx_packet[4] = (uint8_t)(msg);

rcx_packet[5] = (uint8_t)(0xFF - rcx_packet[4]);

rcx_packet[6] = (uint8_t)(OPCODE_RETTOSUB); rcx_packet[7] = (uint8_t)(0xFF -

OPCODE_RETTOSUB); rval = call SendVarLenPacket.send(rcx_packet,

PACKET_SIZE);return rval;

}

IR-to-RF Link for the Lego RCX Slide 16

To send one byte to the RCX…

[0xFF] [~0xFF] [0xF7] [~0xF7] [message] [~message] [0x08] [~0x08]

Mote #1: Not Quite as Glorious

• Messages received from the RF network (i.e. Mote #2) are passed on to the Ethernet gateway, and further to the PC

• Messages received from the Ethernet gateway are sent to the wireless network to be

• Programming is the same as Mote #2, though lacks the RCX encoding

IR-to-RF Link for the Lego RCX Slide 17

MATLAB and the Motes

• Crossbow includes Java tools for sending and receiving messages to and from the wireless network

• Message Interface Generator (MIG) creates a message class unique to the programs installed on the motes

• Connection is made to the Ethernet gateway through a TCP/IP socket

IR-to-RF Link for the Lego RCX Slide 18

RFRCX

• Status of sensors and motors are stored to two global variables

• A variety of functions are assembled into a program to describe the RCX’s behavior

• Each function updates the global variables depending on user input or received messages

• Always something to send! Always something to receive!

IR-to-RF Link for the Lego RCX Slide 19

RFRCX in Actionfunction

setMotorBackward(number)if number = 1 motorSettings(1) = 0; motorSettings(2) = 1;elseif number = 2 motorSettings(3) = 0; motorSettings(4) = 1;elseif number = 3 motorSettings(5) = 0; motorSettings(6) = 1;endsetMotorParity;asInt = buildMessage;oMsg =

net.tinyos.rfrcx.RCXMotorMsg(asInt);

send(2,oMsg);

% drive forward% when a wall is hit% back up, and move forward% again

motorSettings = resetMotors;sensorSettings = resetSensors;setMotorForward(1);while getSensorValue(1) = 0

setMotorOff(2);endsetAllMotors(-1,-1,0);continue(100);setMotorForward(2);continue(100);setMotorForward(1);

IR-to-RF Link for the Lego RCX Slide 20

Problems and Challenges

• UART on the motes is prone to errors and failures

• Poor battery life on the motes without power-saving features

• nesC is not well documented• RCX hardware is proprietary• RFRCX is not as user friendly as it could

be• Price

IR-to-RF Link for the Lego RCX Slide 21

The Future

• Use multiple messages to have more control over the motors and other features

• Control multiple motes through the same gateway to address price issue

• Replace MATLAB with a true Java interface

• Packaging

• A direct-connect solution

IR-to-RF Link for the Lego RCX Slide 22

Acknowledgments

• http://www.xbow.com• http://www.tinyos.net• Kekoa Proudfoot

http://graphics.stanford.edu/~kekoa/rcx/• http://www.csdm.qc.ca/SJdelaLande/lesclasses/

4web/wwwrobotique/robotique_lego.htm• Prof. Spinelli• Crossbow (for their informative training seminar)• The rest of the CN/CS/EE department

IR-to-RF Link for the Lego RCX Slide 23

And a silent wave to all those in the room who were inspired to become engineers by the Legos they played with as a kid… including me.

Questions?