Sunteți pe pagina 1din 7

Line Follower

By: Jessica Noble Tufts University Center for Engineering Education and Outreach https://www.youtube.com/watch?feature=player_embedded&v=4v_iRb2dB oM

This lesson is part of the ROBOT CONTROL ACTIVITY SEQUENCE. For more activities in this sequence, see the Activity Sequences page. Introduction In this activity, we will learn how to create a robot that follows a line on the ground. It will use one light sensor to sense where the line is, and use this to control the motors to steer the car and stay on the line. Light Sensors in Line Following The light sensor measures reflected light. White or light-colored objects reflect more light than black/dark-colored objects. The sensor takes an average of the light reflected from a small area and outputs this value.

When following a line, the light sensor needs to be lined up over the edge of the line:

*Note: the values above are just for example--you need to test for yourself to see what value your sensor reads when it it centered over edge of your line. Changes in room lighting, distance from the floor, and shadows cast can seriously affect your robot's "centered" value. To help make ambient lighting effects negligible, try adding a "shade" made of paper or cardboard around your light sensor.

Experimentation Questions: 1. What would happen if the white and black colors were closer together? Say, dark brown and light brown? 2. What happens when you make the gain really big? Really small? 3. In case the lighting in the room changes, could you program your line follower to re-calibrate the light sensor when you push a button? Other Examples of Line Following Robots NXT Warehouse that uses Line Following Cute Mini-robots Zip around a User-Defined Line Ultra-fast Line Followers at the Robotic Games ___________________________________________________________ ______________________________________________ For the Teacher: We recommend linking your project's content to the nationally recognized Common Core Standards for literacy in science and math Learning Opportunities In this lab students should have the opportunity to understand the following: 1. How to create a system that controls movement to accomplish a goal 2. Light sensors 3. Optics

4. Proportional Control 5. Computer programming 6. Electronics and motors 7. Dynamics 8. Team work and collaboration Key Terms LabVIEW, NI, electronics, motors, light sensor, reflective light, sensitivity, proportional control, gain

Building and Programming Create a car with 2 motors, so that it has the ability to turn easily. Add a light sensor to the front of the car pointed straight down, as close to the ground as possible. You will also need a large piece of white or light colored paper (or several pieces of paper taped together) and a thick, black (or dark colored) marker. Alternatively, you can use a light floor and dark colored tape. Create a line (at least an inch thick) for your robot to follow. Add a few curves and corners to see how your robot will respond to these challenges.

For an in-depth discussion on how to read light sensor values, click here.

To keep the car on this line, you want to program it to stay at the light sensor value it reads when it is centered over the line. To do this, you need to create a proportional controller for your robot. Here are the programming instructions for your line follower: 1. Start with a while loop. Create a constant ("false") for the loop condition so that your program runs infinitely. 2. You need to know how far away the car has moved from "centered" on the line. To do this, you first need to read the light sensor value. Add a "Read Sensor" icon to the block diagram, and select "Read Light-->LED On" from the drop down. Create a constant at the port node and set it to the port you plugged your light sensor into.

3. Create a control to plug in your "centered" light sensor value. Subtract this from the the light sensor's "Scaled Value". 4. Next, you will need to add a gain that you can adjust to change the response of your car. Increasing the gain makes your car more sensitive to changes in the light sensor value. Add a "gain" control to your front panel, and multiply the output of the "Subtract" icon by this gain. This is how much you will need to adjust the left and right motor speeds to keep your robot on the line.

5. So, you now have the "distance" from center that your car has drifted, multiplied by a gain. We want to use this value to steer your robot back to the line. Add two "Motor Control" icons and assign each to a different motor port (e.g. Port A and Port B). You want the car to travel at a constant speed, and have the left and right tires speed up and slow down to turn. To turn left, the right tire should speed up while the left slows down. To turn right, the left tire should speed up while the right slows down. Add a "Subtract" icon in front of one Motor Control and an "Add" icon in front of the other. Create a control for the speed the vehicle should be going while on the line ("50" is a good start--it can be adjusted later), and wire this in to the top input of the Add and Subtract icons. Wire the correction values (the output node of the "Multiply" icon), to the bottom inputs of the Add and Subtract icons. (see the image if this is confusing). Wire these corrected Power values into the Motor Forward icons.

That's your completed line follower program, but how do we know what "centered" light value to plug in? Create a quick program to test light values: Create a while loop with a constant ("false") for the loop condition so that your program runs infinitely. Add a light sensor icon into the while loop and create an indicator coming off the "Scaled Value" node. Now, test your line--when the light sensor is centered over the edge of the line, look at the reading outputted to your front panel.

Remember this value and plug it in to your line follower VI. Target to the NXT and load your program. That's it! Try adjusting the gain and base speed of your line follower to see how fast you can get your robot to follow the line without falling off. If your robot is doing the exact opposite of what it is supposed to (i.e. constantly turning away from the line), you have a sign error somewhere in your program. You can fix this by switching you "Add" and "Subtract" icons,

throwing a negative in front of your gain, or simply moving to the other side of the line.

S-ar putea să vă placă și