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-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 12:51:35 -04:00
|
|
|
//
|
2010-12-25 15:14:47 -04:00
|
|
|
class AP_RcChannel{
|
2010-12-25 03:09:37 -04:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/// Constructor
|
2010-12-24 20:06:37 -04:00
|
|
|
///
|
2010-12-25 15:14:47 -04:00
|
|
|
AP_RcChannel(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) :
|
|
|
|
_scale(scale),
|
|
|
|
_pwmMin(pwmMin),
|
|
|
|
_pwmMax(pwmMax),
|
|
|
|
_pwmNeutral(pwmNeutral),
|
|
|
|
_pwmDeadZone(pwmDeadZone),
|
2010-12-25 03:09:37 -04:00
|
|
|
_pwm(0),
|
|
|
|
_pwmRadio(0),
|
2010-12-25 12:51:35 -04:00
|
|
|
_filter(filter),
|
|
|
|
_reverse(reverse)
|
2010-12-25 03:09:37 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// set servo state
|
|
|
|
void readRadio(uint16_t pwmRadio);
|
|
|
|
void setPwm(uint16_t pwm);
|
|
|
|
void setPosition(float position);
|
|
|
|
void mixRadio(uint16_t infStart);
|
|
|
|
|
|
|
|
// get servo state
|
|
|
|
uint16_t getPwm() { return _pwm; }
|
|
|
|
uint16_t getPwmRadio() { return _pwmRadio; }
|
|
|
|
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
|
|
|
|
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-25 03:09:37 -04:00
|
|
|
uint16_t _pwm; // this is the internal state, positino is just created when needed
|
|
|
|
uint16_t _pwmRadio; // radio pwm input
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|