Differentiate between failsafe having kicked in (which stops the normal output mixing based on RC outputs and prevents unwanted control commands due to failsafe) and a true loss of the receiver, where we stop outputting RC channel readings downstream on FMU.

This commit is contained in:
Lorenz Meier
2014-01-26 15:52:51 +01:00
parent 2a30c574ce
commit 00a3270dc6
2 changed files with 96 additions and 74 deletions
+39 -18
View File
@@ -59,6 +59,11 @@ static perf_counter_t c_gather_ppm;
void void
controls_init(void) controls_init(void)
{ {
/* no channels */
r_raw_rc_count = 0;
rc_channels_timestamp_received = 0;
rc_channels_timestamp_valid = 0;
/* DSM input (USART1) */ /* DSM input (USART1) */
dsm_init("/dev/ttyS0"); dsm_init("/dev/ttyS0");
@@ -121,6 +126,9 @@ controls_tick() {
else else
r_raw_rc_flags &= ~PX4IO_P_RAW_RC_FLAGS_RC_DSM11; r_raw_rc_flags &= ~PX4IO_P_RAW_RC_FLAGS_RC_DSM11;
r_raw_rc_flags &= ~(PX4IO_P_RAW_RC_FLAGS_FRAME_DROP);
r_raw_rc_flags &= ~(PX4IO_P_RAW_RC_FLAGS_FAILSAFE);
} }
perf_end(c_gather_dsm); perf_end(c_gather_dsm);
@@ -164,6 +172,8 @@ controls_tick() {
if (ppm_updated) { if (ppm_updated) {
r_status_flags |= PX4IO_P_STATUS_FLAGS_RC_PPM; r_status_flags |= PX4IO_P_STATUS_FLAGS_RC_PPM;
r_raw_rc_flags &= ~(PX4IO_P_RAW_RC_FLAGS_FRAME_DROP);
r_raw_rc_flags &= ~(PX4IO_P_RAW_RC_FLAGS_FAILSAFE);
} }
perf_end(c_gather_ppm); perf_end(c_gather_ppm);
@@ -185,12 +195,18 @@ controls_tick() {
*/ */
if (dsm_updated || sbus_updated || ppm_updated) { if (dsm_updated || sbus_updated || ppm_updated) {
/* update RC-received timestamp */
system_state.rc_channels_timestamp = hrt_absolute_time();
/* record a bitmask of channels assigned */ /* record a bitmask of channels assigned */
unsigned assigned_channels = 0; unsigned assigned_channels = 0;
/* update RC-received timestamp */
system_state.rc_channels_timestamp_received = hrt_absolute_time();
/* do not command anything in failsafe, kick in the RC loss counter */
if (!(r_raw_rc_flags & PX4IO_P_RAW_RC_FLAGS_FAILSAFE)) {
/* update RC-received timestamp */
system_state.rc_channels_timestamp_valid = system_state.rc_channels_timestamp_received;
/* map raw inputs to mapped inputs */ /* map raw inputs to mapped inputs */
/* XXX mapping should be atomic relative to protocol */ /* XXX mapping should be atomic relative to protocol */
for (unsigned i = 0; i < r_raw_rc_count; i++) { for (unsigned i = 0; i < r_raw_rc_count; i++) {
@@ -264,18 +280,15 @@ controls_tick() {
r_rc_values[i] = 0; r_rc_values[i] = 0;
} }
/* /* set RC OK flag, as we got an update */
* If we got an update with zero channels, treat it as
* a loss of input.
*
* This might happen if a protocol-based receiver returns an update
* that contains no channels that we have mapped.
*/
if (assigned_channels == 0 || (r_raw_rc_flags & (PX4IO_P_RAW_RC_FLAGS_FAILSAFE))) {
rc_input_lost = true;
} else {
/* set RC OK flag */
r_status_flags |= PX4IO_P_STATUS_FLAGS_RC_OK; r_status_flags |= PX4IO_P_STATUS_FLAGS_RC_OK;
/* if we have enough channels (5) to control the vehicle, the mapping is ok */
if (assigned_channels > 4) {
r_raw_rc_flags |= PX4IO_P_RAW_RC_FLAGS_MAPPING_OK;
} else {
r_raw_rc_flags &= ~(PX4IO_P_RAW_RC_FLAGS_MAPPING_OK);
}
} }
/* /*
@@ -288,7 +301,7 @@ controls_tick() {
* If we haven't seen any new control data in 200ms, assume we * If we haven't seen any new control data in 200ms, assume we
* have lost input. * have lost input.
*/ */
if (hrt_elapsed_time(&system_state.rc_channels_timestamp) > 200000) { if (hrt_elapsed_time(&system_state.rc_channels_timestamp_received) > 200000) {
rc_input_lost = true; rc_input_lost = true;
/* clear the input-kind flags here */ /* clear the input-kind flags here */
@@ -296,24 +309,32 @@ controls_tick() {
PX4IO_P_STATUS_FLAGS_RC_PPM | PX4IO_P_STATUS_FLAGS_RC_PPM |
PX4IO_P_STATUS_FLAGS_RC_DSM | PX4IO_P_STATUS_FLAGS_RC_DSM |
PX4IO_P_STATUS_FLAGS_RC_SBUS); PX4IO_P_STATUS_FLAGS_RC_SBUS);
} }
/* /*
* Handle losing RC input * Handle losing RC input
*/ */
if (rc_input_lost) {
/* this kicks in if the receiver is gone or the system went to failsafe */
if (rc_input_lost || (r_raw_rc_flags & PX4IO_P_RAW_RC_FLAGS_FAILSAFE)) {
/* Clear the RC input status flag, clear manual override flag */ /* Clear the RC input status flag, clear manual override flag */
r_status_flags &= ~( r_status_flags &= ~(
PX4IO_P_STATUS_FLAGS_OVERRIDE | PX4IO_P_STATUS_FLAGS_OVERRIDE |
PX4IO_P_STATUS_FLAGS_RC_OK); PX4IO_P_STATUS_FLAGS_RC_OK);
/* Mark all channels as invalid, as we just lost the RX */
r_rc_valid = 0;
/* Set the RC_LOST alarm */ /* Set the RC_LOST alarm */
r_status_alarms |= PX4IO_P_STATUS_ALARMS_RC_LOST; r_status_alarms |= PX4IO_P_STATUS_ALARMS_RC_LOST;
}
/* Mark the arrays as empty */ /* this kicks in if the receiver is completely gone */
if (rc_input_lost) {
/* Set channel count to zero */
r_raw_rc_count = 0; r_raw_rc_count = 0;
r_rc_valid = 0;
} }
/* /*
+2 -1
View File
@@ -116,7 +116,8 @@ extern uint16_t r_page_servo_disarmed[]; /* PX4IO_PAGE_DISARMED_PWM */
*/ */
struct sys_state_s { struct sys_state_s {
volatile uint64_t rc_channels_timestamp; volatile uint64_t rc_channels_timestamp_received;
volatile uint64_t rc_channels_timestamp_valid;
/** /**
* Last FMU receive time, in microseconds since system boot * Last FMU receive time, in microseconds since system boot