SITL: add singleton

This commit is contained in:
Peter Barker 2018-05-02 21:30:59 +10:00 committed by Peter Barker
parent 24dd9a1c2c
commit a137afd11b
2 changed files with 28 additions and 0 deletions

View File

@ -28,6 +28,8 @@ extern const AP_HAL::HAL& hal;
namespace SITL {
SITL *SITL::_s_instance = nullptr;
// table of user settable parameters
const AP_Param::GroupInfo SITL::var_info[] = {
AP_GROUPINFO("BARO_RND", 0, SITL, baro_noise, 0.2f),
@ -220,3 +222,13 @@ Vector3f SITL::convert_earth_frame(const Matrix3f &dcm, const Vector3f &gyro)
}
} // namespace SITL
namespace AP {
SITL::SITL *sitl()
{
return SITL::SITL::get_instance();
}
};

View File

@ -41,8 +41,19 @@ public:
mag_ofs.set(Vector3f(5, 13, -18));
AP_Param::setup_object_defaults(this, var_info);
AP_Param::setup_object_defaults(this, var_info2);
if (_s_instance != nullptr) {
AP_HAL::panic("Too many SITL instances");
}
_s_instance = this;
}
/* Do not allow copies */
SITL(const SITL &other) = delete;
SITL &operator=(const SITL&) = delete;
static SITL *_s_instance;
static SITL *get_instance() { return _s_instance; }
enum GPSType {
GPS_TYPE_NONE = 0,
GPS_TYPE_UBLOX = 1,
@ -193,3 +204,8 @@ public:
};
} // namespace SITL
namespace AP {
SITL::SITL *sitl();
};