I recently had a similar issue with poor Loiter over the summer on one of my SVs and finally got some time to look into the cause. I used one of my stock SVs, which Loitered well, as a baseline and compared the parameters with the one that didn’t.
Granted, I had messed around with things like swapping the STM32 Flight Controller (I burned out the original) and binding to my Taranis radio (which was cool). So I went back to the stock transmitter, Toy Mode, and tried to compare the differences. The main differences are below:
- COMPASS_AUTODEC should be 2 (undocumented, WiKi has 0 or 1) for the automatic calculation of the declination based on gps location.
- COMPASS_LEARN should be 2 for EKF-Learning
- COMPASS_PMOT_EN should be 1 for enabling per-motor compass correction.
Sometimes I made multiple changes at once, which is not good for testing isolation, but it is winter here and I literally fly out of my house in Alt. Hold mode and then switch to Loiter in the backyard for testing. Crazy, huh?
In addition to setting the parameters above (not sure what COMPASS_AUTODEC set to 2 does, perhaps anything non-0 is the same as 1) I realized that the SV uses COMPASS_PMOT_EN set to 1. So I raised the GPS module above the case and re-calibrated the compass using the Onboard Mag Calibration routine successfully. Again, I made multiple changes at once. On my first flight in the backyard using LOITER mode, I could literally see the hover get better and better! It went from toilet bowl to a solid hover! After a minute or two, my SV hovered just fine as if it was fresh out of the box.