2010-11-28 03:03:23 -04:00
|
|
|
/// @file RC_Channel.h
|
|
|
|
/// @brief RC_Channel manager, with EEPROM-backed storage of constants.
|
2016-02-17 21:25:57 -04:00
|
|
|
#pragma once
|
2010-11-23 15:28:19 -04:00
|
|
|
|
2015-08-11 03:28:46 -03:00
|
|
|
#include <AP_Common/AP_Common.h>
|
|
|
|
#include <AP_Param/AP_Param.h>
|
2012-10-26 20:59:16 -03:00
|
|
|
|
2012-12-09 03:42:58 -04:00
|
|
|
#define RC_CHANNEL_TYPE_ANGLE 0
|
|
|
|
#define RC_CHANNEL_TYPE_RANGE 1
|
|
|
|
|
2016-10-22 07:27:40 -03:00
|
|
|
#define NUM_RC_CHANNELS 16
|
2013-08-17 22:37:42 -03:00
|
|
|
|
2010-11-28 03:03:23 -04:00
|
|
|
/// @class RC_Channel
|
|
|
|
/// @brief Object managing one RC channel
|
2012-08-17 03:22:48 -03:00
|
|
|
class RC_Channel {
|
|
|
|
public:
|
2017-01-08 20:47:26 -04:00
|
|
|
friend class SRV_Channels;
|
2016-10-22 07:27:40 -03:00
|
|
|
friend class RC_Channels;
|
|
|
|
// Constructor
|
|
|
|
RC_Channel(void);
|
2012-08-17 03:22:48 -03:00
|
|
|
|
2014-04-20 21:34:10 -03:00
|
|
|
// used to get min/max/trim limit value based on _reverse
|
|
|
|
enum LimitValue {
|
|
|
|
RC_CHANNEL_LIMIT_TRIM,
|
|
|
|
RC_CHANNEL_LIMIT_MIN,
|
|
|
|
RC_CHANNEL_LIMIT_MAX
|
|
|
|
};
|
|
|
|
|
2012-08-17 03:22:48 -03:00
|
|
|
// startup
|
|
|
|
void load_eeprom(void);
|
|
|
|
void save_eeprom(void);
|
|
|
|
void save_trim(void);
|
|
|
|
|
|
|
|
// setup the control preferences
|
2016-10-22 07:27:40 -03:00
|
|
|
void set_range(uint16_t high);
|
|
|
|
void set_angle(uint16_t angle);
|
2014-04-20 21:34:10 -03:00
|
|
|
bool get_reverse(void) const;
|
2013-07-11 11:08:16 -03:00
|
|
|
void set_default_dead_zone(int16_t dzone);
|
2016-10-22 07:27:40 -03:00
|
|
|
uint16_t get_dead_zone(void) const { return dead_zone; }
|
2014-04-20 21:34:10 -03:00
|
|
|
|
2014-11-17 18:00:31 -04:00
|
|
|
// get the center stick position expressed as a control_in value
|
2014-11-17 20:18:51 -04:00
|
|
|
int16_t get_control_mid() const;
|
2014-11-17 18:00:31 -04:00
|
|
|
|
2017-01-07 01:37:00 -04:00
|
|
|
// read input from hal.rcin - create a control_in value
|
2012-08-17 03:22:48 -03:00
|
|
|
void set_pwm(int16_t pwm);
|
2012-12-04 02:27:18 -04:00
|
|
|
void set_pwm_no_deadzone(int16_t pwm);
|
2012-08-17 03:22:48 -03:00
|
|
|
|
2017-01-07 01:37:00 -04:00
|
|
|
// calculate an angle given dead_zone and trim. This is used by the quadplane code
|
|
|
|
// for hover throttle
|
2016-05-08 05:22:32 -03:00
|
|
|
int16_t pwm_to_angle_dz_trim(uint16_t dead_zone, uint16_t trim);
|
2014-11-17 21:44:05 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
return a normalised input for a channel, in range -1 to 1,
|
|
|
|
centered around the channel trim. Ignore deadzone.
|
|
|
|
*/
|
2016-05-08 05:22:32 -03:00
|
|
|
float norm_input();
|
2014-11-17 21:44:05 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
return a normalised input for a channel, in range -1 to 1,
|
|
|
|
centered around the channel trim. Take into account the deadzone
|
|
|
|
*/
|
2016-05-08 05:22:32 -03:00
|
|
|
float norm_input_dz();
|
|
|
|
|
|
|
|
uint8_t percent_input();
|
|
|
|
int16_t pwm_to_range();
|
|
|
|
int16_t pwm_to_range_dz(uint16_t dead_zone);
|
2017-01-07 01:37:00 -04:00
|
|
|
|
|
|
|
// read the input value from hal.rcin for this channel
|
2016-05-08 05:22:32 -03:00
|
|
|
uint16_t read() const;
|
2017-01-07 01:37:00 -04:00
|
|
|
|
|
|
|
// read input from hal.rcin and set as pwm input for channel
|
2016-05-08 05:22:32 -03:00
|
|
|
void input();
|
2012-08-17 03:22:48 -03:00
|
|
|
|
2016-10-22 07:27:40 -03:00
|
|
|
static const struct AP_Param::GroupInfo var_info[];
|
|
|
|
|
2017-01-07 01:37:00 -04:00
|
|
|
// return true if input is within deadzone of trim
|
2016-10-22 07:27:40 -03:00
|
|
|
bool in_trim_dz();
|
|
|
|
|
|
|
|
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;}
|
|
|
|
|
|
|
|
// get control input with zero deadzone
|
|
|
|
int16_t get_control_in_zero_dz(void);
|
|
|
|
|
|
|
|
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;}
|
2012-08-17 03:22:48 -03:00
|
|
|
|
2016-10-22 07:27:40 -03:00
|
|
|
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();}
|
2013-06-03 02:11:17 -03:00
|
|
|
|
2017-07-01 19:46:06 -03:00
|
|
|
void set_and_save_trim() { radio_trim.set_and_save_ifchanged(radio_in);}
|
2017-07-01 07:04:44 -03:00
|
|
|
|
2017-01-19 22:29:37 -04:00
|
|
|
bool min_max_configured() const
|
2016-05-08 05:22:32 -03:00
|
|
|
{
|
2016-10-22 07:27:40 -03:00
|
|
|
return radio_min.configured() && radio_max.configured();
|
2016-03-25 07:35:33 -03:00
|
|
|
}
|
|
|
|
|
2016-10-22 07:27:40 -03:00
|
|
|
private:
|
2016-05-08 05:22:32 -03:00
|
|
|
|
2016-10-22 07:27:40 -03:00
|
|
|
// pwm is stored here
|
|
|
|
int16_t radio_in;
|
2016-05-08 05:22:32 -03:00
|
|
|
|
2016-10-22 07:27:40 -03:00
|
|
|
// value generated from PWM normalised to configured scale
|
|
|
|
int16_t control_in;
|
|
|
|
|
|
|
|
AP_Int16 radio_min;
|
|
|
|
AP_Int16 radio_trim;
|
|
|
|
AP_Int16 radio_max;
|
2016-05-08 05:22:32 -03:00
|
|
|
|
2016-10-22 07:27:40 -03:00
|
|
|
AP_Int8 reversed;
|
|
|
|
AP_Int16 dead_zone;
|
2016-05-08 05:22:32 -03:00
|
|
|
|
2016-10-22 07:27:40 -03:00
|
|
|
uint8_t type_in;
|
|
|
|
int16_t high_in;
|
2015-10-30 02:46:03 -03:00
|
|
|
|
2016-10-22 07:27:40 -03:00
|
|
|
// the input channel this corresponds to
|
|
|
|
uint8_t ch_in;
|
2016-05-08 05:22:32 -03:00
|
|
|
|
2017-01-07 01:37:00 -04:00
|
|
|
int16_t pwm_to_angle();
|
2016-10-22 07:27:40 -03:00
|
|
|
int16_t pwm_to_angle_dz(uint16_t dead_zone);
|
|
|
|
};
|
2016-05-08 05:22:32 -03:00
|
|
|
|
|
|
|
|
2016-10-22 07:27:40 -03:00
|
|
|
/*
|
|
|
|
class RC_Channels. Hold the full set of RC_Channel objects
|
|
|
|
*/
|
|
|
|
class RC_Channels {
|
|
|
|
public:
|
2017-01-08 20:47:26 -04:00
|
|
|
friend class SRV_Channels;
|
2016-10-22 07:27:40 -03:00
|
|
|
// constructor
|
|
|
|
RC_Channels(void);
|
2016-10-11 08:00:48 -03:00
|
|
|
|
2016-10-22 07:27:40 -03:00
|
|
|
static const struct AP_Param::GroupInfo var_info[];
|
|
|
|
|
|
|
|
static RC_Channel *rc_channel(uint8_t chan) {
|
|
|
|
return (chan < NUM_RC_CHANNELS)?&channels[chan]:nullptr;
|
2016-05-08 05:22:32 -03:00
|
|
|
}
|
2016-10-22 07:27:40 -03:00
|
|
|
|
|
|
|
static void set_pwm_all(void);
|
2016-05-08 05:22:32 -03:00
|
|
|
|
2012-08-17 03:22:48 -03:00
|
|
|
private:
|
2016-10-22 07:27:40 -03:00
|
|
|
// this static arrangement is to avoid static pointers in AP_Param tables
|
|
|
|
static RC_Channel *channels;
|
|
|
|
RC_Channel obj_channels[NUM_RC_CHANNELS];
|
2010-11-23 15:28:19 -04:00
|
|
|
};
|