2011-05-14 23:02:09 -03:00
|
|
|
/// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
2012-01-26 02:32:28 -04:00
|
|
|
#if FRAME_CONFIG == HEXA_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
|
2012-01-01 16:50:36 -04:00
|
|
|
APM_RC.SetFastOutputChannels( _BV(MOT_1) | _BV(MOT_2) | _BV(MOT_3) | _BV(MOT_4)
|
|
|
|
| _BV(MOT_5) | _BV(MOT_6) );
|
2011-10-12 02:20:23 -03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-01-17 15:47:27 -04:00
|
|
|
static void motors_output_enable()
|
|
|
|
{
|
|
|
|
APM_RC.enable_out(MOT_1);
|
|
|
|
APM_RC.enable_out(MOT_2);
|
|
|
|
APM_RC.enable_out(MOT_3);
|
|
|
|
APM_RC.enable_out(MOT_4);
|
|
|
|
APM_RC.enable_out(MOT_5);
|
|
|
|
APM_RC.enable_out(MOT_6);
|
|
|
|
}
|
|
|
|
|
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
|
2011-12-29 02:37:44 -04:00
|
|
|
g.rc_3.servo_out = constrain(g.rc_3.servo_out, 0, MAXIMUM_THROTTLE);
|
2011-05-14 23:02:09 -03:00
|
|
|
|
|
|
|
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();
|
|
|
|
|
2012-02-01 14:10:51 -04:00
|
|
|
if(g.frame_orientation == X_FRAME){
|
2011-06-03 15:49:13 -03:00
|
|
|
roll_out = g.rc_1.pwm_out / 2;
|
|
|
|
pitch_out = (float)g.rc_2.pwm_out * .866;
|
2011-05-18 20:38:24 -03:00
|
|
|
|
2012-02-01 14:10:51 -04:00
|
|
|
//left side
|
|
|
|
motor_out[MOT_2] = g.rc_3.radio_out + g.rc_1.pwm_out; // CCW Middle
|
|
|
|
motor_out[MOT_3] = g.rc_3.radio_out + roll_out + pitch_out; // CW Front
|
|
|
|
motor_out[MOT_6] = g.rc_3.radio_out + roll_out - pitch_out; // CW Back
|
|
|
|
|
|
|
|
//right side
|
|
|
|
motor_out[MOT_1] = g.rc_3.radio_out - g.rc_1.pwm_out; // CW Middle
|
|
|
|
motor_out[MOT_5] = g.rc_3.radio_out - roll_out + pitch_out; // CCW Front
|
|
|
|
motor_out[MOT_4] = g.rc_3.radio_out - roll_out - pitch_out; // CCW Back
|
2011-05-18 20:38:24 -03:00
|
|
|
|
2012-02-01 14:10:51 -04:00
|
|
|
}else{
|
2011-06-03 15:49:13 -03:00
|
|
|
roll_out = (float)g.rc_1.pwm_out * .866;
|
2011-05-18 20:38:24 -03:00
|
|
|
pitch_out = g.rc_2.pwm_out / 2;
|
|
|
|
|
2012-02-01 14:10:51 -04:00
|
|
|
//Front side
|
|
|
|
motor_out[MOT_1] = g.rc_3.radio_out + g.rc_2.pwm_out; // CW FRONT
|
|
|
|
motor_out[MOT_5] = g.rc_3.radio_out + roll_out + pitch_out; // CCW FRONT LEFT
|
|
|
|
motor_out[MOT_4] = g.rc_3.radio_out - roll_out + pitch_out; // CCW FRONT RIGHT
|
2011-05-18 20:38:24 -03:00
|
|
|
|
2012-02-01 14:10:51 -04:00
|
|
|
//Back side
|
|
|
|
motor_out[MOT_2] = g.rc_3.radio_out - g.rc_2.pwm_out; // CCW BACK
|
|
|
|
motor_out[MOT_3] = g.rc_3.radio_out + roll_out - pitch_out; // CW, BACK LEFT
|
|
|
|
motor_out[MOT_6] = g.rc_3.radio_out - roll_out - pitch_out; // CW BACK RIGHT
|
|
|
|
}
|
2011-05-14 23:02:09 -03:00
|
|
|
|
|
|
|
// Yaw
|
2012-02-01 14:10:51 -04:00
|
|
|
motor_out[MOT_2] += g.rc_4.pwm_out; // CCW
|
|
|
|
motor_out[MOT_5] += g.rc_4.pwm_out; // CCW
|
|
|
|
motor_out[MOT_4] += g.rc_4.pwm_out; // CCW
|
2011-05-14 23:02:09 -03:00
|
|
|
|
2012-02-01 14:10:51 -04:00
|
|
|
motor_out[MOT_3] -= g.rc_4.pwm_out; // CW
|
|
|
|
motor_out[MOT_1] -= g.rc_4.pwm_out; // CW
|
2012-01-01 16:50:36 -04:00
|
|
|
motor_out[MOT_6] -= g.rc_4.pwm_out; // CW
|
2011-05-14 23:02:09 -03:00
|
|
|
|
2011-08-05 13:43:16 -03:00
|
|
|
|
|
|
|
// Tridge's stability patch
|
2012-01-01 16:49:58 -04:00
|
|
|
for (int m = 0; m <= 6; m++) {
|
|
|
|
int c = ch_of_mot(m);
|
|
|
|
int c_opp = ch_of_mot(m^1); // m^1 is the opposite motor. c_opp is channel of opposite motor.
|
|
|
|
if (motor_out[c] > out_max) {
|
|
|
|
motor_out[c_opp] -= motor_out[c] - out_max;
|
|
|
|
motor_out[c] = out_max;
|
2011-08-05 13:43:16 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-27 14:58:39 -03:00
|
|
|
// limit output so motors don't stop
|
2012-01-01 16:50:36 -04:00
|
|
|
motor_out[MOT_1] = max(motor_out[MOT_1], out_min);
|
|
|
|
motor_out[MOT_2] = max(motor_out[MOT_2], out_min);
|
|
|
|
motor_out[MOT_3] = max(motor_out[MOT_3], out_min);
|
|
|
|
motor_out[MOT_4] = max(motor_out[MOT_4], out_min);
|
|
|
|
motor_out[MOT_5] = max(motor_out[MOT_5], out_min);
|
|
|
|
motor_out[MOT_6] = max(motor_out[MOT_6], out_min);
|
2011-07-16 20:08:07 -03:00
|
|
|
|
2011-06-01 02:50:17 -03:00
|
|
|
#if CUT_MOTORS == ENABLED
|
2011-08-05 13:43:16 -03:00
|
|
|
// if we are not sending a throttle output, we cut the motors
|
|
|
|
if(g.rc_3.servo_out == 0){
|
2012-01-01 16:50:36 -04:00
|
|
|
motor_out[MOT_1] = g.rc_3.radio_min;
|
|
|
|
motor_out[MOT_2] = g.rc_3.radio_min;
|
|
|
|
motor_out[MOT_3] = g.rc_3.radio_min;
|
2012-02-01 14:10:51 -04:00
|
|
|
motor_out[MOT_4] = g.rc_3.radio_min;
|
|
|
|
motor_out[MOT_5] = g.rc_3.radio_min;
|
|
|
|
motor_out[MOT_6] = g.rc_3.radio_min;
|
2011-05-14 23:02:09 -03:00
|
|
|
}
|
2011-06-01 02:50:17 -03:00
|
|
|
#endif
|
2011-08-05 13:43:16 -03:00
|
|
|
|
2011-12-23 18:29:07 -04:00
|
|
|
// this filter slows the acceleration of motors vs the deceleration
|
|
|
|
// Idea by Denny Rowland to help with his Yaw issue
|
2012-01-01 16:49:58 -04:00
|
|
|
for(int8_t m = 0; m <= 6; m++ ) {
|
|
|
|
int c = ch_of_mot(m);
|
|
|
|
if(motor_filtered[c] < motor_out[c]){
|
|
|
|
motor_filtered[c] = (motor_out[c] + motor_filtered[c]) / 2;
|
2011-12-23 18:29:07 -04:00
|
|
|
}else{
|
|
|
|
// don't filter
|
2012-01-01 16:49:58 -04:00
|
|
|
motor_filtered[c] = motor_out[c];
|
2011-12-23 18:29:07 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-01 16:50:36 -04:00
|
|
|
APM_RC.OutputCh(MOT_1, motor_filtered[MOT_1]);
|
|
|
|
APM_RC.OutputCh(MOT_2, motor_filtered[MOT_2]);
|
|
|
|
APM_RC.OutputCh(MOT_3, motor_filtered[MOT_3]);
|
|
|
|
APM_RC.OutputCh(MOT_4, motor_filtered[MOT_4]);
|
|
|
|
APM_RC.OutputCh(MOT_5, motor_filtered[MOT_5]);
|
|
|
|
APM_RC.OutputCh(MOT_6, motor_filtered[MOT_6]);
|
2011-08-05 13:43:16 -03:00
|
|
|
|
2011-10-12 02:20:23 -03:00
|
|
|
#if INSTANT_PWM == 1
|
2011-08-05 13:43:16 -03:00
|
|
|
// InstantPWM
|
|
|
|
APM_RC.Force_Out0_Out1();
|
|
|
|
APM_RC.Force_Out2_Out3();
|
2011-10-12 02:20:23 -03:00
|
|
|
APM_RC.Force_Out6_Out7();
|
|
|
|
#endif
|
|
|
|
|
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
|
2012-01-01 16:50:36 -04:00
|
|
|
APM_RC.OutputCh(MOT_1, g.rc_3.radio_min);
|
|
|
|
APM_RC.OutputCh(MOT_2, g.rc_3.radio_min);
|
|
|
|
APM_RC.OutputCh(MOT_3, g.rc_3.radio_min);
|
|
|
|
APM_RC.OutputCh(MOT_4, g.rc_3.radio_min);
|
|
|
|
APM_RC.OutputCh(MOT_5, g.rc_3.radio_min);
|
|
|
|
APM_RC.OutputCh(MOT_6, g.rc_3.radio_min);
|
2011-05-14 23:02:09 -03:00
|
|
|
}
|
|
|
|
|
2011-07-17 07:32:00 -03:00
|
|
|
static void output_motor_test()
|
2011-05-14 23:02:09 -03:00
|
|
|
{
|
2012-01-01 16:50:36 -04:00
|
|
|
motor_out[MOT_1] = g.rc_3.radio_min;
|
|
|
|
motor_out[MOT_2] = g.rc_3.radio_min;
|
|
|
|
motor_out[MOT_3] = g.rc_3.radio_min;
|
|
|
|
motor_out[MOT_4] = g.rc_3.radio_min;
|
|
|
|
motor_out[MOT_5] = g.rc_3.radio_min;
|
|
|
|
motor_out[MOT_6] = g.rc_3.radio_min;
|
2011-05-31 02:29:06 -03:00
|
|
|
|
|
|
|
|
|
|
|
if(g.frame_orientation == X_FRAME){
|
2012-02-01 14:10:51 -04:00
|
|
|
// 31
|
|
|
|
// 24
|
2011-05-31 02:29:06 -03:00
|
|
|
if(g.rc_1.control_in > 3000){ // right
|
2012-02-01 14:10:51 -04:00
|
|
|
motor_out[MOT_1] += 100;
|
2011-05-31 02:29:06 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
if(g.rc_1.control_in < -3000){ // left
|
2012-02-01 14:10:51 -04:00
|
|
|
motor_out[MOT_2] += 100;
|
2011-05-31 02:29:06 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
if(g.rc_2.control_in > 3000){ // back
|
2012-02-01 14:10:51 -04:00
|
|
|
motor_out[MOT_6] += 100;
|
2012-01-01 16:50:36 -04:00
|
|
|
motor_out[MOT_4] += 100;
|
2011-05-31 02:29:06 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
if(g.rc_2.control_in < -3000){ // front
|
2012-02-01 14:10:51 -04:00
|
|
|
motor_out[MOT_5] += 100;
|
|
|
|
motor_out[MOT_3] += 100;
|
2011-05-31 02:29:06 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
}else{
|
2012-02-01 14:10:51 -04:00
|
|
|
// 3
|
|
|
|
// 2 1
|
|
|
|
// 4
|
2011-05-31 02:29:06 -03:00
|
|
|
if(g.rc_1.control_in > 3000){ // right
|
2012-02-01 14:10:51 -04:00
|
|
|
motor_out[MOT_4] += 100;
|
2012-01-01 16:50:36 -04:00
|
|
|
motor_out[MOT_6] += 100;
|
2011-05-31 02:29:06 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
if(g.rc_1.control_in < -3000){ // left
|
2012-02-01 14:10:51 -04:00
|
|
|
motor_out[MOT_5] += 100;
|
2012-01-01 16:50:36 -04:00
|
|
|
motor_out[MOT_3] += 100;
|
2011-05-31 02:29:06 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
if(g.rc_2.control_in > 3000){ // back
|
2012-02-01 14:10:51 -04:00
|
|
|
motor_out[MOT_2] += 100;
|
2011-05-31 02:29:06 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
if(g.rc_2.control_in < -3000){ // front
|
2012-02-01 14:10:51 -04:00
|
|
|
motor_out[MOT_1] += 100;
|
2011-05-31 02:29:06 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-01-01 16:50:36 -04:00
|
|
|
APM_RC.OutputCh(MOT_1, motor_out[MOT_1]);
|
|
|
|
APM_RC.OutputCh(MOT_2, motor_out[MOT_2]);
|
|
|
|
APM_RC.OutputCh(MOT_3, motor_out[MOT_3]);
|
|
|
|
APM_RC.OutputCh(MOT_4, motor_out[MOT_4]);
|
|
|
|
APM_RC.OutputCh(MOT_5, motor_out[MOT_5]);
|
|
|
|
APM_RC.OutputCh(MOT_6, motor_out[MOT_6]);
|
2011-05-31 02:29:06 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-01-01 16:50:36 -04:00
|
|
|
APM_RC.OutputCh(MOT_2, g.rc_3.radio_min);
|
|
|
|
APM_RC.OutputCh(MOT_3, g.rc_3.radio_min + 100);
|
2011-05-14 23:02:09 -03:00
|
|
|
delay(1000);
|
|
|
|
|
2012-01-01 16:50:36 -04:00
|
|
|
APM_RC.OutputCh(MOT_3, g.rc_3.radio_min);
|
|
|
|
APM_RC.OutputCh(MOT_5, g.rc_3.radio_min + 100);
|
2011-05-14 23:02:09 -03:00
|
|
|
delay(1000);
|
|
|
|
|
2012-01-01 16:50:36 -04:00
|
|
|
APM_RC.OutputCh(MOT_5, g.rc_3.radio_min);
|
|
|
|
APM_RC.OutputCh(MOT_1, g.rc_3.radio_min + 100);
|
2011-05-14 23:02:09 -03:00
|
|
|
delay(1000);
|
|
|
|
|
2012-01-01 16:50:36 -04:00
|
|
|
APM_RC.OutputCh(MOT_1, g.rc_3.radio_min);
|
|
|
|
APM_RC.OutputCh(MOT_4, g.rc_3.radio_min + 100);
|
2011-05-14 23:02:09 -03:00
|
|
|
delay(1000);
|
|
|
|
|
2012-01-01 16:50:36 -04:00
|
|
|
APM_RC.OutputCh(MOT_4, g.rc_3.radio_min);
|
|
|
|
APM_RC.OutputCh(MOT_6, g.rc_3.radio_min + 100);
|
2011-05-14 23:02:09 -03:00
|
|
|
delay(1000);
|
|
|
|
|
2012-01-01 16:50:36 -04:00
|
|
|
APM_RC.OutputCh(MOT_6, g.rc_3.radio_min);
|
|
|
|
APM_RC.OutputCh(MOT_2, g.rc_3.radio_min + 100);
|
2011-05-14 23:02:09 -03:00
|
|
|
delay(1000);
|
|
|
|
}
|
2011-05-31 09:56:58 -03:00
|
|
|
*/
|
2011-06-01 02:50:17 -03:00
|
|
|
|
2011-07-17 07:32:00 -03:00
|
|
|
#endif
|