Question: Write a program to operate the Pololu robot so it follows a black line on the floor. Use the design in the given structure diagrams.

Write a program to operate the Pololu robot so it follows a black line on the floor.

Use the design in the given structure diagrams.

The robot should stop if it goes off the line.

If the line is a loop, the robot should run until you stop it by turning off its power. Suitable lines will be provided (straight line, circle and ellipse).

The Pololu robot has five light reflectance sensors under the front edge of the lower circuit board. These detect the darkness of the surface directly below the sensor. The Atmel microcontroller on the lower circuit board measures the reflection of light and calculates a value from 0 (white) to 1000 (black) for each sensor. The m3pi class has a function (method) named readsensor that gets the values of the five light sensors. In your program, you need to define a suitable int array and use that as a parameter when calling the readsensor function. The function returns the five sensor values in the array. The array contains the values of the sensors from left to right. Array index 0 has the value of the leftmost sensor through to array index 4 with the value of the rightmost sensor. The sensor spacing is designed to work well with black lines that are 1.8cm wide. Before using the sensors, it is necessary to calibrate them to compensate for ambient light conditions. The m3pi class has the function sensor_auto_calibrate to do this. Call this function once near the beginning of the program before using the sensors. Then call the readsensor function to get the sensor values, as often as necessary for your program. When your program uses the light sensors, place the robot sensors over a black line, then start the robot. The calibrate function will turn the robot left and right across the line, to measure the light reflection from white and black regions under ambient light conditions.

Example Program Code:

m3pi robot(p23, p9, p10);

int main()

{

int sensor[5]; // array for the 5 sensor values float line;

robot.sensor_auto_calibrate(); // calibrate the sensors while(1)

{

robot.readsensor(sensor); // get the 5 sensor values

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!