Hey guys, so I’m trying to use a proportional loop in order to keep both sides of my lift stable, so the program I have written makes it so that the lift side that is slower is the target and the other side will correct itself to stay level with the target, using potentiometers. But for some reason, one potentiometer is giving a lower value than the other, even though the lift sides are at the same level. In order to fix this (sort of), I just made the lesser value add 1350 to itself so that they are around the same area on both sides. However, when I tested my program without pressing any buttons, and I just moved the lift by hand , the correcting side tries to adjust to the target, but then it stops for a reason that I can’t find, then moves, then stops. It never actually reaches the target position, as the jittering causes the lift to shake and it goes back down. I’m really scratching my head at what I did wrong, so maybe you guys could help out? (Also, I’m doing this as a side project at home, and so I do not have access to parts at my school, and so all I have is just my computer, and the bot.) The parts that involve the correction of the lift are in the liftCorrection task, and I have already defined all necessary variables.
task correctionLift ()
{
while(true)
{
rightLiftValue = (SensorValue[liftPotR] + 1350);
correctionLiftError = rightLiftValue - SensorValue[liftPotL];
correctionLiftProportional = correctionLiftError * correctionLiftKp;
correctionLiftFinal = correctionLiftProportional;
// motor[liftLeft] = correctionLiftFinal;
wait1Msec(15);
}
}
task chainPid ()
{
while (true)
{
chainError = chainTarget - SensorValue[chainBar];
chainProportional = chainError * chainKp;
chainFinal = chainProportional;
sonarValue = SensorValue[liftSonic];
motor[chainLift] = chainFinal;
writeDebugStreamLine("chainTarget = %d, chainPos = %d, chainError = %d, chainFinal = %d", chainTarget, SensorValue[chainBar], chainProportional, chainFinal);
wait1Msec(10);
}
}
task autonomous()
{
motor[baseLeft] = 100;
motor[midLeft] = 100;
motor[baseRight] = 100;
motor[midRight] = 100;
motor[liftLeft] = 0;
motor[liftRight] = 0;
wait1Msec(4000);
motor[baseLeft] = 0;
motor[midLeft] = 0;
motor[baseRight] = 0;
motor[midRight] = 0;
}
/*---------------------------------------------------------------------------*/
/* */
/* User Control Task */
/* */
/* This task is used to control your robot during the user control phase of */
/* a VEX Competition. */
/* */
/* You must modify the code to add your own robot specific commands here. */
/*---------------------------------------------------------------------------*/
task usercontrol()
{
// User control code here, inside the loop
//startTask (liftPid) ;
startTask (chainPid) ;
startTask(correctionLift);
while (true)
{
motor[baseLeft] = vexRT[Ch3];
motor[midLeft] = vexRT[Ch3];
motor[baseRight] = vexRT[Ch2];
motor[midRight] = vexRT[Ch2];
if (vexRT[Btn8L] == 1)
{
motor[mogoLift] = 45;
}
else if (vexRT[Btn8D] == 1)
{
motor[mogoLift] = -90;
}
else
{
motor[mogoLift] = 0;
}
if (vexRT[Btn6U] == 1)
{
motor[liftLeft] = 80;
motor[liftRight] = 80;
}
else if(vexRT[Btn6D] == 1)
{
motor[liftLeft] = -50;
motor[liftRight] = -50;
}
else
{
motor[liftLeft] = correctionLiftFinal;
motor[liftRight] = 10;
}