IMU Calibration

I’m exploring the API of the vex::inertial class and I’m curious about the calibrate function. I see that it takes in duration seconds and is non-blocking.

What is the recommend duration for calibration? What exactly does calibration do if there is resetRotation function? Should I be calling this function at the start of every autonomous period or just resetRotation?

Thank you

2 Likes

about 2 seconds

probably try to google it because I am not sure and this thread has some good information and some about what you were talking about - When/how to calibrate inertial sensor - #3 by jpearman

1 Like

which platform ?
V5, EXP and IQ generation 2, the calibrate function (although technically accepting a “value”) has a fixed calibration time. IQ generation 1 does accept a time parameter for the legacy gyro.

3 Likes

I’m guessing that the calibrate method’s parameter is unused then? Is it just there for legacy reasons?

Sort of a related issue, but sometimes when using the turnToHeading( ) function, the robot will wait ~3 seconds before turning. The only difference between this happening and its normal turning is the inertial calibration time. Does the turnToHeading( ) function wait until the inertial sensor is calibrated or could there something else wrong?

IMU calibration will already block the task that it’s called in. There shouldn’t be any additional need to wait. The amount of time that calibration takes depends on several conditions, but generally shouldn’t take longer than 3 or 4 seconds. If the sensor is moved off-axis during calibration, it may restart the process and take longer.

Calling resetRotation does not affect calibration. What it does is store an internal offset at the time that it’s called and negate that from future rotation readings. For example, if I called resetRotation while the rotation was 20 degrees, the offset would be stored as -20 and added to future rotation readings (meaning it would read as 0 after being called because 20 - 20 == 0).

Calibration should be performed before any data is read or set on the sensor. It should generally be one of the first things you do in your program.

The inertial sensor is effectively a replacement for the old legacy yaw rate gyro. The legacy gyro did accept a value indicating how long to calibrate. The inertial and gyro classes have the same base class, this allows either to be passed to our drivetrain class as a sensor that can provide a heading/angle. The base class has pure virtual methods that must be implemented in all derived classes, that’s why calibrate has an unused parameter.

calibrate() doesn’t block, you need to check if calibration has completed. For example, VEXcode generates this type of code when you add an IMU to a drivetrain.

  BrainInertial.calibrate();
  while (BrainInertial.isCalibrating()) {
    wait(25, msec);
  }
2 Likes

Thank you all for the information.

Currently, i instruct our driver to only run the program after it is setup for autons just to reduce the chances of IMU screwing up. I was asking so I could call calibrate at the beginning of auton periods but clearly thats not the way to go. I’ll just continue calling resetRotation at the start of auton and only running program after bot setup is completed.

1 Like

Oh, that’s interesting. Guess I always assumed it was the same as the PROS implementation and never noticed since I always calibrated while disabled anyways.

PROS gives you the choice, not sure if that changed with the 4.0 release but this was the comment from 3.8, default for blocking param is false.

/**
 * Calibrate IMU
 *
 * Calibration takes approximately 2 seconds and blocks during this period if 
 * the blocking param is true, with a timeout for this operation being set a 3 
 * seconds as a safety margin. This function also blocks until the IMU 
 * status flag is set properly to E_IMU_STATUS_CALIBRATING, with a minimum 
 * blocking time of 5ms and a timeout of 1 second if it's never set.
2 Likes