I’m trying to write a program that turns the robot about its center for a certain number of degrees, using IMEs. I’m using EasyCv4. When I run autoTurn(360);, the robot just turns for 75 ms (which I included to remove the slop from the drive train before I started measuring data). Can anyone please help? Thanks in advance. The code is below.
#include "Main.h"
void autoTurn(double degrees)
{
setLeftDrive(-127*sign(degrees));
setRightDrive(127*sign(degrees));
Wait(75);
double targetIME = degrees/360*chassisSize*pi/(2*pi*wheelRadius)*261.333;
PresetIntegratedMotorEncoder(3,0);
PresetIntegratedMotorEncoder(8,0);
long rIME = 0;
long lIME = 0;
long Rerror = targetIME;
long Lerror = targetIME;
while(rIME<targetIME||lIME<targetIME)
{
rIME = GetIntegratedMotorEncoder(3);
lIME = GetIntegratedMotorEncoder(8);
Rerror = targetIME-rIME;
Lerror = targetIME-lIME;
RautoMotor = kTurn*Rerror;
RautoMotor = RautoMotor>127?127:RautoMotor<-127?-127:RautoMotor;
LautoMotor = kTurn*Lerror;
LautoMotor = LautoMotor>127?127:LautoMotor<-127?-127:LautoMotor;
setLeftDrive(-LautoMotor*sign(degrees));
setRightDrive(RautoMotor*sign(degrees));
PrintToScreen ( "Left: %f" , lIME ) ;
PrintToScreen ( " Right: %f" , rIME ) ;
PrintToScreen ( " Target: %f" , targetIME ) ;
PrintToScreen(" Avg: %f\n", (lIME+rIME)/2);
Wait(25);
}
}