ardupilot/ArduBoat/ControllerBoat.h

81 lines
2.2 KiB
C
Raw Normal View History

2011-09-28 21:51:12 -03:00
/*
* ControllerBoat.h
*
2011-12-05 13:26:10 -04:00
* Created on: Jun 30, 2011
2011-09-28 21:51:12 -03:00
* Author: jgoppert
*/
#ifndef CONTROLLERBOAT_H_
#define CONTROLLERBOAT_H_
2011-12-05 13:26:10 -04:00
#include "../APO/AP_Controller.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,
2011-12-05 13:26:10 -04:00
AP_HardwareAbstractionLayer * hal) :
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-10-26 14:25:06 -03:00
pidStr(new AP_Var_group(k_pidStr, PSTR("STR_")), 1, steeringP,
2011-12-05 13:26:10 -04:00
steeringI, steeringD, steeringIMax, steeringYMax)
2011-10-26 14:25:06 -03:00
{
_hal->debug->println_P(PSTR("initializing boat controller"));
_hal->rc.push_back(
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(
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-12-05 13:26:10 -04:00
new AP_RcChannel(k_chSail, PSTR("SAIL_"), 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-12-05 13:26:10 -04:00
// methods
2011-10-26 14:25:06 -03:00
void manualLoop(const float dt) {
_strCmd = _hal->rc[ch_str]->getRadioPosition();
2011-12-05 13:26:10 -04:00
_sailCmd = _hal->rc[ch_sail]->getRadioPosition();
2011-10-26 14:25:06 -03:00
}
void autoLoop(const float dt) {
2011-12-05 13:26:10 -04:00
// insert tacking logic here
2011-12-03 13:13:11 -04:00
// neglects heading command derivative
2011-12-05 13:26:10 -04:00
float steering = pidStr.update(_guide->getHeadingError(), -_nav->getYawRate(), dt);
_strCmd = steering;
// insert sail command calculation based on sensor position here
_sailCmd = 0;
2011-10-26 14:25:06 -03:00
}
void setMotors() {
2011-12-05 13:26:10 -04:00
_hal->rc[ch_str]->setPosition(_strCmd);
_hal->rc[ch_sail]->setPosition(_sailCmd);
2011-10-26 14:25:06 -03:00
}
void handleFailsafe() {
2011-12-05 13:26:10 -04:00
// turn off
setMode(MAV_MODE_LOCKED);
}
2011-10-26 14:25:06 -03:00
// attributes
enum {
2011-12-05 13:26:10 -04:00
ch_mode = 0, ch_str, ch_sail
2011-10-26 14:25:06 -03:00
};
enum {
2011-12-05 13:26:10 -04:00
k_chMode = k_radioChannelsStart, k_chStr, k_chSail
2011-10-26 14:25:06 -03:00
};
enum {
2011-12-05 13:26:10 -04:00
k_pidStr = k_controllersStart
2011-10-26 14:25:06 -03:00
};
BlockPIDDfb pidStr;
2011-12-05 13:26:10 -04:00
float _strCmd;
float _sailCmd;
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