ardupilot/ArduBoat/ControllerSailboat.h

81 lines
2.6 KiB
C
Raw Normal View History

2011-12-05 13:26:10 -04:00
/*
* ControllerSailboat.h
*
* Created on: Jun 30, 2011
* Author: jgoppert
*/
#ifndef CONTROLLERSAILBOAT_H_
#define CONTROLLERSAILBOAT_H_
#include "../APO/AP_Controller.h"
namespace apo {
class ControllerSailboat: public AP_Controller {
public:
ControllerSailboat(AP_Navigator * nav, AP_Guide * guide,
AP_HardwareAbstractionLayer * hal) :
2011-12-05 13:32:34 -04:00
AP_Controller(nav, guide, hal,new AP_ArmingMechanism(hal,this,ch_sail,ch_str,0.1,-0.9,0.9), ch_mode, k_cntrl),
2011-12-05 13:26:10 -04:00
pidStr(new AP_Var_group(k_pidStr, PSTR("STR_")), 1, steeringP,
steeringI, steeringD, steeringIMax, steeringYMax),
2011-12-05 13:32:34 -04:00
pidsail(new AP_Var_group(k_pidsail, PSTR("SAIL_")), 1, throttleP,
2011-12-05 13:26:10 -04:00
throttleI, throttleD, throttleIMax, throttleYMax,
2011-12-05 13:32:34 -04:00
throttleDFCut), _strCmd(0), _sailCmd(0)
2011-12-05 13:26:10 -04:00
{
_hal->debug->println_P(PSTR("initializing sailboat controller"));
_hal->rc.push_back(
new AP_RcChannel(k_chMode, PSTR("MODE_"), hal->radio, 5, 1100,
1500, 1900, RC_MODE_IN, false));
_hal->rc.push_back(
new AP_RcChannel(k_chStr, PSTR("STR_"), hal->radio, 3, 1100, 1500,
1900, RC_MODE_INOUT, false));
_hal->rc.push_back(
2011-12-05 13:32:34 -04:00
new AP_RcChannel(k_chsail, PSTR("SAIL_"), hal->radio, 2, 1100, 1500,
2011-12-05 13:26:10 -04:00
1900, RC_MODE_INOUT, false));
}
private:
// methods
void manualLoop(const float dt) {
_strCmd = _hal->rc[ch_str]->getRadioPosition();
2011-12-05 13:32:34 -04:00
_sailCmd = _hal->rc[ch_sail]->getRadioPosition();
2011-12-05 13:26:10 -04:00
}
void autoLoop(const float dt) {
2011-12-05 13:32:34 -04:00
//_hal->debug->printf_P(PSTR("cont: ch1: %f\tch2: %f\n"),_hal->rc[ch_sail]->getRadioPosition(), _hal->rc[ch_str]->getRadioPosition());
2011-12-05 13:26:10 -04:00
// neglects heading command derivative
float steering = pidStr.update(_guide->getHeadingError(), -_nav->getYawRate(), dt);
2011-12-05 13:32:34 -04:00
float sail = 0;
2011-12-05 13:26:10 -04:00
_strCmd = steering;
2011-12-05 13:32:34 -04:00
_sailCmd = sail;
2011-12-05 13:26:10 -04:00
}
void setMotors() {
_hal->rc[ch_str]->setPosition(_strCmd);
2011-12-05 13:32:34 -04:00
_hal->rc[ch_sail]->setPosition(fabs(_sailCmd) < 0.1 ? 0 : _sailCmd);
2011-12-05 13:26:10 -04:00
}
void handleFailsafe() {
// turn off
setMode(MAV_MODE_LOCKED);
}
// attributes
enum {
2011-12-05 13:32:34 -04:00
ch_mode = 0, ch_str, ch_sail
2011-12-05 13:26:10 -04:00
};
enum {
2011-12-05 13:32:34 -04:00
k_chMode = k_radioChannelsStart, k_chStr, k_chsail
2011-12-05 13:26:10 -04:00
};
enum {
2011-12-05 13:32:34 -04:00
k_pidStr = k_controllersStart, k_pidsail
2011-12-05 13:26:10 -04:00
};
BlockPIDDfb pidStr;
2011-12-05 13:32:34 -04:00
BlockPID pidsail;
float _strCmd, _sailCmd;
2011-12-05 13:26:10 -04:00
};
} // namespace apo
#endif /* CONTROLLERSAILBOAT_H_ */
// vim:ts=4:sw=4:expandtab