04 - Intro Lego RCX Code
04 - Intro Lego RCX Code
http://www.gotbots.org
LEGO Mindstorms
http://mindstorms.lego.com
Contents of Kit
RCX Microcomputer CD-ROM Software Contructopedia 3 Guided Challenges 6 Pro Challenges USB Infrared Transmitter 718 pieces, including (the ISL kit has more!): 2 Motors 2 Touch Sensors 1 Light Sensor
Compatibility
Minimum Requirements for your PC:
Operating System CPU RAM Available Hard Disk Space Mouse Sound CD-ROM Speed Video Display Colors Modem (optional) Internet Browser (optional)
Windows 98* Pentium II 233 MHz 32 MB 115 MB Windows Compatible Sound Blaster 16 Windows Compatible Sound Device CD 8X 800 X 600 SVGA with 4 MB RAM Colors 16 bit 28.8 KBPS Netscape Navigator or Microsoft Internet Explorer
Infrared port
Downloads programs from PC, using infrared tower (also called IR Transmitter) Communicates with other robots
Features
Instruction set with 57 basic instructions, including:
Multiply and divide instructions Powerful bit-manipulation instructions
High-speed operation
All frequently-used instructions are executed in two to four states
Software Architecture
System ROM Layer Low level control software Interface to hardware Second piece of software
Firmware Located in RCX ROM
Firmware
Can bypass system ROM software
Allows complete control of RCX
Erased when power removed In RCX RAM Can use standard Firmware OR
Can be replaced with others brickOS, etc.
Caution
When changing batteries you may loose Firmware and all programs
Replace one at a time Do within one minute
Multi-Tasking
Threading
Multiple things at one time
H8/300 CPU
8-bit data 16-bit address space 8 X 16 bit registers (r0-r7) R0 function return R7 stack pointer 16 MHz clock
I/O Devices
Light Sensor
Two components Light detector Small light source Light turned on to find something close. Amplifies difference between light and dark. Great for line following
photo-transistor
electrical flow
Input Device
colors or gray levels on paper.
Touch Sensor
electrical flow
force
voltage measurement
Constant contact
Make sure bot does not fall off of a table
Input Device
Use as a push button
Others
You can buy or make you own sensors
Example: Temperature sensor Search online Lots of resources
http://www.plazaearth.com/usr/gasperi/lego.htm
Mindstorms Programming
LEGO Software
You can download and install the following MS Windows-based software:
The Lego Mindstorms RIS 2.0 software Software CD is in your LEGO Toolkit Bricx Command Center Software http://bricxcc.sourceforge.net/ http://bricxcc.sourceforge.net/nqc/ Also: The Lego Mindstorms SDK http://mindstorms.lego.com/sdk2point5/
Installing Firmware
Click on the Hardware Setup button to confirm correct connection of the IR Tower.
Installing Firmware
Be sure to position the RCX Brick in front of the IR Tower. During test, the IR Tower should emit a green light.
Installing Firmware
Your RCX Brick's display should change to the figure shown above if your computer was able to detect the RCX through the IR Tower.
Installing Firmware
The LEGO Mindstorms RIS 2.0 Launcher displays a final warning message before uploading the firmware to the RCX Brick.
Installing Firmware
As the firmware is being uploaded to the RCX Brick, the counter at the center of the display counts to around 2500 ...
Installing Firmware
Five default programs are also uploaded after successful installation of the firmware; then, the RCX Brick display should be as above.
Installing Firmware
Finally, the LEGO Mindstorms RIS 2.0 Launcher displays the following Settings panel.
Programming Languages
Any programming language has:
Task commands: Decision Structures (If-then, yes-no):
Input/Output, calculation
Statements that let you choose between two or more groups of statements Statements that let you repeat a group of statements
Let you give a name to a whole set of statements to create a new single, complex statement
Wait Blocks (Red) and Repeat Blocks (Orange): Yes or No blocks (yellow) Big blocks and My blocks Sensor Blocks (blue)
Task blocks (Input) Can run sequentially or concurrently
Small Blocks
Power
Turn motors on or off Set power level (1-8) Set or reverse direction
Variable
Do arithmetic operations
Reset
Reset light or timer
Sound
Beep (6 choices) Tone (choose frequency)
Advanced
Comm(unication)
Send or Clear IR message Display variable value Display clock
Repetition Blocks
Repeat blocks
Repeat a set number of times, forever, while some condition is true, until some condition is true Condition is value of internal or external sensor.
Wait blocks
These make the RCX do nothing until some condition is true
Decision block
Yes or No Block
Chooses between two options depending on whether a condition is true or false How could we choose between 3 options? Between 4 options?
Sensor Blocks
Sensors that get outside information:
Touch sensor Light sensor IR sensor Others not part of standard kit: Rotation, temperature, humidity, etc.
Sensor blocks attach to the main program block and operate concurrently to commands under the main program block
Alternate Firmware
Firmware replacements:
BrickOS: open-source, C/C++ based, RTOS http://brickos.sourceforge.net/ leJOS: open-source, Java-based http://lejos.sourceforge.net/ xs Lisp: Lisp-based http://www.xslisp.com/ pbForth: Forth-based http://www.hempeldesigngroup.com/lego/
References
Dean, Alice M. CS 102B: Robot Design, http://www.skidmore.edu/~adean/CS102B0409/ InSciTE: Innovations in Science and Technology Education, www.HighTechKids.org LEGO.com Mindstorms Home, mindstorms.lego.com