Вы находитесь на странице: 1из 4

IR Based Line Following

This document describes: 1. Assumptions about robot construction 2. Information about mounting and calibrating the IR sensors 3. How the control code operates 4. How to troubleshoot and tune the sample code to work after robots are modified and no longer meet the assumptions

1. Assumptions about Robot Construction


Six-wheel drop-center skid-steer robot with gray wheels eight inches in diameter PWM channel 1 controls the left center wheel PWM channel 2 controls the right center wheel Left and right motors are both controlled by Jaguar motor controllers with the jumper set to brake mode IR sensors are rigidly mounted on the front-center of the robot relatively far from the center of rotation and about two inches above the carpet The active portion of the sensors face the carpet and are connected to digital input signals 1, 2, and 3 in slot four and are wired to appropriate power and ground signals

(Note that for general driving, you may want to switch the mode to coast. You can accomplish this using a digital output or you can retune the control code so that it works with the jumper set to coast.)

2. Mounting and Calibrating Sensors


The IR sensors operate by shining light through a lens and measuring the intensity of the light that returns. Since the light wavelength is approximately 850nm, it is not visible to the human eye and is referred to as infrared, or IR. You may be able to view it using an inexpensive digital camera such as in a cell phone. The intensity of the reflected light is compared to a threshold trim setting. If the intensity is above this threshold, the sensor will return a digital true value and if it is below, it will return a digital false. This value is also indicated by the green, yellow, and orange LEDs that surround the calibration trim knob. The goal is to mount and calibrate the sensor such that the sensor shining on carpet produces false and shining on tape produces true. Mounting The sample source code assumes that the sensors are mounted side-by-side, 1.5 inches apart, center-to-center. Because the sensors use a lens to determine the effective distance and spatial sensitivity, the sensors will respond quite differently if rotated 90 degrees about the barrel.

The height of the sensors also affects the intensity of the returned light. If the sensor touches the floor, it will prevent light from entering the sensor entirely. However, if mounted far from the floor, less light will return to the sensor. Once , you have power to the sensor, you can use the built in calibration trim knob and built-in LEDs to determine a good mounting location for the flooring surfaces you are trying to differentiate. As an initial height, try mounting the sensors about two inches above the carpet. Another mounting consideration is the distance between the sensors to the point of rotation of the robot. In the following drawing, assume the robot rotates about point A, and consider the effect of mounting the sensors at points A, B, C, onsider and D. As the sensor is mounted farther from the point of rotation, the width of the tape represents a small robot rotation angle. Since the point of rotation smaller can change radically as the robot is modified, you may need to relocate the sensors or retune the algorithm as the weight, wheel friction, and center of gravity change. The sample code is tuned assuming that the sensor is mounted . relatively far from the point of rotation.

Calibration Before the robot can follow the taped line, each sensor must be calibrated so it can identify the tape and carpet materials. Once you have power to the sensors, an you should see one or more of the LEDs light up. The two states of the digital output are indicated by the green and yellow LEDs, with the orange LED indicating that the light intensity is well above the threshold. The trim knob that changes the intensity threshold is located on the end of the sensor, opposite t the cable. It can be adjusted w a small common screwdriver. with Begin by placing the mounted sensor above the carpet, and if necessary, turn the knob until the green LED is on and yellow is off. Move the sensor over the tape, tape

and if necessary, turn the knob until the green LED turns off and the yellow light turns on. Move the sensor back and forth to observe how it responds. If the tape responds. and carpet have enough contrast, you will be able to set the trim knob such that carpet produces green and tape produces both orange and yellow. duces If you are unable to differentiate the tape and carpet by changing the trim on the sensor, you may need to experiment with mounting height, different tape, etc.

3. Control code
The autonomous sample code is written as an edge follower. It uses two of the mple sensors to identify the edge of the line attempting to keep the outer sensor on the line, tape and the center sensor off the tape. After enough time has elapsed, it pays . attention to the third sensor in order to identify the T. The truth table used to follow the left edge is as follows: eft, -view. When Sensors are labeled as Left, Center, and Right, from the robots point-ofstanding behind the robot, facing the front, your left is the left sensor, etc. S Steer refers to a driving command that steers the robot left, right, or straight. L | C | R | Steer -----------------------0 | 0 | 0 | Defaults Right, but is based on previous nonzero state 0 | 0 | 1 | Straight 0 | 1 | 0 | Left 0 | 1 | 1 | Left 1 | 0 | 0 | Left 1 | 0 | 1 | Left

1 | 1 | 0 | Left 1 | 1 | 1 | Left or T State 0,0,0 uses the previous nonzero sensor state to determine whether the robot drove off the left or right edge of the line. This state data is initialized to turn to the right for following the left edge of the line. The data is not strictly needed to follow the straight line. However, the robot tends to overshoot the Y and this state data allows it to find the line again. The code assumes that the robot steering is symmetric enough to use a single gain and thus the values in the arcade steering table are 0, 1, -1 and are later multiplied by the steering gain. To get the robot to the T fast enough, the code uses a power profile indexed by the elapsed time to drive faster on the portion of the line assumed to be straight, and slows the robot in the sections where turning or stopping is anticipated. Elapsed time is also used to enable the T termination code. There are two profiles, one used to drive the Y and another for the straight line. This supports finer tuning, but may not be necessary, as the Y will work fine for the straight line. In order to follow the right edge instead of the left, the same table is used, but the index number is created with left and right sensors swapped, and the steering direction is negated. Since the table is very repetitive, it is actually implemented using a switch statement.

4. Tuning and Debugging:


If the sample code doesnt drive the robot as well as desired, or drives differently once modified for competition, it may need to be tuned. If the sensor LEDs do not correctly identify the tape and carpet, start by correcting that issue. First, adjust the trim knobs. If this isnt sufficient, consider the type of tape and the height of the sensors above the flooring. As the robot is modified, the robot point of rotation can change by a large amount. The steering gain may need to be increased to compensate for a larger turning friction or decreased if the robot pivots quickly and overshoots the line. The steering gain is simply a power percentage of the battery voltage. If the robot is not moving as quickly and is not steering as strongly, it may be useful to test with a fully charged battery before tuning. The power profile determines when the robot speeds ahead and when it slows to navigate expected turns. You may need to change the power settings depending on the robot weight and gearing. Also consider other ways of creating a power profile; perhaps using distance traveled rather than time.

Вам также может понравиться