V5 Inertial Sensor Problem

We are trying to program our Inertial Sensor but it never work well in our autonomous period. It’s like nothing change with inertial sensor or without inertial sensor.

void turnR(int vel, int deg) {
  DrivetrainInertial.setRotation(0, degrees);
  Drivetrain.setTurnVelocity(vel, pct);
  waitUntil((DrivetrainInertial.rotation(degrees) >= deg));
void turnL(int vel, int deg) {
  DrivetrainInertial.setRotation(0, degrees);
  Drivetrain.setTurnVelocity(vel, pct);
  waitUntil((-DrivetrainInertial.rotation(degrees) >= deg));

Here is our turning functions for autonomous period. Inertial sensor was initalized for “Drivetrain” code. Is there anyone to help?

My first assumption is that the problem is that your robot is overshooting the target. Am I correct? If so, you should implement a PID controller on your drive. As of now, even if your robot is only 0.00001 degrees away from the target, it is still going at max speed. Robots cannot stop immediately, so your robot will inevitably go past where it was supposed to. A PID controller aims to smooth out the velocity of your drive so that it comes to a nice clean stop. Please read this article by George Gillard IN ITS ENTIRETY. It is extremely helpful, and probably the most popular starting point for learning about PID.


Have you tried the turn methods provided in vexcode? turnFor, turnToHeading, turnToRotation tend to work reasonably well.

There are good reasons to develop your own motor control methods, but you can definitely have success with these.

It’s funny that you reset the rotations before each code, I would suspect you would wanna do that in pre auton so that way the headings stay the same.

Idk if you played with turn threshold or turn constant, it should be in the vex library if you don’t wanna try and read that PID guide, it could help a bit.

The Drivetrain has logic included for heading and turning by degrees. You can use turnToHeading and turnFor.


  // Set Drivetrain parameters
  Drivetrain.setHeading(0.0, degrees);
  Drivetrain.setTurnVelocity(50.0, percent);
  Drivetrain.setDriveVelocity(50.0, percent);
  //Make sure the Drivetrain has enough time to make the move.
  Drivetrain.setTimeout(5.0, sec);
  //Drive forward
  Drivetrain.driveFor(forward, 12.0, inches, true);
  // Turn with heading
  Drivetrain.turnToHeading(45.0, degrees, true);
  // Turn with direction and degrees
  Drivetrain.turnFor(right, 45.0, degrees, true);

Be sure to test your inertial sensor.

1 Like