mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-27 19:43:37 +08:00
ekf2: move baro control logic to file
This commit is contained in:
@@ -48,6 +48,7 @@ px4_add_module(
|
|||||||
3600
|
3600
|
||||||
SRCS
|
SRCS
|
||||||
EKF/airspeed_fusion.cpp
|
EKF/airspeed_fusion.cpp
|
||||||
|
EKF/baro_height_control.cpp
|
||||||
EKF/bias_estimator.cpp
|
EKF/bias_estimator.cpp
|
||||||
EKF/control.cpp
|
EKF/control.cpp
|
||||||
EKF/covariance.cpp
|
EKF/covariance.cpp
|
||||||
|
|||||||
@@ -33,6 +33,7 @@
|
|||||||
|
|
||||||
add_library(ecl_EKF
|
add_library(ecl_EKF
|
||||||
airspeed_fusion.cpp
|
airspeed_fusion.cpp
|
||||||
|
baro_height_control.cpp
|
||||||
bias_estimator.cpp
|
bias_estimator.cpp
|
||||||
control.cpp
|
control.cpp
|
||||||
covariance.cpp
|
covariance.cpp
|
||||||
|
|||||||
@@ -0,0 +1,135 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
*
|
||||||
|
* Copyright (c) 2022 PX4 Development Team. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* 3. Neither the name PX4 nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file baro_height_control.cpp
|
||||||
|
* Control functions for ekf barometric height fusion
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ekf.h"
|
||||||
|
|
||||||
|
void Ekf::controlBaroHeightFusion()
|
||||||
|
{
|
||||||
|
if (!(_params.baro_ctrl == 1)) {
|
||||||
|
stopBaroHgtFusion();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_baro_b_est.predict(_dt_ekf_avg);
|
||||||
|
|
||||||
|
// check for intermittent data
|
||||||
|
const bool baro_hgt_intermittent = !isRecent(_time_last_baro, 2 * BARO_MAX_INTERVAL);
|
||||||
|
|
||||||
|
if (_baro_data_ready) {
|
||||||
|
_baro_lpf.update(_baro_sample_delayed.hgt);
|
||||||
|
updateBaroHgt(_baro_sample_delayed, _aid_src_baro_hgt);
|
||||||
|
|
||||||
|
const bool continuing_conditions_passing = !_baro_hgt_faulty && !baro_hgt_intermittent;
|
||||||
|
const bool starting_conditions_passing = continuing_conditions_passing;
|
||||||
|
|
||||||
|
if (_control_status.flags.baro_hgt) {
|
||||||
|
if (continuing_conditions_passing) {
|
||||||
|
fuseBaroHgt(_aid_src_baro_hgt);
|
||||||
|
|
||||||
|
const bool is_fusion_failing = isTimedOut(_aid_src_baro_hgt.time_last_fuse, _params.hgt_fusion_timeout_max);
|
||||||
|
|
||||||
|
if (isHeightResetRequired()) {
|
||||||
|
// All height sources are failing
|
||||||
|
resetHeightToBaro();
|
||||||
|
resetVerticalVelocityToZero();
|
||||||
|
|
||||||
|
} else if (is_fusion_failing) {
|
||||||
|
// Some other height source is still working
|
||||||
|
stopBaroHgtFusion();
|
||||||
|
_baro_hgt_faulty = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
stopBaroHgtFusion();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (starting_conditions_passing) {
|
||||||
|
startBaroHgtFusion();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (_control_status.flags.baro_hgt && baro_hgt_intermittent) {
|
||||||
|
// No baro data anymore. Stop until it comes back.
|
||||||
|
stopBaroHgtFusion();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Ekf::startBaroHgtFusion()
|
||||||
|
{
|
||||||
|
if (!_control_status.flags.baro_hgt) {
|
||||||
|
if (_params.height_sensor_ref == HeightSensor::BARO) {
|
||||||
|
_height_sensor_ref = HeightSensor::BARO;
|
||||||
|
resetHeightToBaro();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
_baro_b_est.setBias(_state.pos(2) + _baro_lpf.getState());
|
||||||
|
}
|
||||||
|
|
||||||
|
_control_status.flags.baro_hgt = true;
|
||||||
|
_baro_b_est.setFusionActive();
|
||||||
|
ECL_INFO("starting baro height fusion");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Ekf::resetHeightToBaro()
|
||||||
|
{
|
||||||
|
ECL_INFO("reset height to baro");
|
||||||
|
_information_events.flags.reset_hgt_to_baro = true;
|
||||||
|
|
||||||
|
resetVerticalPositionTo(-(_baro_sample_delayed.hgt - _baro_b_est.getBias()));
|
||||||
|
|
||||||
|
// the state variance is the same as the observation
|
||||||
|
P.uncorrelateCovarianceSetVariance<1>(9, sq(_params.baro_noise));
|
||||||
|
|
||||||
|
_gps_hgt_b_est.setBias(_gps_hgt_b_est.getBias() + _state_reset_status.posD_change);
|
||||||
|
_rng_hgt_b_est.setBias(_rng_hgt_b_est.getBias() + _state_reset_status.posD_change);
|
||||||
|
_ev_hgt_b_est.setBias(_ev_hgt_b_est.getBias() - _state_reset_status.posD_change);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Ekf::stopBaroHgtFusion()
|
||||||
|
{
|
||||||
|
if (_control_status.flags.baro_hgt) {
|
||||||
|
if (_height_sensor_ref == HeightSensor::BARO) {
|
||||||
|
_height_sensor_ref = HeightSensor::UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
_control_status.flags.baro_hgt = false;
|
||||||
|
_baro_b_est.setFusionInactive();
|
||||||
|
ECL_INFO("stopping baro height fusion");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -759,57 +759,6 @@ bool Ekf::isConditionalRangeAidSuitable()
|
|||||||
return is_range_aid_suitable;
|
return is_range_aid_suitable;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Ekf::controlBaroHeightFusion()
|
|
||||||
{
|
|
||||||
if (!(_params.baro_ctrl == 1)) {
|
|
||||||
stopBaroHgtFusion();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_baro_b_est.predict(_dt_ekf_avg);
|
|
||||||
|
|
||||||
// check for intermittent data
|
|
||||||
const bool baro_hgt_intermittent = !isRecent(_time_last_baro, 2 * BARO_MAX_INTERVAL);
|
|
||||||
|
|
||||||
if (_baro_data_ready) {
|
|
||||||
_baro_lpf.update(_baro_sample_delayed.hgt);
|
|
||||||
updateBaroHgt(_baro_sample_delayed, _aid_src_baro_hgt);
|
|
||||||
|
|
||||||
const bool continuing_conditions_passing = !_baro_hgt_faulty && !baro_hgt_intermittent;
|
|
||||||
const bool starting_conditions_passing = continuing_conditions_passing;
|
|
||||||
|
|
||||||
if (_control_status.flags.baro_hgt) {
|
|
||||||
if (continuing_conditions_passing) {
|
|
||||||
fuseBaroHgt(_aid_src_baro_hgt);
|
|
||||||
|
|
||||||
const bool is_fusion_failing = isTimedOut(_aid_src_baro_hgt.time_last_fuse, _params.hgt_fusion_timeout_max);
|
|
||||||
|
|
||||||
if (isHeightResetRequired()) {
|
|
||||||
// All height sources are failing
|
|
||||||
resetHeightToBaro();
|
|
||||||
resetVerticalVelocityToZero();
|
|
||||||
|
|
||||||
} else if (is_fusion_failing) {
|
|
||||||
// Some other height source is still working
|
|
||||||
stopBaroHgtFusion();
|
|
||||||
_baro_hgt_faulty = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
stopBaroHgtFusion();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (starting_conditions_passing) {
|
|
||||||
startBaroHgtFusion();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (_control_status.flags.baro_hgt && baro_hgt_intermittent) {
|
|
||||||
// No baro data anymore. Stop until it comes back.
|
|
||||||
stopBaroHgtFusion();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Ekf::controlGnssHeightFusion()
|
void Ekf::controlGnssHeightFusion()
|
||||||
{
|
{
|
||||||
if (!(_params.gnss_ctrl & GnssCtrl::VPOS)) {
|
if (!(_params.gnss_ctrl & GnssCtrl::VPOS)) {
|
||||||
|
|||||||
@@ -251,21 +251,6 @@ void Ekf::resetVerticalPositionTo(const float new_vert_pos)
|
|||||||
_time_last_hgt_fuse = _time_last_imu;
|
_time_last_hgt_fuse = _time_last_imu;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Ekf::resetHeightToBaro()
|
|
||||||
{
|
|
||||||
ECL_INFO("reset height to baro");
|
|
||||||
_information_events.flags.reset_hgt_to_baro = true;
|
|
||||||
|
|
||||||
resetVerticalPositionTo(-(_baro_sample_delayed.hgt - _baro_b_est.getBias()));
|
|
||||||
|
|
||||||
// the state variance is the same as the observation
|
|
||||||
P.uncorrelateCovarianceSetVariance<1>(9, sq(_params.baro_noise));
|
|
||||||
|
|
||||||
_gps_hgt_b_est.setBias(_gps_hgt_b_est.getBias() + _state_reset_status.posD_change);
|
|
||||||
_rng_hgt_b_est.setBias(_rng_hgt_b_est.getBias() + _state_reset_status.posD_change);
|
|
||||||
_ev_hgt_b_est.setBias(_ev_hgt_b_est.getBias() - _state_reset_status.posD_change);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Ekf::resetHeightToGps()
|
void Ekf::resetHeightToGps()
|
||||||
{
|
{
|
||||||
ECL_INFO("reset height to GPS");
|
ECL_INFO("reset height to GPS");
|
||||||
@@ -1303,36 +1288,6 @@ void Ekf::startMag3DFusion()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Ekf::startBaroHgtFusion()
|
|
||||||
{
|
|
||||||
if (!_control_status.flags.baro_hgt) {
|
|
||||||
if (_params.height_sensor_ref == HeightSensor::BARO) {
|
|
||||||
_height_sensor_ref = HeightSensor::BARO;
|
|
||||||
resetHeightToBaro();
|
|
||||||
|
|
||||||
} else {
|
|
||||||
_baro_b_est.setBias(_state.pos(2) + _baro_lpf.getState());
|
|
||||||
}
|
|
||||||
|
|
||||||
_control_status.flags.baro_hgt = true;
|
|
||||||
_baro_b_est.setFusionActive();
|
|
||||||
ECL_INFO("starting baro height fusion");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Ekf::stopBaroHgtFusion()
|
|
||||||
{
|
|
||||||
if (_control_status.flags.baro_hgt) {
|
|
||||||
if (_height_sensor_ref == HeightSensor::BARO) {
|
|
||||||
_height_sensor_ref = HeightSensor::UNKNOWN;
|
|
||||||
}
|
|
||||||
|
|
||||||
_control_status.flags.baro_hgt = false;
|
|
||||||
_baro_b_est.setFusionInactive();
|
|
||||||
ECL_INFO("stopping baro height fusion");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Ekf::startGpsHgtFusion()
|
void Ekf::startGpsHgtFusion()
|
||||||
{
|
{
|
||||||
if (!_control_status.flags.gps_hgt) {
|
if (!_control_status.flags.gps_hgt) {
|
||||||
|
|||||||
Reference in New Issue
Block a user