From 9ce02bc50414bf864b9fbd9870e90be7ab781246 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Fri, 27 Apr 2018 11:01:37 +1000 Subject: [PATCH] Plane: minimal support for inheritting from RC_Channel --- ArduPlane/Parameters.cpp | 2 +- ArduPlane/Parameters.h | 2 +- ArduPlane/Plane.h | 3 ++- ArduPlane/RC_Channel.cpp | 17 +++++++++++++++++ ArduPlane/RC_Channel.h | 33 +++++++++++++++++++++++++++++++++ ArduPlane/radio.cpp | 2 +- ArduPlane/system.cpp | 3 +++ 7 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 ArduPlane/RC_Channel.cpp create mode 100644 ArduPlane/RC_Channel.h diff --git a/ArduPlane/Parameters.cpp b/ArduPlane/Parameters.cpp index c532aa6c8c..853a889899 100644 --- a/ArduPlane/Parameters.cpp +++ b/ArduPlane/Parameters.cpp @@ -1138,7 +1138,7 @@ const AP_Param::GroupInfo ParametersG2::var_info[] = { // @Group: RC // @Path: ../libraries/RC_Channel/RC_Channels.cpp - AP_SUBGROUPINFO(rc_channels, "RC", 7, ParametersG2, RC_Channels), + AP_SUBGROUPINFO(rc_channels, "RC", 7, ParametersG2, RC_Channels_Plane), #if SOARING_ENABLED == ENABLED // @Group: SOAR_ diff --git a/ArduPlane/Parameters.h b/ArduPlane/Parameters.h index 805e117e7e..867bcd0e5e 100644 --- a/ArduPlane/Parameters.h +++ b/ArduPlane/Parameters.h @@ -518,7 +518,7 @@ public: AP_ICEngine ice_control; // RC input channels - RC_Channels rc_channels; + RC_Channels_Plane rc_channels; // control over servo output ranges SRV_Channels servo_channels; diff --git a/ArduPlane/Plane.h b/ArduPlane/Plane.h index ad642363cb..ee347d31f9 100644 --- a/ArduPlane/Plane.h +++ b/ArduPlane/Plane.h @@ -40,7 +40,6 @@ #include // Inertial Sensor Library #include // interface and maths for accelerometer calibration #include // ArduPilot Mega DCM Library -#include // RC Channel Library #include #include // Range finder library #include // Filter library @@ -109,6 +108,7 @@ // Local modules #include "defines.h" +#include "RC_Channel.h" // RC Channel Library #include "Parameters.h" #include "avoidance_adsb.h" #include "AP_Arming.h" @@ -150,6 +150,7 @@ public: friend class AP_AdvancedFailsafe_Plane; friend class AP_Avoidance_Plane; friend class GCS_Plane; + friend class RC_Channels_Plane; Plane(void); diff --git a/ArduPlane/RC_Channel.cpp b/ArduPlane/RC_Channel.cpp new file mode 100644 index 0000000000..60fc33003b --- /dev/null +++ b/ArduPlane/RC_Channel.cpp @@ -0,0 +1,17 @@ +#include "Plane.h" + +#include "RC_Channel.h" + +// defining these two macros and including the RC_Channels_VarInfo +// header defines the parameter information common to all vehicle +// types +#define RC_CHANNELS_SUBCLASS RC_Channels_Plane +#define RC_CHANNEL_SUBCLASS RC_Channel_Plane + +#include + +// note that this callback is not presently used on Plane: +int8_t RC_Channels_Plane::flight_mode_channel_number() const +{ + return plane.g.flight_mode_channel.get(); +} diff --git a/ArduPlane/RC_Channel.h b/ArduPlane/RC_Channel.h new file mode 100644 index 0000000000..1966d51268 --- /dev/null +++ b/ArduPlane/RC_Channel.h @@ -0,0 +1,33 @@ +#pragma once + +#include + +class RC_Channel_Plane : public RC_Channel +{ + +public: + +protected: + +private: + +}; + +class RC_Channels_Plane : public RC_Channels +{ +public: + + RC_Channel_Plane obj_channels[NUM_RC_CHANNELS]; + RC_Channel_Plane *channel(const uint8_t chan) override { + if (chan > NUM_RC_CHANNELS) { + return nullptr; + } + return &obj_channels[chan]; + } + +protected: + + // note that these callbacks are not presently used on Plane: + int8_t flight_mode_channel_number() const override; + +}; diff --git a/ArduPlane/radio.cpp b/ArduPlane/radio.cpp index 7eb977cd03..ab00b0665e 100644 --- a/ArduPlane/radio.cpp +++ b/ArduPlane/radio.cpp @@ -174,7 +174,7 @@ void Plane::rudder_arm_disarm_check() void Plane::read_radio() { - if (!RC_Channels::read_input()) { + if (!rc().read_input()) { control_failsafe(); return; } diff --git a/ArduPlane/system.cpp b/ArduPlane/system.cpp index 10b075b73f..a23d40fbed 100644 --- a/ArduPlane/system.cpp +++ b/ArduPlane/system.cpp @@ -84,6 +84,9 @@ void Plane::init_ardupilot() BoardConfig_CAN.init(); #endif + // initialise rc channels including setting mode + rc().init(); + relay.init(); // initialise notify system