2011-05-14 23:02:09 -03:00
|
|
|
/// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
2011-05-18 20:38:24 -03:00
|
|
|
#if FRAME_CONFIG == QUAD_FRAME
|
2011-05-14 23:02:09 -03:00
|
|
|
|
2011-10-12 02:20:23 -03:00
|
|
|
static void init_motors_out()
|
|
|
|
{
|
|
|
|
#if INSTANT_PWM == 0
|
2011-11-16 00:59:06 -04:00
|
|
|
APM_RC.SetFastOutputChannels( MSK_CH_1 | MSK_CH_2 | MSK_CH_3 | MSK_CH_4 );
|
2011-10-12 02:20:23 -03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-07-17 07:32:00 -03:00
|
|
|
static void output_motors_armed()
|
2011-05-14 23:02:09 -03:00
|
|
|
{
|
2011-05-18 20:38:24 -03:00
|
|
|
int roll_out, pitch_out;
|
2011-05-14 23:02:09 -03:00
|
|
|
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-14 23:02:09 -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-14 23:02:09 -03:00
|
|
|
|
|
|
|
g.rc_1.calc_pwm();
|
|
|
|
g.rc_2.calc_pwm();
|
|
|
|
g.rc_3.calc_pwm();
|
|
|
|
g.rc_4.calc_pwm();
|
|
|
|
|
2011-05-18 20:38:24 -03:00
|
|
|
if(g.frame_orientation == X_FRAME){
|
|
|
|
roll_out = g.rc_1.pwm_out * .707;
|
|
|
|
pitch_out = g.rc_2.pwm_out * .707;
|
|
|
|
|
|
|
|
// left
|
|
|
|
motor_out[CH_3] = g.rc_3.radio_out + roll_out + pitch_out; // FRONT
|
|
|
|
motor_out[CH_2] = g.rc_3.radio_out + roll_out - pitch_out; // BACK
|
|
|
|
|
|
|
|
// right
|
|
|
|
motor_out[CH_1] = g.rc_3.radio_out - roll_out + pitch_out; // FRONT
|
|
|
|
motor_out[CH_4] = g.rc_3.radio_out - roll_out - pitch_out; // BACK
|
|
|
|
|
|
|
|
}else{
|
2011-05-30 01:24:07 -03:00
|
|
|
|
2011-05-18 20:38:24 -03:00
|
|
|
roll_out = g.rc_1.pwm_out;
|
|
|
|
pitch_out = g.rc_2.pwm_out;
|
|
|
|
|
2011-12-12 06:01:58 -04:00
|
|
|
// right motor
|
2011-05-18 20:38:24 -03:00
|
|
|
motor_out[CH_1] = g.rc_3.radio_out - roll_out;
|
2011-12-12 06:01:58 -04:00
|
|
|
// left motor
|
2011-05-18 20:38:24 -03:00
|
|
|
motor_out[CH_2] = g.rc_3.radio_out + roll_out;
|
2011-12-12 06:01:58 -04:00
|
|
|
// front motor
|
2011-05-18 20:38:24 -03:00
|
|
|
motor_out[CH_3] = g.rc_3.radio_out + pitch_out;
|
2011-12-12 06:01:58 -04:00
|
|
|
// back motor
|
2011-05-18 20:38:24 -03:00
|
|
|
motor_out[CH_4] = g.rc_3.radio_out - pitch_out;
|
|
|
|
}
|
2011-05-14 23:02:09 -03:00
|
|
|
|
|
|
|
// Yaw input
|
|
|
|
motor_out[CH_1] += g.rc_4.pwm_out; // CCW
|
|
|
|
motor_out[CH_2] += g.rc_4.pwm_out; // CCW
|
|
|
|
motor_out[CH_3] -= g.rc_4.pwm_out; // CW
|
|
|
|
motor_out[CH_4] -= g.rc_4.pwm_out; // CW
|
|
|
|
|
2011-07-19 21:33:04 -03:00
|
|
|
/* We need to clip motor output at out_max. When cipping a motors
|
|
|
|
* output we also need to compensate for the instability by
|
|
|
|
* lowering the opposite motor by the same proportion. This
|
|
|
|
* ensures that we retain control when one or more of the motors
|
|
|
|
* is at its maximum output
|
|
|
|
*/
|
|
|
|
for (int i=CH_1; i<=CH_4; i++) {
|
2011-07-22 18:25:59 -03:00
|
|
|
if (motor_out[i] > out_max) {
|
|
|
|
// note that i^1 is the opposite motor
|
|
|
|
motor_out[i^1] -= motor_out[i] - out_max;
|
2011-07-19 21:33:04 -03:00
|
|
|
motor_out[i] = out_max;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-14 23:02:09 -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);
|
|
|
|
|
2011-06-01 02:50:17 -03:00
|
|
|
#if CUT_MOTORS == ENABLED
|
2011-08-05 13:44:42 -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;
|
|
|
|
}
|
2011-06-01 02:50:17 -03:00
|
|
|
#endif
|
2011-08-05 13:44:42 -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]);
|
|
|
|
|
2011-10-12 02:20:23 -03:00
|
|
|
#if INSTANT_PWM == 1
|
2011-06-26 03:38:11 -03:00
|
|
|
// InstantPWM
|
|
|
|
APM_RC.Force_Out0_Out1();
|
|
|
|
APM_RC.Force_Out2_Out3();
|
2011-10-12 02:20:23 -03:00
|
|
|
#endif
|
2011-12-09 19:51:45 -04:00
|
|
|
|
|
|
|
//debug_motors();
|
2011-05-14 23:02:09 -03:00
|
|
|
}
|
|
|
|
|
2011-07-17 07:32:00 -03:00
|
|
|
static void output_motors_disarmed()
|
2011-05-14 23:02:09 -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 < 8; 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_3, g.rc_3.radio_min);
|
|
|
|
APM_RC.OutputCh(CH_4, g.rc_3.radio_min);
|
|
|
|
}
|
|
|
|
|
2011-08-05 13:44:42 -03:00
|
|
|
/*
|
2011-11-27 23:11:44 -04:00
|
|
|
//static void debug_motors()
|
2011-08-05 13:44:42 -03:00
|
|
|
{
|
|
|
|
Serial.printf("1:%d\t2:%d\t3:%d\t4:%d\n",
|
|
|
|
motor_out[CH_1],
|
|
|
|
motor_out[CH_2],
|
|
|
|
motor_out[CH_3],
|
|
|
|
motor_out[CH_4]);
|
|
|
|
}
|
2011-12-09 19:51:45 -04:00
|
|
|
//*/
|
2011-08-05 13:44:42 -03:00
|
|
|
|
2011-07-17 07:32:00 -03:00
|
|
|
static void output_motor_test()
|
2011-05-14 23:02:09 -03:00
|
|
|
{
|
2011-05-31 02:29:06 -03:00
|
|
|
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;
|
2011-05-14 23:02:09 -03:00
|
|
|
|
|
|
|
|
2011-05-31 02:29:06 -03:00
|
|
|
if(g.frame_orientation == X_FRAME){
|
|
|
|
// 31
|
|
|
|
// 24
|
|
|
|
if(g.rc_1.control_in > 3000){
|
2011-09-11 18:32:04 -03:00
|
|
|
motor_out[CH_1] += 100;
|
|
|
|
motor_out[CH_4] += 100;
|
2011-05-31 02:29:06 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
if(g.rc_1.control_in < -3000){
|
2011-09-11 18:32:04 -03:00
|
|
|
motor_out[CH_2] += 100;
|
|
|
|
motor_out[CH_3] += 100;
|
2011-05-31 02:29:06 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
if(g.rc_2.control_in > 3000){
|
2011-09-11 18:32:04 -03:00
|
|
|
motor_out[CH_2] += 100;
|
|
|
|
motor_out[CH_4] += 100;
|
2011-05-31 02:29:06 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
if(g.rc_2.control_in < -3000){
|
2011-09-11 18:32:04 -03:00
|
|
|
motor_out[CH_1] += 100;
|
|
|
|
motor_out[CH_3] += 100;
|
2011-05-31 02:29:06 -03:00
|
|
|
}
|
2011-05-14 23:02:09 -03:00
|
|
|
|
2011-05-31 02:29:06 -03:00
|
|
|
}else{
|
|
|
|
// 3
|
|
|
|
// 2 1
|
|
|
|
// 4
|
|
|
|
if(g.rc_1.control_in > 3000)
|
2011-09-11 18:32:04 -03:00
|
|
|
motor_out[CH_1] += 100;
|
2011-05-31 02:29:06 -03:00
|
|
|
|
|
|
|
if(g.rc_1.control_in < -3000)
|
2011-09-11 18:32:04 -03:00
|
|
|
motor_out[CH_2] += 100;
|
2011-05-31 02:29:06 -03:00
|
|
|
|
|
|
|
if(g.rc_2.control_in > 3000)
|
2011-09-11 18:32:04 -03:00
|
|
|
motor_out[CH_4] += 100;
|
2011-05-31 02:29:06 -03:00
|
|
|
|
|
|
|
if(g.rc_2.control_in < -3000)
|
2011-09-11 18:32:04 -03:00
|
|
|
motor_out[CH_3] += 100;
|
2011-05-31 02:29:06 -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]);
|
2011-05-14 23:02:09 -03:00
|
|
|
}
|
|
|
|
|
2011-07-17 07:32:00 -03:00
|
|
|
#endif
|