From 1ba0901e51b08f5553e97d684d879b0799e14442 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Fri, 27 Apr 2018 12:26:38 +1000 Subject: [PATCH] Sub: minimal support for inheritting from RC_Channel --- ArduSub/ArduSub.cpp | 2 +- ArduSub/Parameters.h | 2 +- ArduSub/RC_Channel.cpp | 17 +++++++++++++++++ ArduSub/RC_Channel.h | 33 +++++++++++++++++++++++++++++++++ ArduSub/Sub.h | 3 ++- ArduSub/system.cpp | 3 +++ 6 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 ArduSub/RC_Channel.cpp create mode 100644 ArduSub/RC_Channel.h diff --git a/ArduSub/ArduSub.cpp b/ArduSub/ArduSub.cpp index e3ef289262..c8fcb8427f 100644 --- a/ArduSub/ArduSub.cpp +++ b/ArduSub/ArduSub.cpp @@ -158,7 +158,7 @@ void Sub::fifty_hz_loop() failsafe_sensors_check(); // Update rc input/output - RC_Channels::read_input(); + rc().read_input(); SRV_Channels::output_ch_all(); } diff --git a/ArduSub/Parameters.h b/ArduSub/Parameters.h index f878d4d267..a17a302dd7 100644 --- a/ArduSub/Parameters.h +++ b/ArduSub/Parameters.h @@ -327,7 +327,7 @@ public: #endif // RC input channels - RC_Channels rc_channels; + RC_Channels_Sub rc_channels; // control over servo output ranges SRV_Channels servo_channels; diff --git a/ArduSub/RC_Channel.cpp b/ArduSub/RC_Channel.cpp new file mode 100644 index 0000000000..0c4cc58725 --- /dev/null +++ b/ArduSub/RC_Channel.cpp @@ -0,0 +1,17 @@ +#include "Sub.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_Sub +#define RC_CHANNEL_SUBCLASS RC_Channel_Sub + +#include + +// note that this callback is not presently used on Plane: +int8_t RC_Channels_Sub::flight_mode_channel_number() const +{ + return 1; // sub does not have a flight mode channel +} diff --git a/ArduSub/RC_Channel.h b/ArduSub/RC_Channel.h new file mode 100644 index 0000000000..52b33c9d53 --- /dev/null +++ b/ArduSub/RC_Channel.h @@ -0,0 +1,33 @@ +#pragma once + +#include + +class RC_Channel_Sub : public RC_Channel +{ + +public: + +protected: + +private: + +}; + +class RC_Channels_Sub : public RC_Channels +{ +public: + + RC_Channel_Sub obj_channels[NUM_RC_CHANNELS]; + RC_Channel_Sub *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/ArduSub/Sub.h b/ArduSub/Sub.h index 6c3674a220..f0cc5d643c 100644 --- a/ArduSub/Sub.h +++ b/ArduSub/Sub.h @@ -54,7 +54,6 @@ #include // PID library (2-axis) #include // Attitude control library #include // Position control library -#include // RC Channel Library #include // AP Motors library #include // Range finder library #include // Filter library @@ -82,6 +81,7 @@ #include "defines.h" #include "config.h" #include "GCS_Mavlink.h" +#include "RC_Channel.h" // RC Channel Library #include "Parameters.h" #include "AP_Arming_Sub.h" #include "GCS_Sub.h" @@ -130,6 +130,7 @@ public: friend class Parameters; friend class ParametersG2; friend class AP_Arming_Sub; + friend class RC_Channels_Sub; Sub(void); diff --git a/ArduSub/system.cpp b/ArduSub/system.cpp index aecca33b85..10fe8f8dd1 100644 --- a/ArduSub/system.cpp +++ b/ArduSub/system.cpp @@ -87,6 +87,9 @@ void Sub::init_ardupilot() gcs().set_dataflash(&DataFlash); + // initialise rc channels including setting mode + rc().init(); + init_rc_in(); // sets up rc channels from radio init_rc_out(); // sets up motors and output to escs init_joystick(); // joystick initialization