IME problem

I’m using IMEs on my base to drive straight and to the correct distance and it works but sometimes the robot keeps going forward or keeps turning, etc. and doesn’t stop when the target is reached. When the robot gets stuck turning or going forward, the lights on the IMEs are still flashing green so I think the IMEs aren’t damaged

  1. Do I have to reset the IMEs in another place other than in preauton and in the function itself.
  2. Is it better to use abs() f an encoder or to multiply the value by -1?

This is the code for the 4 drive functions
/// pot

void Backward (int distance, int speed, int correction)
{

resetMotorEncoder(port9);
resetMotorEncoder(port2);
while (getMotorEncoder(port9) < distance && ((getMotorEncoder(port2)) * -1 ) < distance)
{

if( getMotorEncoder(port9) > ((getMotorEncoder(port2)) * -1) )
{
motor[LDriveBack] = speed - correction;
motor[RDriveBack] = -speed;

}
if( getMotorEncoder(port9) < ((getMotorEncoder(port2)) * -1) )
{
motor[LDriveBack] = speed;
motor[RDriveBack] = -speed + correction ;
}
else if ( getMotorEncoder(port9) == ((getMotorEncoder(port2)) * -1) )
{
motor[LDriveBack] = speed;
motor[RDriveBack] = -speed;
}

}

motor[LDriveBack] = 0;
motor[RDriveBack] = 0;

}

void Forward (int distance, int speed, int correction)
{

resetMotorEncoder(port9);
resetMotorEncoder(port2);
while (((getMotorEncoder(port9)) * -1) < distance && getMotorEncoder(port2) < distance)
{

if( getMotorEncoder(port2) > ((getMotorEncoder(port9)) * -1) )
{
motor[LDriveBack] = -speed ;
motor[RDriveBack] = speed - correction;

}
if( getMotorEncoder(port2) < ((getMotorEncoder(port9)) * -1) )
{
motor[LDriveBack] = -speed + correction;
motor[RDriveBack] = speed ;
}
else if ( ((getMotorEncoder(port9)) * -1) == getMotorEncoder(port2) )
{
motor[LDriveBack] = -speed;
motor[RDriveBack] = speed;
}

}

motor[LDriveBack] = 0;
motor[RDriveBack] = 0;

}

void TurnR (int distance, int speed, int correction)
{

resetMotorEncoder(port9);
resetMotorEncoder(port2);
while (getMotorEncoder(port2) < distance && ((getMotorEncoder(port9)) *-1) < distance)
{

if( getMotorEncoder(port9) > getMotorEncoder(port2) )
{
motor[LDriveBack] = speed - correction;
motor[RDriveBack] = speed;

}
if( getMotorEncoder(port9) < getMotorEncoder(port2) )
{
motor[LDriveBack] = speed;
motor[RDriveBack] = speed - correction ;
}
else if ( getMotorEncoder(port9) == getMotorEncoder(port2) )
{
motor[LDriveBack] = speed;
motor[RDriveBack] = speed;
}

}

motor[LDriveBack] = 0;
motor[RDriveBack] = 0;

}

void TurnL (int distance, int speed, int correction)
{

resetMotorEncoder(port9);
resetMotorEncoder(port2);
while ( ((getMotorEncoder(port9)) *-1) < distance && ((getMotorEncoder(port2)) *-1) < distance)
{

if( getMotorEncoder(port9) > getMotorEncoder(port2) )
{
motor[LDriveBack] = -speed ;
motor[RDriveBack] = -speed + correction;

}
if( getMotorEncoder(port9) < getMotorEncoder(port2) )
{
motor[LDriveBack] = -speed + correction ;
motor[RDriveBack] = -speed ;
}
else if ( getMotorEncoder(port9) == getMotorEncoder(port2) )
{
motor[LDriveBack] = -speed;
motor[RDriveBack] = -speed;
}

}

motor[LDriveBack] = 0;
motor[RDriveBack] = 0;

}

Thanks in advance

Your correction value is static for the entire length of the run. If your distance its great, the correction may be too much.

Can you verify in the debugger the values of the encoder are what you want them to be?

Maybe put a write debug line in each while loop?

Also you may want to put a wait1Msec(20); befor elooping around again as you will be setting the values over and over again before the motor can react. But that is probably not the issue.

One issue we had is that 1/5 runs our robot wouldn’t stop at the correct IME values and the solution we came up with was grounding the robot and unplugging and replugging the IMEs before every run. After doing this we haven’t had the issue again.

That seems to fix the issue for now.

If the problem continues, I’ll keep updating the thread.
Thanks and on a side note, how do I write a debug line in RobotC@Team80_Giraffes ?

http://robotc.net/w/index.php/Debug_Stream


writeDebugStreamLine("port9 is: %d,  port2 is: %d",getMotorEncoder(port9),getMotorEncoder(port2));

I would prefer getting the motor encoder values once in the while loop up top and then use the if statements to evaluate against the local variables, but it will work this way. You just might have a background tasks cycle the new encoder values on one or both of them from the top of the while to the bottom of the while loop. But most likely it will be the same.