Hello My name is Jesus Rodríguez and i am from team 98782B Matbotz!!!. We are having problems with integrated encoders our counts are negative and on the debugger window they show as left= -6234 And right as 5678. How can we achieve staraightness and precision. Thank you!
P.S here is my program :
#pragma config(I2C_Usage, I2C1, i2cSensors)
#pragma config(Sensor, I2C_1, , sensorQuadEncoderOnI2CPort, , AutoAssign )
#pragma config(Sensor, I2C_2, , sensorQuadEncoderOnI2CPort, , AutoAssign )
#pragma config(Motor, port2, leftmotor, tmotorVex393_MC29, PIDControl, driveLeft, encoderPort, I2C_2)
#pragma config(Motor, port3, rightmotor, tmotorVex393_MC29, PIDControl, reversed, driveRight, encoderPort, I2C_1)
//!!Code automatically generated by ‘ROBOTC’ configuration wizard !!//
task main()
{
int slowspeed;
int fastspeed;
slowspeed=60;
fastspeed=80;
wait1Msec(2000);
clearLCDLine(0);
clearLCDLine(1);
displayLCDString(0, 0, "R: ");
displayLCDString(1, 0, "L: ");
nMotorEncoder[rightmotor] = 0;
nMotorEncoder[leftmotor] = 0;
while(nMotorEncoder[rightmotor] < 1450)
{
if(nMotorEncoder[leftmotor]> nMotorEncoder[rightmotor])
{
displayLCDNumber(0, 3, nMotorEncoder[rightmotor], 6);
displayLCDNumber(1, 3, nMotorEncoder[leftmotor], 6);
motor[rightmotor]=fastspeed;
motor[leftmotor]=slowspeed;
}
if(nMotorEncoder[rightmotor]> nMotorEncoder[leftmotor])
{
displayLCDNumber(0, 3, nMotorEncoder[rightmotor], 6);
displayLCDNumber(1, 3, nMotorEncoder[leftmotor], 6);
motor[rightmotor]=slowspeed;
motor[leftmotor]=fastspeed;
}
if(nMotorEncoder[rightmotor]==nMotorEncoder[leftmotor])
{
displayLCDNumber(0, 3, nMotorEncoder[rightmotor], 6);
displayLCDNumber(1, 3, nMotorEncoder[leftmotor], 6);
motor[rightmotor] = fastspeed;
motor[leftmotor] = fastspeed;
}
}
nMotorEncoder[rightmotor] = 0;
nMotorEncoder[leftmotor] = 0;
while(nMotorEncoder[rightmotor] < 450)
{
displayLCDNumber(0, 3, nMotorEncoder[rightmotor], 6);
displayLCDNumber(1, 3, nMotorEncoder[leftmotor], 6);
motor[rightmotor]=63;
motor[leftmotor]=-63;
}
nMotorEncoder[rightmotor]=0;
nMotorEncoder[leftmotor]=0;
while(nMotorEncoder[rightmotor] <1400)
{
if(nMotorEncoder[leftmotor]> nMotorEncoder[rightmotor])
{
displayLCDNumber(0, 3, nMotorEncoder[rightmotor], 6);
displayLCDNumber(1, 3, nMotorEncoder[leftmotor], 6);
motor[rightmotor]=fastspeed;
motor[leftmotor]=slowspeed;
}
if(nMotorEncoder[rightmotor]> nMotorEncoder[leftmotor])
{
displayLCDNumber(0, 3, nMotorEncoder[rightmotor], 6);
displayLCDNumber(1, 3, nMotorEncoder[leftmotor], 6);
motor[rightmotor]=slowspeed;
motor[leftmotor]=fastspeed;
}
if(nMotorEncoder[rightmotor]==nMotorEncoder[leftmotor])
{
displayLCDNumber(0, 3, nMotorEncoder[rightmotor], 6);
displayLCDNumber(1, 3, nMotorEncoder[leftmotor], 6);
motor[rightmotor]= fastspeed;
motor[leftmotor] = fastspeed;
}
}
nMotorEncoder[leftmotor]=0;
nMotorEncoder[rightmotor]=0;
while(nMotorEncoder[rightmotor]< 450)
{
displayLCDNumber(0, 3, nMotorEncoder[rightmotor], 6);
displayLCDNumber(1, 3, nMotorEncoder[leftmotor], 6);
motor[rightmotor]=63;
motor[leftmotor]=-63;
}
nMotorEncoder[leftmotor]=0;
nMotorEncoder[rightmotor]=0;
while(nMotorEncoder[rightmotor] <1200)
{
if(nMotorEncoder[leftmotor]> nMotorEncoder[rightmotor])
{
displayLCDNumber(0, 3, nMotorEncoder[rightmotor], 6);
displayLCDNumber(1, 3, nMotorEncoder[leftmotor], 6);
motor[rightmotor]=fastspeed;
motor[leftmotor]=slowspeed;
}
if(nMotorEncoder[rightmotor]> nMotorEncoder[leftmotor])
{
displayLCDNumber(0, 3, nMotorEncoder[rightmotor], 6);
displayLCDNumber(1, 3, nMotorEncoder[leftmotor], 6);
motor[rightmotor]=slowspeed;
motor[leftmotor]=fastspeed;
}
if(nMotorEncoder[rightmotor]==nMotorEncoder[leftmotor])
{
displayLCDNumber(0, 3, nMotorEncoder[rightmotor], 6);
displayLCDNumber(1, 3, nMotorEncoder[leftmotor], 6);
motor[rightmotor]= fastspeed;
motor[leftmotor] = fastspeed;
}
}
nMotorEncoder[leftmotor]=0;
nMotorEncoder[rightmotor]=0;
while(nMotorEncoder[rightmotor]< 400)
{
displayLCDNumber(0, 3, nMotorEncoder[rightmotor], 6);
displayLCDNumber(1, 3, nMotorEncoder[leftmotor], 6);
motor[rightmotor]=63;
motor[leftmotor]=-63;
}
nMotorEncoder[leftmotor]=0;
nMotorEncoder[rightmotor]=0;
while(nMotorEncoder[rightmotor] <1200)
{
if(nMotorEncoder[leftmotor]> nMotorEncoder[rightmotor])
{
displayLCDNumber(0, 3, nMotorEncoder[rightmotor], 6);
displayLCDNumber(1, 3, nMotorEncoder[leftmotor], 6);
motor[rightmotor]=fastspeed;
motor[leftmotor]=slowspeed;
}
if(nMotorEncoder[rightmotor]> nMotorEncoder[leftmotor])
{
displayLCDNumber(0, 3, nMotorEncoder[rightmotor], 6);
displayLCDNumber(1, 3, nMotorEncoder[leftmotor], 6);
motor[rightmotor]=slowspeed;
motor[leftmotor]=fastspeed;
}
if(nMotorEncoder[rightmotor]==nMotorEncoder[leftmotor])
{
displayLCDNumber(0, 3, nMotorEncoder[rightmotor], 6);
displayLCDNumber(1, 3, nMotorEncoder[leftmotor], 6);
motor[rightmotor]= fastspeed;
motor[leftmotor] = fastspeed;
}
}
}