There’s an issue with Airbot’s PX4MiniAIO board where, when a second compass is used, the second compass is always forced to be “internal” in the configuration. I’ve traced it down code in “modules/PX4Firmware/src/drivers/hmc5883/hmc5883_i2c.cpp” that sets the compass to internal if it’s on a PX4-V1 and not using the I2C_BUS_EXPANSION port.
A fix I see for this is to modify the “libraries/AP_Compass/AP_Compass_PX4.cpp” code so that the second and third compasses are always set to be “external.” This will fix the PX4MiniAIO-compass issue, while preserving the current functionality of having a possible internal (first) compass on PX4-V1 boards.
The code change may be viewed here. Does this look like an OK fix? If so, I’ll post it as a PR.
Looking at it some more, there’s still a case that this patch doesn’t fix: If the user disables the (default) compass on the USB dongle and uses only a compass on the GPS unit (hooked up to the IIC2/GPS connector), that compass will be forced to be set as “internal.” (This is problematic because then a compass orientation cannot be configured.)
Are there current PX4-V1 boards where the compass(es) really want to be forced to be set to internal based on which I2C port is used? I’m wondering if it would be best to just have “AP_Compass_PX4.cpp” set all compasses to “external” (like here). Worst case scenario is that an internal compass would be setup as external and might need to have its orientation configured by the user.
I think instead we should make the COMPASS_EXTERNAL parameters take on 3 values:
- 0: not external, with auto-detection
- 1: external, with auto-detection
- 2: forced external, no auto-detection
that provides compatibility with existing setups while allowing anyone to override the external detection. Doing it based on the compass index doesn’t work in many cases
That looks good; thanks for implementing it, Tridge. Once it gets in it’d be good if the external-compass option on the Mission Planner “Compass” page could be changed from a check box to a pull-down combo-box with the three options.
yep, a MP update would be good. Do you want to open an issue for Michael?