Before You Begin RCX to RCX Communication What’s the point?

RCX to RCX Communication
Before You Begin
What’s the point? Working with RCX messages may help students develop a better understanding of how
input is used by a program to determine its path. Since they set up a message as a numeric value
transmitted via infrared, it may become clearer to students that a program processes input digitally.
Identifying attributes shared by the light sensor watcher and the message watcher (both work with ranges
of values) may help students form a more general view of sensor input and how it affects a program.
What you will need:
For each group:
The Robotics Inventions™ kit
A disk
A copy of the Technical Guide
Any two pre-built robots (will need to coordinate with another group)
A small flashlight
A building bin (optional)
Student activity sheets
For the class: (Demonstration)
• 2 pre-built robots, one with a light sensor, and the other without a light sensor
• A flashlight
• Transparencies # 8 and 9
Programs used: Sender; Receiver
© 2002 The LEGO Group. Used here with permission.
Prepare Ahead:
Make enough copies of the RCX to RCX Communication student activity sheets for each student
to have one.
Download the program Sender onto a robot with a light sensor.
Download the program Receiver onto another robot (preferably a vehicle).
Prepare the materials needed for the “container analogy”. (See page 7-3 for details.)
New commands introduced in
this activity:
Activity Overview
This activity is designed to give students additional and somewhat
more complex problems to solve. Introducing the RCX to RCX
communication creates opportunities for students from different
groups to work together because two robots are needed to
establish communication, and each group has only one robot.
You will decide whether to introduce this activity while students are
still working with Roverbot or whether to postpone it until they build
new robots. By now, students might be asking to build something
new. If this is the case, we suggest delaying the introduction of this
section until after they have had a chance to build a robot of their
choice. Also, having different kinds of robots communicate with
each other may inspire students to come up with new project
First you will show the class how one robot is activated by another
one. You will tell the class that you have two robots, one with a light
sensor and the other without, explaining that you will set the robot
that doesn’t have a light sensor in motion using a flashlight. You will
then show the class the programs that run these robots and explain
the relationships between the sender and the receiver.
It is important for students to understand that for a receiver to get
more than one message, an old message has to be cleared before
a new one can be received. You will use a container analogy in a
class discussion to illustrate this point.
Students will then follow the RCX to RCX communication activity
sheet, first figuring out how to set up communication between two
robots, and then solving some problems.
© 2002 The LEGO Group. Used here with permission.
Discussion Points
Getting Information from a Light Sensor
Whole Class Activity
In this class discussion you will demonstrate how two robots communicate with each other. The sample
programs provided, Sender and Receiver work only if the sender has a light sensor and the receiver can
move. Depending on when you decide to introduce this lesson, students may still have their Roverbots built,
or they may already have other robots such as the Acrobot or the Inventorbot ready. Be sure to choose
one robot with a light sensor (or simply add a light sensor to it) and one that moves.
Set the robots so that they are within communication range. Note that they do not have to be pointing at
each other in order to communicate. Turn on both robots and set them to the appropriate program slots,
holding Sender and Receiver. Tell the students that you are going to shine a light at one robot and ask
them to pay attention to what happens. If needed, repeat this part of the demonstration, pointing out that
both RCXes are running before you shine a light at one of them.
Students will soon realize that shining a light at one robot generates a response in the other robot. You can
show them that the longer you wait before shining a light at one, the longer the other robot waits before
Tell the class that, indeed, the robots communicate. Explain that one robot sends a message and the other
robot has a program set to receive the message and act on it.
Show the class Transparency # 8. Explain that when two robots communicate, one sends a message and
the other one is set to receive a message. Point out that the message is just a number; it has no meaning
except for setting off a stack of commands in the receiver’s program.
It is important that students understand that a robot can send and receive messages and that an old
message must be cleared before a new message can come in. This concept of clearing a variable may be
foreign to your students. Consider using a container analogy here:
Write a short set of instructions on a piece of paper (e.g., touch your forehead 3 times) and tape it to a
small container such as a cup, a jar, or a box.
Write the range 10 to 20 on a label and tape it to the container.
Write some numbers on pieces of paper, small enough to fit in the container and large enough for the
students to see. Be sure to have some numbers between 10 and 20 and some that are outside that
Tell the class that you will carry out the instructions attached to the box each time a message within
range arrives.
Emphasize that there’s one rule: there can only be one message in the box at a time. If the box is
occupied, a new message can’t come in.
Put the first number in the box and ask the class:
a) Is the number within the set range?
b) Should I touch my forehead 3 times?
Leaving the card in the box, try inserting another message as you remind the class of the rule—one
message at a time. It will be obvious to the students that the old message has to be cleared before a
new one can come in.
Tell the class that the command to clear the message box is called Clear IR Message. Write this
command at the end of your set of instructions and repeat the demonstration one more time.
Have students work in small groups, coordinating the communication between their RCXes. The
Programming Highlights below explain the commands students must use to set up their senders and
Programming Highlights
RCXes can communicate with each other via their infrared ports. To communicate, one RCX sends a
message to another RCX that is programmed to receive a message. Just as an RCX must be programmed
to get input from touch or light sensors, it must be programmed to receive and process messages. Thinking
about the receiving end, it may be helpful to draw an analogy to the light sensor watcher. In the case of a
light sensor, a watcher is set to check whether light values fall within or outside a set range. A comparable
mechanism is set for the message watcher that checks whether an incoming message (number) is within or
outside a set range. If the incoming message is within the set range, the attached stack is set off. There are
two ways to check messages—IR Sensor Watcher and IR Stack Decision Makers. Note that all Stack
Decision Makers but Repeat While can make decisions based on IR input.
Sending a message A program can send a message
at any time. The message is sent via the infrared port
on the RCX (located on the side you would point to
the IR tower when downloading a program). The
message is a single, arbitrary number between 1 and
255. A program can be constructed to send a
message once, repeatedly, or whenever a condition
becomes true or false. The following examples illustrate
each of the above options.
Be on the lookout
Many students think that a set of
instructions is transmitted rather than a
signal that can be used to set off a
stack. In other words, students
sometimes expect to send a whole
program via infrared, just as a
program is downloaded to the RCX.
What you can do: Help students
Here the message “40”
is sent once.
by drawing an analogy to a person
receiving a signal or a password rather
message “52” is
sent over and
© 2002 The LEGO Group. Used here with permission.
Here the
than a set of instructions. The person
knows what to do when he or she
receives the signal. The signal just tells
the person “do it now,” the person
already knows what “it” means. For
example, tell a student to raise her hand
each time she hears the number 87.
Explain that the receiver already has
the instruction to raise her hand. She’s
just waiting for a signal to set off that
Use Transparency #9 to help guide a
discussion about sending messages.
Here the message “40” is sent
each time a bright light is
shined at the light sensor.
Be on the lookout
Receiving a message: A program has to be set to
receive a message and act on it, just as it has to be
set to receive light or touch information and act
There are two ways to set up a program to receive
a message: IR Sensor Watcher and Stack IR Decision
Makers (Yes or No, Wait Until and Repeat Until). In
both the receiver sets the condition for the
incoming message. It then evaluates incoming
messages for whether or not they meet the
condition (e.g., equal to a number, greater or
smaller than a number, or within a range). The
range can be set to any numbers between 1 and
Sometimes students set the widest range
possible, from 1 to 255. Later on, they are
surprised when their robot triggers
unexpectedly. (Basically what happens is
that any message sent across the room
triggers it. This can lead to some surprises
when different groups in the same room
are sending messages at the same time.)
What you can do: Tell students that
it is important to limit the range and to
coordinate it with the sender. Explain that
the wider the range, the more incoming
messages will be evaluated as true.
Here is an analogy that might be useful.
Describe a situation where at school, each
class has a letter code. When the letter is
The IR Sensor Watcher checks for messages over
announced, it’s their turn to go to the
and 10 it runs a stack attached to it. Here you can
happen if a teacher instructed a class to go
within the range.
letters in the alphabet.
and over again. If the incoming message is between 1
cafeteria. Ask students what would
attach only one stack. It is set off when the message is
to the cafeteria when they hear any of the
© 2002 The LEGO Group. Used here with permission.
Sometimes students think that a robot
can be either a sender or a receiver but
not both. In fact, a robot can send and
receive messages within the same
The IR Yes or No Stack Decision Maker checks
for a message once. If the incoming message is
greater than 200, it triggers the Yes stack,
otherwise it triggers the No stack.
Be on the lookout Many students think
Clearing a message An RCX starts with a clean
slate in the “message box” the first time a program
is run. When the first message is received and
evaluated, the message stays in memory. For a new
message to come in, the old message must be
cleared first.
that if they are using an RCX Sensor
Watcher, their program is set to check
the message repeatedly. They are right
to a certain extent—a sensor watcher
does check for messages repeatedly.
What they sometimes forget, however, is
that there’s already a message stored in
its memory and that it can’t receive a
new one until the old one is cleared.
What you can do: Use the container
analogy described in the Discussion
Points section above.
Message block must
© 2002 The LEGO Group. Used he re with permission.
The Clear IR
be added if the
program is to accept
additional messages.
If you do not clear a message, the program will
receive a message once (i.e., it captures the 1st
incoming message)and will then ignore subsequent
incoming messages.
Going Independent
Problem from student activity sheets: Recreate the sender program from the previous page. Change it
so that it will send a message only after a touch sensor has been pressed or a light is shined on a light
sensor. Have the receiver’s group program the robot to receive your message. (It’s okay for the receiver to
recreate the programs on the previous page.)
RCXamples: Here are some solutions to the problem.
Sender’s programs
The RCX sends a message
sends a
once after the
message just
every time the touch sensor is
touch sensor is
The RCX sends a
message every time you
shine a light at it.
Note that the programs can contain additional blocks in the same stack as the message, and can also
contain additional Sensor Watcher or Stack Decision Maker stacks.
Receiver’s programs
Note that here there’s no need to
clear the message under the Stack
Decision Maker Yes or No
because the program will look for a
message only once.
© 2002 The LEGO Group. Used here with permission.
When the IR Stack Decision
Maker Yes or No is nested within a
Repeat Forever command, the
message must be cleared because
the IR Stack Decision Maker will
check for a message repeatedly.
Problem from the student activity sheets: Write a program that has a robot return a message to the
sender, making the sender do something. (A sender can also be programmed to be a receiver.)
RCXample: Here is a program where the Receiver sends a message after it has received one.
message is sent after
the receiver has
received a message.
The Clear IR
Message block will
not affect the Send
IR Message block.
© 2002 The LEGO Group. Used here with permission.
Note that here a
Problem from the student activity sheets: Write a program that has the receiving robot respond to a
message only after its touch sensor was pressed (or a light shined on its light sensor).
RCXamples: Here is a sample solution.
© 2002 The LEGO Group. Used here with permission.
In this program either one
of the sensors or both can
receive input that will set
off the IR Message Stack
Decision Maker.
Important note: Because the Yes or No Stack Decision Maker will look for a message only once—
immediately after the sensor condition was met—the Sender must send the message repeatedly (i.e., in a
Repeat Forever block). This will ensure that whenever the touch sensor is pressed or a light is shined at the
light sensor a message will be coming.