2010-12-24 20:06:37 -04:00
|
|
|
// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: t -*-
|
|
|
|
|
2010-12-25 15:14:47 -04:00
|
|
|
/// @file AP_RcChannel.h
|
|
|
|
/// @brief AP_RcChannel manager
|
2010-12-24 20:06:37 -04:00
|
|
|
|
2010-12-25 15:14:47 -04:00
|
|
|
#ifndef AP_RcChannel_h
|
|
|
|
#define AP_RcChannel_h
|
2010-12-24 20:06:37 -04:00
|
|
|
|
|
|
|
#include <stdint.h>
|
2010-12-25 12:51:35 -04:00
|
|
|
#include <FastSerial.h>
|
2010-12-26 14:07:08 -04:00
|
|
|
#include <APM_RC.h>
|
2010-12-24 20:06:37 -04:00
|
|
|
|
2010-12-25 15:14:47 -04:00
|
|
|
/// @class AP_RcChannel
|
2010-12-24 20:06:37 -04:00
|
|
|
/// @brief Object managing one RC channel
|
2010-12-25 15:14:47 -04:00
|
|
|
class AP_RcChannel{
|
2010-12-25 03:09:37 -04:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/// Constructor
|
2010-12-26 14:07:08 -04:00
|
|
|
AP_RcChannel(const APM_RC_Class & rc, const uint16_t & ch,
|
|
|
|
const float & scale, const uint16_t & pwmMin, const uint16_t & pwmNeutral,
|
2010-12-25 12:51:35 -04:00
|
|
|
const uint16_t & pwmMax, const uint16_t & pwmDeadZone,
|
|
|
|
const bool & filter, const bool & reverse) :
|
2010-12-26 14:07:08 -04:00
|
|
|
_rc(rc),
|
|
|
|
_ch(ch),
|
2010-12-25 12:51:35 -04:00
|
|
|
_scale(scale),
|
|
|
|
_pwmMin(pwmMin),
|
|
|
|
_pwmMax(pwmMax),
|
|
|
|
_pwmNeutral(pwmNeutral),
|
|
|
|
_pwmDeadZone(pwmDeadZone),
|
2010-12-25 03:09:37 -04:00
|
|
|
_pwm(0),
|
2010-12-25 12:51:35 -04:00
|
|
|
_filter(filter),
|
|
|
|
_reverse(reverse)
|
2010-12-25 03:09:37 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// set servo state
|
2010-12-26 14:07:08 -04:00
|
|
|
void readRadio();
|
2010-12-25 03:09:37 -04:00
|
|
|
void setPwm(uint16_t pwm);
|
|
|
|
void setPosition(float position);
|
|
|
|
void mixRadio(uint16_t infStart);
|
|
|
|
|
|
|
|
// get servo state
|
|
|
|
uint16_t getPwm() { return _pwm; }
|
|
|
|
float getPosition() { return _pwmToPosition(_pwm); }
|
|
|
|
float getNormalized() { return getPosition()/_scale; }
|
2010-12-24 20:06:37 -04:00
|
|
|
|
|
|
|
// did our read come in 50µs below the min?
|
2010-12-25 03:09:37 -04:00
|
|
|
bool failSafe() { _pwm < (_pwmMin - 50); }
|
2010-12-24 20:06:37 -04:00
|
|
|
|
2010-12-25 03:09:37 -04:00
|
|
|
private:
|
2010-12-24 20:06:37 -04:00
|
|
|
|
2010-12-25 12:51:35 -04:00
|
|
|
// configuration
|
2010-12-26 14:07:08 -04:00
|
|
|
const APM_RC_Class & _rc;
|
|
|
|
const uint16_t _ch;
|
2010-12-25 12:51:35 -04:00
|
|
|
const float & _scale;
|
|
|
|
const uint16_t & _pwmMin;
|
|
|
|
const uint16_t & _pwmNeutral;
|
|
|
|
const uint16_t & _pwmMax;
|
|
|
|
const uint16_t & _pwmDeadZone;
|
|
|
|
const bool & _filter;
|
2010-12-25 15:03:38 -04:00
|
|
|
const bool & _reverse;
|
2010-12-25 12:51:35 -04:00
|
|
|
|
|
|
|
// internal states
|
2010-12-26 14:07:08 -04:00
|
|
|
uint16_t _pwm; // this is the internal state, position is just created when needed
|
2010-12-25 03:09:37 -04:00
|
|
|
|
|
|
|
// private methods
|
2010-12-25 15:03:38 -04:00
|
|
|
uint16_t _positionToPwm(const float & position);
|
|
|
|
float _pwmToPosition(const uint16_t & pwm);
|
2010-12-24 20:06:37 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|