In the tutorial Navigate with Visible Light, you built a circuit and program that allowed an ActivityBot to seek out a bright light. What if you need the robot to seek out a target that you don't want to be visible to people? This tutorial will show you how to use the IR sensors from the Navigate with IR Headlights activitiy, along with an IR LED on another Activity Board, to build both a beacon and an ActivityBot that will seek out the beacon.
The most significant differences between the phototransistors used in the Navigate with Visible Light tutorial and the IR receivers used in the Navigate with Infrared Headlights tutorial are that:
The key to making this application work is to get the IR detectors to provide an analog-like output. Unfortunately, there isn’t a good way to do that directly. Instead, what we will do is make the beacon (IR transmitter) behave in an analog manner by varying its brightness. If we check the IR detectors over a period, the more times one of the IR detectors “sees” the beacon, the more directly lined up it is.
We'll test the beacon in a little bit.
WARNING: When the ActivityBot runs the code above, it will NOT stop when it gets to the IR Beacon! Although the code is designed to help the ActivityBot seek the beacon, there is no good way for it to know when it makes it to the beacon. You will need to add another sensor for that!
Remember that the IR receivers can only report that there is or is not a signal - they cannot report the strength or brightness of the IR signal. Instead, we are varying the strength of the transmitter - the beacon itself. By measuring how many times the beacon is seen over a period while its light is varying allows us to get the IR receivers to behave in a more analog manner.
To generate both the modulated (pulsed) IR signal AND the varying brightness, we will feed two different signals into the LED at the same time. The positive leg of the LED connects to P11, where the code is sending it pulses by turning it on and off 38000 times per second. The negative leg of the LED connects to D/A0, which is changing its voltage output from 0V (full brightness for the LED) to 1.6V (nearly off). Why is 0V bright and 1.6V dim? Because this is where we are connecting the negative leg. The result is that the “Sawtooth”-like output of D/A0 is subtracted from the 3.3V pulses from P11:
Three things can be adjusted to alter how the ActivityBot moves toward the beacon.
A low-pass filter is something that lets slow changes through but blocks fast changes. It does this by adding the newest measurements to the old ones, then averaging them. If you make smoothing smaller, it will give the old values less weight, so more rapid changes are allowed through it. If you make smoothing too large, the ActivityBot may not be able to react quickly enough to turn toward the beacon.
Links
[1] https://learn.parallax.com/tutorials/robot/activitybot/blocklyprop-robotics-activitybot-360%C2%B0
[2] http://www.parallax.com/product/32600