Is there a way to clamp a rotation in code

Our team has a clamp/latch on the back of our robot and there has been a problem where it rotates too far back is there any way to kind of clamp the rotation so it can’t rotate past a certain point like 90 degrees. maybe like this?:

void clampRot(){
if(Motor.rotation == 90){
Motor.stop
}
}
I tried something along those lines and it didn’t work.
(I’m using vex code pro C++)

Have you tried motor.rotation(degrees); ?
Or you could add limit switches to the robot

yes I have tried motor.rotation(degrees) the code I put in the question was just a
concept not the actual code I tested. Also I thought about adding a limit switch but I think there is probably a way to do this in code.

In driver control, I do it like this

double maxPos = 90;
double minPos = 0;
if(Controller.ButtonL1.pressing() && lift.position(deg) <= maxPos){
  lift.spin(fwd, 100, pct);
}
else if(Controller.ButtonL2.pressing() && lift.position(deg) >= minPos){
  lift.spin(fwd, -100, pct);
}
else{
  lift.stop();
}
1 Like

I’ll test that next meeting (Tuesday)
Thank you