00001 // -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: t -*- 00002 00005 00006 #ifndef RC_Channel_h 00007 #define RC_Channel_h 00008 00009 #include <stdint.h> 00010 00013 class RC_Channel{ 00014 public: 00019 RC_Channel() : 00020 _address(0) 00021 {} 00022 00029 RC_Channel(uint16_t address) : 00030 _address(address), 00031 _high(1), 00032 _filter(true), 00033 _reverse(1) 00034 {} 00035 00036 // setup min and max radio values in CLI 00037 void update_min_max(); 00038 void zero_min_max(); 00039 00040 // startup 00041 void load_eeprom(void); 00042 void save_eeprom(void); 00043 void save_trim(void); 00044 void set_filter(bool filter); 00045 00046 // setup the control preferences 00047 void set_range(int low, int high); 00048 void set_angle(int angle); 00049 void set_reverse(bool reverse); 00050 00051 // read input from APM_RC - create a control_in value 00052 void set_pwm(int pwm); 00053 00054 // pwm is stored here 00055 int16_t radio_in; 00056 00057 // call after first set_pwm 00058 void trim(); 00059 00060 // did our read come in 50µs below the min? 00061 bool get_failsafe(void); 00062 00063 // value generated from PWM 00064 int16_t control_in; 00065 int16_t dead_zone; // used to keep noise down and create a dead zone. 00066 00067 int control_mix(float value); 00068 00069 // current values to the servos - degrees * 100 (approx assuming servo is -45 to 45 degrees except [3] is 0 to 100 00070 int16_t servo_out; 00071 00072 // generate PWM from servo_out value 00073 void calc_pwm(void); 00074 00075 // PWM is without the offset from radio_min 00076 int16_t pwm_out; 00077 int16_t radio_out; 00078 00079 int16_t radio_min; 00080 int16_t radio_trim; 00081 int16_t radio_max; 00082 00083 // includes offset from PWM 00084 //int16_t get_radio_out(void); 00085 00086 int16_t pwm_to_angle(); 00087 float norm_input(); 00088 float norm_output(); 00089 int16_t angle_to_pwm(); 00090 int16_t pwm_to_range(); 00091 int16_t range_to_pwm(); 00092 00093 float scale_output; 00094 00095 private: 00096 bool _filter; 00097 int8_t _reverse; 00098 00099 int16_t _address; 00100 bool _type; 00101 int16_t _high; 00102 int16_t _low; 00103 }; 00104 00105 #endif 00106 00107 00108 00109