123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377 |
- #pragma once
- #include <AP_Common/AP_Common.h>
- #include <AP_Param/AP_Param.h>
- #define NUM_RC_CHANNELS 16
- class RC_Channel {
- public:
- friend class SRV_Channels;
- friend class RC_Channels;
-
- RC_Channel(void);
-
- int16_t radio_in;
- AP_Int16 radio_min;
- AP_Int16 radio_trim;
- AP_Int16 radio_max;
- enum ChannelType {
- RC_CHANNEL_TYPE_ANGLE = 0,
- RC_CHANNEL_TYPE_RANGE = 1,
- };
-
- void set_range(uint16_t high);
- uint16_t get_range() const { return high_in; }
- void set_angle(uint16_t angle);
- bool get_reverse(void) const;
- void set_default_dead_zone(int16_t dzone);
- uint16_t get_dead_zone(void) const { return dead_zone; }
-
- int16_t get_control_mid() const;
-
- bool update(void);
- void recompute_pwm_no_deadzone();
-
-
- int16_t pwm_to_angle_dz_trim(uint16_t dead_zone, uint16_t trim) const;
-
- float norm_input() const;
-
- float norm_input_dz() const;
- uint8_t percent_input() const;
- int16_t pwm_to_range() const;
- int16_t pwm_to_range_dz(uint16_t dead_zone) const;
- static const struct AP_Param::GroupInfo var_info[];
-
- bool in_trim_dz() const;
- int16_t get_radio_in() const { return radio_in;}
- void set_radio_in(int16_t val) {radio_in = val;}
- int16_t get_control_in() const { return control_in;}
- void set_control_in(int16_t val) { control_in = val;}
- void clear_override();
- void set_override(const uint16_t v, const uint32_t timestamp_us);
- bool has_override() const;
- int16_t stick_mixing(const int16_t servo_in);
-
- int16_t get_control_in_zero_dz(void) const;
- int16_t get_radio_min() const {return radio_min.get();}
- void set_radio_min(int16_t val) { radio_min = val;}
- int16_t get_radio_max() const {return radio_max.get();}
- void set_radio_max(int16_t val) {radio_max = val;}
- int16_t get_radio_trim() const { return radio_trim.get();}
- void set_radio_trim(int16_t val) { radio_trim.set(val);}
- void save_radio_trim() { radio_trim.save();}
- void set_and_save_trim() { radio_trim.set_and_save_ifchanged(radio_in);}
-
- void set_and_save_radio_trim(int16_t val) { radio_trim.set_and_save_ifchanged(val);}
- ChannelType get_type(void) const { return type_in; }
- AP_Int16 option;
-
- void init_aux();
- bool read_aux();
-
- enum class AUX_FUNC {
- DO_NOTHING = 0,
- FLIP = 2,
- SIMPLE_MODE = 3,
- RTL = 4,
- SAVE_TRIM = 5,
- SAVE_WP = 7,
- CAMERA_TRIGGER = 9,
- RANGEFINDER = 10,
- FENCE = 11,
- RESETTOARMEDYAW = 12,
- SUPERSIMPLE_MODE = 13,
- ACRO_TRAINER = 14,
- SPRAYER = 15,
- AUTO = 16,
- AUTOTUNE = 17,
- LAND = 18,
- GRIPPER = 19,
- PARACHUTE_ENABLE = 21,
- PARACHUTE_RELEASE = 22,
- PARACHUTE_3POS = 23,
- MISSION_RESET = 24,
- ATTCON_FEEDFWD = 25,
- ATTCON_ACCEL_LIM = 26,
- RETRACT_MOUNT = 27,
- RELAY = 28,
- LANDING_GEAR = 29,
- LOST_VEHICLE_SOUND = 30,
- MOTOR_ESTOP = 31,
- MOTOR_INTERLOCK = 32,
- BRAKE = 33,
- RELAY2 = 34,
- RELAY3 = 35,
- RELAY4 = 36,
- THROW = 37,
- AVOID_ADSB = 38,
- PRECISION_LOITER = 39,
- AVOID_PROXIMITY = 40,
- ARMDISARM = 41,
- SMART_RTL = 42,
- INVERTED = 43,
- WINCH_ENABLE = 44,
- WINCH_CONTROL = 45,
- RC_OVERRIDE_ENABLE = 46,
- USER_FUNC1 = 47,
- USER_FUNC2 = 48,
- USER_FUNC3 = 49,
- LEARN_CRUISE = 50,
- MANUAL = 51,
- ACRO = 52,
- STEERING = 53,
- HOLD = 54,
- GUIDED = 55,
- LOITER = 56,
- FOLLOW = 57,
- CLEAR_WP = 58,
- SIMPLE = 59,
- ZIGZAG = 60,
- ZIGZAG_SaveWP = 61,
- COMPASS_LEARN = 62,
- SAILBOAT_TACK = 63,
- REVERSE_THROTTLE = 64,
- GPS_DISABLE = 65,
- RELAY5 = 66,
- RELAY6 = 67,
- STABILIZE = 68,
- POSHOLD = 69,
- ALTHOLD = 70,
- FLOWHOLD = 71,
- CIRCLE = 72,
- DRIFT = 73,
- SAILBOAT_MOTOR_3POS = 74,
- KILL_IMU1 = 100,
- KILL_IMU2 = 101,
-
-
-
- MAINSAIL = 207,
- };
- typedef enum AUX_FUNC aux_func_t;
- protected:
-
- enum aux_switch_pos_t : uint8_t {
- LOW,
- MIDDLE,
- HIGH
- };
- virtual void init_aux_function(aux_func_t ch_option, aux_switch_pos_t);
- virtual void do_aux_function(aux_func_t ch_option, aux_switch_pos_t);
- void do_aux_function_avoid_proximity(const aux_switch_pos_t ch_flag);
- void do_aux_function_camera_trigger(const aux_switch_pos_t ch_flag);
- void do_aux_function_fence(const aux_switch_pos_t ch_flag);
- void do_aux_function_clear_wp(const aux_switch_pos_t ch_flag);
- void do_aux_function_gripper(const aux_switch_pos_t ch_flag);
- void do_aux_function_lost_vehicle_sound(const aux_switch_pos_t ch_flag);
- void do_aux_function_mission_reset(const aux_switch_pos_t ch_flag);
- void do_aux_function_rc_override_enable(const aux_switch_pos_t ch_flag);
- void do_aux_function_relay(uint8_t relay, bool val);
- void do_aux_function_sprayer(const aux_switch_pos_t ch_flag);
- typedef int8_t modeswitch_pos_t;
- virtual void mode_switch_changed(modeswitch_pos_t new_pos) {
-
- };
- private:
-
-
-
- int16_t control_in;
- AP_Int8 reversed;
- AP_Int16 dead_zone;
- ChannelType type_in;
- int16_t high_in;
-
- uint8_t ch_in;
-
- uint16_t override_value;
- uint32_t last_override_time;
- int16_t pwm_to_angle() const;
- int16_t pwm_to_angle_dz(uint16_t dead_zone) const;
-
- static const uint16_t AUX_PWM_TRIGGER_HIGH = 1800;
-
- static const uint16_t AUX_PWM_TRIGGER_LOW = 1200;
- bool read_3pos_switch(aux_switch_pos_t &ret) const WARN_IF_UNUSED;
-
- struct {
- int8_t debounce_position = -1;
- int8_t current_position = -1;
- uint32_t last_edge_time_ms;
- } switch_state;
- void reset_mode_switch();
- void read_mode_switch();
- bool debounce_completed(int8_t position);
- };
- class RC_Channels {
- public:
- friend class SRV_Channels;
- friend class RC_Channel;
-
- RC_Channels(void);
- void init(void);
-
- static RC_Channels *get_singleton() {
- return _singleton;
- }
- static const struct AP_Param::GroupInfo var_info[];
-
- static uint16_t get_radio_in(const uint8_t chan) {
- RC_Channel *c = _singleton->channel(chan);
- if (c == nullptr) {
- return 0;
- }
- return c->get_radio_in();
- }
- static RC_Channel *rc_channel(const uint8_t chan) {
- return _singleton->channel(chan);
- }
-
- virtual RC_Channel *channel(uint8_t chan) = 0;
- uint8_t get_radio_in(uint16_t *chans, const uint8_t num_channels);
-
- static uint8_t get_valid_channel_count(void);
- static int16_t get_receiver_rssi(void);
- bool read_input(void);
- static void clear_overrides(void);
- static bool receiver_bind(const int dsmMode);
- static void set_override(const uint8_t chan, const int16_t value, const uint32_t timestamp_ms = 0);
- static bool has_active_overrides(void);
- class RC_Channel *find_channel_for_option(const RC_Channel::aux_func_t option);
- bool duplicate_options_exist();
- void init_aux_all();
- void read_aux_all();
-
- void reset_mode_switch();
- virtual void read_mode_switch();
-
- virtual bool has_valid_input() const { return false; };
- bool gcs_overrides_enabled() const { return _gcs_overrides_enabled; }
- void set_gcs_overrides_enabled(bool enable) {
- _gcs_overrides_enabled = enable;
- if (!_gcs_overrides_enabled) {
- clear_overrides();
- }
- }
-
- bool ignore_rc_failsafe(void) const {
- return get_singleton() != nullptr && (_options & uint32_t(Option::IGNORE_FAILSAFE));
- }
- bool ignore_overrides() const {
- return _options & uint32_t(Option::IGNORE_OVERRIDES);
- }
- bool ignore_receiver() const {
- return _options & uint32_t(Option::IGNORE_RECEIVER);
- }
- float override_timeout_ms() const {
- return _override_timeout.get() * 1e3f;
- }
- protected:
- enum class Option {
- IGNORE_RECEIVER = (1 << 0),
- IGNORE_OVERRIDES = (1 << 1),
- IGNORE_FAILSAFE = (1 << 2),
- };
- void new_override_received() {
- has_new_overrides = true;
- }
- private:
- static RC_Channels *_singleton;
-
- static RC_Channel *channels;
- bool has_new_overrides;
- AP_Float _override_timeout;
- AP_Int32 _options;
-
- virtual int8_t flight_mode_channel_number() const = 0;
- RC_Channel *flight_mode_channel();
-
- bool _gcs_overrides_enabled = true;
- };
- RC_Channels &rc();
|