We use an AutonTurnAutonomous function during autonomous to turn. But when we enter the values for how much we want to turn, it doesn’t do what we want it to. For example, I said for it to turn 90 degrees but it turned 20 and self corrected itself back to the original starting position. Then I tried 360 and it kept on spinning for more than 15 secs. What could be the problem?
// Used to turn the robot in autonomous
void autonTurnAutonomous(int degrees, bool isRight)
{
// resets the value of the inertia sensor
inertia.resetRotation();
// while the intertia sensor is not equal to the number of degrees desired
while (inertia.value() < degrees)
{
// If turning right
if (isRight)
{
DriveL.spin(forward, 20, percent);
DriveR.spin(reverse, 20, percent);
}
else if (!isRight)
{
DriveL.spin(reverse, 20, percent);
DriveR.spin(forward, 20, percent);
}
wait (20, msec);
}
while (inertia.value() == degrees)
{
DriveL.setStopping(hold);
DriveR.setStopping(hold);
}
while (inertia.value() > degrees)
{
// If turning right
if (isRight)
{
DriveL.spin(reverse, 10, percent);
DriveR.spin(forward, 10, percent);
}
else if (!isRight)
{
DriveL.spin(forward, 10, percent);
DriveR.spin(reverse, 10, percent);
}
}
// stops the motors
DriveL.stop();
DriveR.stop();
wait (20, msec);
}