Motors not exiting loops

Hello, my motors won’t exit a loop after it has been 3 rotations and the program
told them to stop after 3 have past.

Well I assure you that the software isn’t the issue, we need to see your code.

1 Like

When my students have issue with this it is almost always because you are running a task that has not completed.

For example if you had in your code:

Drivetrain.driveFor(360, degrees);

but your robot for whatever reason (usually physical) could not complete the full 360, then it will not move on in the code.

1 Like

Here is my code:
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!

Gyro1.setHeading(0.0, degrees);
Gyro1.setRotation(0.0, degrees);
while (LeftMotor.value()<= 3){

Gyro1.setHeading(0, degrees);
if(Gyro1.heading(degrees) != 0)
  LeftMotor.spin(directionType::fwd, 15+(0-Gyro1.heading(deg)), velocityUnits::pct);
  RightMotor.spin(directionType::rev, 15-(0-Gyro1.heading(deg)), velocityUnits::pct);

  LeftMotor.spin(directionType::fwd, 15, velocityUnits::pct);
  RightMotor.spin(directionType::rev, 15, velocityUnits::pct);


Try changing LeftMotor.value() to LeftMotor.value(rotationUnits::rev)

And after the while loop you need to turn off the motors by doing


rotation units don’t work

Actually change LeftMotor.value() to LeftMotor.rotation(rotationUnits::rev)

And did you turn off the motors after the while loop?

1 Like

Also note that motor::value() returns int32 while motor::position() returns double.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.