2011-10-19 01:21:19 -03:00
|
|
|
/*
|
|
|
|
* AP_ArmingMechanism.cpp
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "AP_ArmingMechanism.h"
|
2011-11-22 17:42:51 -04:00
|
|
|
#include "AP_Controller.h"
|
2011-10-19 01:21:19 -03:00
|
|
|
#include "AP_RcChannel.h"
|
|
|
|
#include "../FastSerial/FastSerial.h"
|
|
|
|
#include "AP_HardwareAbstractionLayer.h"
|
|
|
|
#include "AP_CommLink.h"
|
|
|
|
|
|
|
|
namespace apo {
|
|
|
|
|
|
|
|
void AP_ArmingMechanism::update(const float dt) {
|
2011-10-26 15:59:40 -03:00
|
|
|
//_hal->debug->printf_P(PSTR("ch1: %f\tch2: %f\n"),_hal->rc[_ch1]->getRadioPosition(), _hal->rc[_ch2]->getRadioPosition());
|
2011-10-19 01:25:00 -03:00
|
|
|
// arming
|
2011-11-22 17:42:51 -04:00
|
|
|
if ( (_controller->getState() != MAV_STATE_ACTIVE) &&
|
2011-10-26 13:31:11 -03:00
|
|
|
(fabs(_hal->rc[_ch1]->getRadioPosition()) < _ch1Min) &&
|
|
|
|
(_hal->rc[_ch2]->getRadioPosition() < _ch2Min) ) {
|
2011-10-19 01:25:00 -03:00
|
|
|
|
|
|
|
// always start clock at 0
|
|
|
|
if (_armingClock<0) _armingClock = 0;
|
|
|
|
|
|
|
|
if (_armingClock++ >= 100) {
|
2011-11-22 17:42:51 -04:00
|
|
|
_controller->setMode(MAV_MODE_READY);
|
2011-10-19 01:25:00 -03:00
|
|
|
} else {
|
|
|
|
_hal->gcs->sendText(SEVERITY_HIGH, PSTR("arming"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// disarming
|
2011-11-22 17:42:51 -04:00
|
|
|
else if ( (_controller->getState() == MAV_STATE_ACTIVE) &&
|
2011-10-26 13:31:11 -03:00
|
|
|
(fabs(_hal->rc[_ch1]->getRadioPosition()) < _ch1Min) &&
|
|
|
|
(_hal->rc[_ch2]->getRadioPosition() > _ch2Max) ) {
|
2011-10-19 01:25:00 -03:00
|
|
|
|
|
|
|
// always start clock at 0
|
|
|
|
if (_armingClock>0) _armingClock = 0;
|
|
|
|
|
|
|
|
if (_armingClock-- <= -100) {
|
2011-11-22 17:42:51 -04:00
|
|
|
_controller->setMode(MAV_MODE_LOCKED);
|
2011-10-19 01:25:00 -03:00
|
|
|
} else {
|
|
|
|
_hal->gcs->sendText(SEVERITY_HIGH, PSTR("disarming"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// reset arming clock and report status
|
|
|
|
else if (_armingClock != 0) {
|
|
|
|
_armingClock = 0;
|
2011-11-22 17:42:51 -04:00
|
|
|
if (_controller->getState()==MAV_STATE_ACTIVE) _hal->gcs->sendText(SEVERITY_HIGH, PSTR("armed"));
|
|
|
|
else if (_controller->getState()!=MAV_STATE_ACTIVE) _hal->gcs->sendText(SEVERITY_HIGH, PSTR("disarmed"));
|
2011-10-19 01:25:00 -03:00
|
|
|
}
|
2011-10-19 01:21:19 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
} // apo
|
2011-10-19 01:25:00 -03:00
|
|
|
|
|
|
|
// vim:ts=4:sw=4:expandtab
|