mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-03 06:28:27 -04:00
AP_NavEKF2: added checkLaneSwitch()
this allows the vehicle code to ask the EKF to change lanes if it is about to do an EKF failsafe
This commit is contained in:
parent
82369a0602
commit
3073c4da7a
@ -761,12 +761,54 @@ void NavEKF2::UpdateFilter(void)
|
||||
updateLaneSwitchPosResetData(newPrimaryIndex, primary);
|
||||
updateLaneSwitchPosDownResetData(newPrimaryIndex, primary);
|
||||
primary = newPrimaryIndex;
|
||||
lastLaneSwitch_ms = AP_HAL::millis();
|
||||
}
|
||||
}
|
||||
|
||||
check_log_write();
|
||||
}
|
||||
|
||||
/*
|
||||
check if switching lanes will reduce the normalised
|
||||
innovations. This is called when the vehicle code is about to
|
||||
trigger an EKF failsafe, and it would like to avoid that by
|
||||
using a different EKF lane
|
||||
*/
|
||||
void NavEKF2::checkLaneSwitch(void)
|
||||
{
|
||||
uint32_t now = AP_HAL::millis();
|
||||
if (lastLaneSwitch_ms != 0 && now - lastLaneSwitch_ms < 5000) {
|
||||
// don't switch twice in 5 seconds
|
||||
return;
|
||||
}
|
||||
float primaryErrorScore = core[primary].errorScore();
|
||||
float lowestErrorScore = primaryErrorScore;
|
||||
uint8_t newPrimaryIndex = primary;
|
||||
for (uint8_t coreIndex=0; coreIndex<num_cores; coreIndex++) {
|
||||
if (coreIndex != primary) {
|
||||
// an alternative core is available for selection only if healthy and if states have been updated on this time step
|
||||
bool altCoreAvailable = core[coreIndex].healthy();
|
||||
float altErrorScore = core[coreIndex].errorScore();
|
||||
if (altCoreAvailable &&
|
||||
altErrorScore < lowestErrorScore &&
|
||||
altErrorScore < 0.9) {
|
||||
newPrimaryIndex = coreIndex;
|
||||
lowestErrorScore = altErrorScore;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// update the yaw and position reset data to capture changes due to the lane switch
|
||||
if (newPrimaryIndex != primary) {
|
||||
updateLaneSwitchYawResetData(newPrimaryIndex, primary);
|
||||
updateLaneSwitchPosResetData(newPrimaryIndex, primary);
|
||||
updateLaneSwitchPosDownResetData(newPrimaryIndex, primary);
|
||||
primary = newPrimaryIndex;
|
||||
lastLaneSwitch_ms = now;
|
||||
gcs().send_text(MAV_SEVERITY_CRITICAL, "NavEKF2: lane switch %u", primary);
|
||||
}
|
||||
}
|
||||
|
||||
// Check basic filter health metrics and return a consolidated health status
|
||||
bool NavEKF2::healthy(void) const
|
||||
{
|
||||
|
@ -341,6 +341,14 @@ public:
|
||||
*/
|
||||
void writeExtNavData(const Vector3f &sensOffset, const Vector3f &pos, const Quaternion &quat, float posErr, float angErr, uint32_t timeStamp_ms, uint32_t resetTime_ms);
|
||||
|
||||
/*
|
||||
check if switching lanes will reduce the normalised
|
||||
innovations. This is called when the vehicle code is about to
|
||||
trigger an EKF failsafe, and it would like to avoid that by
|
||||
using a different EKF lane
|
||||
*/
|
||||
void checkLaneSwitch(void);
|
||||
|
||||
private:
|
||||
uint8_t num_cores; // number of allocated cores
|
||||
uint8_t primary; // current primary core
|
||||
@ -472,6 +480,9 @@ private:
|
||||
|
||||
bool inhibitGpsVertVelUse; // true when GPS vertical velocity use is prohibited
|
||||
|
||||
// time of last lane switch
|
||||
uint32_t lastLaneSwitch_ms;
|
||||
|
||||
// update the yaw reset data to capture changes due to a lane switch
|
||||
// new_primary - index of the ekf instance that we are about to switch to as the primary
|
||||
// old_primary - index of the ekf instance that we are currently using as the primary
|
||||
|
Loading…
Reference in New Issue
Block a user