Vex Line Follower Robot not detecting dark line on light surface

Hi, I am currently doing a school project for a VEX 2.0 3 Line Follower Robot. The integrity of the parts, sensors, cortex, and controller is perfecrly fine. The problem is that the robot will not follow the dark line on the light surface, and I believe is in the code. The current state of my code is:

#pragma config(Sensor, in6,    rline,          sensorLineFollower)
#pragma config(Sensor, in7,    cline,          sensorLineFollower)
#pragma config(Sensor, in8,    lline,          sensorLineFollower)
#pragma config(Motor,  port3,           rmotor,        tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor,  port9,           lmotor,        tmotorVex393_MC29, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task straight()
{
	motor(lmotor) = 30;
	motor(rmotor) = 25;
}

task turnleft ()
{
	motor(lmotor) = 25;
	motor(rmotor) = 25;
}

task turnright ()
{
	motor(lmotor) = -30;
	motor(lmotor) = 30;
}

task main(){

	while (1==1){
		startTask(straight);

		if (SensorValue[lline]  >  4000)
		{
			startTask(turnleft);
		//	untilDark(2200, cline);
		}

		if (SensorValue[rline]  >  4000)
		{
			startTask(turnright);
	//		(2200,cline);
		}


		if (SensorValue[cline]  >  2250)
		{
			startTask(straight);
		}
	}
}

Have you calibrated the sensors to know that 4000 is the correct value to use?

2 Likes

It’s been awhile since I’ve worked with VEX robots, which it’s a 2.0 robot. I forgot how to calibrate the sensors, so no, I haven’t.

Take a look at this Carnegie Mellon lesson. It should teach you what you need to know.

http://cmra.rec.ri.cmu.edu/previews/robot_c_products/teaching_rc_cortex_v2/

Edit: see the line tracking lesson

1 Like

Also, there is no untilDark function in the library of the RobotC program version that I am using. The version is 4.26.

Go through the lesson. I don’t think you need an UntilDark command - just use sensor values.

1 Like

Make sure the robot isn’t casting too much of a shadow on the light surface, it might help too add a flashlight under it

1 Like

I have put a light source underneith the robot to see if it would respond to the light. I’ve also put my hand over the sensors to see if the line followers would detect the dark and then move, but it did not work. I checked the debugger many times to see if the values through the sensors are within optimal range, and they are, but they are still unresponsive.

Are you using VEX Light Sensor or the Line Tracker Sensor?

Unlike Light sensor, Line Tracker has its own built-in infrared light source and doesn’t need any additional lighting.

Here is a great resource on how to use Line Trackers:

The main problem that I see with your code is that motor values for turnleft() and straight() are incorrect. Also you don’t have to start new task every time you need to adjust your heading.

And this is the sample code for the Line Follower robot with Triple Line Tracker:

2 Likes

I just got to class, and I downloaded the sample code into the robot, and it still isn’t detecting the line.

@MattyIce, next time when you get a chance, could you start your program under RobotC debugger, open sensors tab and see what values do you get when you move your robot over the line?

http://cdn.robotc.net/pdfs/cortex/support/testing.pdf

http://cdn.robotc.net/pdfs/cortex/support/robotc_debugger.pdf

https://www.youtube.com/results?search_query=robotc+cortex+debugging

2 Likes

Did you watch the lesson I posted?

1 Like