[Help] If statement not reading .isSpinning() == false

Hello, my program isn’t working as I expect it to and cannot figure out how to fix it. My problem is whenever my if-statement calls to see if the motor is stopped (LeftDrive.isSpinning() == false) it doesn’t work. While the motor is spinning, then it is printing to the brain. As seen in my code the if-statement looks to see whenever the motors rotations are changed and the motor is stopped, then print to the brain, but that isn’t how it is working. Thank you all for your time and all of yalls help.

The code above int main is the competition template, but nothing above int main was changed ,

  // Set up callbacks for autonomous and driver control periods.
  Competition.autonomous(autonomous);
  Competition.drivercontrol(usercontrol);

  // Run the pre-autonomous function.
  pre_auton();

  // Prevent main from exiting with an infinite loop.
  int currentRotationM5 = 0;
  int oldRotationM5 = 0;
  bool M5changed = false;
  while (true) {
    

// Variable to store rotations
currentRotationM5 = leftDrive.rotation(degrees);


if(currentRotationM5 != oldRotationM5){
  M5changed = true; // Indicating Change in rotation, so it doesn't print multiple times
}
else{
  M5changed = false;
}


if(M5changed == true && leftDrive.isSpinning() == false ){ // Makes sure the motor is done spinning before printing
Brain.Screen.clearScreen();
Brain.Screen.setCursor(1,1);
wait(0.1, sec);
  Brain.Screen.print("Left Drive Spun %d degrees", currentRotationM5);      
}

oldRotationM5 = currentRotationM5;
wait(100, msec); 
  }
}

doesn’t mean “is the motor moving”.

it means “is the motor spinning to a target position” given to it by the spinTo or spinFor functions.

and I don’t see anywhere where you actually tell the motor to move at all.

2 Likes

i was physically turning the motor and alright, thank you.

you could check for velocity being 0.

4 Likes