Autonomous with Encoder not working

Here’s the relevant code. It doesn’t stop driving forward, like it doesn’t even register the condition. We’re using a Quadrature encoder. It’s driving us a little crazy.

task autonomous() {
motor[port2] = 127; // this section just raises our lift up 
motor[port3] = 127; 
motor[port10] = 127; 
wait1Msec(1100); 
motor[port2] = 0;
motor[port3] = 0;
motor[port10] = 0; 

motor[port8] = -127;
wait1Msec(1500); 
motor[port8] = 0;

SensorValue[rightEncoder] = 0; 

while(SensorValue[rightEncoder] < 720) { 
motor[port4] = 127; // our four driving motors - just want to drive forward a bit 
motor[port5] = 127; 
motor[port6] = 127;
motor[port7] = 127;
} 
} 

When your while loop ends, you need to set your motors to 0 manually. RobotC doesn’t do that for you.

Also, just as a side note, if the above suggestion doesn’t work try and change your while statement to this:

while(abs(sensorValue[rightEncoder]) < 720)         {

} 

So that if your encoder’s counting negative it will still stop :slight_smile:

That worked! Going to change that while loop as you suggested too. Thank you both.