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.
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.
Here is my code:
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
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);
}
else
{
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
LeftMotor.stop(coast);
RightMotor.stop(coast);
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?
Also note that motor::value() returns int32 while motor::position() returns double.
https://api.vexcode.cloud/v5/html/classvex_1_1motor.html#a16746eaf0955f4c9c5d6330834288a59
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.