Odd lifting issue only in autonomous

Our team is having an issue with our lift tilting to one side, but only in autonomous.

We have an 8 bar lift and do not experience the same tilting issue in driver control. However, in autonomous, our lift leans towards the right side even without being under any load.

We are using ROBOTC 4.27 with updated firmware on our joystick and cortex.

Our entire code for the lift in driver control is as follows(ignore the lift balancing code in the middle of the program, that is no longer in use):
5U and 5D are the buttons being used for going up and down.

if(vexRT[Btn7D] == 1 && RightLower)//Automagic down
		{
			motor[RtFrontLift] = -50;
			motor[LtFrontLift] = 17;
			motor[RtBackLift] = -50;
			motor[LtBackLift] = 17;
		}
		else if(vexRT[Btn7D] == 1 && !RightLower)
		{
			motor[RtFrontLift] = 17;
			motor[LtFrontLift] = -50;
			motor[RtBackLift] = 17;
			motor[LtBackLift] = -50;
		}
		else if(vexRT[Btn7U] == 1 && !leftHigher)//Automagic up
		{
			motor[RtFrontLift] = 40;
			motor[LtFrontLift] = 80;
			motor[RtBackLift] = 40;
			motor[LtBackLift] = 80;
		}
		else if(vexRT[Btn7U] == 1 && leftHigher)
		{
			motor[RtFrontLift] = 80;
			motor[LtFrontLift] = 40;
			motor[RtBackLift] = 80;
			motor[LtBackLift] = 40;
		}
		else if(vexRT[Btn5D] == 1 && vexRT[Btn5U] == 1)//lifthold
		{
			motor[RtFrontLift] = 10;
			motor[LtFrontLift] = 10;
			motor[RtBackLift] = 10;
			motor[LtBackLift] = 10;
		}
		else if(vexRT[Btn8L] == 1)//lift adjust
		{
			if((SensorValue(potentiometerLt) + offSet) > SensorValue(potentiometerRt)/* && threshold*/)
			{
				motor[RtFrontLift] = 127 - error;
				motor[LtFrontLift] = 127;
				motor[RtBackLift] = 127 - error;
				motor[LtBackLift] = 127;
			}
			else if(SensorValue(potentiometerRt) > (SensorValue(potentiometerLt) + offSet)/* && threshold*/)
			{
				motor[RtFrontLift] = 127;
				motor[LtFrontLift] = 127 - error;
				motor[RtBackLift] = 127;
				motor[LtBackLift] = 127 - error;
			}
			else
			{
				motor[RtFrontLift] = 127;
				motor[LtFrontLift] = 127;
				motor[RtBackLift] = 127;
				motor[LtBackLift] = 127;
			}
		}
		else if(vexRT[Btn5D] == 1)//lift down
		{
			motor[RtFrontLift] = -127;
			motor[LtFrontLift] = -127;
			motor[RtBackLift] = -127;
			motor[LtBackLift] = -127;
		}
		else if(vexRT[Btn5U] == 1)//lift up
		{
			motor[RtFrontLift] = 127;
			motor[LtFrontLift] = 127;
			motor[RtBackLift] = 127;
			motor[LtBackLift] = 127;
		}
		else if(vexRT[Btn7L] == 1)//autotap
		{
			if(SensorValue(potentiometerRt) > 2300)
			{
				if(SensorValue(potentiometerRt) > 2450)
				{
					motor[RtFrontLift] = 30;
					motor[LtFrontLift] = 30;
					motor[RtBackLift] = 30;
					motor[LtBackLift] = 30;
				}
				else
				{
					motor[RtFrontLift] = 10;
					motor[LtFrontLift] = 10;
					motor[RtBackLift] = 10;
					motor[LtBackLift] = 10;
				}
			}
			else
			{
				if(SensorValue(potentiometerRt) < 2300)
				{
					motor[RtFrontLift] = -127;
					motor[LtFrontLift] = -127;
					motor[RtBackLift] = -127;
					motor[LtBackLift] = -127;
				}
				else
				{
					motor[RtFrontLift] = 10;
					motor[LtFrontLift] = 10;
					motor[RtBackLift] = 10;
					motor[LtBackLift] = 10;
				}
			}
		}
		else
		{
			motor[RtFrontLift] = 0;
			motor[LtFrontLift] = 0;
			motor[RtBackLift] = 0;
			motor[LtBackLift] = 0;
		}

Function being used to lift up:

