From eb3aca7acfdbbbe7f5e06b40661f139c994d1cd6 Mon Sep 17 00:00:00 2001 From: Randy Mackay Date: Wed, 14 Oct 2020 14:25:41 +0900 Subject: [PATCH] Copter: add GUIDED_OPTIONS to allow arming from transmitter --- ArduCopter/Parameters.cpp | 9 +++++++++ ArduCopter/Parameters.h | 4 ++++ ArduCopter/mode.h | 7 ++++++- ArduCopter/mode_guided.cpp | 11 +++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/ArduCopter/Parameters.cpp b/ArduCopter/Parameters.cpp index 75cccef350..6f9ba5bfbc 100644 --- a/ArduCopter/Parameters.cpp +++ b/ArduCopter/Parameters.cpp @@ -985,6 +985,15 @@ const AP_Param::GroupInfo ParametersG2::var_info[] = { AP_GROUPINFO("AUTO_OPTIONS", 40, ParametersG2, auto_options, 0), #endif +#if MODE_GUIDED_ENABLED == ENABLED + // @Param: GUIDED_OPTIONS + // @DisplayName: Guided mode options + // @Description: Options that can be applied to change guided mode behaviour + // @Bitmask: 0:Allow Arming from Transmitter + // @User: Advanced + AP_GROUPINFO("GUIDED_OPTIONS", 41, ParametersG2, guided_options, 0), +#endif + AP_GROUPEND }; diff --git a/ArduCopter/Parameters.h b/ArduCopter/Parameters.h index 0f584e5a69..9c8f67ecc2 100644 --- a/ArduCopter/Parameters.h +++ b/ArduCopter/Parameters.h @@ -623,6 +623,10 @@ public: AP_Int32 auto_options; #endif +#if MODE_GUIDED_ENABLED == ENABLED + AP_Int32 guided_options; +#endif + }; extern const AP_Param::Info var_info[]; diff --git a/ArduCopter/mode.h b/ArduCopter/mode.h index e98f18f288..472c7a07f1 100644 --- a/ArduCopter/mode.h +++ b/ArduCopter/mode.h @@ -794,7 +794,7 @@ public: bool requires_GPS() const override { return true; } bool has_manual_throttle() const override { return false; } - bool allows_arming(bool from_gcs) const override { return from_gcs; } + bool allows_arming(bool from_gcs) const override; bool is_autopilot() const override { return true; } bool has_user_takeoff(bool must_navigate) const override { return true; } bool in_guided_mode() const override { return true; } @@ -833,6 +833,11 @@ protected: private: + // enum for GUIDED_OPTIONS parameter + enum class Options : int32_t { + AllowArmingFromTX = (1 << 0U), + }; + void pos_control_start(); void vel_control_start(); void posvel_control_start(); diff --git a/ArduCopter/mode_guided.cpp b/ArduCopter/mode_guided.cpp index 5a8cd3538e..28129c8fa3 100644 --- a/ArduCopter/mode_guided.cpp +++ b/ArduCopter/mode_guided.cpp @@ -384,6 +384,17 @@ void ModeGuided::run() } } +bool ModeGuided::allows_arming(bool from_gcs) const +{ + // always allow arming from the ground station + if (from_gcs) { + return true; + } + + // optionally allow arming from the transmitter + return (copter.g2.guided_options & (int32_t)Options::AllowArmingFromTX) != 0; +}; + // guided_takeoff_run - takeoff in guided mode // called by guided_run at 100hz or more void ModeGuided::takeoff_run()