Ok, so I am getting a robot to follow a line and stop at an intersection. I am having trouble with the code for it stopping at an intersection. I don’t know why but the task intersection doesn’t work. The robot can still follow the line and the emergency stop still works when I compile and download it.
task intersection()
{
while(true)
{
if(SensorValue(lineFollowerRIGHT) > 2750)
if(SensorValue(lineFollowerCENTER) > 2708)
if(SensorValue(lineFollowerLEFT) > 2810)
{
stopMotor(port2);
stopMotor(port3);
wait(3);
}
}
}
task e_stop()
{
while(true)
{
if(SensorValue(dgtl1) == 1)
{
stopAllTasks();
}
wait1Msec(10); // this prevents the current task from hogging the CPU
}
}
task main()
{
startTask(e_stop);
startTask(intersection);
wait1Msec(500); // The program waits for 500 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) > 2750)
{
// counter-steer right:
motor[leftMotor] = 63;
motor[rightMotor] = 0;
}
// LEFT sensor sees dark:
if(SensorValue(lineFollowerLEFT) > 2810)
{
// counter-steer left:
motor[leftMotor] = 0;
motor[rightMotor] = 63;
}
// CENTER sensor sees dark:
if(SensorValue(lineFollowerCENTER) > 2708)
{
// go straight
motor[leftMotor] = 33;
motor[rightMotor] = 33;
}
}
}