From e4fbe64616ad4bd3b44f9a03786ecea30f323c8e Mon Sep 17 00:00:00 2001 From: Iampete1 Date: Fri, 6 Nov 2020 16:20:02 +0000 Subject: [PATCH] Plane: add QuadPlane singleton --- ArduPlane/quadplane.cpp | 7 +++++++ ArduPlane/quadplane.h | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/ArduPlane/quadplane.cpp b/ArduPlane/quadplane.cpp index bda2aba99e..b3654e4398 100644 --- a/ArduPlane/quadplane.cpp +++ b/ArduPlane/quadplane.cpp @@ -597,6 +597,11 @@ QuadPlane::QuadPlane(AP_AHRS_NavEKF &_ahrs) : { AP_Param::setup_object_defaults(this, var_info); AP_Param::setup_object_defaults(this, var_info2); + + if (_singleton != nullptr) { + AP_HAL::panic("Can only be one Quadplane"); + } + _singleton = this; } @@ -3573,3 +3578,5 @@ bool QuadPlane::show_vtol_view() const return show_vtol; } + +QuadPlane *QuadPlane::_singleton = nullptr; diff --git a/ArduPlane/quadplane.h b/ArduPlane/quadplane.h index 5ad3edfbaf..717991d272 100644 --- a/ArduPlane/quadplane.h +++ b/ArduPlane/quadplane.h @@ -43,6 +43,10 @@ public: QuadPlane(AP_AHRS_NavEKF &_ahrs); + static QuadPlane *get_singleton() { + return _singleton; + } + // var_info for holding Parameter information static const struct AP_Param::GroupInfo var_info[]; static const struct AP_Param::GroupInfo var_info2[]; @@ -652,4 +656,6 @@ public: uint8_t motor_count); private: void motor_test_stop(); + + static QuadPlane *_singleton; };