RCX to RCX Communication

advertisement
RCX to RCX Communication
For two robots to communicate, one has to send a message and the other has to be
prepared to receive the message. We will call one the sender and the other one the
receiver. A Mindstorms™ robot can send a message to another robot, making it do
whatever it is programmed to do when it gets the message. The infrared port that is
usually used for downloading programs is also used to send messages.
In this activity you will learn how to program your robot to send a message to another
robot. You will also figure out how to program the “other robot” to receive a message.
What you will need:
Two robots (cooperate with another group)
The Robotics Invention™ Kit
A flashlight
A disk to save your work
A copy of the Technical Guide
There is one way to send a message and many ways to receive one.
The Sender
You can have a send to RCX block anywhere in your program. When your program gets
to that block, it will send out a number.
© 2002 The LEGO Group. Used here with permission.
C-1
You can choose to send any number between 1-255. The number you send has no
meaning by itself. It is used to set off the receiver if it is in the range of numbers the
receiver is programmed to accept. Therefore, sender and receiver programmers must
work together to decide which number to send and which range to set.
The Receiver
For a program to receive a message, it has to have either an IR watcher or one of the
IR Stack Decision Makers. It also has to set the condition for which numbers to accept.
IR Watcher
IR Stack Decision Makers
Like all other sensor watchers, the IR
watcher keeps looking for a message
over and over again. When it gets a
message in its range, it will set off the
stack underneath it.
Like all other Stack decision Makers, the IR
Yes or No looks for a message once. If the
message is in its range, it will set off the
Yes stack. If the message is not in its
range, it will set off the No stack.
SW-4
SDM-4
© 2002 The LEGO Group. Used h ere with permission.
Wait Until The Wait until block will wait until
a number in its range comes in.
SDM-1
Here the program will wait for
a number between 10 and 20.
Here the program will wait
for a number greater than 35.
IMPORTANT: If your program is set up to look for a new message over and over again, you
must clear an old message so a new message can come in. Use the Clear IR Message block
to erase an old message from memory.
C-2
Here are some examples of simple sending-receiving programs. These programs can
work with many kinds of robots.
Sender Program
Receiver Program
Receiver Program
© 2002 The LEGO Group. Used here with permission.
RCXtras
Remember you can always come up with a problem of your own to solve.
1. 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 is okay for the receiver to recreate the programs on the previous
page.)
2. 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.)
3. 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).
Download