This doesn’t work. It gives me an error for the >, and if I remove it, there is no error, but it doesn’t fulfill my purpose. How would i make it so that the robot turns until the sensor reads 90 degrees? Also, if I were to successfully do this, would it make completely accurate turns?
Sorry if this was the confusion, but you still need to have the Drivetrain.turn(left); function inside the while loop. I’m not sure why I didn’t include it in my reply.
In this instance, you first set the heading to 0. You then start your while loop with Inertia.heading(degrees) equal to zero. The while loop, as configured, will only run when Inertia.heading(degrees) is greater than 90 so, in short, it will never execute the turn. You want your loop to run when Inertia.heading(degrees) is less than 90.
You also may want to investigate using rotation instead of heading.
Of course, as to the theoretical perfect 90? The saying attributed to either (or both) Yogi Berra and Albert Einstein very much applies to VEX: " In theory there is no difference between theory and practice** - in practice there is"
What @willjlong said will move the robot, but it will never stop. This is because you never told the robot to stop. After the while loop, you also need to tell the drivetrain to stop.
First off you need to calibrate your inertia/gyroscope (they are same thing). You also are going to want to round the inertia heading because the while commands are slower.
I would use the rotation instead of heading as once you get to 180 or -180 it loops around to the other end of the scale. Rotation keeps increasing until you reset it. This allows you to turn more than 180 degrees.
Also if you overshoot the target the robot would go all the way back round. And this would repeat forever, meaning the robot would turn on the spot forever.
I would suggest researching PID controllers or adding an inertial sensor to your drive train in the port config and using the turn-to-heading function. What you are trying to do is built in the VEXCode V5 drivetrain tool.
Since you’re using a drivetrain you can just include the inertial sensor inside the making of that. Inside the robot-config.cpp file, find the line where your drivetrain is declared and change it to look something like this, just with the names of your motors / motor groups and the name of your inertial sensor.
while(Inertia.heading(degrees > 90)){ // Your comparission needs to be somewhere else
Drivetrain.turn(left);
}
you are basicly saying is the unit degrees > 90 that doesn’t make sense to the computer and your comparasion is also the wrong direction because that will not be true when you start., 0 is not greater than 90 so it exits. What you actually need is this updated code :
Drivetrain.turn(right); // This is most efficent
while(Inertia.heading(degrees) < 90){
task::sleep(25) // You were telling it to constantly turn which is not needed
}
Drivetrain.stop( );// Put your stop here (I haven't worked with drivetrain functions much thou)