Line tracking and Shaft Encoders

How would I incorporate line tracking and shaft encoders together to make an autonomous code that is super accurate?

I am using robot c, and I know I know how to program each sensor to get our robot moving straight accurately by themselves.

Also any ample code would be nice.

After solving that problem how would I incorporate this code into this problem?
What if I had the robot following a line all the way to a goal. But while following this line I want to stop a little bit before the goal so I can score using our manipulator. How would I do this using the 2 sensors together? Is there even away without using ultrasonic sensors. (Don’t say touch sensors because I don’t want the robot to hit the goal then back up.)

If you know how to program each sensor individually, then this will not be difficult at all. You just follow the line, and check to see if you have arrived at a specific encoder value. Like this:


task main(){
  int endEncoderValue = 400; //whichever value you want the robot to travel to before it stops
  while(((SensorValue[enc1] + SensorValue[enc2]) / 2) < endEncoderValue){
    followLine();
  }
}

Now obviously this is a simple implementation that just checks the encoder value and doesn’t use PID or anything, but if you’re line following, it should not be a problem.

task main()
{
int endEncoderValue = 400; //whichever value you want the robot to travel to before it stops
while(((SensorValue[enc1] + SensorValue[enc2]) / 2) < endEncoderValue){
followLine();
}
}

After this code runs what if I want to go a different distance. Like instead of going until endEncoderValue = 400. What if I want to go until encoder value is 1000? How would I change the value of endEncoderValue? Would the code look like this?

task main()
{
int endEncoderValue = 400; //whichever value you want the robot to travel to before it stops
int endEncoderValue2 = 1000;
while(((SensorValue[enc1] + SensorValue[enc2]) / 2) < endEncoderValue){
followLine();
}
while(((SensorValue[enc1] + SensorValue[enc2]) / 2) < endEncoderValue2){
followLine();
}
}

That would work. You could also just change the value of endEncoderValue to 1000 after the first while loop ends.

If you look at Titan’s EasyC code from Roundup, Or Jordan’s Sparcs code,
you can see that he made a bunch of subroutines to do specific tasks,
then called them in a sequence to get a long autonomous or programming skills run.

The subroutines accept parameters like how far to drive, whether to drive straight or turn, max timeout, speed to drive, whether to stop on bump or stop on line crossing, etc.