|
|
|
@ -44,6 +44,7 @@
@@ -44,6 +44,7 @@
|
|
|
|
|
#include "estimator_22states.h" |
|
|
|
|
|
|
|
|
|
#include <px4_config.h> |
|
|
|
|
#include <px4_tasks.h> |
|
|
|
|
#include <stdio.h> |
|
|
|
|
#include <stdlib.h> |
|
|
|
|
#include <string.h> |
|
|
|
@ -281,7 +282,7 @@ AttitudePositionEstimatorEKF::~AttitudePositionEstimatorEKF()
@@ -281,7 +282,7 @@ AttitudePositionEstimatorEKF::~AttitudePositionEstimatorEKF()
|
|
|
|
|
|
|
|
|
|
/* if we have given up, kill it */ |
|
|
|
|
if (++i > 50) { |
|
|
|
|
task_delete(_estimator_task); |
|
|
|
|
px4_task_delete(_estimator_task); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} while (_estimator_task != -1); |
|
|
|
@ -490,7 +491,8 @@ void AttitudePositionEstimatorEKF::task_main()
@@ -490,7 +491,8 @@ void AttitudePositionEstimatorEKF::task_main()
|
|
|
|
|
_filter_start_time = hrt_absolute_time(); |
|
|
|
|
|
|
|
|
|
if (!_ekf) { |
|
|
|
|
errx(1, "OUT OF MEM!"); |
|
|
|
|
warnx("OUT OF MEM!"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
@ -696,10 +698,8 @@ void AttitudePositionEstimatorEKF::task_main()
@@ -696,10 +698,8 @@ void AttitudePositionEstimatorEKF::task_main()
|
|
|
|
|
|
|
|
|
|
_task_running = false; |
|
|
|
|
|
|
|
|
|
warnx("exiting.\n"); |
|
|
|
|
|
|
|
|
|
_estimator_task = -1; |
|
|
|
|
_exit(0); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AttitudePositionEstimatorEKF::initializeGPS() |
|
|
|
@ -1039,7 +1039,7 @@ int AttitudePositionEstimatorEKF::start()
@@ -1039,7 +1039,7 @@ int AttitudePositionEstimatorEKF::start()
|
|
|
|
|
SCHED_DEFAULT, |
|
|
|
|
SCHED_PRIORITY_MAX - 40, |
|
|
|
|
7500, |
|
|
|
|
(main_t)&AttitudePositionEstimatorEKF::task_main_trampoline, |
|
|
|
|
(px4_main_t)&AttitudePositionEstimatorEKF::task_main_trampoline, |
|
|
|
|
nullptr); |
|
|
|
|
|
|
|
|
|
if (_estimator_task < 0) { |
|
|
|
@ -1155,7 +1155,7 @@ void AttitudePositionEstimatorEKF::pollData()
@@ -1155,7 +1155,7 @@ void AttitudePositionEstimatorEKF::pollData()
|
|
|
|
|
float deltaT = (_sensor_combined.timestamp - _last_run) / 1e6f; |
|
|
|
|
|
|
|
|
|
/* guard against too large deltaT's */ |
|
|
|
|
if (!isfinite(deltaT) || deltaT > 1.0f || deltaT < 0.000001f) { |
|
|
|
|
if (!std::isfinite(deltaT) || deltaT > 1.0f || deltaT < 0.000001f) { |
|
|
|
|
deltaT = 0.01f; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1167,9 +1167,9 @@ void AttitudePositionEstimatorEKF::pollData()
@@ -1167,9 +1167,9 @@ void AttitudePositionEstimatorEKF::pollData()
|
|
|
|
|
|
|
|
|
|
int last_gyro_main = _gyro_main; |
|
|
|
|
|
|
|
|
|
if (isfinite(_sensor_combined.gyro_rad_s[0]) && |
|
|
|
|
isfinite(_sensor_combined.gyro_rad_s[1]) && |
|
|
|
|
isfinite(_sensor_combined.gyro_rad_s[2]) && |
|
|
|
|
if (std::isfinite(_sensor_combined.gyro_rad_s[0]) && |
|
|
|
|
std::isfinite(_sensor_combined.gyro_rad_s[1]) && |
|
|
|
|
std::isfinite(_sensor_combined.gyro_rad_s[2]) && |
|
|
|
|
(_sensor_combined.gyro_errcount <= _sensor_combined.gyro1_errcount)) { |
|
|
|
|
|
|
|
|
|
_ekf->angRate.x = _sensor_combined.gyro_rad_s[0]; |
|
|
|
@ -1178,9 +1178,9 @@ void AttitudePositionEstimatorEKF::pollData()
@@ -1178,9 +1178,9 @@ void AttitudePositionEstimatorEKF::pollData()
|
|
|
|
|
_gyro_main = 0; |
|
|
|
|
_gyro_valid = true; |
|
|
|
|
|
|
|
|
|
} else if (isfinite(_sensor_combined.gyro1_rad_s[0]) && |
|
|
|
|
isfinite(_sensor_combined.gyro1_rad_s[1]) && |
|
|
|
|
isfinite(_sensor_combined.gyro1_rad_s[2])) { |
|
|
|
|
} else if (std::isfinite(_sensor_combined.gyro1_rad_s[0]) && |
|
|
|
|
std::isfinite(_sensor_combined.gyro1_rad_s[1]) && |
|
|
|
|
std::isfinite(_sensor_combined.gyro1_rad_s[2])) { |
|
|
|
|
|
|
|
|
|
_ekf->angRate.x = _sensor_combined.gyro1_rad_s[0]; |
|
|
|
|
_ekf->angRate.y = _sensor_combined.gyro1_rad_s[1]; |
|
|
|
@ -1528,25 +1528,29 @@ int AttitudePositionEstimatorEKF::trip_nan()
@@ -1528,25 +1528,29 @@ int AttitudePositionEstimatorEKF::trip_nan()
|
|
|
|
|
int ekf_att_pos_estimator_main(int argc, char *argv[]) |
|
|
|
|
{ |
|
|
|
|
if (argc < 2) { |
|
|
|
|
errx(1, "usage: ekf_att_pos_estimator {start|stop|status|logging}"); |
|
|
|
|
warnx("usage: ekf_att_pos_estimator {start|stop|status|logging}"); |
|
|
|
|
return 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!strcmp(argv[1], "start")) { |
|
|
|
|
|
|
|
|
|
if (estimator::g_estimator != nullptr) { |
|
|
|
|
errx(1, "already running"); |
|
|
|
|
warnx("already running"); |
|
|
|
|
return 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
estimator::g_estimator = new AttitudePositionEstimatorEKF(); |
|
|
|
|
|
|
|
|
|
if (estimator::g_estimator == nullptr) { |
|
|
|
|
errx(1, "alloc failed"); |
|
|
|
|
warnx("alloc failed"); |
|
|
|
|
return 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (OK != estimator::g_estimator->start()) { |
|
|
|
|
delete estimator::g_estimator; |
|
|
|
|
estimator::g_estimator = nullptr; |
|
|
|
|
err(1, "start failed"); |
|
|
|
|
warnx("start failed"); |
|
|
|
|
return 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* avoid memory fragmentation by not exiting start handler until the task has fully started */ |
|
|
|
@ -1558,64 +1562,46 @@ int ekf_att_pos_estimator_main(int argc, char *argv[])
@@ -1558,64 +1562,46 @@ int ekf_att_pos_estimator_main(int argc, char *argv[])
|
|
|
|
|
|
|
|
|
|
printf("\n"); |
|
|
|
|
|
|
|
|
|
exit(0); |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (estimator::g_estimator == nullptr) { |
|
|
|
|
warnx("not running"); |
|
|
|
|
return 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!strcmp(argv[1], "stop")) { |
|
|
|
|
if (estimator::g_estimator == nullptr) { |
|
|
|
|
errx(1, "not running"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
delete estimator::g_estimator; |
|
|
|
|
estimator::g_estimator = nullptr; |
|
|
|
|
exit(0); |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!strcmp(argv[1], "status")) { |
|
|
|
|
if (estimator::g_estimator) { |
|
|
|
|
warnx("running"); |
|
|
|
|
warnx("running"); |
|
|
|
|
|
|
|
|
|
estimator::g_estimator->print_status(); |
|
|
|
|
estimator::g_estimator->print_status(); |
|
|
|
|
|
|
|
|
|
exit(0); |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
errx(1, "not running"); |
|
|
|
|
} |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!strcmp(argv[1], "trip")) { |
|
|
|
|
if (estimator::g_estimator) { |
|
|
|
|
int ret = estimator::g_estimator->trip_nan(); |
|
|
|
|
|
|
|
|
|
exit(ret); |
|
|
|
|
int ret = estimator::g_estimator->trip_nan(); |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
errx(1, "not running"); |
|
|
|
|
} |
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!strcmp(argv[1], "logging")) { |
|
|
|
|
if (estimator::g_estimator) { |
|
|
|
|
int ret = estimator::g_estimator->enable_logging(true); |
|
|
|
|
int ret = estimator::g_estimator->enable_logging(true); |
|
|
|
|
|
|
|
|
|
exit(ret); |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
errx(1, "not running"); |
|
|
|
|
} |
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!strcmp(argv[1], "debug")) { |
|
|
|
|
if (estimator::g_estimator) { |
|
|
|
|
int debug = strtoul(argv[2], NULL, 10); |
|
|
|
|
int ret = estimator::g_estimator->set_debuglevel(debug); |
|
|
|
|
|
|
|
|
|
exit(ret); |
|
|
|
|
int debug = strtoul(argv[2], NULL, 10); |
|
|
|
|
int ret = estimator::g_estimator->set_debuglevel(debug); |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
errx(1, "not running"); |
|
|
|
|
} |
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
warnx("unrecognized command"); |
|
|
|
|