mirror of
https://github.com/ArduPilot/ardupilot.git
synced 2026-10-06 19:00:27 +08:00
AP_Compass: fix issue with compass registration for more than 3 compasses
This fixes an issue where we would fail to register a dronecan compass if its not already in the stored DEV_ID position that matches the detection order This is fixed by ensuring that we try our best to register the compass in the stored DEV_ID position that matches the priority order. This in turn allows for over 3 dronecan compasses to appear and not cause incorrect registration failures at boot.
This commit is contained in:
committed by
Andrew Tridgell
parent
d0554c3ce3
commit
a6d03bb8a1
@@ -991,6 +991,17 @@ bool Compass::register_compass(int32_t dev_id, uint8_t& instance)
|
||||
|
||||
// This might be a replacement compass module, find any unregistered compass
|
||||
// instance and replace that
|
||||
priority = _update_priority_list(dev_id);
|
||||
// try to match priority and state index if possible, this ensure that compass order
|
||||
// to state order while detection is preserved, this ensures that if compasses in priority
|
||||
// list show up out of order during detection, it does not replace the state.
|
||||
StateIndex priority_index = StateIndex(uint8_t(priority));
|
||||
if (!_state[priority_index].registered && priority < COMPASS_MAX_INSTANCES) {
|
||||
_state[priority_index].registered = true;
|
||||
_state[priority_index].priority = priority;
|
||||
instance = uint8_t(priority_index);
|
||||
return true;
|
||||
}
|
||||
for (StateIndex i(0); i<COMPASS_MAX_INSTANCES; i++) {
|
||||
priority = _update_priority_list(dev_id);
|
||||
if (!_state[i].registered && priority < COMPASS_MAX_INSTANCES) {
|
||||
|
||||
Reference in New Issue
Block a user