Potentiometer auto lift

Right now I am programming a potentiometer for my teams lift. I have most of the concepts except for a few things.
-1.) How do you create the joystick values? ( for hitting a button so the lift goes to an appointed height) The controls I want to use are joystick 1, channel 5, buttons 1-4.
2.) Do I put the motors that move the lift inside each if statement?
-3.) Once I have it programmed I want to be able to put in autonomous lift_to 30 for example. Do I need to create a different user function for each one?

Okay, I tried to be as clear as possible but tell me if you want something clarified. Since I know someone will probably ask: I don’t have the computer so I can’t give the code so far. Thanks everyone.

Oh by the way I’m using easyC v4 for cortex.
Thanks again!

We do this in robotC. I don’t know easyC, but what we have is something like this:

void lifthigh() //use this to lift to the highest position
const int lifthigh=235; //This is the potentiometer value for high position
const int safety=100; //used to account for potentiometer error
if(SensorValue(Leftangle)>lifthigh && SensorValue(Rightangle)>lifthigh)
while(SensorValue(Leftangle)>lifthigh && SensorValue(Rightangle)>lifthigh && (vexRT[Btn7R]==0 && vexRT[Btn7RXmtr2]==0)) //while the button is pressed and the lift is lower
lifteven(); //this is another function that lifts both sides of arm evenly
else if(SensorValue(Leftangle)<lifthigh && SensorValue(Rightangle)<lifthigh) //otherwise if the lift is lower
while(SensorValue(Leftangle)<lifthigh-safety && SensorValue(Rightangle)<lifthigh-safety && (vexRT[Btn7R]==0 && vexRT[Btn7RXmtr2]==0)) //while the button is pressed and the lift is lower
lowereven(); //another function that lowers evenly
else //if the lift is in the correct position

also note that another part of our code is required to keep it at this position, otherwise it will fall due to gravity. You could simply change the motor values at the end to compensate for this, at risk of harming the motors in some way. Hope this helps and you can translate it somehow into easyC.:slight_smile:

I don’t know easyC, but here’s how I’d do it in pseudo-code:

final int highPos = <sensorValue>;
final int medPos = <sensorValue>;
final int lowPos = <sensorValue>;
final int floorPos = <sensorValue>;

int armPos = 0;  //0 = floor, 1 = low, 2 = med, 3 = high
while(true){ //User control loop
  //Figure out which button is pressed
  if (bottomButton == pressed)
    armPos = 0;
  else if (leftButton == pressed)
    armPos = 1;
  else if (rightButton == pressed)
    armPos = 2;
  else if (topButton == pressed)
    armPos = 3;

  //Use correct control loop for target
  int scale = 0.2;  //Needs to be tweaked based on arm
  int add = 20;  //Tweak
  switch armPos{
    case 0:
       motor[arm] = (SensorValue[pot] - floorPos) * (scale) + add;
    case 1:
       motor[arm] = (SensorValue[pot] - lowPos) * (scale) + add;
    (and similar)


It’s basically a P control loop. Read this for more information on the general idea: http://www.inpharmix.com/jps/PID_Controller_For_Lego_Mindstorms_Robots.html

“pot” is a potentiometer.


Seems like we talked about this a few weeks back. See if anything in this thread helps.


Thanks for the feedback everyone. Two more questions.
1.) do I just define the joystick values j1c5b1-4 in operator control and then do something like this.
If- j1c5b1 = 1
Then Lift_to_30
2.) when I define each Lift_To statement do I put the motors and the direction they need to turn in below?