2011-05-23 23:23:26 -03:00
|
|
|
/// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
|
|
|
#if FRAME_CONFIG == OCTA_FRAME
|
|
|
|
|
2011-07-17 07:32:00 -03:00
|
|
|
static void output_motors_armed()
|
2011-05-23 23:23:26 -03:00
|
|
|
{
|
|
|
|
int roll_out, pitch_out;
|
|
|
|
int out_min = g.rc_3.radio_min;
|
2011-07-16 20:08:07 -03:00
|
|
|
int out_max = g.rc_3.radio_max;
|
2011-05-23 23:23:26 -03:00
|
|
|
|
|
|
|
// Throttle is 0 to 1000 only
|
|
|
|
g.rc_3.servo_out = constrain(g.rc_3.servo_out, 0, 1000);
|
|
|
|
|
|
|
|
if(g.rc_3.servo_out > 0)
|
2011-06-19 02:31:33 -03:00
|
|
|
out_min = g.rc_3.radio_min + MINIMUM_THROTTLE;
|
2011-05-23 23:23:26 -03:00
|
|
|
|
|
|
|
g.rc_1.calc_pwm();
|
|
|
|
g.rc_2.calc_pwm();
|
|
|
|
g.rc_3.calc_pwm();
|
|
|
|
g.rc_4.calc_pwm();
|
|
|
|
|
|
|
|
if(g.frame_orientation == X_FRAME){
|
|
|
|
roll_out = (float)g.rc_1.pwm_out * 0.4;
|
|
|
|
pitch_out = (float)g.rc_2.pwm_out * 0.4;
|
|
|
|
|
|
|
|
//Front side
|
|
|
|
motor_out[CH_1] = g.rc_3.radio_out + g.rc_2.pwm_out - roll_out; // CW FRONT RIGHT
|
2011-08-05 13:44:22 -03:00
|
|
|
motor_out[CH_7] = g.rc_3.radio_out + g.rc_2.pwm_out + roll_out; // CCW FRONT LEFT
|
2011-05-23 23:23:26 -03:00
|
|
|
|
2011-08-05 13:44:22 -03:00
|
|
|
//Back side
|
|
|
|
motor_out[CH_2] = g.rc_3.radio_out - g.rc_2.pwm_out + roll_out; // CW BACK LEFT
|
|
|
|
motor_out[CH_4] = g.rc_3.radio_out - g.rc_2.pwm_out - roll_out; // CCW BACK RIGHT
|
|
|
|
|
|
|
|
//Left side
|
2011-05-23 23:23:26 -03:00
|
|
|
motor_out[CH_10] = g.rc_3.radio_out + g.rc_1.pwm_out + pitch_out; // CW LEFT FRONT
|
|
|
|
motor_out[CH_8] = g.rc_3.radio_out + g.rc_1.pwm_out - pitch_out; // CCW LEFT BACK
|
|
|
|
|
2011-08-05 13:44:22 -03:00
|
|
|
//Right side
|
|
|
|
motor_out[CH_11] = g.rc_3.radio_out - g.rc_1.pwm_out - pitch_out; // CW RIGHT BACK
|
|
|
|
motor_out[CH_3] = g.rc_3.radio_out - g.rc_1.pwm_out + pitch_out; // CCW RIGHT FRONT
|
2011-05-23 23:23:26 -03:00
|
|
|
|
2011-08-05 13:44:22 -03:00
|
|
|
}else if(g.frame_orientation == PLUS_FRAME){
|
2011-05-23 23:23:26 -03:00
|
|
|
roll_out = (float)g.rc_1.pwm_out * 0.71;
|
|
|
|
pitch_out = (float)g.rc_2.pwm_out * 0.71;
|
|
|
|
|
|
|
|
//Front side
|
|
|
|
motor_out[CH_1] = g.rc_3.radio_out + g.rc_2.pwm_out; // CW FRONT
|
2011-08-05 13:44:22 -03:00
|
|
|
motor_out[CH_3] = g.rc_3.radio_out - roll_out + pitch_out; // CCW FRONT RIGHT
|
|
|
|
motor_out[CH_7] = g.rc_3.radio_out + roll_out + pitch_out; // CCW FRONT LEFT
|
2011-05-23 23:23:26 -03:00
|
|
|
|
2011-08-05 13:44:22 -03:00
|
|
|
//Left side
|
|
|
|
motor_out[CH_10] = g.rc_3.radio_out + g.rc_1.pwm_out; // CW LEFT
|
2011-05-23 23:23:26 -03:00
|
|
|
|
2011-08-05 13:44:22 -03:00
|
|
|
//Right side
|
|
|
|
motor_out[CH_11] = g.rc_3.radio_out - g.rc_1.pwm_out; // CW RIGHT
|
2011-06-01 02:50:17 -03:00
|
|
|
|
2011-05-23 23:23:26 -03:00
|
|
|
//Back side
|
2011-08-05 13:44:22 -03:00
|
|
|
motor_out[CH_2] = g.rc_3.radio_out - g.rc_2.pwm_out; // CW BACK
|
2011-05-23 23:23:26 -03:00
|
|
|
motor_out[CH_4] = g.rc_3.radio_out - roll_out - pitch_out; // CCW BACK RIGHT
|
|
|
|
motor_out[CH_8] = g.rc_3.radio_out + roll_out - pitch_out; // CCW BACK LEFT
|
2011-06-24 01:37:54 -03:00
|
|
|
|
2011-08-05 13:44:22 -03:00
|
|
|
}else if(g.frame_orientation == V_FRAME){
|
2011-06-24 01:37:54 -03:00
|
|
|
|
|
|
|
int roll_out2, pitch_out2;
|
|
|
|
int roll_out3, pitch_out3;
|
|
|
|
int roll_out4, pitch_out4;
|
|
|
|
|
|
|
|
roll_out = g.rc_1.pwm_out;
|
|
|
|
pitch_out = g.rc_2.pwm_out;
|
|
|
|
roll_out2 = (float)g.rc_1.pwm_out * 0.833;
|
|
|
|
pitch_out2 = (float)g.rc_2.pwm_out * 0.34;
|
|
|
|
roll_out3 = (float)g.rc_1.pwm_out * 0.666;
|
|
|
|
pitch_out3 = (float)g.rc_2.pwm_out * 0.32;
|
2011-08-05 13:44:22 -03:00
|
|
|
roll_out4 = g.rc_1.pwm_out / 2;
|
2011-06-24 01:37:54 -03:00
|
|
|
pitch_out4 = (float)g.rc_2.pwm_out * 0.98;
|
|
|
|
|
|
|
|
//Front side
|
2011-08-05 13:44:22 -03:00
|
|
|
motor_out[CH_10] = g.rc_3.radio_out + g.rc_2.pwm_out - roll_out; // CW FRONT RIGHT
|
|
|
|
motor_out[CH_7] = g.rc_3.radio_out + g.rc_2.pwm_out + roll_out; // CCW FRONT LEFT
|
2011-06-24 01:37:54 -03:00
|
|
|
|
|
|
|
//Left side
|
2011-08-05 13:44:22 -03:00
|
|
|
motor_out[CH_1] = g.rc_3.radio_out + g.rc_1.pwm_out + pitch_out2; // CW LEFT FRONT
|
|
|
|
motor_out[CH_3] = g.rc_3.radio_out + g.rc_1.pwm_out - pitch_out3; // CCW LEFT BACK
|
2011-06-24 01:37:54 -03:00
|
|
|
|
|
|
|
//Right side
|
2011-08-05 13:44:22 -03:00
|
|
|
motor_out[CH_2] = g.rc_3.radio_out - g.rc_1.pwm_out - pitch_out3; // CW RIGHT BACK
|
|
|
|
motor_out[CH_8] = g.rc_3.radio_out - g.rc_1.pwm_out + pitch_out2; // CCW RIGHT FRONT
|
2011-06-24 01:37:54 -03:00
|
|
|
|
|
|
|
//Back side
|
2011-08-05 13:44:22 -03:00
|
|
|
motor_out[CH_11] = g.rc_3.radio_out - g.rc_2.pwm_out + roll_out4; // CW BACK LEFT
|
2011-06-24 01:37:54 -03:00
|
|
|
motor_out[CH_4] = g.rc_3.radio_out - g.rc_2.pwm_out - roll_out4; // CCW BACK RIGHT
|
|
|
|
|
2011-05-23 23:23:26 -03:00
|
|
|
}
|
2011-06-01 02:50:17 -03:00
|
|
|
|
2011-05-23 23:23:26 -03:00
|
|
|
// Yaw
|
2011-08-05 13:44:22 -03:00
|
|
|
motor_out[CH_3] += g.rc_4.pwm_out; // CCW
|
2011-05-23 23:23:26 -03:00
|
|
|
motor_out[CH_4] += g.rc_4.pwm_out; // CCW
|
2011-08-05 13:44:22 -03:00
|
|
|
motor_out[CH_7] += g.rc_4.pwm_out; // CCW
|
2011-05-23 23:23:26 -03:00
|
|
|
motor_out[CH_8] += g.rc_4.pwm_out; // CCW
|
|
|
|
|
|
|
|
motor_out[CH_1] -= g.rc_4.pwm_out; // CW
|
2011-08-05 13:44:22 -03:00
|
|
|
motor_out[CH_2] -= g.rc_4.pwm_out; // CW
|
|
|
|
motor_out[CH_10] -= g.rc_4.pwm_out; // CW
|
|
|
|
motor_out[CH_11] -= g.rc_4.pwm_out; // CW
|
2011-05-23 23:23:26 -03:00
|
|
|
|
|
|
|
|
2011-08-05 13:44:22 -03:00
|
|
|
// TODO add stability patch
|
2011-07-16 20:08:07 -03:00
|
|
|
motor_out[CH_1] = min(motor_out[CH_1], out_max);
|
|
|
|
motor_out[CH_2] = min(motor_out[CH_2], out_max);
|
|
|
|
motor_out[CH_3] = min(motor_out[CH_3], out_max);
|
|
|
|
motor_out[CH_4] = min(motor_out[CH_4], out_max);
|
|
|
|
motor_out[CH_7] = min(motor_out[CH_7], out_max);
|
|
|
|
motor_out[CH_8] = min(motor_out[CH_8], out_max);
|
|
|
|
motor_out[CH_10] = min(motor_out[CH_10], out_max);
|
|
|
|
motor_out[CH_11] = min(motor_out[CH_11], out_max);
|
|
|
|
|
|
|
|
|
2011-08-05 13:44:22 -03:00
|
|
|
// limit output so motors don't stop
|
|
|
|
motor_out[CH_1] = max(motor_out[CH_1], out_min);
|
|
|
|
motor_out[CH_2] = max(motor_out[CH_2], out_min);
|
|
|
|
motor_out[CH_3] = max(motor_out[CH_3], out_min);
|
|
|
|
motor_out[CH_4] = max(motor_out[CH_4], out_min);
|
|
|
|
motor_out[CH_7] = max(motor_out[CH_7], out_min);
|
|
|
|
motor_out[CH_8] = max(motor_out[CH_8], out_min);
|
|
|
|
motor_out[CH_10] = max(motor_out[CH_10], out_min);
|
|
|
|
motor_out[CH_11] = max(motor_out[CH_11], out_min);
|
|
|
|
|
|
|
|
|
2011-06-01 02:50:17 -03:00
|
|
|
#if CUT_MOTORS == ENABLED
|
2011-08-05 13:44:22 -03:00
|
|
|
// if we are not sending a throttle output, we cut the motors
|
|
|
|
if(g.rc_3.servo_out == 0){
|
|
|
|
motor_out[CH_1] = g.rc_3.radio_min;
|
|
|
|
motor_out[CH_2] = g.rc_3.radio_min;
|
|
|
|
motor_out[CH_3] = g.rc_3.radio_min;
|
|
|
|
motor_out[CH_4] = g.rc_3.radio_min;
|
|
|
|
motor_out[CH_7] = g.rc_3.radio_min;
|
|
|
|
motor_out[CH_8] = g.rc_3.radio_min;
|
|
|
|
motor_out[CH_10] = g.rc_3.radio_min;
|
|
|
|
motor_out[CH_11] = g.rc_3.radio_min;
|
|
|
|
}
|
2011-06-01 02:50:17 -03:00
|
|
|
#endif
|
2011-08-05 13:44:22 -03:00
|
|
|
|
|
|
|
APM_RC.OutputCh(CH_1, motor_out[CH_1]);
|
|
|
|
APM_RC.OutputCh(CH_2, motor_out[CH_2]);
|
|
|
|
APM_RC.OutputCh(CH_3, motor_out[CH_3]);
|
|
|
|
APM_RC.OutputCh(CH_4, motor_out[CH_4]);
|
|
|
|
APM_RC.OutputCh(CH_7, motor_out[CH_7]);
|
|
|
|
APM_RC.OutputCh(CH_8, motor_out[CH_8]);
|
|
|
|
APM_RC.OutputCh(CH_10, motor_out[CH_10]);
|
|
|
|
APM_RC.OutputCh(CH_11, motor_out[CH_11]);
|
|
|
|
|
|
|
|
// InstantPWM
|
|
|
|
APM_RC.Force_Out0_Out1();
|
|
|
|
APM_RC.Force_Out6_Out7();
|
|
|
|
APM_RC.Force_Out2_Out3();
|
2011-05-23 23:23:26 -03:00
|
|
|
}
|
|
|
|
|
2011-07-17 07:32:00 -03:00
|
|
|
static void output_motors_disarmed()
|
2011-05-23 23:23:26 -03:00
|
|
|
{
|
|
|
|
if(g.rc_3.control_in > 0){
|
|
|
|
// we have pushed up the throttle
|
|
|
|
// remove safety
|
|
|
|
motor_auto_armed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// fill the motor_out[] array for HIL use
|
|
|
|
for (unsigned char i = 0; i < 11; i++) {
|
|
|
|
motor_out[i] = g.rc_3.radio_min;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Send commands to motors
|
|
|
|
APM_RC.OutputCh(CH_1, g.rc_3.radio_min);
|
|
|
|
APM_RC.OutputCh(CH_2, g.rc_3.radio_min);
|
|
|
|
APM_RC.OutputCh(CH_7, g.rc_3.radio_min);
|
|
|
|
APM_RC.OutputCh(CH_8, g.rc_3.radio_min);
|
|
|
|
APM_RC.OutputCh(CH_11, g.rc_3.radio_min);
|
2011-08-05 13:44:22 -03:00
|
|
|
|
|
|
|
APM_RC.OutputCh(CH_3, g.rc_3.radio_min);
|
|
|
|
APM_RC.OutputCh(CH_4, g.rc_3.radio_min);
|
|
|
|
APM_RC.OutputCh(CH_10, g.rc_3.radio_min);
|
2011-05-23 23:23:26 -03:00
|
|
|
}
|
|
|
|
|
2011-07-17 07:32:00 -03:00
|
|
|
static void output_motor_test()
|
2011-05-23 23:23:26 -03:00
|
|
|
{
|
2011-08-05 13:44:22 -03:00
|
|
|
APM_RC.OutputCh(CH_7, g.rc_3.radio_min);
|
2011-09-11 18:32:04 -03:00
|
|
|
APM_RC.OutputCh(CH_1, g.rc_3.radio_min + 100);
|
2011-05-23 23:23:26 -03:00
|
|
|
delay(1000);
|
|
|
|
|
2011-08-05 13:44:22 -03:00
|
|
|
APM_RC.OutputCh(CH_1, g.rc_3.radio_min);
|
2011-09-11 18:32:04 -03:00
|
|
|
APM_RC.OutputCh(CH_3, g.rc_3.radio_min + 100);
|
2011-05-23 23:23:26 -03:00
|
|
|
delay(1000);
|
|
|
|
|
2011-08-05 13:44:22 -03:00
|
|
|
APM_RC.OutputCh(CH_3, g.rc_3.radio_min);
|
2011-09-11 18:32:04 -03:00
|
|
|
APM_RC.OutputCh(CH_11, g.rc_3.radio_min + 100);
|
2011-05-23 23:23:26 -03:00
|
|
|
delay(1000);
|
|
|
|
|
2011-08-05 13:44:22 -03:00
|
|
|
APM_RC.OutputCh(CH_11, g.rc_3.radio_min);
|
2011-09-11 18:32:04 -03:00
|
|
|
APM_RC.OutputCh(CH_4, g.rc_3.radio_min + 100);
|
2011-05-23 23:23:26 -03:00
|
|
|
delay(1000);
|
|
|
|
|
|
|
|
APM_RC.OutputCh(CH_4, g.rc_3.radio_min);
|
2011-09-11 18:32:04 -03:00
|
|
|
APM_RC.OutputCh(CH_2, g.rc_3.radio_min + 100);
|
2011-08-05 13:44:22 -03:00
|
|
|
delay(1000);
|
|
|
|
|
|
|
|
APM_RC.OutputCh(CH_2, g.rc_3.radio_min);
|
2011-09-11 18:32:04 -03:00
|
|
|
APM_RC.OutputCh(CH_8, g.rc_3.radio_min + 100);
|
2011-05-23 23:23:26 -03:00
|
|
|
delay(1000);
|
|
|
|
|
|
|
|
APM_RC.OutputCh(CH_8, g.rc_3.radio_min);
|
2011-09-11 18:32:04 -03:00
|
|
|
APM_RC.OutputCh(CH_10, g.rc_3.radio_min + 100);
|
2011-05-23 23:23:26 -03:00
|
|
|
delay(1000);
|
|
|
|
|
|
|
|
APM_RC.OutputCh(CH_10, g.rc_3.radio_min);
|
2011-09-11 18:32:04 -03:00
|
|
|
APM_RC.OutputCh(CH_7, g.rc_3.radio_min + 100);
|
2011-05-23 23:23:26 -03:00
|
|
|
delay(1000);
|
|
|
|
}
|
|
|
|
|
2011-06-01 02:50:17 -03:00
|
|
|
#endif
|
|
|
|
|