Turn left with inertia sensor

Can anyone supply a normal turn left code with inertial sensors like what is in the example program for turning with inertial sensors

Well, to do a left turn, the left motor has to spin reverse and the right motor has to spin forward. Based off the example code, this would work as a left turn.

#include “vex.h”

using namespace vex;

int main() {


while (Inertial20.isCalibrating()) {
wait(100, msec);


waitUntil((Inertial20.rotation(degrees) <= 270.0));
wait(1, seconds);

This should work. If there are any issues, feel free to post again in this thread!


This does not work because once the sensors calibrate they reset to 0 and 0 is <270

1 Like

I think he meant >=, but you probably figured that one out by now.


or use abs()
20 char

Inertial.rotation returns values between 0 and 360. And while ours tend to read 359 right after calibration, one shouldn’t count on that. So the code posted may work, it is not likely to work in all situations.

I would suggest looking at the SmartDrive class. One can use the UI to set up a DriveTrain instance that includes the IMU. This version allows one to specify a turnToHeading (May have the method name wrong). One could pass either of -90 or 270, and observe the robot turning to a right angle to facing left from where the robot’s starting facing was.

Even more, even after driving with other turns, turnToHeading with -90 or 270 will still orient the robot facing left from its initial orientation


Actually inertial.rotation() returns values in the range +/- DBL_MAX (or at least should be in the latest VEXcode). Inertial.heading() returns 0 through 359.99 degrees.


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