Beispiel #1
0
/**
 * @brief  This function handles the DMA end of transfer fro ADC read
 *          and processing of ADC stick data then calls the mixer.
 * @param  None
 * @retval None
 */
void DMA1_Channel1_IRQHandler(void) {

	DMA_ClearFlag(DMA1_FLAG_TC1);
	DMA_ClearITPendingBit(DMA_IT_TC);

	// update the sticks data now
	sticks_update();

	// Don't run the mixer if we're calibrating
	if (cal_state == CAL_OFF) {
		if (!g_modelInvalid) {
			// Run the mixer.
			mixer_update();
		}
	} else // if (cal_state != CAL_OFF)
	{
		cal_update();
	}
}
Beispiel #2
0
static void
mixer_tick(void *arg)
{
	uint16_t *control_values;
	int control_count;
	int i;
	bool should_arm;

	/*
	 * Start by looking for R/C control inputs.
	 * This updates system_state with any control inputs received.
	 */
	mixer_get_rc_input();

	/*
	 * Decide which set of inputs we're using.
	 */
	if (system_state.mixer_use_fmu) {
		/* we have recent control data from the FMU */
		control_count = PX4IO_OUTPUT_CHANNELS;
		control_values = &system_state.fmu_channel_data[0];

		/* check that we are receiving fresh data from the FMU */
		if (!system_state.fmu_data_received) {
			fmu_input_drops++;

			/* too many frames without FMU input, time to go to failsafe */
			if (fmu_input_drops >= FMU_INPUT_DROP_LIMIT) {
				system_state.mixer_use_fmu = false;
			}
		} else {
			fmu_input_drops = 0;
			system_state.fmu_data_received = false;
		}

	} else if (system_state.rc_channels > 0) {
		/* we have control data from an R/C input */
		control_count = system_state.rc_channels;
		control_values = &system_state.rc_channel_data[0];

	} else {
		/* we have no control input */
		control_count = 0;
	}

	/*
	 * Tickle each mixer, if we have control data.
	 */
	if (control_count > 0) {
		for (i = 0; i < PX4IO_OUTPUT_CHANNELS; i++) {
			mixer_update(i, control_values, control_count);

			/*
			 * If we are armed, update the servo output.
			 */
			if (system_state.armed)
				ioctl(mixer_servo_fd, PWM_SERVO_SET(i), mixers[i].current_value);
		}

	}

	/*
	 * Decide whether the servos should be armed right now.
	 */
	should_arm = system_state.armed && (control_count > 0);
	if (should_arm && !mixer_servos_armed) {
		/* need to arm, but not armed */
		ioctl(mixer_servo_fd, PWM_SERVO_ARM, 0);
		mixer_servos_armed = true;

	} else if (!should_arm && mixer_servos_armed) {
		/* armed but need to disarm*/
		ioctl(mixer_servo_fd, PWM_SERVO_DISARM, 0);		
		mixer_servos_armed = false;
	}
}