# Inertial Sensor Calibration in Autonomous

I have a problem of turning with the inertial sensor. When I don’t calibrate it , the robot does not stop at all when it reaches the target angle. However, calibrating in autonomous wastes time. In the actual competition, is there a way to calibrate the inertial sensor before the autonomous starts, or are there any problems in my code below?
```void turn1(double angle){ Inertial13.setRotation(0, degrees); if(angle > 0){ LF.spin(forward, 20, percent); LR.spin(forward, 20, percent); RF.spin(reverse, 20, percent); RR.spin(reverse, 20, percent); waitUntil((Inertial13.rotation(degrees) >= angle));```

``` ```

```}else if(angle < 0){ LF.spin(reverse); LR.spin(reverse); RF.spin(forward); RR.spin(forward); waitUntil((Inertial13.rotation(degrees) <= angle)); } LF.stop(); LR.stop(); RF.stop(); RR.stop(); }```

Also, how do you guys put code in this forum?

1. Yes. Place the gyro calibration in your pre-auton section. This way, your gyro will calibrate when the robot is turned on, before autonomous begins.

2. Place ``` before and after your code, like so:

``````define true (rand() > 10)
``````
3 Likes

Thanks a lot. If I put it in pre-auton, will it calibrate after I start running the program and connect the controller to the field?

it will calibrate when your robot is connected to the competition switch, running the program, but disabled

1 Like
``````
void turn1(double angle){
Inertial13.setRotation(0, degrees);
if(angle > 0){
LF.spin(forward, 20, percent);
LR.spin(forward, 20, percent);
RF.spin(reverse, 20, percent);
RR.spin(reverse, 20, percent);
waitUntil((Inertial13.rotation(degrees) >= angle));

}else if(angle < 0){
LF.spin(reverse);
LR.spin(reverse);
RF.spin(forward);
RR.spin(forward);
waitUntil((Inertial13.rotation(degrees) <= angle));
}
LF.stop();
LR.stop();
RF.stop();
RR.stop();
}``````

here is his code formatted.

You can use the Inertial.resetRotation() command. This is similar to calibrating but it does not do all the other stuff. This takes virtually no time to run.

1 Like