Rover: Added mode switch debouncing from Plane.

This commit is contained in:
Grant Morphett 2015-07-22 11:13:02 +10:00 committed by Andrew Tridgell
parent 7935bf70f1
commit 4f6259f374

View File

@ -4,7 +4,7 @@
void Rover::read_control_switch()
{
static bool switch_debouncer;
uint8_t switchPosition = readSwitch();
// If switchPosition = 255 this indicates that the mode control channel input was out of range
@ -26,6 +26,15 @@ void Rover::read_control_switch()
(g.reset_switch_chan != 0 &&
hal.rcin->read(g.reset_switch_chan-1) > RESET_SWITCH_CHAN_PWM)) {
if (switch_debouncer == false) {
// this ensures that mode switches only happen if the
// switch changes for 2 reads. This prevents momentary
// spikes in the mode control channel from causing a mode
// switch
switch_debouncer = true;
return;
}
set_mode((enum mode)modes[switchPosition].get());
oldSwitchPosition = switchPosition;
@ -35,6 +44,8 @@ void Rover::read_control_switch()
g.pidSpeedThrottle.reset_I();
}
switch_debouncer = false;
}
uint8_t Rover::readSwitch(void){