Before You Begin Lighten up! What’s the point?

advertisement
Lighten up!
Before You Begin
What’s the point?
To help students understand that, like a touch sensor, a light sensor detects information from the
environment. The program then uses this information to determine the direction it will flow.
To help students understand that different kinds of sensors specialize in the different kinds of information
they detect. In designing a robot, the designer must consider the kind of information available in the
environment and use the appropriate sensors and programs.
To give students additional opportunities to compare programs that use sensor input to those that do not.
What you will need:
For each group:
The Robotics Inventions™ kit
A disk
A copy of the Technical Guide
Light sensor attachment building instructions, Constructopedia, pages 34-35
A small flashlight
A set of reflection stands (See A Note on Materials box page 6-4)
A building bin (optional)
• Student Activity Sheets
•
•
•
•
•
•
•
For the class:
• One pre-built Roverbot with a light sensor attachment
• Posterboards—one white, one black
• Transparencies # 6 and 7
Programs used: StartLight (to initialize all three input ports for the light sensor); Linetracker; StopNow;
StopShine
© 2002 The LEGO Group. Used here with permission.
6-1
© 2002 The LEGO Group. Used here with permission.
About the light sensor The light sensor can detect changes in light levels. It converts raw values read by the
sensor to percentages. Its values can range from 0 to 100. The RCX will register 100 when a bright light is
shined directly at the sensor. Ambient room light is around the 50s, and a dark closet is around the 20s.
Many factors affect the light sensor, including the RCX batteries (as they get older, programs may need
adjustments to light ranges previously used), ambient light, and interference from an IR tower. Therefore, it
happens that a program using a light sensor may work perfectly well one day and not at all the next.
Practically, that means that the light ranges set in a program may need to be adjusted.
Sensor Watcher
A light sensor can be set to detect a brighter or darker light reading, a blink, or any range between 0 and 100.
Stack Decision Makers
A light sensor can be set to detect a brighter or darker light reading, or any range between 0 and 100.
The Wait Until and Repeat Until can also detect a blink.
You can check the reading of a light sensor using the View button on the RCX. The numbers displayed
range from 0 to 100, where lower numbers represent areas that are darker than those represented by
higher numbers.
B-5
Important Note: Use the View button
on the RCX to get a reading from the light sensor on the display
window. Accurate information will be displayed only after you initialize the input port for that sensor. That
means that you have to download and run a program containing a light sensor block every time you-install
firmware.
Troubleshooting: If you are getting light readings that are not between 0 and 100, or the light reading
doesn’t make sense to you, download a program containing a light Sensor Watcher or a light Stack
Decision Maker and run it once before using the View button.
New commands introduced in
this activity
6-2
Activity Overview
By now, students have had some experience working with sensor input.
In this activity you will introduce the light sensor, a sensor that detects
light information.
First, you will introduce the need for a light sensor using one of several
options.
SW-2
SDM-2
If you choose to introduce it by the example of a robot tracking a line,
you will use the Linetracker program. Students will observe and will be
quite impressed with the jiggling nature of its behavior. First you will run it
on the track provided with the Mindstorms™ kit. Then you will remove
Roverbot from the track, placing it on plain paper, first on white paper
then on black. Students will observe that Roverbot turns one way on
white and the opposite way on black. From this behavior they will infer
that the RCX has a way of telling when it’s on a dark area and when on
a bright area. You will then show them the light sensor, explaining its
function.
© 2002 The LEGO Group. Used here with permission.
If you choose to introduce the need for a light sensor by analogy to the
touch sensor, you will place a white posterboard next to a black
posterboard. You will then remind the students of the robot that hit the
wall and stopped, asking them to think of how a robot would know to
stop if instead of a wall it had a black posterboard. It will be obvious to
students that a touch sensor could not obtain that information and they
are likely to suggest a light sensor (or a sensor that can tell light from
dark).
SDM-5
SDM-6
Next, you will have students work in small groups. Since the nature of light
input is more abstract than the press and release states of the touch
sensor, you will have the students first work on getting light readings from
different surfaces. This will help students understand that different
surfaces reflect different amounts of light. Only then you will have
students work on solving problems using information detected by a light
sensor.
As students work in small groups, you will direct them to take light
measurements from the relevant surfaces and to use these
measurements to set the thresholds in their programs.
Finally, you will have a class discussion, comparing the Table Bumper (if
students didn’t have a chance to build it, consider building one for
demonstration) and the light sensor as devices that can get information
from the environment and inform a program that can prevent Roverbot
from falling off the table.
(See Additional Programming
Highlights)
Prepare Ahead:
1.
Make enough copies of the Lighten Up! student activity for each student to have one.
2.
Make the Reflection Stands (See A Note on Materials box below).
3.
Download the StartLight program into slot #5 of an RCX. This program must run at least one time
before you can get light sensor readings from View on the display window. (See Important Note in
the box, page 6-2.) The StartLight program has 3 light sensor watchers, one for each port. By
running this program once, you configure all three ports for a light sensor.
6-3
4.
Prepare a Roverbot to track a line (If you choose to demonstrate in Whole Class Activity).
Suggestion: We recommend doing this part of the Prepare Ahead section after you have had a
chance to read through this Lighten Up! activity guide.
a) Build a light sensor attachment, following building instruction on pages 34 an 35 of the
Constructopedia.
b) Connect the light sensor attachment to one of the Roverbots, placing the connector wire on
input port #1.
c) Place Roverbot so that the light sensor is directly above the black line on the Track Sheet
provided in each Mindstorms™ kit. Use the View button on the RCX to get a light reading, and
write it down. Then move Roverbot so that the light sensor is directly above the light (white)
area. Write down the light reading you get here.
d) Open the Linetracker program. Look at the light ranges set for “if light” on each event
watcher. Check the reading with the light sensor above the black line to see if it falls within the
25..38 range set in the program. (For example, if your reading of the black line was 34 and the
range set in the program is 25 to 38, you do not have to adjust the range. However, if your
reading was 23, you must change the program to include the number 23 in the range set for
this event watcher.) Do the same for your light reading with the light sensor pointing at the
white background.
e) Download the Linetracker program into slot #5.
f)
Place Roverbot near or on the dark track and run it on program 5. It should track the edge of
the black line if the ranges are correct.
Important Note: Ambient light conditions may change from one day to another or at different hours of the
day. If your Linetracker does not behave as expected, check the light readings and see if they fall within
your dark and light ranges. Change the ranges as needed.
Also, turning on/off overhead lights may help, because it will change the light readings, and they may then
fall within your set ranges.
A Note on Materials
The Reflection Stands: There are many ways to prepare the reflection stands. The main idea here is to get a light reading
from different surfaces by aiming a light sensor at each surface and observing the value it displays on the RCX when you
use the View function. In order to compare the amount of light reflected from these surfaces, it is important to keep their
distance from the light sensor constant. The stands should be constructed so that the materials used can be placed
vertically on a table.
Surface considerations: We recommend using an array of achromatic surfaces (paper), including white, black, gray
and highly reflective metallic silver, such as Mylar. A word of caution is in place here regarding the gray sheets. When
we bought materials for our stands, we took an RCX with a light sensor to the art supply store and checked many gray
sheets. We were surprised by how much light was reflected or absorbed by some. Some sheets looked lighter than
others, but ended up reflecting less light because of their texture. Your objective is to find a gray that reflects a value in
between the black and the white values.
Stand construction: We suggest cutting the sheets to size and taping one sheet onto each side of a small box such as an
audio cassette case, so that each group will have 2 stands with 4 surfaces altogether.
Another way to prepare the stands could be to mount the different surfaces side-by-side onto a box such as a shoebox.
To do so, first cut each sheet into rectangles about the size of a small index card then tape them to the side(s) of the
box.
6-4
Programming for light sensor input: Like programming for touch sensor input, the RCX has to have a
program that can act on incoming light sensor information. For example, if a program is set to run a certain
way if the sensor detects bright light, then the program must have a way of monitoring changes in light
levels.
RCX Code offers several ways to obtain light sensor input, using Stack Decision Makers (red, orange, or
purple blocks) and Sensor Watchers (blue blocks).
Stack Decision Makers are incorporated in a stack of commands, checking for sensor input when their turn
to run comes. The program then continues top-down, block after block. The Wait Until block does what it
says, it waits until a certain condition is met. The Repeat While repeats a stack of commands while a certain
condition is met, and the Repeat Until does the same until a certain condition is met.
Sensor Watchers also check for sensor input, but they are not embedded in a stack of commands. They are
connected to the program at the top level (to the program’s title block). At this level, Sensor Watchers
monitor the sensors all the time (with preset intervals), checking for input repeatedly while other parts of the
program continue to run. With Sensor Watchers, a program can monitor up to nine sensor events.
Discussion Points
Getting Information from a Light Sensor
Whole Class Activity
Before students build a light sensor attachment: There are several ways to motivate a discussion about
light sensors and the kind of problems they help solve. In the following section of the whole class discussion
we outline three possible ways to get started.
a) For this example, you will need to download the program Linetracker.
Show the class the sheet printed with a black track that is in your Mindstorms™ kit. Place Roverbot
on the track and run it, using the Linetracker program. Encourage students to describe its behavior
as Roverbot moves along the track. Ask the students how they think Roverbot is following the line. It
is likely that students will notice that Roverbot is jiggling rather than moving in a straight line. To help
them focus on which motor is turned on, remove Roverbot from the track and place it on a clear,
white area (You can use the reverse side of the sheet or have some white posterboard within
reach). Students will see that it’s turning in one direction. Move it to a plain darker area (e.g., the
floor or a black posterboard) and it will turn in the opposite direction. If needed, remind students of
programs they wrote to have Roverbot turn. This hint usually helps students realize that Roverbot is
programmed to turn one way on dark and the other way on light. The question then becomes how
Roverbot gets light information.
If you choose to start with this example, be sure to download the program Linetracker onto your
Roverbot and test it in your room before you demonstrate it.
b) For this example, you will need to download the program StopNow.
Place a white posterboard adjacent to a black posterboard. Then place Roverbot on the far end
of the white posterboard.
Remind the student of the problems they solved previously, having Roverbot with a single bumper
move toward a wall, hit it, and then stop. Tell them that instead of a wall, you now have a light
area followed by a dark area. Your problem is to have Roverbot move on the white board and
stop when it gets to the black posterboard. It will be obvious to the students that a touch sensor
could not gather that information. The question then becomes how Roverbot gets information
about light and dark areas.
If you choose to start this way, download the program StopNow onto your Roverbot and test it in
your room before you use it for demonstration.
6-5
c) For this example, you will need to download the StopShine program.
Connect a light sensor to a long connector wire and attach it to port 1 of your Roverbot. Remind
students of a program they wrote for the touch sensor, telling Roverbot to stop moving when the
sensor is pressed. Now, run Roverbot using the StopShine program. Flash a light at the light sensor.
Roverbot will stop.
Following whichever example you chose to introduce the need for a light sensor, show the class the light
sensor. Explain that in order to tell changes in light (i.e., moving from a dark area to a lighter area; having a
light shined at it) a robot must have a way of getting that information. A light sensor gets light information
from the environment and converts it to percents. Therefore, the range is between 0 and 100.
Programming with Light Input
Small Group Activity
Taking light sensor measurements: Have students work in small groups, following the Lighten Up!
worksheet. Give each group the Reflection Stands and a flashlight. Students are instructed first to configure
a port for the light sensor and then to get light measurements. The most important point here is for students
to realize that light readings from surfaces change when the surface changes or when the light conditions
change. Dark surfaces reflect less of the light that hits them than lighter surfaces.
When students have finished the reflection activity, have them move on to solve the problem of having
Roverbot move about on the floor and stop when it reaches a white piece of paper laid on the floor.
Students will first build a light sensor attachment, following building instructions on page 34-35 of the
Constructopedia, then work on solving the problem. Since they already have some experience
programming with Wait Until or with a Sensor Watcher, allow them enough time to try solving the problem
on their own.
When students have had enough time to work on some of the problems, we recommend having a class
discussion, comparing the Table Bumper, Touch and Go activity, and the light sensor. Use Transparency 6 to
help guide the discussion. Remind the students of the problem—Roverbot should move on the table and
stop at the edge—and show that it can be solved with a touch sensor or a light sensor. Point out that the
kind of information coming in through the sensors is different, but the resulting behavior is the same.
Students will be able to see that programs are similar in structure, only one has a light sensor watcher with
defined ranges and the other has a touch sensor watcher with press and release states.
Transparency 6
© 2002 The LEGO Group. Used here with permission.
6-6
Programming Highlights
Setting a light sensor condition for a
Sensor Watcher or a Stack Decision Maker
Testing for a light condition can be set
automatically by the program or manually by the
user.
Autoset: Three conditions can be set automatically
© 2002 The LEGO Group. Used here with permission.
—Bright, Dark, and Blink. For the Bright or Dark
conditions the program registers the first incoming
reading from the light sensor as “neutral.” Any
subsequent light reading is then compared to the
neutral value. It is considered Bright when it’s higher
than neutral and Dark when lower. It might be
helpful to think of these conditions as relative to a
neutral, either brighter or darker than that first
reading. The range designated to Dark is always
lower than neutral, and the range designated to
bright is always higher than neutral.
The Blink condition is always a quick change
between bright and dark, analogous to the touch
sensor’s click event.
Here is an example of a program that sets the light
sensor conditions automatically.
SW-2
Be on the lookout Using the Autoset
mode to set sensor conditions for bright
and dark looks deceivingly simple.
However, students may have difficulties in
both understanding the concept of a
neutral reading and in actually obtaining
one when first running the program.
What you can do: You can start by
explaining manually set ranges. Tell
students that there is some trial and error
involved in determining the best ranges for
a problem. Point out that getting light
readings using the View button can reduce
the guesswork involved.
You can model the steps you would take in
solving a problem. For example, using a
black marker, draw two dime-size circles on
a piece of paper and color them in black.
Attach a light sensor to a long connector
wire and connect to the RCX. Moving the
light sensor over the paper, tell students
that you want the RCX to beep each time
it detects a black circle.
Explain that before you write the program,
you would get a light reading over a black
circle, say 38. You will then use this number
to help you determine the dark range where
If you use the gray, white, and black reflection
stands, pointing the light sensor at the gray when
you press the run button, the light reading obtained
is set as neutral. Pointing the light sensor to the white
stand will trigger the “Bright” stack; pointing it to the
black will trigger the “Dark.” Note that moving back
and forth between the white and the black stands,
will re-trigger the corresponding stacks.
you will tell the RCX to beep. In this case
you will probably set the range to 35-40.
Use the problem of having a vehicle moving
on an area and stopping when it gets to a
brighter area (e.g., move about on the floor
and stop when it reaches a white sheet of
paper.) to introduce the idea of an
automatically set range.
6-7
Beyond the Basics
What happens if a light is shined while a stack is still running?
If you shine a light at the light sensor once, the stack attached to the
watcher is set off. If uninterrupted, all the blocks in the stack will be carried
out. However, if you happen to shine a light again before the stack is
finished, the stack will start over from the top without executing the rest of
the commands.
Here a bright light will trigger
the stack. If shined once, the
entire stack will be carried out,
ending with a beep sound.
However, if a light is shined
again, while the stack is still
executing (e.g., while moving
backwards), the stack will start
over again and won’t carry out
the beep block.
Another important point here is that the Sensor Watcher runs independent of
other parts of the program. That means that the RCX can do more than one
thing at a time.
Here’s a simple example:
It beeps 3 times when it gets a
light reading between 80 and
100, then it spins. It moves
backwards for 3 seconds then
forward again when it gets a
reading between 35 and 50.
6-8
© 2002 The LEGO Group. Used here with pe rmission.
Here motors A and C are on.
Manual Set: Bright, Dark and Range can be set
manually by the programmer.
SW-2
Explain that what constitutes bright is
defined by what the program considers as
neutral. Point out that “bright” is used here
as a relative term, where bright means a
higher reading than neutral. In this case, the
light sensor is pointing to the floor where it
gets its first light reading, establishing this
as neutral. As long as the white sheet of
paper is brighter than the floor, the vehicle
When the condition If Bright is set manually, you decide
will stop when it gets there.
on the lower limit of the condition, say 75. Bright is then
considered as a light reading greater than 75. Note that
the block changed from reading “If bright” to “If light.”
As shown here in the
When the condition If Dark is set manually, you decide
on the upper limit of the condition, say 45. Dark is then
considered as a light reading less than 45. Note that the
block changed from reading “If dark” to “If light.”
StopBright program a
robot will move forward in
ambient light and to stop
when the light is brighter.
A range is always set manually. When setting the
range you define both the lower and upper limits of the
light range.
© 2002 The LEGO Group. Used here with permission.
6-9
Different programs, similar output: We use the
ZZforever and the Follower programs in the “Thinking
about It” section of the student activity to help
students understand the difference between a
program that uses input and a program that does
not use input.
In a program that does not use input to control its
flow, the behavior is predictable. In other words,
for a given robot, looking at the program one can
describe the path the robot will follow under any
conditions.
Be on the lookout
Working with a light sensor watcher,
students may continue to use the timed
stack components used in the ZZforever
program. In other words, students ignore
the function input serves in a decision
branch. They use a sensor watcher, but
they do not allow input to dictate
behavior.
The program ZigZagDark illustrates this
point.
In the ZZforever program, a
two-wheeled robot will move
in a zigzag fashion each time
the program runs.
By contrast, looking at the Follower program, one
cannot predict the path a two-wheeled vehicle will
follow.
Depending on the
light input, it could spin
right or it could spin
left for unknown
lengths of time, or with
certain alternate light
changes, it could move
in a zigzag fashion.
Here is an example of what some do:
In this program,
Roverbot will
zigzag when it’s
dark (range set
for 20-40)
rather than
when there are
alterations of
light and dark.
© 2002 The LEGO Group. Used here with permission.
6-10
Transparency #7
What you can do: Show students the
programs StopAt2 and StopLight,
Transparency #7.
Ask students which program they’d use if
they wanted their robot to move forward
while it’s dark. Have them explain how the
programs are different from each other.
© 2002 The LEGO Group. Used here with permission.
Note: Depending on your robot, you may
need to change the timing on the single
motor blocks in the sample program.
Going Independent
Allow enough time for students to solve the problems or to come up with their own problems to
solve. Encourage students to take light measurements using the View button to help them set
the thresholds of what would be considered as dark or bright areas. In all the problems, the
basic idea is that the program watches for changes in light readings. It then uses these changes
to direct the flow of the program.
Problem from student activity sheets: Write a program to make Roverbot stop when it gets to the
white paper on the floor.
6-11
RCXamples: Here are some sample solutions.
Once the motors are turned off,
Motors will turn on and off as Roverbot enters each light range.
they won’t turn on again.
When it hits the white paper (60-70), the robot will stop. If you
moved it to a dark area, the motors would turn on again.
Here is a common error. Thinking that Roverbot will continue to move while the range is between 40 and
50, students assume that when the light reading is out of the range, Roverbot will stop. But motors don’t
stop unless they are told to do so specifically (i.e., Off AC).
Motors won’t stop when you
move to a bright area. They’ll
stay on because nothing stops
them.
A proper solution would be to have Roverbot move when
the light readings are within range and stop when it’s above
the range as in the example above.
© 2002 The LEGO Group. Used here with permission.
6-12
Using the Repeat While or the Repeat Until Stack Decision Makers provides yet another set of solutions.
© 2002 The LEGO Group. Used here with permission.
Motors stay on
Motors stay on
is within range
reading is greater
while light reading
until the light
than 50. Then
(40-50). Then
they turn off.
they turn off.
Problem from student activity sheet: Make Roverbot move on the table and stop at the edge. (Robot lifesaving suggestion: when you try out your program, be prepared to catch your robot. Remember that
programs rarely work on the first trial.)
RCXample: Having a robot move on a table and stop at the edge is a variation of the above problem. The
idea here is that as soon as the light sensor is over the edge of the table (Roverbot is still on the table), it
gets a light reading from the floor rather than from the table. Usually this reading is lower than the one
obtained from the table’s surface.
As with the Table Bumper problem in the previous activity, encourage students to be prepared to catch
the robot in the first several trials.
Common Errors:
Students may expect motors to turn on while
the light reading is within range. But that’s
not the case. Motors stay on because there’s
no command that turns them off when the light
reading is out of range.
Motors stay on for 3 seconds. If
there is no change in light
reading, they won’t turn on again.
6-13
Problem from student activity sheets: Connect two light sensors to two long connector wires.
Write a program that will let you use the light sensors as remote controls to “take Roverbot for a
walk.”
Hint: Color one half of a small index card black. Leave the other half white. Use it to change the
input the program is receiving. This is easier to do if two people monitor the light sensor, each
responsible for one sensor.
RCXamples: Taking Roverbot for a walk using a “remote control”. Here students can either use a
flashlight to control the robot or a small card with black and white areas they can point at the
light sensor as needed.
apressing
Here activating both sensors makes Roverbot move forward. Activating one sensor makes it turn.
RCXtras: If appropriate, ask students to program Roverbot to follow a light, so that if they flash a
light at it, it would follow the light, otherwise it would turn.
Here are some sample solutions:
Roverbot will spin when the
light reading is equal to or less
than 70. It will move forward
each time a bright light is shined
at the sensor.
© 2002 The LEGO Group. Used here with permission.
Motor A turns on. When the light reading is between 90 and 100, motor
C turns on. Now that the two motors are on, Roverbot moves forward
6-14
as if following the light. Otherwise, it turns.
Download