diff --git a/libraries/SITL/SITL.cpp b/libraries/SITL/SITL.cpp index 51c0878ee4..8264ef95e1 100644 --- a/libraries/SITL/SITL.cpp +++ b/libraries/SITL/SITL.cpp @@ -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(); +} + +}; diff --git a/libraries/SITL/SITL.h b/libraries/SITL/SITL.h index 2e0229c063..54a610905c 100644 --- a/libraries/SITL/SITL.h +++ b/libraries/SITL/SITL.h @@ -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(); +};