2013-05-29 20:48:45 -03:00
|
|
|
// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
2011-09-11 14:13:01 -03:00
|
|
|
|
|
|
|
/// @file RC_Channel_aux.h
|
2012-06-13 15:55:19 -03:00
|
|
|
/// @brief RC_Channel manager for auxiliary channels (5..8), with EEPROM-backed storage of constants.
|
2011-09-11 14:13:01 -03:00
|
|
|
/// @author Amilcar Lucas
|
2016-02-17 21:25:57 -04:00
|
|
|
#pragma once
|
2011-09-11 14:13:01 -03:00
|
|
|
|
2015-08-11 03:28:46 -03:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
2011-09-11 14:13:01 -03:00
|
|
|
#include "RC_Channel.h"
|
|
|
|
|
2014-03-25 01:42:48 -03:00
|
|
|
#define RC_AUX_MAX_CHANNELS 12
|
2014-02-05 19:04:05 -04:00
|
|
|
|
2011-09-11 14:13:01 -03:00
|
|
|
/// @class RC_Channel_aux
|
|
|
|
/// @brief Object managing one aux. RC channel (CH5-8), with information about its function
|
2012-08-17 03:22:48 -03:00
|
|
|
class RC_Channel_aux : public RC_Channel {
|
2011-09-11 14:13:01 -03:00
|
|
|
public:
|
2012-08-17 03:22:48 -03:00
|
|
|
/// Constructor
|
|
|
|
///
|
|
|
|
/// @param key EEPROM storage key for the channel trim parameters.
|
|
|
|
/// @param name Optional name for the group.
|
|
|
|
///
|
|
|
|
RC_Channel_aux(uint8_t ch_out) :
|
|
|
|
RC_Channel(ch_out)
|
|
|
|
{
|
2014-02-05 19:04:05 -04:00
|
|
|
for (uint8_t i=0; i<RC_AUX_MAX_CHANNELS; i++) {
|
|
|
|
if (_aux_channels[i] == NULL) {
|
|
|
|
_aux_channels[i] = this;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-12-12 17:47:22 -04:00
|
|
|
AP_Param::setup_object_defaults(this, var_info);
|
2012-08-17 03:22:48 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
k_none = 0, ///< disabled
|
|
|
|
k_manual = 1, ///< manual, just pass-thru the RC in signal
|
|
|
|
k_flap = 2, ///< flap
|
|
|
|
k_flap_auto = 3, ///< flap automated
|
|
|
|
k_aileron = 4, ///< aileron
|
2014-02-05 21:35:32 -04:00
|
|
|
k_unused1 = 5, ///< unused function
|
2012-08-17 03:22:48 -03:00
|
|
|
k_mount_pan = 6, ///< mount yaw (pan)
|
2013-10-31 03:23:52 -03:00
|
|
|
k_mount_tilt = 7, ///< mount pitch (tilt)
|
|
|
|
k_mount_roll = 8, ///< mount roll
|
|
|
|
k_mount_open = 9, ///< mount open (deploy) / close (retract)
|
|
|
|
k_cam_trigger = 10, ///< camera trigger
|
2012-08-17 03:22:48 -03:00
|
|
|
k_egg_drop = 11, ///< egg drop
|
2013-10-31 03:23:52 -03:00
|
|
|
k_mount2_pan = 12, ///< mount2 yaw (pan)
|
|
|
|
k_mount2_tilt = 13, ///< mount2 pitch (tilt)
|
|
|
|
k_mount2_roll = 14, ///< mount2 roll
|
|
|
|
k_mount2_open = 15, ///< mount2 open (deploy) / close (retract)
|
|
|
|
k_dspoiler1 = 16, ///< differential spoiler 1 (left wing)
|
|
|
|
k_dspoiler2 = 17, ///< differential spoiler 2 (right wing)
|
2012-11-20 20:47:36 -04:00
|
|
|
k_aileron_with_input = 18, ///< aileron, with rc input
|
2013-02-04 17:57:28 -04:00
|
|
|
k_elevator = 19, ///< elevator
|
|
|
|
k_elevator_with_input = 20, ///< elevator, with rc input
|
2013-06-28 21:14:43 -03:00
|
|
|
k_rudder = 21, ///< secondary rudder channel
|
2013-08-04 09:25:41 -03:00
|
|
|
k_sprayer_pump = 22, ///< crop sprayer pump channel
|
|
|
|
k_sprayer_spinner = 23, ///< crop sprayer spinner channel
|
2014-02-05 21:35:32 -04:00
|
|
|
k_flaperon1 = 24, ///< flaperon, left wing
|
|
|
|
k_flaperon2 = 25, ///< flaperon, right wing
|
2014-03-04 21:09:02 -04:00
|
|
|
k_steering = 26, ///< ground steering, used to separate from rudder
|
2014-04-01 08:57:49 -03:00
|
|
|
k_parachute_release = 27, ///< parachute release
|
2014-09-15 03:50:32 -03:00
|
|
|
k_epm = 28, ///< epm gripper
|
2015-01-06 00:26:18 -04:00
|
|
|
k_landing_gear_control = 29, ///< landing gear controller
|
2015-10-14 12:18:25 -03:00
|
|
|
k_engine_run_enable = 30, ///< engine kill switch, used for gas airplanes and helicopters
|
2015-12-05 06:07:51 -04:00
|
|
|
k_heli_rsc = 31, ///< helicopter RSC output
|
|
|
|
k_heli_tail_rsc = 32, ///< helicopter tail RSC output
|
2016-01-04 02:06:57 -04:00
|
|
|
k_motor1 = 33, ///< these allow remapping of copter motors
|
|
|
|
k_motor2 = 34,
|
|
|
|
k_motor3 = 35,
|
|
|
|
k_motor4 = 36,
|
|
|
|
k_motor5 = 37,
|
|
|
|
k_motor6 = 38,
|
|
|
|
k_motor7 = 39,
|
|
|
|
k_motor8 = 40,
|
2012-08-17 03:22:48 -03:00
|
|
|
k_nr_aux_servo_functions ///< This must be the last enum value (only add new values _before_ this one)
|
|
|
|
} Aux_servo_function_t;
|
|
|
|
|
|
|
|
AP_Int8 function; ///< see Aux_servo_function_t enum
|
|
|
|
|
2014-04-02 22:18:56 -03:00
|
|
|
// output one auxillary channel
|
|
|
|
void output_ch(void);
|
|
|
|
|
|
|
|
// output all auxillary channels
|
|
|
|
static void output_ch_all(void);
|
2012-08-17 03:22:48 -03:00
|
|
|
|
2012-10-30 22:38:26 -03:00
|
|
|
// set radio_out for a function channel
|
|
|
|
static void set_radio(Aux_servo_function_t function, int16_t value);
|
|
|
|
|
2014-11-24 17:19:27 -04:00
|
|
|
// set radio_out for all channels matching the given function type, allow radio_trim to center servo
|
|
|
|
static void set_radio_trimmed(Aux_servo_function_t function, int16_t value);
|
|
|
|
|
2012-09-08 02:12:28 -03:00
|
|
|
// set and save the trim for a function channel to radio_in
|
|
|
|
static void set_radio_trim(Aux_servo_function_t function);
|
|
|
|
|
|
|
|
// set radio_out to radio_min
|
|
|
|
static void set_radio_to_min(Aux_servo_function_t function);
|
|
|
|
|
|
|
|
// set radio_out to radio_max
|
|
|
|
static void set_radio_to_max(Aux_servo_function_t function);
|
|
|
|
|
2012-10-30 22:38:26 -03:00
|
|
|
// set radio_out to radio_trim
|
|
|
|
static void set_radio_to_trim(Aux_servo_function_t function);
|
|
|
|
|
2012-09-08 02:12:28 -03:00
|
|
|
// copy radio_in to radio_out
|
2012-11-26 02:16:25 -04:00
|
|
|
static void copy_radio_in_out(Aux_servo_function_t function, bool do_input_output=false);
|
2012-09-08 02:12:28 -03:00
|
|
|
|
|
|
|
// set servo_out
|
|
|
|
static void set_servo_out(Aux_servo_function_t function, int16_t value);
|
|
|
|
|
2014-04-20 21:34:10 -03:00
|
|
|
// setup failsafe for an auxillary channel function
|
|
|
|
static void set_servo_failsafe(Aux_servo_function_t function, RC_Channel::LimitValue limit);
|
|
|
|
|
|
|
|
// set servo to a LimitValue
|
|
|
|
static void set_servo_limit(Aux_servo_function_t function, RC_Channel::LimitValue limit);
|
|
|
|
|
2012-09-08 02:12:28 -03:00
|
|
|
// return true if a function is assigned to a channel
|
|
|
|
static bool function_assigned(Aux_servo_function_t function);
|
|
|
|
|
|
|
|
// set a servo_out value, and angle range, then calc_pwm
|
|
|
|
static void move_servo(Aux_servo_function_t function,
|
|
|
|
int16_t value, int16_t angle_min, int16_t angle_max);
|
|
|
|
|
2012-08-17 03:22:48 -03:00
|
|
|
static const struct AP_Param::GroupInfo var_info[];
|
2011-09-11 14:13:01 -03:00
|
|
|
|
2014-02-05 19:04:05 -04:00
|
|
|
// assigned and enable auxillary channels
|
|
|
|
static void enable_aux_servos(void);
|
2014-02-06 06:30:55 -04:00
|
|
|
|
|
|
|
// prevent a channel from being used for auxillary functions
|
|
|
|
static void disable_aux_channel(uint8_t channel);
|
2014-02-05 19:04:05 -04:00
|
|
|
|
2014-11-06 02:28:38 -04:00
|
|
|
// return the current function for a channel
|
|
|
|
static Aux_servo_function_t channel_function(uint8_t channel);
|
|
|
|
|
2015-06-10 02:59:46 -03:00
|
|
|
// refresh aux servo to function mapping
|
|
|
|
static void update_aux_servo_function(void);
|
|
|
|
|
2015-12-05 06:07:51 -04:00
|
|
|
// set default channel for an auxillary function
|
|
|
|
static bool set_aux_channel_default(Aux_servo_function_t function, uint8_t channel);
|
2016-01-04 02:06:57 -04:00
|
|
|
|
|
|
|
// find first channel that a function is assigned to
|
|
|
|
static bool find_channel(Aux_servo_function_t function, uint8_t &chan);
|
2015-12-05 06:07:51 -04:00
|
|
|
|
2014-02-05 19:04:05 -04:00
|
|
|
private:
|
2015-12-05 06:07:51 -04:00
|
|
|
static uint64_t _function_mask;
|
2016-01-04 02:48:14 -04:00
|
|
|
static bool _initialised;
|
2014-02-05 19:04:05 -04:00
|
|
|
static RC_Channel_aux *_aux_channels[RC_AUX_MAX_CHANNELS];
|
2015-12-05 06:07:51 -04:00
|
|
|
|
|
|
|
void aux_servo_function_setup(void);
|
2014-02-05 19:04:05 -04:00
|
|
|
};
|