Datasheet
Page 200 · Robotics with the Boe-Bot
measurements. The program has a subroutine named Duty_Auto_Adjust that
automatically adjusts the
duty variable to help prevent rooms that are too dark from
disabling the Boe-Bot’s servos and rooms that are bright from blinding the light sensors.
After calling the
Light_Sensors subroutine, the Light_Shade_Info subroutine does
some math on
tLeft, tRight, and the duty variable to calculate the light variable’s
value, which again indicates the overall light level. Next, it calls the
Duty_Auto_Adjust
subroutine, which adjusts the
duty variable to try to keep the sum of the RCTIME
measurements in the 1800 to 2200 range. Really dark rooms will still cause the servos to
make the wheels twitch instead of turn, and direct sunlight will still blind the Boe-Bot,
but
Duty_Auto_Adjust significantly extends the range of light conditions that the
Boe-Bot can automatically adjust to and navigate in.
Next, the
Light_Shade_Info subroutine normalizes the difference between the two
sensors by calculating how much of the total light (measured by both sensors) a single
sensor sees. It does that by solving this equation:
tRighttLeft
tLeft
ndShade 1000500
This equation solves the problem of shade having different values in rooms with different
light levels. It simply divides one measurement into the sum of both measurements for a
fractional result that could range from 0 to 1. It then multiplies this by 1000 for a result
that could range from 0 to 1000. It then subtracts all that from 500, for the
ndShade
variable value, which ranges from -500 to 500.
Let’s say that
tLeft is 1500 and tRight is 500. That means there’s shade over the
Boe-Bot’s left light sensor. If you plug the values into the equation, the result will be
-250. Now, in a darker room, that same shade condition might cause
tLeft to be 3600
and
tRight to be 1200. Those values still result in an ndShade value of -250.
Use the
ndShade equation to calculate both pairs of values discussed in the
paragraph above.
You might have also noticed a new and different feature in the Constants/Variables
section:
Negative CON 1. This is a constant declaration, and it allows you to use a
name in place of a number in your program. Instead of using the number 1 at a certain
point in the program to check to find out if a number is negative, the program uses the