Coding the lift to move to a certain height automatically

Im using a DR4B this year and was thinking in my code I could create certain heights for my lift to automatically move to by pressing a button to make it rotate to a certain position. Nothing is happening when I am pressing th buttons. Is this an error in my code?

int i = 0;
void height_up(void) {

 i++;

  if (i > 0 && i < 4) {
    if (i == 1) {
      RLift.rotateTo(double(-129), vex::rotationUnits::deg, double(75),
                     vex::velocityUnits::pct);
      LLift.rotateTo(double(88), vex::rotationUnits::deg, double(75),
                     vex::velocityUnits::pct);
    } else if (i == 2) {
      RLift.rotateTo(double(-859), vex::rotationUnits::deg, double(75),
                     vex::velocityUnits::pct);
      LLift.rotateTo(double(787), vex::rotationUnits::deg, double(75),
                     vex::velocityUnits::pct);
    } else {
      RLift.rotateTo(double(-1420), vex::rotationUnits::deg, double(75),
                     vex::velocityUnits::pct);
      LLift.rotateTo(double(1370), vex::rotationUnits::deg, double(75),
                     vex::velocityUnits::pct);
    }
  }

  else {
    i--;
  }
}

void height_down(void) {
  

  i--;

  if (i > 0 && i < 4) {
    if (i == 1) {
      RLift.rotateTo(double(-129), vex::rotationUnits::deg, double(75),
                     vex::velocityUnits::pct);
      LLift.rotateTo(double(88), vex::rotationUnits::deg, double(75),
                     vex::velocityUnits::pct);
    } else if (i == 2) {
      RLift.rotateTo(double(-859), vex::rotationUnits::deg, double(75),
                     vex::velocityUnits::pct);
      LLift.rotateTo(double(787), vex::rotationUnits::deg, double(75),
                     vex::velocityUnits::pct);
    } else {
      RLift.rotateTo(double(-1420), vex::rotationUnits::deg, double(75),
                     vex::velocityUnits::pct);
      LLift.rotateTo(double(1370), vex::rotationUnits::deg, double(75),
                     vex::velocityUnits::pct);
    }
  }

  else {
    i++;
  }
}

To test the logic, I would put some print statements in the code to make sure the value of I isnt stuck out of range. If I works fine, test the rotateTo method to make sure that it works as intended. I don’t see anything wrong with the immediately.

1 Like

Are you using RLift or LLift anywhere else in your code? If so you may be assigning it to stop continuously so that the functions are overruled each time through your while(1) loop.

Perhaps use BrakeType(). It knows where to go to, just not when to stop.

We need to see how you called the function

2 Likes

I have a lne of code that says If my RJoy = 0 then it puts my Lift motors on hold. would that still effect this code?

Controller1.ButtonUp.pressed(height_up);
    Controller1.ButtonDown.pressed(height_down);