0% found this document useful (0 votes)
329 views

04 - Intro Lego RCX Code

RCX Brick An autonomous LEGO microcomputer that can be programmed using a PC. RIS Kit contains 718 pieces, including (the ISL kit has more!): - 2 motors - 2 Touch Sensors - 1 Light Sensor

Uploaded by

gatobravo
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
329 views

04 - Intro Lego RCX Code

RCX Brick An autonomous LEGO microcomputer that can be programmed using a PC. RIS Kit contains 718 pieces, including (the ISL kit has more!): - 2 motors - 2 Touch Sensors - 1 Light Sensor

Uploaded by

gatobravo
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 53

California State University, Chico Intelligent Systems Laboratory Chico, CA 95929-0410

http://www.gotbots.org

LEGO Mindstorms RIS 2.0


Programming: Lego RCX Code
B.A. Juliano and R.S. Renner
September 2004

LEGO Mindstorms
http://mindstorms.lego.com

Robotics Invention System 2.0


RIS Kit

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

Not compatible with Windows NT or Windows 2000 operating systems.

Lego Electronic Components


The RCX Brick
A microcomputer 3 Output Ports (A, B, C)
For motors and other output devices

3 Input Ports (1, 2, 3)


For sensors

Infrared port
Downloads programs from PC, using infrared tower (also called IR Transmitter) Communicates with other robots

RIS 2.0 RCX Brick


An autonomous LEGO microcomputer that can be programmed using a PC. The RCX serves as the brain of LEGO MINDSTORMS inventions.

About the Brick


LCD (Liquid Crystal Display) Four buttons One internal speaker Three sensor inputs Three actuator outputs IR (Infrared) interface Battery level monitor

About the Brick


Hitachi H8 series microcontroller 8 bit CPU at 16 MHz 32 KByte RAM 16 KByte ROM for the BIOS serial I/O (input/output) ADC (analog digital converter) built-in timers

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

Can create new threads to accomplish Multi-Tasking

Hitachi H8/3292 Microcontroller

Hitachi H8/3292 diagram

Hitachi H8/3292 package

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

H8/3292 Block Diagram

RCX Memory Layout

I/O Devices

Output: Motor Input: Touch sensor, light sensor (builtin wire)


Also available: rotation sensors

Connectors: Wires with 2x2 connector plates on ends

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

Light Sensor cont.


Highly sensitive to ambient light
Sunlight is the worst

How to solve problem


Take two light sensor readings and subtract the background light

Sensitive to objects reflective surface.


Thus, difficult to measure distance.

Light Sensor cont.


Light measured as
0% (total darkness) to 100% (very bright).

Light Sensor cont.


light energy voltage measurement

photo-transistor

light energy voltage measurement

electrical flow

Uses for Light Sensor


Navigation
Black on white White on black

Find light Avoid light Sort colors


black Lego bricks yellow Lego bricks.

Input Device
colors or gray levels on paper.

Touch Sensor
electrical flow

force

voltage measurement

Uses for Touch Sensor


Detect contact
Wall detection Internal contact
Arm contact with internal parts

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

Sample Program Blocks

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/

Robot Design Process


1. Start with some task/project that requires a robot with certain capabilities 2. Plan out a combination of (a) physical design and (b) program design 3. Build the physical robot. 4. Create a program in a robot programming language 5. Download the program to robot using IR Tower. 6. Design and carry out a series of tests of your robot 7. Modify plan of mechanics and/or program as needed and repeat from step 3.

Robot Initialization: Firmware


The RCX brick has some built-in programming to provide basic functionality (like ROM or BIOS on a computer) Requires additional programming before you can write and download programs this is called firmware (like operating system on PC) Firmware lives in RAM random access memory that retains content only as long as power is supplied (batteries) Your programs live in RAM too, translated from your PC program to bytecode (like translating Java or C++ to machine code)

Before Installing Firmware


The LEGO Mindstorms RIS 2.0 Launcher must be installed (from the CD; be sure to reboot your computer after initial installation). Leave the LEGO Mindstorms RIS 2.0 CD in the drive when you plug in your USB IR Tower. Exit all Quick Launch applications on the Task Bar that rely on a USB connection these may interfere with the IR Tower. For example, PDA HotSync Manager applications are notorious for such interference.

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

Repetition Structures (Repeat, For, While):

Statements that let you choose between two or more groups of statements Statements that let you repeat a group of statements

Most modern programming languages have:


Subprograms (Subroutines, functions):

Some modern programming languages have:


Parallel processing (Concurrency)
Perform two or more sets of tasks at the same time

Let you give a name to a whole set of statements to create a new single, complex statement

Lego RCX Code Blocks


Program block: Small blocks (green):
Repetition commands Decision commands Subprograms Top block to begin every RCX Program Task commands, such as input, output, calculations

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.

Sensors that get internal information


Timer sensor Variable sensor

Sensor blocks attach to the main program block and operate concurrently to commands under the main program block

Limits of RCX Code


Example 1: Program robot to distinguish dark from light that works in a variety of room conditions. Example 2: Program robot to wander randomly, recording 50 light readings for later analysis These tasks cannot be done with RCX Code.

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

You might also like