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
|
|
|
|
2011-06-16 14:03:26 -03:00
|
|
|
#define ARM_DELAY 10 // one secon
|
|
|
|
#define DISARM_DELAY 10 // one secon
|
|
|
|
#define LEVEL_DELAY 120 // twelve seconds
|
|
|
|
#define AUTO_LEVEL_DELAY 250 // twentyfive seconds
|
2011-01-23 22:04:44 -04:00
|
|
|
|
2011-06-16 14:03:26 -03:00
|
|
|
|
|
|
|
// called at 10hz
|
2011-01-23 22:04:44 -04:00
|
|
|
void arm_motors()
|
|
|
|
{
|
2011-06-16 14:03:26 -03:00
|
|
|
static int 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-06-16 14:03:26 -03:00
|
|
|
|
2011-04-13 13:33:06 -03:00
|
|
|
// full right
|
|
|
|
if (g.rc_4.control_in > 4000) {
|
2011-06-16 14:03:26 -03:00
|
|
|
|
|
|
|
if (arming_counter > AUTO_LEVEL_DELAY){
|
|
|
|
auto_level_counter = 255;
|
|
|
|
arming_counter = 0;
|
|
|
|
|
|
|
|
}else if (arming_counter == ARM_DELAY){
|
2011-04-13 13:33:06 -03:00
|
|
|
motor_armed = true;
|
|
|
|
arming_counter = ARM_DELAY;
|
2011-04-15 13:45:47 -03:00
|
|
|
|
|
|
|
// Remember Orientation
|
|
|
|
// ---------------------------
|
|
|
|
init_simple_bearing();
|
|
|
|
|
2011-06-16 14:03:26 -03:00
|
|
|
arming_counter++;
|
2011-03-21 04:35:54 -03:00
|
|
|
} else{
|
|
|
|
arming_counter++;
|
2011-01-23 22:04:44 -04:00
|
|
|
}
|
2011-05-29 01:02:01 -03:00
|
|
|
|
2011-04-13 13:33:06 -03:00
|
|
|
// full left
|
|
|
|
}else if (g.rc_4.control_in < -4000) {
|
2011-06-16 14:03:26 -03:00
|
|
|
//Serial.print(arming_counter, DEC);
|
|
|
|
if (arming_counter > LEVEL_DELAY){
|
|
|
|
//Serial.print("init");
|
|
|
|
imu.init_accel();
|
|
|
|
arming_counter = 0;
|
|
|
|
|
|
|
|
}else if (arming_counter == DISARM_DELAY){
|
2011-04-13 13:33:06 -03:00
|
|
|
motor_armed = false;
|
|
|
|
arming_counter = DISARM_DELAY;
|
2011-05-29 01:02:01 -03:00
|
|
|
compass.save_offsets();
|
2011-06-16 14:03:26 -03:00
|
|
|
arming_counter++;
|
2011-05-29 01:02:01 -03:00
|
|
|
|
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
|
|
|
{
|
2011-05-14 23:02:09 -03:00
|
|
|
if (motor_armed == true && motor_auto_armed == true) {
|
2011-01-23 22:04:44 -04:00
|
|
|
// creates the radio_out and pwm_out values
|
2011-05-14 23:02:09 -03:00
|
|
|
output_motors_armed();
|
|
|
|
} else{
|
|
|
|
output_motors_disarmed();
|
|
|
|
}
|
|
|
|
}
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-05-14 23:02:09 -03:00
|
|
|
/*****************************************
|
|
|
|
* Set the flight control servos based on the current calculated values
|
|
|
|
*****************************************/
|
2011-02-17 05:36:33 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2011-05-12 12:58:27 -03:00
|
|
|
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-05-14 23:02:09 -03:00
|
|
|
//if (num++ > 25){
|
|
|
|
// 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-05-14 23:02:09 -03:00
|
|
|
//}
|