Inertial Sensor never stops. Keep spinning

I wanted to use inertial sensor in my drivetrain code but it’s always turning and i couldn’t do anything about this. Here is my code :

vexcodeInit();
DrivetrainInertial.calibrate();
DrivetrainInertial.setRotation(0,deg);
while(DrivetrainInertial.isCalibrating()){
  wait(100,msec);
}
Drivetrain.setTurnVelocity(50,pct);
Drivetrain.turn(right);
waitUntil((DrivetrainInertial.rotation(degrees) >= 45.0));
Drivetrain.stop(brakeType::brake);

Usually this means you are turning the wrong direction. The inertial sensor’s rotation is going down into the negatives, so it never reaches 45 because it is going the wrong direction to reach 45. Try changing Drivetrain.turn(right); to Drivetrain.turn(left);.

2 Likes

i want to turn right but when i tried to use drivetrain.turn(right) and degrees >= -90 it couldn’t work

You need to change the >= to <= to turn the other way

3 Likes