aboutsummaryrefslogtreecommitdiff
path: root/apps/px4io/controls.c
diff options
context:
space:
mode:
authorLorenz Meier <lm@inf.ethz.ch>2012-12-30 10:03:05 +0100
committerLorenz Meier <lm@inf.ethz.ch>2012-12-30 10:03:05 +0100
commit142556b442b1c88ed2ede2cb9904a6a324051e71 (patch)
tree0ad4357be8b5ef9ccab6ea6c5fa125a19e8a29d9 /apps/px4io/controls.c
parentb8250de1e67f63f9ca3b990e016744584a328922 (diff)
parent62a95bf8e6592b31ae7e84e53b654bc5e6b71cd1 (diff)
downloadpx4-firmware-142556b442b1c88ed2ede2cb9904a6a324051e71.tar.gz
px4-firmware-142556b442b1c88ed2ede2cb9904a6a324051e71.tar.bz2
px4-firmware-142556b442b1c88ed2ede2cb9904a6a324051e71.zip
merged
Diffstat (limited to 'apps/px4io/controls.c')
-rw-r--r--apps/px4io/controls.c43
1 files changed, 37 insertions, 6 deletions
diff --git a/apps/px4io/controls.c b/apps/px4io/controls.c
index 43e811ab0..564687b58 100644
--- a/apps/px4io/controls.c
+++ b/apps/px4io/controls.c
@@ -60,6 +60,10 @@
#define DEBUG
#include "px4io.h"
+#define RC_FAILSAFE_TIMEOUT 2000000 /**< two seconds failsafe timeout */
+#define RC_CHANNEL_HIGH_THRESH 1700
+#define RC_CHANNEL_LOW_THRESH 1300
+
static void ppm_input(void);
void
@@ -88,11 +92,23 @@ controls_main(void)
*/
bool locked = false;
+ /*
+ * Store RC channel count to detect switch to RC loss sooner
+ * than just by timeout
+ */
+ unsigned rc_channels = system_state.rc_channels;
+
+ /*
+ * Track if any input got an update in this round
+ */
+ bool rc_updated;
+
if (fds[0].revents & POLLIN)
locked |= dsm_input();
if (fds[1].revents & POLLIN)
- locked |= sbus_input();
+ locked |= sbus_input(fds[1].fd, PX4IO_INPUT_CHANNELS, &system_state.rc_channel_data,
+ &system_state.rc_channels, &system_state.rc_channels_timestamp, &rc_updated);
/*
* If we don't have lock from one of the serial receivers,
@@ -107,6 +123,15 @@ controls_main(void)
if (!locked)
ppm_input();
+ /* check for manual override status */
+ if (system_state.rc_channel_data[4] > RC_CHANNEL_HIGH_THRESH) {
+ /* force manual input override */
+ system_state.mixer_manual_override = true;
+ } else {
+ /* override not engaged, use FMU */
+ system_state.mixer_manual_override = false;
+ }
+
/*
* If we haven't seen any new control data in 200ms, assume we
* have lost input and tell FMU.
@@ -115,14 +140,20 @@ controls_main(void)
/* set the number of channels to zero - no inputs */
system_state.rc_channels = 0;
-
- /* trigger an immediate report to the FMU */
- system_state.fmu_report_due = true;
+ rc_updated = true;
}
- /* XXX do bypass mode, etc. here */
+ /*
+ * If there was a RC update OR the RC signal status (lost / present) has
+ * just changed, request an update immediately.
+ */
+ system_state.fmu_report_due |= rc_updated;
- /* do PWM output updates */
+ /*
+ * PWM output updates are performed in addition on each comm update.
+ * the updates here are required to ensure operation if FMU is not started
+ * or stopped responding.
+ */
mixer_tick();
}
}