Browse Source

AP_AHRS: add AP::ahrs() singleton

master
Peter Barker 7 years ago committed by Francisco Ferreira
parent
commit
dc30197ca7
  1. 12
      libraries/AP_AHRS/AP_AHRS.cpp
  2. 15
      libraries/AP_AHRS/AP_AHRS.h

12
libraries/AP_AHRS/AP_AHRS.cpp

@ -411,3 +411,15 @@ Vector2f AP_AHRS::rotate_body_to_earth2D(const Vector2f &bf) const
return Vector2f(bf.x * _cos_yaw - bf.y * _sin_yaw, return Vector2f(bf.x * _cos_yaw - bf.y * _sin_yaw,
bf.x * _sin_yaw + bf.y * _cos_yaw); bf.x * _sin_yaw + bf.y * _cos_yaw);
} }
// singleton instance
AP_AHRS *AP_AHRS::_singleton;
namespace AP {
AP_AHRS &ahrs()
{
return *AP_AHRS::get_singleton();
}
}

15
libraries/AP_AHRS/AP_AHRS.h

@ -76,6 +76,8 @@ public:
_sin_yaw(0.0f), _sin_yaw(0.0f),
_active_accel_instance(0) _active_accel_instance(0)
{ {
_singleton = this;
// load default values from var_info table // load default values from var_info table
AP_Param::setup_object_defaults(this, var_info); AP_Param::setup_object_defaults(this, var_info);
@ -100,6 +102,11 @@ public:
// empty virtual destructor // empty virtual destructor
virtual ~AP_AHRS() {} virtual ~AP_AHRS() {}
// get singleton instance
static AP_AHRS *get_singleton() {
return _singleton;
}
// init sets up INS board orientation // init sets up INS board orientation
virtual void init() { virtual void init() {
set_orientation(); set_orientation();
@ -670,6 +677,10 @@ protected:
// AOA and SSA // AOA and SSA
float _AOA, _SSA; float _AOA, _SSA;
uint32_t _last_AOA_update_ms; uint32_t _last_AOA_update_ms;
private:
static AP_AHRS *_singleton;
}; };
#include "AP_AHRS_DCM.h" #include "AP_AHRS_DCM.h"
@ -680,3 +691,7 @@ protected:
#else #else
#define AP_AHRS_TYPE AP_AHRS #define AP_AHRS_TYPE AP_AHRS
#endif #endif
namespace AP {
AP_AHRS &ahrs();
};

Loading…
Cancel
Save