2011-03-19 07:20:11 -03:00
|
|
|
/// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
2011-01-23 22:04:44 -04:00
|
|
|
|
|
|
|
#define ARM_DELAY 10
|
|
|
|
#define DISARM_DELAY 10
|
|
|
|
|
|
|
|
void arm_motors()
|
|
|
|
{
|
|
|
|
static byte arming_counter;
|
2011-03-21 04:35:54 -03:00
|
|
|
|
2011-01-23 22:04:44 -04:00
|
|
|
// Arm motor output : Throttle down and full yaw right for more than 2 seconds
|
2011-03-21 04:35:54 -03:00
|
|
|
if (g.rc_3.control_in == 0){
|
2011-04-13 13:33:06 -03:00
|
|
|
// full right
|
|
|
|
if (g.rc_4.control_in > 4000) {
|
|
|
|
if (arming_counter >= ARM_DELAY) {
|
|
|
|
motor_armed = true;
|
|
|
|
arming_counter = ARM_DELAY;
|
2011-04-15 13:45:47 -03:00
|
|
|
|
|
|
|
// Remember Orientation
|
|
|
|
// ---------------------------
|
|
|
|
init_simple_bearing();
|
|
|
|
|
2011-03-21 04:35:54 -03:00
|
|
|
} else{
|
|
|
|
arming_counter++;
|
2011-01-23 22:04:44 -04:00
|
|
|
}
|
2011-04-13 13:33:06 -03:00
|
|
|
// full left
|
|
|
|
}else if (g.rc_4.control_in < -4000) {
|
|
|
|
if (arming_counter >= DISARM_DELAY){
|
|
|
|
motor_armed = false;
|
|
|
|
arming_counter = DISARM_DELAY;
|
2011-03-21 04:35:54 -03:00
|
|
|
}else{
|
|
|
|
arming_counter++;
|
2011-02-17 05:36:33 -04:00
|
|
|
}
|
2011-04-13 13:33:06 -03:00
|
|
|
// centered
|
2011-03-21 04:35:54 -03:00
|
|
|
}else{
|
|
|
|
arming_counter = 0;
|
2011-01-23 22:04:44 -04:00
|
|
|
}
|
2011-04-13 13:33:06 -03:00
|
|
|
}else{
|
|
|
|
arming_counter = 0;
|
2011-01-23 22:04:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************
|
|
|
|
* Set the flight control servos based on the current calculated values
|
|
|
|
*****************************************/
|
2011-02-17 05:36:33 -04:00
|
|
|
void
|
2011-01-25 01:53:36 -04:00
|
|
|
set_servos_4()
|
2011-01-23 22:04:44 -04:00
|
|
|
{
|
|
|
|
static byte num;
|
2011-02-23 01:12:41 -04:00
|
|
|
int out_min;
|
2011-01-23 22:04:44 -04:00
|
|
|
|
|
|
|
// Quadcopter mix
|
2011-01-25 01:53:36 -04:00
|
|
|
if (motor_armed == true && motor_auto_safe == true) {
|
2011-02-23 01:12:41 -04:00
|
|
|
out_min = g.rc_3.radio_min;
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-01-23 22:04:44 -04:00
|
|
|
// Throttle is 0 to 1000 only
|
2011-02-17 05:36:33 -04:00
|
|
|
g.rc_3.servo_out = constrain(g.rc_3.servo_out, 0, 1000);
|
2011-01-23 22:04:44 -04:00
|
|
|
|
2011-02-17 03:09:13 -04:00
|
|
|
if(g.rc_3.servo_out > 0)
|
2011-04-17 02:17:42 -03:00
|
|
|
out_min = g.rc_3.radio_min + 90;
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-02-17 03:09:13 -04:00
|
|
|
//Serial.printf("out: %d %d %d %d\t\t", g.rc_1.servo_out, g.rc_2.servo_out, g.rc_3.servo_out, g.rc_4.servo_out);
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-01-23 22:04:44 -04:00
|
|
|
// creates the radio_out and pwm_out values
|
2011-02-17 03:09:13 -04:00
|
|
|
g.rc_1.calc_pwm();
|
|
|
|
g.rc_2.calc_pwm();
|
|
|
|
g.rc_3.calc_pwm();
|
|
|
|
g.rc_4.calc_pwm();
|
2011-01-23 22:04:44 -04:00
|
|
|
|
2011-04-14 02:56:39 -03:00
|
|
|
// limit Yaw control so we don't clip and loose altitude
|
|
|
|
// this is only a partial solution.
|
2011-04-17 02:17:42 -03:00
|
|
|
|
|
|
|
// g.rc_4.pwm_out = min(g.rc_4.pwm_out, (g.rc_3.radio_out - out_min));
|
2011-04-14 02:56:39 -03:00
|
|
|
|
2011-02-17 03:09:13 -04:00
|
|
|
//Serial.printf("out: %d %d %d %d\n", g.rc_1.radio_out, g.rc_2.radio_out, g.rc_3.radio_out, g.rc_4.radio_out);
|
|
|
|
//Serial.printf("yaw: %d ", g.rc_4.radio_out);
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-02-17 03:27:57 -04:00
|
|
|
if(g.frame_type == PLUS_FRAME){
|
2011-02-21 00:30:56 -04:00
|
|
|
//Serial.println("P_FRAME");
|
2011-02-17 03:09:13 -04:00
|
|
|
motor_out[CH_1] = g.rc_3.radio_out - g.rc_1.pwm_out;
|
|
|
|
motor_out[CH_2] = g.rc_3.radio_out + g.rc_1.pwm_out;
|
|
|
|
motor_out[CH_3] = g.rc_3.radio_out + g.rc_2.pwm_out;
|
|
|
|
motor_out[CH_4] = g.rc_3.radio_out - g.rc_2.pwm_out;
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-03-15 02:55:51 -03:00
|
|
|
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-02-17 05:36:33 -04:00
|
|
|
|
2011-02-17 03:27:57 -04:00
|
|
|
}else if(g.frame_type == X_FRAME){
|
2011-02-21 00:30:56 -04:00
|
|
|
//Serial.println("X_FRAME");
|
2011-02-25 01:33:39 -04:00
|
|
|
int roll_out = g.rc_1.pwm_out * .707;
|
|
|
|
int pitch_out = g.rc_2.pwm_out * .707;
|
2011-01-23 22:04:44 -04:00
|
|
|
|
2011-02-17 03:09:13 -04:00
|
|
|
motor_out[CH_3] = g.rc_3.radio_out + roll_out + pitch_out;
|
|
|
|
motor_out[CH_2] = g.rc_3.radio_out + roll_out - pitch_out;
|
2011-01-23 22:04:44 -04:00
|
|
|
|
2011-02-17 03:09:13 -04:00
|
|
|
motor_out[CH_1] = g.rc_3.radio_out - roll_out + pitch_out;
|
|
|
|
motor_out[CH_4] = g.rc_3.radio_out - roll_out - pitch_out;
|
2011-02-17 05:36:33 -04:00
|
|
|
|
|
|
|
//Serial.printf("\tb4: %d %d %d %d ", motor_out[CH_1], motor_out[CH_2], motor_out[CH_3], motor_out[CH_4]);
|
|
|
|
|
2011-02-17 03:09:13 -04:00
|
|
|
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-02-17 05:36:33 -04:00
|
|
|
|
2011-02-05 02:14:44 -04:00
|
|
|
//Serial.printf("\tl8r: %d %d %d %d\n", motor_out[CH_1], motor_out[CH_2], motor_out[CH_3], motor_out[CH_4]);
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-02-17 03:27:57 -04:00
|
|
|
}else if(g.frame_type == TRI_FRAME){
|
2011-01-23 22:04:44 -04:00
|
|
|
|
2011-02-21 00:30:56 -04:00
|
|
|
//Serial.println("TRI_FRAME");
|
2011-01-23 22:04:44 -04:00
|
|
|
// Tri-copter power distribution
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-02-17 03:09:13 -04:00
|
|
|
int roll_out = (float)g.rc_1.pwm_out * .866;
|
|
|
|
int pitch_out = g.rc_2.pwm_out / 2;
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-03-19 16:21:43 -03:00
|
|
|
//left front
|
2011-02-17 03:09:13 -04:00
|
|
|
motor_out[CH_2] = g.rc_3.radio_out + roll_out + pitch_out;
|
2011-03-19 16:21:43 -03:00
|
|
|
|
|
|
|
//right front
|
2011-02-17 03:09:13 -04:00
|
|
|
motor_out[CH_1] = g.rc_3.radio_out - roll_out + pitch_out;
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-03-19 16:21:43 -03:00
|
|
|
// rear
|
2011-02-17 03:09:13 -04:00
|
|
|
motor_out[CH_4] = g.rc_3.radio_out - g.rc_2.pwm_out;
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-02-21 16:58:10 -04:00
|
|
|
// this is a compensation for the angle of the yaw motor. Its linear, but should work ok.
|
2011-05-07 17:26:43 -03:00
|
|
|
//motor_out[CH_4] += (float)(abs(g.rc_4.control_in)) * .013;
|
2011-02-21 16:58:10 -04:00
|
|
|
|
2011-01-23 22:04:44 -04:00
|
|
|
// servo Yaw
|
2011-02-17 03:09:13 -04:00
|
|
|
APM_RC.OutputCh(CH_7, g.rc_4.radio_out);
|
2011-01-23 22:04:44 -04:00
|
|
|
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-04-11 22:58:46 -03:00
|
|
|
}else if (g.frame_type == HEXAX_FRAME) {
|
2011-02-21 00:30:56 -04:00
|
|
|
//Serial.println("6_FRAME");
|
2011-01-23 22:04:44 -04:00
|
|
|
|
2011-02-17 03:09:13 -04:00
|
|
|
int roll_out = (float)g.rc_1.pwm_out * .866;
|
|
|
|
int pitch_out = g.rc_2.pwm_out / 2;
|
2011-01-25 01:53:36 -04:00
|
|
|
|
2011-02-17 05:36:33 -04:00
|
|
|
//left side
|
2011-02-23 01:12:41 -04:00
|
|
|
motor_out[CH_2] = g.rc_3.radio_out + g.rc_1.pwm_out; // CCW
|
|
|
|
motor_out[CH_3] = g.rc_3.radio_out + roll_out + pitch_out; // CW
|
2011-03-15 02:55:51 -03:00
|
|
|
motor_out[CH_8] = g.rc_3.radio_out + roll_out - pitch_out; // CW
|
2011-02-05 02:14:44 -04:00
|
|
|
|
2011-02-17 05:36:33 -04:00
|
|
|
//right side
|
2011-02-23 01:12:41 -04:00
|
|
|
motor_out[CH_1] = g.rc_3.radio_out - g.rc_1.pwm_out; // CW
|
2011-03-15 02:55:51 -03:00
|
|
|
motor_out[CH_7] = g.rc_3.radio_out - roll_out + pitch_out; // CCW
|
2011-02-23 01:12:41 -04:00
|
|
|
motor_out[CH_4] = g.rc_3.radio_out - roll_out - pitch_out; // CCW
|
2011-02-05 02:14:44 -04:00
|
|
|
|
2011-03-19 16:21:43 -03:00
|
|
|
motor_out[CH_2] += g.rc_4.pwm_out; // CCW
|
2011-02-23 01:12:41 -04:00
|
|
|
motor_out[CH_7] += g.rc_4.pwm_out; // CCW
|
2011-03-19 16:21:43 -03:00
|
|
|
motor_out[CH_4] += g.rc_4.pwm_out; // CCW
|
|
|
|
|
|
|
|
motor_out[CH_3] -= g.rc_4.pwm_out; // CW
|
|
|
|
motor_out[CH_1] -= g.rc_4.pwm_out; // CW
|
|
|
|
motor_out[CH_8] -= g.rc_4.pwm_out; // CW
|
|
|
|
|
|
|
|
}else if (g.frame_type == Y6_FRAME) {
|
|
|
|
//Serial.println("Y6_FRAME");
|
|
|
|
|
|
|
|
int roll_out = (float)g.rc_1.pwm_out * .866;
|
|
|
|
int pitch_out = g.rc_2.pwm_out / 2;
|
|
|
|
|
|
|
|
//left
|
2011-04-17 20:12:27 -03:00
|
|
|
motor_out[CH_2] = ((g.rc_3.radio_out * Y6_scaling) + roll_out + pitch_out); // CCW TOP
|
2011-03-19 16:21:43 -03:00
|
|
|
motor_out[CH_3] = g.rc_3.radio_out + roll_out + pitch_out; // CW
|
|
|
|
|
|
|
|
//right
|
2011-04-17 20:12:27 -03:00
|
|
|
motor_out[CH_7] = ((g.rc_3.radio_out * Y6_scaling) - roll_out + pitch_out); // CCW TOP
|
2011-03-19 16:21:43 -03:00
|
|
|
motor_out[CH_1] = g.rc_3.radio_out - roll_out + pitch_out; // CW
|
|
|
|
|
|
|
|
//back
|
2011-04-17 20:12:27 -03:00
|
|
|
motor_out[CH_8] = ((g.rc_3.radio_out * Y6_scaling) - g.rc_2.pwm_out); // CCW TOP
|
2011-04-01 11:45:35 -03:00
|
|
|
motor_out[CH_4] = g.rc_3.radio_out - g.rc_2.pwm_out; // CW
|
2011-03-19 16:21:43 -03:00
|
|
|
|
|
|
|
//yaw
|
2011-02-17 03:09:13 -04:00
|
|
|
motor_out[CH_2] += g.rc_4.pwm_out; // CCW
|
2011-03-19 16:21:43 -03:00
|
|
|
motor_out[CH_7] += g.rc_4.pwm_out; // CCW
|
2011-04-01 11:45:35 -03:00
|
|
|
motor_out[CH_8] += g.rc_4.pwm_out; // CCW
|
2011-02-05 02:14:44 -04:00
|
|
|
|
2011-02-17 03:09:13 -04:00
|
|
|
motor_out[CH_3] -= g.rc_4.pwm_out; // CW
|
|
|
|
motor_out[CH_1] -= g.rc_4.pwm_out; // CW
|
2011-04-01 11:45:35 -03:00
|
|
|
motor_out[CH_4] -= g.rc_4.pwm_out; // CW
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-03-15 02:55:51 -03:00
|
|
|
}else{
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-03-23 22:36:52 -03:00
|
|
|
//Serial.print("frame error");
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-01-23 22:04:44 -04:00
|
|
|
}
|
2011-02-17 05:36:33 -04:00
|
|
|
|
|
|
|
|
2011-02-05 02:31:03 -04:00
|
|
|
// limit output so motors don't stop
|
2011-02-17 03:25:31 -04:00
|
|
|
motor_out[CH_1] = constrain(motor_out[CH_1], out_min, g.rc_3.radio_max.get());
|
|
|
|
motor_out[CH_2] = constrain(motor_out[CH_2], out_min, g.rc_3.radio_max.get());
|
|
|
|
motor_out[CH_3] = constrain(motor_out[CH_3], out_min, g.rc_3.radio_max.get());
|
|
|
|
motor_out[CH_4] = constrain(motor_out[CH_4], out_min, g.rc_3.radio_max.get());
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-04-11 22:58:46 -03:00
|
|
|
if ((g.frame_type == HEXAX_FRAME) || (g.frame_type == Y6_FRAME)) {
|
2011-02-17 03:25:31 -04:00
|
|
|
motor_out[CH_7] = constrain(motor_out[CH_7], out_min, g.rc_3.radio_max.get());
|
|
|
|
motor_out[CH_8] = constrain(motor_out[CH_8], out_min, g.rc_3.radio_max.get());
|
2011-02-05 02:14:44 -04:00
|
|
|
}
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-04-17 20:08:16 -03:00
|
|
|
if (num++ > 25){
|
2011-01-23 22:04:44 -04:00
|
|
|
num = 0;
|
2011-04-17 02:17:42 -03:00
|
|
|
|
2011-01-23 22:04:44 -04:00
|
|
|
//Serial.print("kP: ");
|
2011-02-17 03:09:13 -04:00
|
|
|
//Serial.println(g.pid_stabilize_roll.kP(),3);
|
2011-02-06 03:03:28 -04:00
|
|
|
//*/
|
2011-01-23 22:04:44 -04:00
|
|
|
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-04-17 02:17:42 -03:00
|
|
|
/*
|
|
|
|
Serial.printf("yaw: %d, lat_e: %ld, lng_e: %ld, \tnlat: %ld, nlng: %ld,\tnrll: %ld, nptc: %ld, \tcx: %.2f, sy: %.2f, \ttber: %ld, \tnber: %ld\n",
|
|
|
|
(int)(dcm.yaw_sensor / 100),
|
|
|
|
lat_error,
|
|
|
|
long_error,
|
|
|
|
nav_lat,
|
|
|
|
nav_lon,
|
|
|
|
nav_roll,
|
|
|
|
nav_pitch,
|
|
|
|
cos_yaw_x,
|
|
|
|
sin_yaw_y,
|
|
|
|
target_bearing,
|
|
|
|
nav_bearing);
|
|
|
|
//*/
|
|
|
|
|
2011-03-15 02:55:51 -03:00
|
|
|
/*
|
2011-04-10 20:07:24 -03:00
|
|
|
|
2011-04-13 13:33:06 -03:00
|
|
|
gcs_simple.write_byte(control_mode);
|
2011-04-17 02:17:42 -03:00
|
|
|
//gcs_simple.write_int(motor_out[CH_1]);
|
|
|
|
//gcs_simple.write_int(motor_out[CH_2]);
|
|
|
|
//gcs_simple.write_int(motor_out[CH_3]);
|
|
|
|
//gcs_simple.write_int(motor_out[CH_4]);
|
|
|
|
|
2011-04-13 13:33:06 -03:00
|
|
|
gcs_simple.write_int(g.rc_3.servo_out);
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-04-17 02:17:42 -03:00
|
|
|
gcs_simple.write_int((int)(dcm.yaw_sensor / 100));
|
|
|
|
|
2011-03-23 22:36:52 -03:00
|
|
|
gcs_simple.write_int((int)nav_lat);
|
|
|
|
gcs_simple.write_int((int)nav_lon);
|
|
|
|
gcs_simple.write_int((int)nav_roll);
|
|
|
|
gcs_simple.write_int((int)nav_pitch);
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-04-17 02:17:42 -03:00
|
|
|
//gcs_simple.write_int((int)(cos_yaw_x * 100));
|
|
|
|
//gcs_simple.write_int((int)(sin_yaw_y * 100));
|
|
|
|
|
2011-03-23 22:36:52 -03:00
|
|
|
gcs_simple.write_long(current_loc.lat); //28
|
|
|
|
gcs_simple.write_long(current_loc.lng); //32
|
|
|
|
gcs_simple.write_int((int)current_loc.alt); //34
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-03-23 22:36:52 -03:00
|
|
|
gcs_simple.write_long(next_WP.lat);
|
|
|
|
gcs_simple.write_long(next_WP.lng);
|
|
|
|
gcs_simple.write_int((int)next_WP.alt); //44
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-04-17 02:17:42 -03:00
|
|
|
gcs_simple.write_int((int)(target_bearing / 100));
|
|
|
|
gcs_simple.write_int((int)(nav_bearing / 100));
|
|
|
|
gcs_simple.write_int((int)(nav_yaw / 100));
|
2011-04-13 13:33:06 -03:00
|
|
|
|
|
|
|
if(altitude_sensor == BARO){
|
|
|
|
gcs_simple.write_int((int)g.pid_baro_throttle.get_integrator());
|
|
|
|
}else{
|
|
|
|
gcs_simple.write_int((int)g.pid_sonar_throttle.get_integrator());
|
|
|
|
}
|
|
|
|
|
|
|
|
gcs_simple.write_int(g.throttle_cruise);
|
2011-04-17 02:17:42 -03:00
|
|
|
gcs_simple.write_int(g.throttle_cruise);
|
2011-04-13 13:33:06 -03:00
|
|
|
|
|
|
|
//24
|
2011-03-23 22:36:52 -03:00
|
|
|
gcs_simple.flush(10); // Message ID
|
2011-04-17 02:17:42 -03:00
|
|
|
|
2011-02-06 03:03:28 -04:00
|
|
|
//*/
|
2011-04-17 02:17:42 -03:00
|
|
|
//Serial.printf("\n tb %d\n", (int)(target_bearing / 100));
|
|
|
|
//Serial.printf("\n nb %d\n", (int)(nav_bearing / 100));
|
|
|
|
//Serial.printf("\n dcm %d\n", (int)(dcm.yaw_sensor / 100));
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-02-13 18:32:34 -04:00
|
|
|
/*Serial.printf("a %ld, e %ld, i %d, t %d, b %4.2f\n",
|
|
|
|
current_loc.alt,
|
|
|
|
altitude_error,
|
2011-02-17 03:09:13 -04:00
|
|
|
(int)g.pid_baro_throttle.get_integrator(),
|
2011-02-13 18:32:34 -04:00
|
|
|
nav_throttle,
|
|
|
|
angle_boost());
|
|
|
|
*/
|
2011-01-23 22:04:44 -04:00
|
|
|
}
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-01-23 22:04:44 -04:00
|
|
|
// Send commands to motors
|
2011-02-17 03:09:13 -04:00
|
|
|
if(g.rc_3.servo_out > 0){
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-02-05 02:14:44 -04: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-01-23 22:04:44 -04:00
|
|
|
// InstantPWM
|
|
|
|
APM_RC.Force_Out0_Out1();
|
|
|
|
APM_RC.Force_Out2_Out3();
|
|
|
|
|
2011-04-11 22:58:46 -03:00
|
|
|
if ((g.frame_type == HEXAX_FRAME) || (g.frame_type == Y6_FRAME)) {
|
2011-02-05 02:14:44 -04:00
|
|
|
APM_RC.OutputCh(CH_7, motor_out[CH_7]);
|
|
|
|
APM_RC.OutputCh(CH_8, motor_out[CH_8]);
|
2011-01-23 22:04:44 -04:00
|
|
|
APM_RC.Force_Out6_Out7();
|
|
|
|
}
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-01-23 22:04:44 -04:00
|
|
|
}else{
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-02-17 03:09:13 -04:00
|
|
|
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-01-23 22:04:44 -04:00
|
|
|
// InstantPWM
|
|
|
|
APM_RC.Force_Out0_Out1();
|
|
|
|
APM_RC.Force_Out2_Out3();
|
|
|
|
|
2011-04-11 22:58:46 -03:00
|
|
|
if ((g.frame_type == HEXAX_FRAME) || (g.frame_type == Y6_FRAME)) {
|
2011-02-17 03:09:13 -04:00
|
|
|
APM_RC.OutputCh(CH_7, g.rc_3.radio_min);
|
|
|
|
APM_RC.OutputCh(CH_8, g.rc_3.radio_min);
|
2011-01-23 22:04:44 -04:00
|
|
|
APM_RC.Force_Out6_Out7();
|
|
|
|
}
|
|
|
|
}
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-01-23 22:04:44 -04:00
|
|
|
}else{
|
2011-02-05 02:31:03 -04:00
|
|
|
// our motor is unarmed, we're on the ground
|
2011-04-25 02:12:59 -03:00
|
|
|
//reset_I();
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-02-17 03:09:13 -04:00
|
|
|
if(g.rc_3.control_in > 0){
|
2011-01-25 01:53:36 -04:00
|
|
|
// we have pushed up the throttle
|
|
|
|
// remove safety
|
|
|
|
motor_auto_safe = true;
|
|
|
|
}
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-03-06 05:35:50 -04:00
|
|
|
// fill the motor_out[] array for HIL use
|
2011-03-11 17:37:37 -04:00
|
|
|
for (unsigned char i = 0; i < 8; i++) {
|
|
|
|
motor_out[i] = g.rc_3.radio_min;
|
2011-03-06 05:35:50 -04:00
|
|
|
}
|
|
|
|
|
2011-03-11 17:37:37 -04:00
|
|
|
// Send commands to motors
|
|
|
|
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-04-11 22:58:46 -03:00
|
|
|
if ((g.frame_type == HEXAX_FRAME) || (g.frame_type == Y6_FRAME)){
|
2011-03-11 17:37:37 -04:00
|
|
|
APM_RC.OutputCh(CH_7, motor_out[CH_7]);
|
|
|
|
APM_RC.OutputCh(CH_8, motor_out[CH_8]);
|
2011-01-23 22:04:44 -04:00
|
|
|
}
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-01-23 22:04:44 -04:00
|
|
|
// reset I terms of PID controls
|
2011-04-25 02:12:59 -03:00
|
|
|
//reset_I();
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-01-23 22:04:44 -04:00
|
|
|
// Initialize yaw command to actual yaw when throttle is down...
|
2011-02-18 23:59:58 -04:00
|
|
|
g.rc_4.control_in = ToDeg(dcm.yaw);
|
2011-01-23 22:04:44 -04:00
|
|
|
}
|
|
|
|
}
|
2011-03-02 22:32:50 -04:00
|
|
|
|