Go to the documentation of this file.00001
00002
00005
00006 #ifndef AP_RcChannel_h
00007 #define AP_RcChannel_h
00008
00009 #include <stdint.h>
00010 #include <FastSerial.h>
00011 #include <APM_RC.h>
00012 #include <AP_Var.h>
00013 #include <AP_Common.h>
00014 #include <AP_EEProm.h>
00015
00018 class AP_RcChannel{
00019
00020 public:
00021
00023 AP_RcChannel(const char * name, const APM_RC_Class & rc, const uint8_t & ch,
00024 const float & scale=45.0, const float & center=0.0,
00025 const uint16_t & pwmMin=1200,
00026 const uint16_t & pwmNeutral=1500, const uint16_t & pwmMax=1800,
00027 const uint16_t & pwmDeadZone=10,
00028 const bool & filter=false, const bool & reverse=false);
00029
00030
00031 void readRadio();
00032 void setPwm(uint16_t pwm);
00033 void setPosition(float position);
00034 void setNormalized(float normPosition) { setPosition(normPosition*getScale()); }
00035 void mixRadio(uint16_t infStart);
00036 void setCh(const uint8_t & ch) { _ch->set(ch); }
00037 void setScale(const float & scale) { _scale->set(scale); }
00038 void setCenter(const float & center) { _center->set(center); }
00039 void setPwmMin(const uint16_t & pwmMin) { _pwmMin->set(pwmMin); }
00040 void setPwmNeutral(const uint16_t & pwmNeutral) { _pwmNeutral->set(pwmNeutral); }
00041 void setPwmMax(const uint16_t & pwmMax) { _pwmMax->set(pwmMax); }
00042 void setPwmDeadZone(const uint16_t & pwmDeadZone) { _pwmDeadZone->set(pwmDeadZone); }
00043 void setFilter(const bool & filter) { _filter->set(filter); }
00044
00045
00046 uint16_t getPwm() { return _pwm; }
00047 float getPosition() { return _pwmToPosition(_pwm); }
00048 float getNormalized() { return getPosition()/_scale->get(); }
00049 const char * getName() { return _name; }
00050 const uint8_t & getCh() { return _ch->get(); }
00051 const float & getScale() { return _scale->get(); }
00052 const float & getCenter() { return _center->get(); }
00053 const uint16_t & getPwmMin() { return _pwmMin->get(); }
00054 const uint16_t & getPwmNeutral() { return _pwmNeutral->get(); }
00055 const uint16_t & getPwmMax() { return _pwmMax->get(); }
00056 const uint16_t & getPwmDeadZone() { return _pwmDeadZone->get(); }
00057 const bool & getFilter() { return _filter->get(); }
00058 const bool & getReverse() { return _reverse->get(); }
00059
00060
00061 bool failSafe() { _pwm < (_pwmMin->get() - 50); }
00062
00063 private:
00064
00065
00066 const char * _name;
00067 const APM_RC_Class & _rc;
00068 AP_Uint8 * _ch;
00069 AP_Float * _scale;
00070 AP_Float * _center;
00071 AP_Uint16 * _pwmMin;
00072 AP_Uint16 * _pwmNeutral;
00073 AP_Uint16 * _pwmMax;
00074 AP_Uint16 * _pwmDeadZone;
00075 AP_Bool * _filter;
00076 AP_Bool * _reverse;
00077
00078
00079 uint16_t _pwm;
00080
00081
00082 uint16_t _positionToPwm(const float & position);
00083 float _pwmToPosition(const uint16_t & pwm);
00084 };
00085
00086 #endif
00087
00088
00089
00090