Most of the time there will be small differences between the encoder counts, you should use a tolerance value here, something like “if the difference between the encoders is less than 10 drive straight”
As Doug said, once you have given a motor a value of 90 or over the increase in power is minimal.
You need a couple more else statements, two of you tests are the same but set the wheel speeds the opposite way. Here is a revised version with the changes I described.
task autonomous()
{
SensorValue[LeftEncoder] = 0;
SensorValue[RightEncoder] = 0;
// This will drive forwards for the entire 15 second auton period
while (1 == 1)
{
// The assumption is that both encoders count up when motors are running forward
if( abs( SensorValue[LeftEncoder] - SensorValue[RightEncoder]) < 10 )
{
// Both motors the same speed
motor(leftwheels) = 127;
motor(rightwheels) = 127;
}
else
if(SensorValue[LeftEncoder] > SensorValue[RightEncoder])
{
// Left running too fast
motor(leftwheels) = 80;
motor(rightwheels) = 127;
}
else
{
// right running too fast
motor(leftwheels) = 127;
motor(rightwheels) = 80;
}
}
}