2011-09-28 21:51:12 -03:00
|
|
|
/*
|
|
|
|
* ControllerBoat.h
|
|
|
|
*
|
2011-11-01 14:59:34 -03:00
|
|
|
* Created on: Nov 1, 2011
|
2011-09-28 21:51:12 -03:00
|
|
|
* Author: jgoppert
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CONTROLLERBOAT_H_
|
|
|
|
#define CONTROLLERBOAT_H_
|
|
|
|
|
2011-11-24 14:28:14 -04:00
|
|
|
#include "../APO/APO.h"
|
2011-09-28 21:51:12 -03:00
|
|
|
|
|
|
|
namespace apo {
|
|
|
|
|
|
|
|
class ControllerBoat: public AP_Controller {
|
2011-10-25 20:40:07 -03:00
|
|
|
public:
|
2011-10-26 14:25:06 -03:00
|
|
|
ControllerBoat(AP_Navigator * nav, AP_Guide * guide,
|
|
|
|
AP_HardwareAbstractionLayer * hal) :
|
2011-11-24 14:28:14 -04:00
|
|
|
AP_Controller(nav, guide, hal,new AP_ArmingMechanism(hal,this,ch_thrust,ch_str,0.1,-0.9,0.9), ch_mode, k_cntrl),
|
2011-10-26 14:25:06 -03:00
|
|
|
pidStr(new AP_Var_group(k_pidStr, PSTR("STR_")), 1, steeringP,
|
|
|
|
steeringI, steeringD, steeringIMax, steeringYMax,steeringDFCut),
|
|
|
|
pidThrust(new AP_Var_group(k_pidThrust, PSTR("THR_")), 1, throttleP,
|
|
|
|
throttleI, throttleD, throttleIMax, throttleYMax,
|
|
|
|
throttleDFCut), _strCmd(0), _thrustCmd(0)
|
|
|
|
{
|
|
|
|
_hal->debug->println_P(PSTR("initializing boat controller"));
|
|
|
|
|
|
|
|
_hal->rc.push_back(
|
2011-11-28 01:53:30 -04:00
|
|
|
new AP_RcChannel(k_chMode, PSTR("MODE_"), hal->radio, 5, 1100,
|
2011-10-26 14:25:06 -03:00
|
|
|
1500, 1900, RC_MODE_IN, false));
|
|
|
|
_hal->rc.push_back(
|
2011-11-28 01:53:30 -04:00
|
|
|
new AP_RcChannel(k_chStr, PSTR("STR_"), hal->radio, 3, 1100, 1500,
|
2011-10-26 14:25:06 -03:00
|
|
|
1900, RC_MODE_INOUT, false));
|
|
|
|
_hal->rc.push_back(
|
2011-11-28 01:53:30 -04:00
|
|
|
new AP_RcChannel(k_chThrust, PSTR("THR_"), hal->radio, 2, 1100, 1500,
|
2011-10-26 14:25:06 -03:00
|
|
|
1900, RC_MODE_INOUT, false));
|
|
|
|
}
|
2011-10-25 20:40:07 -03:00
|
|
|
|
|
|
|
private:
|
2011-10-26 14:25:06 -03:00
|
|
|
// methdos
|
|
|
|
void manualLoop(const float dt) {
|
|
|
|
setAllRadioChannelsManually();
|
|
|
|
_strCmd = _hal->rc[ch_str]->getRadioPosition();
|
|
|
|
_thrustCmd = _hal->rc[ch_thrust]->getRadioPosition();
|
|
|
|
}
|
|
|
|
void autoLoop(const float dt) {
|
|
|
|
_strCmd = pidStr.update(_guide->getHeadingError(), _nav->getYawRate(), dt);
|
|
|
|
_thrustCmd = pidThrust.update(
|
|
|
|
_guide->getGroundSpeedCommand()
|
|
|
|
- _nav->getGroundSpeed(), dt);
|
|
|
|
}
|
2011-11-22 17:42:51 -04:00
|
|
|
void setMotors() {
|
2011-10-26 14:25:06 -03:00
|
|
|
// turn all motors off if below 0.1 throttle
|
|
|
|
if (fabs(_hal->rc[ch_thrust]->getRadioPosition()) < 0.1) {
|
|
|
|
setAllRadioChannelsToNeutral();
|
|
|
|
} else {
|
|
|
|
_hal->rc[ch_thrust]->setPosition(_thrustCmd);
|
|
|
|
_hal->rc[ch_str]->setPosition(_strCmd);
|
|
|
|
}
|
|
|
|
}
|
2011-11-22 17:42:51 -04:00
|
|
|
void handleFailsafe() {
|
|
|
|
// failsafe is to turn off
|
|
|
|
setMode(MAV_MODE_LOCKED);
|
|
|
|
}
|
2011-10-26 14:25:06 -03:00
|
|
|
|
|
|
|
// attributes
|
|
|
|
enum {
|
|
|
|
ch_mode = 0, ch_str, ch_thrust
|
|
|
|
};
|
|
|
|
enum {
|
|
|
|
k_chMode = k_radioChannelsStart, k_chStr, k_chThrust
|
|
|
|
};
|
|
|
|
enum {
|
|
|
|
k_pidStr = k_controllersStart, k_pidThrust
|
|
|
|
};
|
|
|
|
BlockPIDDfb pidStr;
|
|
|
|
BlockPID pidThrust;
|
|
|
|
float _strCmd, _thrustCmd;
|
2011-09-28 21:51:12 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace apo
|
|
|
|
|
|
|
|
#endif /* CONTROLLERBOAT_H_ */
|
2011-10-26 14:25:06 -03:00
|
|
|
// vim:ts=4:sw=4:expandtab
|