We are running a program using the triple line follower sample program and when we run the program the robot will follow the line for 6 inches and the begin spinning searching for the line and not be able to correct. We have the line sensors spaced out 1 inch between each, all motors and sensors plugged in properly and have made no edits to the sample code. If you cold plese give us some input that would be greatly appreciated.
Here is the sample program.
#pragma config(Sensor, in1, lineFollowerRIGHT, sensorLineFollower)
#pragma config(Sensor, in2, lineFollowerCENTER, sensorLineFollower)
#pragma config(Sensor, in3, lineFollowerLEFT, sensorLineFollower)
#pragma config(Motor, port2, rightMotor, tmotorNormal, openLoop, reversed)
#pragma config(Motor, port3, leftMotor, tmotorNormal, openLoop)
//!!Code automatically generated by ‘ROBOTC’ configuration wizard !!//
/----------------------------------------------------------------------------------------------------
|* - Triple Sensor Line Tracking - |
| ROBOTC on VEX 2.0 CORTEX |
| |
| This program uses 3 VEX Line Follower Sensors to track a black line on a light(er) surface. |
| There is a two second pause at the beginning of the program. |
| |
| ROBOT CONFIGURATION |
| NOTES: |
| 1) Reversing ‘rightMotor’ (port 2) in the “Motors and Sensors Setup” is needed with the |
| “Squarebot” mode, but may not be needed for all robot configurations. |
| 2) Lighting conditions, line darkness, and surface lightness change from place to place, |
| so the value of ‘threshold’ may need to be changed to better suit your environment. |
| |
| MOTORS & SENSORS: |
| * [Name] [Type] [Description] |
| Motor - Port 2 rightMotor VEX 3-wire module Right side motor |
| Motor - Port 3 leftMotor VEX 3-wire module Left side motor |
| Analog - Port 1 lineFollowerRIGHT VEX Light Sensor Front-right, facing down |
| Analog - Port 2 lineFollowerCENTER VEX Light Sensor Front-center, facing down |
| Analog - Port 3 lineFollowerLEFT VEX Light Sensor Front-left, facing down |
*-----------------------------------------------------------------------------------------------4246-/
//+++++++++++++++++++++++++++++++++++++++++++++| MAIN |+++++++++++++++++++++++++++++++++++++++++++++++
task main()
{
wait1Msec(2000); // The program waits for 2000 milliseconds before continuing.
int threshold = 505; /* found by taking a reading on both DARK and LIGHT /
/ surfaces, adding them together, then dividing by 2. */
while(true)
{
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -+
displayLCDCenteredString(0, “LEFT CNTR RGHT”); // Display |
displayLCDPos(1,0); // Sensor |
displayNextLCDNumber(SensorValue(lineFollowerLEFT)); // Readings |
displayLCDPos(1,6); // to LCD. |
displayNextLCDNumber(SensorValue(lineFollowerCENTER)); // |
displayLCDPos(1,12); // L C R |
displayNextLCDNumber(SensorValue(lineFollowerRIGHT)); // x x x |
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -+
// RIGHT sensor sees dark:
if(SensorValue(lineFollowerRIGHT) > threshold)
{
// counter-steer right:
motor[leftMotor] = 63;
motor[rightMotor] = 0;
}
// CENTER sensor sees dark:
if(SensorValue(lineFollowerCENTER) > threshold)
{
// go straight
motor[leftMotor] = 63;
motor[rightMotor] = 63;
}
// LEFT sensor sees dark:
if(SensorValue(lineFollowerLEFT) > threshold)
{
// counter-steer left:
motor[leftMotor] = 0;
motor[rightMotor] = 63;
}
}
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*
I really don’t like the sample code as if the left one sees a line it always executes that. It also loops through too fast.
is your threshold really 505??? What are your values for dark mat reading versus light mat reading?
try this…
task main()
{
wait1Msec(2000); // The program waits for 2000 milliseconds before continuing.
int threshold = 505; /* found by taking a reading on both DARK and LIGHT */
/* surfaces, adding them together, then dividing by 2. */
while(true)
{
// CENTER sensor sees dark:
if(SensorValue(lineFollowerCENTER) > threshold)
{
// go straight
motor[leftMotor] = 63;
motor[rightMotor] = 63;
}
// RIGHT sensor sees dark:
else if(SensorValue(lineFollowerRIGHT) > threshold)
{
// counter-steer right:
motor[leftMotor] = 63;
motor[rightMotor] = 0;
}
// LEFT sensor sees dark:
else if(SensorValue(lineFollowerLEFT) > threshold)
{
// counter-steer left:
motor[leftMotor] = 0;
motor[rightMotor] = 63;
}
wait1Msec(20);
}
}
Thank you! Will try that today!