void liftup(int distance, int speed)
{
	while(SensorValue[potentiometerLt] > distance)
	{
		motor[LtFrontLift] = speed - 50;
		motor[LtBackLift] = speed - 50;
		motor[RtFrontLift] = speed;
		motor[RtBackLift] = speed;
	}
	motor[LtFrontLift] = 10;
	motor[LtBackLift] = 10;
	motor[RtFrontLift] = 10;
	motor[RtBackLift] = 10;
}

and is called in the program using:


liftup(1200,127);

This issue is still present if we lift using time instead of potentiometer values and set the power to 127:

void liftTime(int time)
{
	motor[RtFrontLift] = 127;
	motor[LtFrontLift] = 127;
	motor[RtBackLift] = 127;
	motor[LtBackLift] = 127;
	wait1Msec(time);
	motor[RtFrontLift] = 0;
	motor[LtFrontLift] = 0;
	motor[RtBackLift] = 0;
	motor[LtBackLift] = 0;
}

called using:


liftTime(2000);

Does anyone have any ideas as to why this is only happening in autonomous and not driver control?

Things we have ruled out:
Physical issue- the lift lifts fine in driver control
Potentiometer issue- the lift is stopping fine once it reaches the target position and other parts of the program which use the potentiometer work fine.

We have also tried subtracting power from the side which is moving up faster(the left side). Even subtracting 30-40 power from that side does not get rid of the tilt.

COMPLETE ROBOT CODE: http://pastebin.com/T189tLUt
Lift functions start on line 157
The button used to activate autonomous(we lost our competition switch) and the autonomous code is on line 380
Buttons to lift up and down start on line 557

Thank you!

Have you tried using RobotC’s debugger window to trace what is happening to your variables in autonomous?

I don’t think this would help us figure out what is going on. We aren’t having problems with the potentiometers; our problem is that we are signaling for each motor to go at full power but one side is slower/weaker than the other.

RobotC has a built-in debugger that provides a virtual competition switch. I think you can use that the same way you would a physical competition switch. Maybe if you restructure your code so it works with a competition switch and isn’t faking it, the mysterious error will evaporate.

http://help.robotc.net/WebHelpVEX/index.htm#Topics/ROBOTC%20Debugger/Debug%20Windows/Competition%20Control.htm%3FTocPath%3DROBOTC%2520Debugger%7C_____9

Also, you can always use the debugger window to look at any variables you might have, or create variables for the sole purpose of debugging, just to step through the code and see what is really happening.

Here is a more concise paraphrase of original question:

Correct me if I misrepresented you…

Comments on code, regarding the code in the forum that I can see:
It would be easier to see the flow of code with these changes;

  • all 4 motor sets were in one function call. eg: motor_set( 40,80,40,80);
  • omit ==1 for vexRt[Btn7D] checks, it works without it, right?
  • avoid < 2300, >2300 type comparisons, use (< , else), or use <=, avoid special tree branches for == cases, which never happen anyway;
  • ‘Angle’ is shorter and better than ‘potentiometer’
  • refactor the last group of SensorValue checks as a straight chain of else if, rather than if else tree.
  • Anytime you want to do only one thing like motor_set(), use a subr or loop, and break instead of else; much much cleaner

Unrequested solution idea:
Physically tying the left and right side motors together would fix this if it is not a mechanical load twisting issue.

Here are some ideas using Science Method format:

Hypothesis0: the posted code assigns motors in order LtF,LtB,RtF,RtB;
but liftTime(time) does a different order.
H0Test1: using same motor_set in both would help.

H1: its due to actual code I can’t see,
such as other task control processes running in Auton that steal time at the wrong time.
H1Test1: but you think you’ve tested for this with simpler code.
H1Test2: Make autonmous code that does wait 5000ms, liftTime(2000) only, nothing else
Make driver code that waits for button push, then does wait 5000ms, liftTime(2000), nothing else.
and compare these results in multiple trials, with different batteries.

H2: Its due to some other factor you haven’t described,
such as Autonomous is driving while lifting, which affects current available for motor balance.
H2Test1: Are your left and right arm motors balanced across ports 1…5 and 6…10? Are your driving motors balanced also?

H3: It is an unlikely real RobotC difference in the motor value or delta time between motor assignment statements for Auton and Driver, unrelated to H2 differences in task control.
H3Test1: Same as H1Test2: It is required to make an example with
the simplest possible identical code in both Auton and Driver control.
If that still shows a difference, then RobotC guys should take a real interest.

Here my example refactored code that might be easier to follow, (but code posting doesn’t preserve indentation well, you’d have to cut/paste to a fixed font wordpad, and insert reasonable leading spacing)