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() {

vexcodeInit();
Inertial20.calibrate();

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

LeftMotor.spin(reverse);
RightMotor.spin(forward);

waitUntil((Inertial20.rotation(degrees) <= 270.0));
LeftMotor.stop();
RightMotor.stop();
wait(1, seconds);
}``````

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

5 Likes

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.

2 Likes

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

3 Likes

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.

5 Likes

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