FIXED
Hi, our team is having a problem with our autonomous code being inconsistent, but it doesn’t seem to be from sensor values being inaccurate.
When we run our autonomous code, it either works fine, or one of the first turns in the program will be completely off(turns about half of what is is supposed to). When the first turn is not accurate, it throws off our lift heights and turns throughout the rest of the program.
We are using a potentiometer to control our lift height, and the lift will only lift to about half of what it is supposed to if the first turn is not correct.
We are using ROBOTC 4.27, and all the firmware is up to date.
Here is our code:
#pragma config(I2C_Usage, I2C1, i2cSensors)
#pragma config(Sensor, in1, potentiometerLt, sensorPotentiometer)
#pragma config(Sensor, dgtl2, claw, sensorDigitalOut)
#pragma config(Sensor, I2C_1, , sensorQuadEncoderOnI2CPort, , AutoAssign)
#pragma config(Sensor, I2C_2, , sensorQuadEncoderOnI2CPort, , AutoAssign)
#pragma config(Motor, port1, Intake1, tmotorVex393_HBridge, openLoop, reversed)
#pragma config(Motor, port2, RtBackWheel, tmotorVex393HighSpeed_MC29, openLoop, reversed, encoderPort, I2C_1)
#pragma config(Motor, port3, RtDrive, tmotorVex393HighSpeed_MC29, openLoop, reversed)
#pragma config(Motor, port4, RtBottomLift, tmotorVex393HighSpeed_MC29, openLoop)
#pragma config(Motor, port5, RtTopLift, tmotorVex393HighSpeed_MC29, openLoop)
#pragma config(Motor, port6, LtBackWheel, tmotorVex393HighSpeed_MC29, openLoop, encoderPort, I2C_2)
#pragma config(Motor, port7, LtDrive, tmotorVex393HighSpeed_MC29, openLoop)
#pragma config(Motor, port8, LtBottomLift, tmotorVex393HighSpeed_MC29, openLoop, reversed)
#pragma config(Motor, port9, LtTopLift, tmotorVex393HighSpeed_MC29, openLoop, reversed)
#pragma config(Motor, port10, Intake2, tmotorVex393_HBridge, openLoop, reversed)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
#pragma platform(VEX)
void fwds(int distance, int speed)
{
nMotorEncoder[RtBackWheel] = 0;
nMotorEncoder[LtBackWheel] = 0;
while(nMotorEncoder[RtBackWheel] < distance && nMotorEncoder[LtBackWheel] > (distance * -1))
{
motor[LtDrive] = speed;
motor[LtBackWheel] = speed;
motor[RtDrive] = speed;
motor[RtBackWheel] = speed;
}
motor[LtDrive] = 0;
motor[LtBackWheel] = 0;
motor[RtDrive] = 0;
motor[RtBackWheel] = 0;
}
void bwds(int distance, int speed)
{
nMotorEncoder[RtBackWheel] = 0;
nMotorEncoder[LtBackWheel] = 0;
while(nMotorEncoder[RtBackWheel] > (distance * -1) && nMotorEncoder[LtBackWheel] < distance)
{
motor[LtDrive] = -speed;
motor[LtBackWheel] = -speed;
motor[RtDrive] = -speed;
motor[RtBackWheel] = -speed;
}
motor[LtDrive] = 0;
motor[LtBackWheel] = 0;
motor[RtDrive] = 0;
motor[RtBackWheel] = 0;
}
void turnL(int distance, int speed)
{
nMotorEncoder[LtBackWheel] = 0;
nMotorEncoder[RtBackWheel] = 0;
while(nMotorEncoder[LtBackWheel] < distance && nMotorEncoder[RtBackWheel] < distance)
{
motor[LtBackWheel] = -speed;
motor[LtDrive] = -speed;
motor[RtBackWheel] = speed;
motor[RtDrive] = speed;
}
motor[LtBackWheel] = 0;
motor[LtDrive] = 0;
motor[RtBackWheel] = 0;
motor[RtDrive] = 0;
}
void turnR(int distance, int speed)
{
nMotorEncoder[LtBackWheel] = 0;
nMotorEncoder[RtBackWheel] = 0;
while(nMotorEncoder[LtBackWheel] > -distance && nMotorEncoder[RtBackWheel] > -distance)
{
motor[LtBackWheel] = speed;
motor[LtDrive] = speed;
motor[RtBackWheel] = -speed;
motor[RtDrive] = -speed;
}
motor[LtBackWheel] = 0;
motor[LtDrive] = 0;
motor[RtBackWheel] = 0;
motor[RtDrive] = 0;
}
void bwdslft(int distance, int speed)
{
nMotorEncoder[RtBackWheel] = 0;
nMotorEncoder[LtBackWheel] = 0;
while(nMotorEncoder[RtBackWheel] > (distance * -1) && nMotorEncoder[LtBackWheel] < distance)
{
motor[LtDrive] = -speed;
motor[LtBackWheel] = -speed;
motor[RtDrive] = -speed;
motor[RtBackWheel] = -speed;
motor[RtBottomLift] = 127;
motor[RtTopLift] = 127;
motor[LtBottomLift] = 127;
motor[LtTopLift] = 127;
}
motor[LtDrive] = 0;
motor[LtBackWheel] = 0;
motor[RtDrive] = 0;
motor[RtBackWheel] = 0;
motor[RtBottomLift] = 0;
motor[RtTopLift] = 0;
motor[LtBottomLift] = 0;
motor[LtTopLift] = 0;
}
void liftHold()
{
motor[RtTopLift] = 17;
motor[LtTopLift] = 17;
motor[RtBottomLift] = 17;
motor[LtBottomLift] = 17;
}
void liftup(int speed, int distance)
{
while(SensorValue[potentiometerLt] > distance)
{
motor[LtTopLift] = speed;
motor[LtBottomLift] = speed;
motor[RtTopLift] = speed;
motor[RtBottomLift] = speed;
}
motor[LtTopLift] = 0;
motor[LtBottomLift] = 0;
motor[RtTopLift] = 0;
motor[RtBottomLift] = 0;
}
void liftdown(int speed, int distance)
{
while(SensorValue[potentiometerLt] < distance)
{
motor[LtTopLift] = -speed;
motor[LtBottomLift] = -speed;
motor[RtTopLift] = -speed;
motor[RtBottomLift] = -speed;
}
motor[LtTopLift] = 0;
motor[LtBottomLift] = 0;
motor[RtTopLift] = 0;
motor[RtTopLift] = 0;
}
void intake(int speed, int time)
{
motor[Intake1] = -speed;
motor[Intake2] = -speed;
wait1Msec(time);
motor[Intake1] = 0;
motor[Intake2] = 0;
}
void outtake(int speed, int time)
{
motor[Intake1] = speed;
motor[Intake2] = speed;
wait1Msec(time);
motor[Intake1] = 0;
motor[Intake2] = 0;
}
void skyriseintake()
{
SensorValue[claw] = 1;
}
void skyriseouttake()
{
SensorValue[claw] = 0;
}
void liftTick (int speed, int distance, int maxTicks)
{
int ticks = 0;
while(ticks <= maxTicks)
{
if(SensorValue[potentiometerLt] > distance)
{
motor[LtTopLift] = speed;
motor[LtBottomLift] = speed;
motor[RtTopLift] = speed;
motor[RtBottomLift] = speed;
}
else if(SensorValue[potentiometerLt] < (distance - 150))
{
motor[RtTopLift] = -speed;
motor[LtTopLift] = -speed;
motor[RtBottomLift] = -speed;
motor[LtBottomLift] = -speed;
}
else
{
motor[LtTopLift] = 17;
motor[LtBottomLift] = 17;
motor[RtTopLift] = 17;
motor[RtBottomLift] = 17;
ticks++;
}
wait1Msec(25);
}
motor[LtTopLift] = 0;
motor[LtBottomLift] = 0;
motor[RtTopLift] = 0;
motor[RtBottomLift] = 0;
}
task main()
{
//RED SKYRISE 8 PT
outtake(127,250);
intake(127,250);
outtake(127,250);
intake(127,400);
bwds(80,127);
turnL(50,100);
turnR(1,17);
wait1Msec(1000);
liftTick(127,1900,3);
liftHold();
bwds(50,50);
wait1Msec(500);
fwds(70,50);
wait1Msec(1000);
skyriseintake();
wait1Msec(500);
bwdslft(300,75);
turnL(195,70);
turnR(1,17);
fwds(10,50);
wait1Msec(1000);
liftdown(35,1800);
liftHold();
wait1Msec(1000);
skyriseouttake();
bwds(125,75);
liftup(127,1500);
liftHold();
fwds(90,75);
outtake(127,3000);
}
One thing we tried to fix this was the “liftTick” function, where the potentiometer value would be checked multiple times before the function was stopped. We noticed that this function only had to correct the lift height when the first turn was off(just like before). This fixed the problem with the lift height, but the turns throughout the program seemed to still be off.
We have also tried using another cortex, but had the same problem.
Both IME’s are also reading values.
Any help is appreciated. Thanks!