RobotC Sensor Program

I would like someone to check my program for any errors and if it seems like it should work.

task autonomous()
{
resetSensor(LeftEncoder);
resetSensor(RightEncoder);

SensorValue[LeftEncoder] = 0;
SensorValue[RightEncoder] =0;

while (1 == 1)
{
if(SensorValue[LeftEncoder] == SensorValue[RightEncoder])
{
motor(leftwheels) = 127;
motor(rightwheels) = 127;
}
if(SensorValue[LeftEncoder] > SensorValue[RightEncoder])
{
motor(leftwheels) = 100;
motor(rightwheels) = 127;
}
if(SensorValue[LeftEncoder] > SensorValue[RightEncoder])
{
motor(leftwheels) = 127;
motor(rightwheels) = 100;
}
else
{
motor(leftwheels) = 0;
motor(rightwheels) = 0;
}
}}

I can give my motor and sensor setup if needed.

It looks like there is some assistance for you in this thread.
https://vexforum.com/t/response-to-robotc-sensor-program/38507/1

A few more comments.

  resetSensor(LeftEncoder);
  resetSensor(RightEncoder);

  SensorValue[LeftEncoder] = 0;
  SensorValue[RightEncoder] =0;

resetSensor and SensorValue] = 0 do the same thing, resetSensor is the natural language equivalent of setting the value to 0.

if(SensorValue[LeftEncoder] == SensorValue[RightEncoder])
{
motor(leftwheels) = 127;
motor(rightwheels) = 127;
}

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;
    }
  }
}