mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-20 06:23:34 +08:00
Better / cleaner initialization of the attitude estimator
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
// Define EKF_DEBUG here to enable the debug print calls
|
// Define EKF_DEBUG here to enable the debug print calls
|
||||||
// if the macro is not set, these will be completely
|
// if the macro is not set, these will be completely
|
||||||
// optimized out by the compiler.
|
// optimized out by the compiler.
|
||||||
//#define EKF_DEBUG
|
#define EKF_DEBUG
|
||||||
|
|
||||||
#ifdef EKF_DEBUG
|
#ifdef EKF_DEBUG
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -2263,21 +2263,29 @@ bool AttPosEKF::StatesNaN(struct ekf_status_report *err_report) {
|
|||||||
if (!isfinite(KH[i][j])) {
|
if (!isfinite(KH[i][j])) {
|
||||||
|
|
||||||
err_report->covarianceNaN = true;
|
err_report->covarianceNaN = true;
|
||||||
ekf_debug("KH NaN");
|
|
||||||
err = true;
|
err = true;
|
||||||
} // intermediate result used for covariance updates
|
} // intermediate result used for covariance updates
|
||||||
|
if (err) {
|
||||||
|
ekf_debug("KH NaN");
|
||||||
|
}
|
||||||
|
|
||||||
if (!isfinite(KHP[i][j])) {
|
if (!isfinite(KHP[i][j])) {
|
||||||
|
|
||||||
err_report->covarianceNaN = true;
|
err_report->covarianceNaN = true;
|
||||||
ekf_debug("KHP NaN");
|
|
||||||
err = true;
|
err = true;
|
||||||
} // intermediate result used for covariance updates
|
} // intermediate result used for covariance updates
|
||||||
|
if (err) {
|
||||||
|
ekf_debug("KHP NaN");
|
||||||
|
}
|
||||||
|
|
||||||
if (!isfinite(P[i][j])) {
|
if (!isfinite(P[i][j])) {
|
||||||
|
|
||||||
err_report->covarianceNaN = true;
|
err_report->covarianceNaN = true;
|
||||||
ekf_debug("P NaN");
|
|
||||||
err = true;
|
err = true;
|
||||||
} // covariance matrix
|
} // covariance matrix
|
||||||
|
if (err) {
|
||||||
|
ekf_debug("P NaN");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isfinite(Kfusion[i])) {
|
if (!isfinite(Kfusion[i])) {
|
||||||
@@ -2461,12 +2469,12 @@ void AttPosEKF::InitializeDynamic(float (&initvelNED)[3])
|
|||||||
summedDelVel.z = 0.0f;
|
summedDelVel.z = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AttPosEKF::InitialiseFilter(float (&initvelNED)[3])
|
void AttPosEKF::InitialiseFilter(float (&initvelNED)[3], double referenceLat, double referenceLon, float referenceHgt)
|
||||||
{
|
{
|
||||||
//store initial lat,long and height
|
//store initial lat,long and height
|
||||||
latRef = gpsLat;
|
latRef = referenceLat;
|
||||||
lonRef = gpsLon;
|
lonRef = referenceLon;
|
||||||
hgtRef = gpsHgt;
|
hgtRef = referenceHgt;
|
||||||
|
|
||||||
memset(&last_ekf_error, 0, sizeof(last_ekf_error));
|
memset(&last_ekf_error, 0, sizeof(last_ekf_error));
|
||||||
|
|
||||||
|
|||||||
@@ -308,7 +308,7 @@ void OnGroundCheck();
|
|||||||
|
|
||||||
void CovarianceInit();
|
void CovarianceInit();
|
||||||
|
|
||||||
void InitialiseFilter(float (&initvelNED)[3]);
|
void InitialiseFilter(float (&initvelNED)[3], double referenceLat, double referenceLon, float referenceHgt);
|
||||||
|
|
||||||
float ConstrainFloat(float val, float min, float max);
|
float ConstrainFloat(float val, float min, float max);
|
||||||
|
|
||||||
|
|||||||
@@ -606,7 +606,6 @@ FixedwingEstimator::task_main()
|
|||||||
/* guard against too large deltaT's */
|
/* guard against too large deltaT's */
|
||||||
if (!isfinite(deltaT) || deltaT > 1.0f || deltaT < 0.000001f) {
|
if (!isfinite(deltaT) || deltaT > 1.0f || deltaT < 0.000001f) {
|
||||||
deltaT = 0.01f;
|
deltaT = 0.01f;
|
||||||
warnx("TS fail");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -650,14 +649,14 @@ FixedwingEstimator::task_main()
|
|||||||
IMUmsec = _sensor_combined.timestamp / 1e3f;
|
IMUmsec = _sensor_combined.timestamp / 1e3f;
|
||||||
|
|
||||||
float deltaT = (_sensor_combined.timestamp - last_run) / 1e6f;
|
float deltaT = (_sensor_combined.timestamp - last_run) / 1e6f;
|
||||||
last_run = _sensor_combined.timestamp;
|
|
||||||
|
|
||||||
/* guard against too large deltaT's */
|
/* guard against too large deltaT's */
|
||||||
if (!isfinite(deltaT) || deltaT > 1.0f || deltaT < 0.000001f) {
|
if (!isfinite(deltaT) || deltaT > 1.0f || deltaT < 0.000001f) {
|
||||||
deltaT = 0.01f;
|
deltaT = 0.01f;
|
||||||
warnx("TS fail");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
last_run = _sensor_combined.timestamp;
|
||||||
|
|
||||||
// Always store data, independent of init status
|
// Always store data, independent of init status
|
||||||
/* fill in last data set */
|
/* fill in last data set */
|
||||||
_ekf->dtIMU = deltaT;
|
_ekf->dtIMU = deltaT;
|
||||||
@@ -823,6 +822,8 @@ FixedwingEstimator::task_main()
|
|||||||
*/
|
*/
|
||||||
int check = _ekf->CheckAndBound();
|
int check = _ekf->CheckAndBound();
|
||||||
|
|
||||||
|
const char* ekfname = "[ekf] ";
|
||||||
|
|
||||||
switch (check) {
|
switch (check) {
|
||||||
case 0:
|
case 0:
|
||||||
/* all ok */
|
/* all ok */
|
||||||
@@ -830,27 +831,34 @@ FixedwingEstimator::task_main()
|
|||||||
case 1:
|
case 1:
|
||||||
{
|
{
|
||||||
const char* str = "NaN in states, resetting";
|
const char* str = "NaN in states, resetting";
|
||||||
warnx(str);
|
warnx("%s%s", ekfname, str);
|
||||||
mavlink_log_critical(_mavlink_fd, str);
|
mavlink_log_critical(_mavlink_fd, "%s%s", ekfname, str);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 2:
|
case 2:
|
||||||
{
|
{
|
||||||
const char* str = "stale IMU data, resetting";
|
const char* str = "stale IMU data, resetting";
|
||||||
warnx(str);
|
warnx("%s%s", ekfname, str);
|
||||||
mavlink_log_critical(_mavlink_fd, str);
|
mavlink_log_critical(_mavlink_fd, "%s%s", ekfname, str);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 3:
|
case 3:
|
||||||
{
|
{
|
||||||
const char* str = "switching dynamic / static state";
|
const char* str = "switching to dynamic state";
|
||||||
warnx(str);
|
warnx("%s%s", ekfname, str);
|
||||||
mavlink_log_critical(_mavlink_fd, str);
|
mavlink_log_critical(_mavlink_fd, "%s%s", ekfname, str);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
const char* str = "unknown reset condition";
|
||||||
|
warnx("%s%s", ekfname, str);
|
||||||
|
mavlink_log_critical(_mavlink_fd, "%s%s", ekfname, str);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If non-zero, we got a problem
|
// If non-zero, we got a filter reset
|
||||||
if (check) {
|
if (check) {
|
||||||
|
|
||||||
struct ekf_status_report ekf_report;
|
struct ekf_status_report ekf_report;
|
||||||
@@ -912,7 +920,7 @@ FixedwingEstimator::task_main()
|
|||||||
double lon = home.lon;
|
double lon = home.lon;
|
||||||
float alt = home.alt;
|
float alt = home.alt;
|
||||||
|
|
||||||
_ekf->InitialiseFilter(_ekf->velNED);
|
_ekf->InitialiseFilter(_ekf->velNED, math::radians(lat), math::radians(lon) - M_PI, alt);
|
||||||
|
|
||||||
// Initialize projection
|
// Initialize projection
|
||||||
_local_pos.ref_lat = home.lat * 1e7;
|
_local_pos.ref_lat = home.lat * 1e7;
|
||||||
@@ -942,7 +950,7 @@ FixedwingEstimator::task_main()
|
|||||||
|
|
||||||
_ekf->posNE[0] = _ekf->posNED[0];
|
_ekf->posNE[0] = _ekf->posNED[0];
|
||||||
_ekf->posNE[1] = _ekf->posNED[1];
|
_ekf->posNE[1] = _ekf->posNED[1];
|
||||||
_ekf->InitialiseFilter(_ekf->velNED);
|
_ekf->InitialiseFilter(_ekf->velNED, 0.0, 0.0, 0.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user