AP_AHRS: support locked access to AHRS data

This commit is contained in:
Andrew Tridgell 2018-08-20 11:18:03 +10:00
parent 0aeceb22d9
commit 9897bf6127
3 changed files with 31 additions and 1 deletions

View File

@ -29,6 +29,7 @@
#include <AP_InertialSensor/AP_InertialSensor.h>
#include <AP_Baro/AP_Baro.h>
#include <AP_Param/AP_Param.h>
#include <AP_Common/Semaphore.h>
class OpticalFlow;
#define AP_AHRS_TRIM_LIMIT 10.0f // maximum trim angle in degrees
@ -571,7 +572,16 @@ public:
// Write position and quaternion data from an external navigation system
virtual void writeExtNavData(const Vector3f &sensOffset, const Vector3f &pos, const Quaternion &quat, float posErr, float angErr, uint32_t timeStamp_ms, uint32_t resetTime_ms) { }
// allow threads to lock against AHRS update
HAL_Semaphore &get_semaphore(void) {
return _rsem;
}
protected:
// multi-thread access support
HAL_Semaphore_Recursive _rsem;
AHRS_VehicleClass _vehicle_class;
// settable parameters

View File

@ -49,6 +49,9 @@ AP_AHRS_DCM::reset_gyro_drift(void)
void
AP_AHRS_DCM::update(bool skip_ins_update)
{
// support locked access functions to AHRS data
WITH_SEMAPHORE(_rsem);
float delta_t;
if (_last_startup_ms == 0) {
@ -141,6 +144,9 @@ AP_AHRS_DCM::matrix_update(float _G_Dt)
void
AP_AHRS_DCM::reset(bool recover_eulers)
{
// support locked access functions to AHRS data
WITH_SEMAPHORE(_rsem);
// reset the integration terms
_omega_I.zero();
_omega_P.zero();

View File

@ -70,6 +70,9 @@ const Vector3f &AP_AHRS_NavEKF::get_gyro_drift(void) const
// should be called if gyro offsets are recalculated
void AP_AHRS_NavEKF::reset_gyro_drift(void)
{
// support locked access functions to AHRS data
WITH_SEMAPHORE(_rsem);
// update DCM
AP_AHRS_DCM::reset_gyro_drift();
@ -80,6 +83,9 @@ void AP_AHRS_NavEKF::reset_gyro_drift(void)
void AP_AHRS_NavEKF::update(bool skip_ins_update)
{
// support locked access functions to AHRS data
WITH_SEMAPHORE(_rsem);
// drop back to normal priority if we were boosted by the INS
// calling delay_microseconds_boost()
hal.scheduler->boost_end();
@ -89,7 +95,6 @@ void AP_AHRS_NavEKF::update(bool skip_ins_update)
_ekf_type.set(2);
}
update_DCM(skip_ins_update);
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
@ -366,6 +371,9 @@ const Vector3f &AP_AHRS_NavEKF::get_accel_ef_blended(void) const
void AP_AHRS_NavEKF::reset(bool recover_eulers)
{
// support locked access functions to AHRS data
WITH_SEMAPHORE(_rsem);
AP_AHRS_DCM::reset(recover_eulers);
_dcm_attitude(roll, pitch, yaw);
if (_ekf2_started) {
@ -379,6 +387,9 @@ void AP_AHRS_NavEKF::reset(bool recover_eulers)
// reset the current attitude, used on new IMU calibration
void AP_AHRS_NavEKF::reset_attitude(const float &_roll, const float &_pitch, const float &_yaw)
{
// support locked access functions to AHRS data
WITH_SEMAPHORE(_rsem);
AP_AHRS_DCM::reset_attitude(_roll, _pitch, _yaw);
_dcm_attitude(roll, pitch, yaw);
if (_ekf2_started) {
@ -1395,6 +1406,9 @@ uint32_t AP_AHRS_NavEKF::getLastPosDownReset(float &posDelta) const
// If using a range finder for height no reset is performed and it returns false
bool AP_AHRS_NavEKF::resetHeightDatum(void)
{
// support locked access functions to AHRS data
WITH_SEMAPHORE(_rsem);
switch (ekf_type()) {
case 2: