Cannot trim AHRS on IMU 2

It seems I have a Cube Black that has an IMU 2 that is a bit misaligned. The drone flies fine when the the EKF is using IMU 1, but if it switches to IMU 2, the level trim is way off. I expected to be able to compensate for this by doing an accel cal with some appropriate combination of INS_ACC_BODYFIX and INS_TRIM_OPTION, but no matter what I do, I cannot get IMU 2 to fly level.

@rmackay9 does this sound weird to you? Was going to make an issue, but I wasn’t sure if I was doing something wrong.

So the questions/problems are:

  • Is it supposed to be possible to level AHRS based on IMU 2 or 3? If so, what am I doing wrong?
  • Would Ardupilot have save trim values for each IMU to guarantee that they’re all trimmed?

I flew this on Copter 3.6.9 because I could easily force the EKF to use a different IMU without disabling them (in later versions it resets to IMU 1 when disarmed). Haven’t done testing on 4.0, but I didn’t see any commits that might have changed this.

The regular accel calibration should ensure that all the accelerometers are calibrated (offsets added, scaling applied) so that they all point in the same direction. The AHRS_TRIM values should then be applied to all accelerometers.

A random guess without seeing a log is that there’s high vibration and/or aliasing happening which is affecting only the 2nd IMU. The two IMUs update at different rates (1600Hz vs 1000hz) so they can be affected by different frequencies of vibration meaning that one might work well while the other doesn’t.

EK2_IMU_MASK = 2 should allow using only the 2nd IMU. This is slightly less safe than flying with both but if you’re ready with a manual flight mode (stabilize) it’s probably safe.

It’s probably best to attach an onboard log file and maybe try with Copter-4.0.3.

That’s what I thought, but things weren’t making sense. And now I know why:

For some reason, rebooting the FC may cause IMU 2 to change its behavior. Here are two flights:

Good flight (log, it’s the second flight in this log):

Bad flight (log):

Both flights are using IMU 2 in very low wind conditions. The first one flies well - the average roll/pitch during loiter is ~0 degrees and the drone holds position easily. In the second flight, you can see that the drone is oscillating. This is not a PID/filter/vibration problem - it is a 5 Hz signal from the position controller trying to hold position while the IMU makes it feel like it is flying forward and left, hence the average -2 degree attitude in pitch and roll while it is holding position (the drone is actually level). Notice the oscillations disappear immediately when I switch to althold. And here’s the weird part that was confusing me earlier: The only difference between these two flights is a FC reboot. Accel offsets and AHRS trim are unchanged. For some reason, this problem doesn’t always manifest.

This sounds like the leans we have been seeing on smaller copters. There always used to be issues with one of the Pixhawk 1 IMUs due to transient power supply issues at boot. Could this be similar? What FC is this? What is the IMU?

It’s a Cube Black, so IMU 2 is an LSM303D.

What are typical values for accel drift with temperature? Maybe it’s an issue with cold start vs. hot start? Doesn’t really make sense, though, I performed my calibrations after the IMU was hot, and both of those flights had similar IMU temps.

Disarmed logging after a cold start: