Inertial Sensor Not Reading during Autonomous

Hello,
When I run a very simple Inertial reading code autonomous, I keep getting inertial readings of 0 for the first 2-3 seconds.

bool stepper_enabled = true;
int code_stepper(){
  while(stepper_enabled){
    cout << Inertial.rotation(degrees) << endl;
    task::sleep(time_sleep);
  }
  return 1;
}

void autonomous(void) {
  task Stepp(code_stepper);
}

My procedure:

  1. I uploaded my code with this simple auton reading ruitine
  2. On the controller, I went to the program β†’ Competition β†’ Programming Skills
  3. I then pressed β€œA” and the inertial readings are incorrect

The inertial sensor showed 0 for about 2 seconds before actually reading accurate values

0
0
0
0
0
0
0
0
0
0.0048
0.0051
0.0059
0.0072
0.0078
0.01
0.011

How can I make it such that when I run the auton routine, I don’t have to physically make the robot wait 2 seconds just for the inertial sensor to initialize?

It sounds like your brain and/or controller are not on latest firmware. The program should run at the beginning of the 3 second countdown so when auton starts the imu has finished calibration.

6 Likes

Thank you!

Just in case, in the future if someone goes back to this thread I built a simple safeguard for anyone having this issue and cannot update their brain. Note: This may chop off about 1-2 seconds of auton, but at least you have something in case of an emergency

wait_until_inertial_initialized(){
  while(inertial_sensor.isCalibrating())
    vex::task::sleep(20);
}

void autonomous(void) {

wait_until_inertial_initialized();
//Then do stuff 
}
1 Like

When was this updated? I feel like this is a relatively recent change.

itd probably be better to use vex::inertial::isCalibrating() for this

3 Likes

July 2021, so not that recent.

3 Likes

What is the difference?

He provided a construction of the actual function itself and where it comes from. I edited my post after he made that response to have the function as he requested. (Aka if you look at my code it implements exactly what he said)