Line Tracking Code

Hi everyone.

I’m a programmer on a rookie team and we are trying to set up our line sensors. The line trackers are set up according to the guide released by NI, http://decibel.ni.com/content/docs/DOC-14730,although we wrote our own program in C instead of LabView. Does anyone have any advice or see any errors?

Also, I would like to try and debug this, but I can’t find the target console! I think it’s because I can’t connect to the cRIO, but I can still upload programs to it! It’s all very confusing. Yes, the cRIO has power when I am trying to connect it.

void Autonomous(void)
{
myRobot.SetSafetyEnabled(false);
if (ds->GetDigitalIn(ENABLE_AUTONOMOUS) == 1) // only run the autonomous program if jumper is in place
{
printf(“Entering autonomnous mode”);
/TrackingThreshold tdata = getTrackingData(WHITE, FLUORESCENT);
ParticleAnalysisReport par;
/

  	/*DigitalInput(UINT32 slot, UINT32 channel);*/

DigitalInput photoSensor1(8,3);
DigitalInput photoSensor2(8,4);
DigitalInput photoSensor3(8,5);

while ((photoSensor1 != 1) && (photoSensor2 != 1) && (photoSensor3 != 1)){
/getting digital input/
photoSensor1.Get(); //get for sensor 1
photoSensor2.Get(); // get for sensor 2
photoSensor3.Get(); //get for sensor 3

if((photoSensor == 0) && (photoSensor2 == 0) && (photoSensor3 == 1)){
printf(“Photo sensor 3 is active”);
myRobot->Drive(0.1, 0.0);
wait(0.5);
}else if((photoSensor1 == 0) && (photoSensor2 == 1) && (photoSensor3 == 1)){
printf(“Photo sensor 2 and 3 is active”);
myRobot->Drive(0.1, 30.0); //drive at .1 intensity at 30 degrees
Wait(0.5); //for .5 seconds
}else if((photoSensor1 == 1) && (photoSensor2 == 0) && (photoSensor3 == 1)){
printf(“Photo sensor 1 and 3 is active”);
myRobot->Drive(0.1, 30.0); //drive at .1 intensity at 30 degrees
Wait(0.5); //for .5 seconds
}else if((photoSensor1 == 1) && (photoSenosr2 == 0) && (photoSenosr3 == 0)){
printf(“Photo sensor 1 is active”);
myRobot->Drive(0.1, 30.0); //drive at .1 intensity at 30 degrees
Wait(0.5); //for .5 seconds
}else if((photoSensor1 == 0) && (photoSensor2 == 1) && (photoSensor3 == 0)){
printf(“Photo sensor 2 is active”);
myRobot->Drive(0.1, 30.0); //drive at .1 intensity at 30 degrees
Wait(0.5); //for .5 seconds
}else if((photoSensor1 == 1) && (photoSensor2 == 1) && (photoSensor3 == 0)){
printf(“Photo sensor 1 and 2 is active”);
myRobot->Drive(0.1, 30.0); //drive at .1 intensity at 30 degrees
Wait(0.5); //for .5 seconds
}else{

myRobot->Drive(0.1, -30.0); //drive at .1 intensity at -30 degrees
Wait(0.5); //for .5 seconds
}
}
//stop driving
//raise claw
//move backwards
}
myRobot.SetSafetyEnabled(true);
}

Thank you immensely

There’s a lot of problems.


/*DigitalInput(UINT32 slot, UINT32 channel);*/
DigitalInput photoSensor1(8,3);
DigitalInput photoSensor2(8,4);
DigitalInput photoSensor3(8,5);

You can’t have those sensors in that slot. Your digital sidecars have to be in slots 4 and 6, not 8.


/*getting digital input*/
photoSensor1.Get(); //get for sensor 1
photoSensor2.Get(); // get for sensor 2
photoSensor3.Get(); //get for sensor 3

This doesn’t do anything useful. You need to assign the result of those function calls to a variable, otherwise the data is lost. Something like:


bool left, middle, right;

left = photoSensor1.Get(); //get for sensor 1
middle = photoSensor2.Get(); // get for sensor 2
right = photoSensor3.Get(); //get for sensor 3

Then in your if/if else lines you’d use left, middle, and right instead of photoSensorX, e.g.


if((!left) && (!middle) && (right)){


myRobot->Drive(0.1, 30.0); 

You’re using this same command for every case; why? Don’t you want it to do different things depending on which sensors are active? Also, 0.1 is probably too slow. I’d say you should be doing at least 0.7 for your speed.

EDIT: There might be more, but that’s what jumped out at me.

I suggest pulling out the Line Tracking example code and using it as a REFERENCE
In WindRiver go to New > Example > VxWorks Downloadable Kernel > FRC Line Tracker Sample Program.

It can be very useful for getting an understanding to the way the sensors work