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;
|
|
|
|
|
|
|
|
// Arm motor output : Throttle down and full yaw right for more than 2 seconds
|
2011-02-17 05:36:33 -04:00
|
|
|
if (g.rc_3.control_in == 0){
|
2011-02-17 03:09:13 -04:00
|
|
|
if (g.rc_4.control_in > 2700) {
|
2011-01-23 22:04:44 -04:00
|
|
|
if (arming_counter > ARM_DELAY) {
|
|
|
|
motor_armed = true;
|
|
|
|
} else{
|
|
|
|
arming_counter++;
|
|
|
|
}
|
2011-02-17 03:09:13 -04:00
|
|
|
}else if (g.rc_4.control_in < -2700) {
|
2011-01-23 22:04:44 -04:00
|
|
|
if (arming_counter > DISARM_DELAY){
|
|
|
|
motor_armed = false;
|
|
|
|
}else{
|
|
|
|
arming_counter++;
|
2011-02-17 05:36:33 -04:00
|
|
|
}
|
2011-01-23 22:04:44 -04:00
|
|
|
}else{
|
|
|
|
arming_counter = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************
|
|
|
|
* 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)
|
|
|
|
out_min = g.rc_3.radio_min + 50;
|
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-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.
|
|
|
|
motor_out[CH_4] += (float)(abs(g.rc_4.control_in)) * .013;
|
|
|
|
|
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-02-17 03:27:57 -04:00
|
|
|
}else if (g.frame_type == HEXA_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
|
|
|
|
motor_out[CH_2] = (g.rc_3.radio_out + roll_out + pitch_out) * 0.95; // CCW TOP
|
|
|
|
motor_out[CH_3] = g.rc_3.radio_out + roll_out + pitch_out; // CW
|
|
|
|
|
|
|
|
//right
|
|
|
|
motor_out[CH_7] = (g.rc_3.radio_out - roll_out + pitch_out) * 0.95; // CCW TOP
|
|
|
|
motor_out[CH_1] = g.rc_3.radio_out - roll_out + pitch_out; // CW
|
|
|
|
|
|
|
|
//back
|
|
|
|
motor_out[CH_8] = (g.rc_3.radio_out - g.rc_2.pwm_out) * 0.95; // CW TOP
|
|
|
|
motor_out[CH_4] = g.rc_3.radio_out - g.rc_2.pwm_out; // CCW
|
|
|
|
|
|
|
|
//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-02-17 03:09:13 -04:00
|
|
|
motor_out[CH_4] += 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-03-19 16:21:43 -03:00
|
|
|
motor_out[CH_8] -= 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-01-23 22:04:44 -04: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-03-19 16:21:43 -03:00
|
|
|
if ((g.frame_type == HEXA_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-01-23 22:04:44 -04:00
|
|
|
num++;
|
2011-02-21 00:30:56 -04:00
|
|
|
if (num > 50){
|
2011-01-23 22:04:44 -04:00
|
|
|
num = 0;
|
2011-03-06 20:57:06 -04:00
|
|
|
/*
|
2011-02-21 00:30:56 -04:00
|
|
|
Serial.printf("t_alt:%ld, alt:%ld, thr: %d sen: ",
|
|
|
|
target_altitude,
|
|
|
|
current_loc.alt,
|
|
|
|
g.rc_3.servo_out);
|
|
|
|
|
|
|
|
if(altitude_sensor == BARO){
|
|
|
|
Serial.println("Baro");
|
|
|
|
}else{
|
|
|
|
Serial.println("Sonar");
|
|
|
|
}
|
2011-03-06 20:57:06 -04:00
|
|
|
*/
|
|
|
|
|
2011-01-26 03:14:54 -04:00
|
|
|
//Serial.print("!");
|
2011-01-23 22:04:44 -04:00
|
|
|
//debugging with Channel 6
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-02-17 03:09:13 -04:00
|
|
|
//g.pid_baro_throttle.kD((float)g.rc_6.control_in / 1000); // 0 to 1
|
|
|
|
//g.pid_baro_throttle.kP((float)g.rc_6.control_in / 4000); // 0 to .25
|
2011-02-05 02:14:44 -04:00
|
|
|
|
2011-01-23 22:04:44 -04:00
|
|
|
/*
|
2011-02-17 05:36:33 -04:00
|
|
|
// ROLL and PITCH
|
2011-01-23 22:04:44 -04:00
|
|
|
// make sure you init_pids() after changing the kP
|
2011-02-17 03:09:13 -04:00
|
|
|
g.pid_stabilize_roll.kP((float)g.rc_6.control_in / 1000);
|
2011-01-23 22:04:44 -04:00
|
|
|
init_pids();
|
|
|
|
//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
|
|
|
|
|
|
|
/*
|
|
|
|
// YAW
|
|
|
|
// make sure you init_pids() after changing the kP
|
2011-02-17 03:09:13 -04:00
|
|
|
g.pid_yaw.kP((float)g.rc_6.control_in / 1000);
|
2011-01-23 22:04:44 -04:00
|
|
|
init_pids();
|
2011-02-06 03:03:28 -04:00
|
|
|
//*/
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-03-15 02:55:51 -03:00
|
|
|
/*
|
2011-02-06 03:03:28 -04:00
|
|
|
write_int(motor_out[CH_1]);
|
|
|
|
write_int(motor_out[CH_2]);
|
|
|
|
write_int(motor_out[CH_3]);
|
|
|
|
write_int(motor_out[CH_4]);
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-02-17 03:09:13 -04:00
|
|
|
write_int(g.rc_3.servo_out);
|
2011-02-10 03:11:55 -04:00
|
|
|
write_int((int)(cos_yaw_x * 100));
|
|
|
|
write_int((int)(sin_yaw_y * 100));
|
2011-02-06 03:03:28 -04:00
|
|
|
write_int((int)(dcm.yaw_sensor / 100));
|
|
|
|
write_int((int)(nav_yaw / 100));
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-02-06 03:03:28 -04:00
|
|
|
write_int((int)nav_lat);
|
|
|
|
write_int((int)nav_lon);
|
|
|
|
|
|
|
|
write_int((int)nav_roll);
|
|
|
|
write_int((int)nav_pitch);
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-03-15 02:55:51 -03:00
|
|
|
//24
|
|
|
|
write_long(current_loc.lat); //28
|
|
|
|
write_long(current_loc.lng); //32
|
|
|
|
write_int((int)current_loc.alt); //34
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-02-10 03:11:55 -04:00
|
|
|
write_long(next_WP.lat);
|
|
|
|
write_long(next_WP.lng);
|
2011-03-15 02:55:51 -03:00
|
|
|
write_int((int)next_WP.alt); //44
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-02-06 03:03:28 -04:00
|
|
|
flush(10);
|
|
|
|
//*/
|
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-03-19 16:21:43 -03:00
|
|
|
if ((g.frame_type == HEXA_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-03-19 16:21:43 -03:00
|
|
|
if ((g.frame_type == HEXA_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-01-30 21:54:07 -04: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-03-19 16:21:43 -03:00
|
|
|
if ((g.frame_type == HEXA_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
|
|
|
|
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
|
|
|
|