Locomotion:Exercise2-Path Following
Contents |
Overview
This exercise involves programming the Create to follow a black line using two photoresistors. There is a small amount of setup required in order to use the photoresistors. Most of this setup amounts to taping, gluing, and experimentation.
The photoresistors used in this exercise measure light intensity. For the purpose of line following, they will detect a black line on a white surface that the robot should follow. Photoresistors work best with large differences in light intensity, thus the black line on a white background. The amount of ambient light in the room will also affect the photoresistors. After some trial and error, you will learn how to calibrate the sensors properly.
The rest of this exercise is organized as follows. First we will go over what must be done to setup the Create for line following. Then we will present the line following problem, and provide you with some hints. Expect to spend some time understanding how to best use and configure the photoresistors on the robot.
Setup
This exercise will require a little bit of manual setup, most of which is fairly easy. The first step is to hook-up the photoresistors, followed by mounting the photoresistors to the Create.
Photoresistor Setup
Photoresistors have the property of changing their resistance as light intensity changes. However, the analog-to-digital (A2D) converter on a microcontroller requires a voltage value. Therefore photoresistor must be modified to output a voltage change instead of a resistance change. This is accomplished by using a voltage divider circuit. This is a simple circuit and only requires soldering three wires and a resistor.
A voltage divider consists of two resistors in series. The voltage measured between these two resistors is dependent on the ohms of each resistor. If one resistor remains constant, while the other changes, then the voltage will also change thereby providing us with an input to a microntroller.
The equation for the voltage divider circuit is:
The diagram above depicts how the photoresitor circuit should be constructed. So let's walk through through this construction.
HowTo: Make A Photoresistor Cable
At this point we have a photoresistor connected to three wires. Now we need a method to connect this to our microcontroller. There are two different types of connections, one if you are using the gumstix/robostix and one if you are using the Create alone.
Gumstix/Robostix connection
Howto:Build a Robostix Sensor Cable Connector
Create E-Port connection
This will require three crimp pins for each of the wires.
Mounting Photoresistors
Mounting the photoresistors on the Create will require a little experimentation. Think about the problem, and how best you might attach the photoresistors to the Create. Some questions you might consider:
- Should they be placed in the front or back?
- Side by side or one in front of one another?
- Should they be place wide apart or close together?
There is no one correct answer. Try different configurations and find the best that works for you.
Paths
Use white paper, such as white butcher paper, as the background for the path. Use black electrical tape, or a black magic marker, to create a path. Start with a simple straight line, and move up to more complex patterns.
The Problem
The goal of this exercise is to have the robot follow a path. By this point, you should have created two photoresistors, and connected them to either the Robostix. Now we need to write control code for the robot. I will assume by this point that you know how to edit the exercise.cc file, compile and run your program.
A majority of the coding is left for you to fill in. As you will find, problem solving and analytical thinking are major requirements in robotics. So, I will only describe a few of the relevant functions you might use to solve this problem.
In order to get data back from the sensors, a few things need to be in place. First the photoresistors should be plugged into a pin that has an analog to digital converter. They should also be attached to a 5volt power supply and ground. Now to read the data we can use a function built into the Player Client: double Client::GetRobostixAnalog(unsigned int pin). This function takes an integer pin identifier, and returns the value that pin detects. For example, if we have a photoresistor attached to Pin 0 of the A2D port, then we would us this function:
double value = client->GetRobostixAnalog(0);
Here are few tips and tricks.
- Try shrouding the photoresistors. For example, you can use electrical tape to make tube to fit around the photoresistor. This will help reduce noise, and focus the photoresistor on the area immediatley below it.
- Solve this problem in steps. First just try to understand the values returned by the photoresistor, and how you might go about detecting the line. Remember to test, test, test.
- Try using a calibration routine. For example, measure the values from the photoresistor at the start of the program to form a basis.
- Play with velocities, if the robot moves too fast it may overshoot the line.
Here is one solution
![[LOGO]](/workbook/skins/workbook/create_small2.png)



