2011-04-16 17:44:44 -03:00
|
|
|
// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
|
|
|
/*****************************************************************************
|
|
|
|
The init_ardupilot function processes everything we need for an in - air restart
|
|
|
|
We will determine later if we are actually on the ground and process a
|
|
|
|
ground start in that case.
|
|
|
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2011-07-17 07:34:05 -03:00
|
|
|
#if CLI_ENABLED == ENABLED
|
2011-04-16 17:44:44 -03:00
|
|
|
// Functions called from the top-level menu
|
2011-07-17 07:32:00 -03:00
|
|
|
static int8_t process_logs(uint8_t argc, const Menu::arg *argv); // in Log.pde
|
|
|
|
static int8_t setup_mode(uint8_t argc, const Menu::arg *argv); // in setup.pde
|
|
|
|
static int8_t test_mode(uint8_t argc, const Menu::arg *argv); // in test.cpp
|
|
|
|
static int8_t planner_mode(uint8_t argc, const Menu::arg *argv); // in planner.pde
|
2011-04-16 17:44:44 -03:00
|
|
|
|
|
|
|
// This is the help function
|
|
|
|
// PSTR is an AVR macro to read strings from flash memory
|
|
|
|
// printf_P is a version of print_f that reads from flash memory
|
|
|
|
static int8_t main_menu_help(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
|
|
|
Serial.printf_P(PSTR("Commands:\n"
|
2011-04-21 02:15:45 -03:00
|
|
|
" logs\n"
|
|
|
|
" setup\n"
|
|
|
|
" test\n"
|
2011-06-20 12:17:08 -03:00
|
|
|
" planner\n"
|
|
|
|
"\n"
|
2011-04-16 17:44:44 -03:00
|
|
|
"Move the slide switch and reset to FLY.\n"
|
|
|
|
"\n"));
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Command/function table for the top-level menu.
|
|
|
|
const struct Menu::command main_menu_commands[] PROGMEM = {
|
|
|
|
// command function called
|
|
|
|
// ======= ===============
|
|
|
|
{"logs", process_logs},
|
|
|
|
{"setup", setup_mode},
|
|
|
|
{"test", test_mode},
|
2011-06-20 12:17:08 -03:00
|
|
|
{"help", main_menu_help},
|
|
|
|
{"planner", planner_mode}
|
2011-04-16 17:44:44 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
// Create the top-level menu object.
|
2011-09-17 15:25:31 -03:00
|
|
|
MENU(main_menu, THISFIRMWARE, main_menu_commands);
|
2011-04-16 17:44:44 -03:00
|
|
|
|
2011-07-17 07:34:05 -03:00
|
|
|
#endif // CLI_ENABLED
|
|
|
|
|
2011-07-17 07:32:00 -03:00
|
|
|
static void init_ardupilot()
|
2011-04-16 17:44:44 -03:00
|
|
|
{
|
|
|
|
// Console serial port
|
|
|
|
//
|
|
|
|
// The console port buffers are defined to be sufficiently large to support
|
|
|
|
// the console's use as a logging device, optionally as the GPS port when
|
|
|
|
// GPS_PROTOCOL_IMU is selected, and as the telemetry port.
|
|
|
|
//
|
|
|
|
// XXX This could be optimised to reduce the buffer sizes in the cases
|
|
|
|
// where they are not otherwise required.
|
|
|
|
//
|
|
|
|
Serial.begin(SERIAL0_BAUD, 128, 128);
|
|
|
|
|
|
|
|
// GPS serial port.
|
|
|
|
//
|
|
|
|
// Not used if the IMU/X-Plane GPS is in use.
|
|
|
|
//
|
|
|
|
// XXX currently the EM406 (SiRF receiver) is nominally configured
|
|
|
|
// at 57600, however it's not been supported to date. We should
|
|
|
|
// probably standardise on 38400.
|
|
|
|
//
|
|
|
|
// XXX the 128 byte receive buffer may be too small for NMEA, depending
|
|
|
|
// on the message set configured.
|
|
|
|
//
|
2011-04-17 02:17:42 -03:00
|
|
|
#if GPS_PROTOCOL != GPS_PROTOCOL_IMU
|
2011-04-16 17:44:44 -03:00
|
|
|
Serial1.begin(38400, 128, 16);
|
2011-04-17 02:17:42 -03:00
|
|
|
#endif
|
2011-04-16 17:44:44 -03:00
|
|
|
|
2011-09-17 15:25:31 -03:00
|
|
|
Serial.printf_P(PSTR("\n\nInit " THISFIRMWARE
|
|
|
|
"\n\nFree RAM: %lu\n"),
|
2011-10-09 08:38:14 -03:00
|
|
|
memcheck_available_memory());
|
2011-04-16 17:44:44 -03:00
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Check the EEPROM format version before loading any parameters from EEPROM.
|
|
|
|
//
|
|
|
|
report_version();
|
|
|
|
|
2011-06-16 14:03:26 -03:00
|
|
|
// setup IO pins
|
|
|
|
pinMode(C_LED_PIN, OUTPUT); // GPS status LED
|
|
|
|
pinMode(A_LED_PIN, OUTPUT); // GPS status LED
|
|
|
|
pinMode(B_LED_PIN, OUTPUT); // GPS status LED
|
|
|
|
pinMode(SLIDE_SWITCH_PIN, INPUT); // To enter interactive mode
|
|
|
|
pinMode(PUSHBUTTON_PIN, INPUT); // unused
|
|
|
|
DDRL |= B00000100; // Set Port L, pin 2 to output for the relay
|
|
|
|
|
2011-06-25 02:59:06 -03:00
|
|
|
// XXX set Analog out 14 to output
|
2011-06-26 03:38:11 -03:00
|
|
|
// 76543210
|
|
|
|
//DDRK |= B01010000;
|
2011-06-25 02:59:06 -03:00
|
|
|
|
2011-06-16 14:03:26 -03:00
|
|
|
#if MOTOR_LEDS == 1
|
|
|
|
pinMode(FR_LED, OUTPUT); // GPS status LED
|
|
|
|
pinMode(RE_LED, OUTPUT); // GPS status LED
|
|
|
|
pinMode(RI_LED, OUTPUT); // GPS status LED
|
|
|
|
pinMode(LE_LED, OUTPUT); // GPS status LED
|
|
|
|
#endif
|
|
|
|
|
2011-09-18 21:12:28 -03:00
|
|
|
#if PIEZO == 1
|
|
|
|
pinMode(PIEZO_PIN,OUTPUT);
|
|
|
|
piezo_beep();
|
|
|
|
#endif
|
|
|
|
|
2011-06-16 14:03:26 -03:00
|
|
|
|
2011-04-16 17:44:44 -03:00
|
|
|
if (!g.format_version.load() ||
|
|
|
|
g.format_version != Parameters::k_format_version) {
|
|
|
|
//Serial.printf_P(PSTR("\n\nForcing complete parameter reset..."));
|
|
|
|
|
|
|
|
/*Serial.printf_P(PSTR("\n\nEEPROM format version %d not compatible with this firmware (requires %d)"
|
|
|
|
"\n\nForcing complete parameter reset..."),
|
|
|
|
g.format_version.get(),
|
|
|
|
Parameters::k_format_version);
|
|
|
|
*/
|
|
|
|
|
|
|
|
// erase all parameters
|
2011-09-04 20:56:19 -03:00
|
|
|
Serial.printf_P(PSTR("Firmware change: erasing EEPROM...\n"));
|
|
|
|
delay(100); // wait for serial send
|
2011-04-16 17:44:44 -03:00
|
|
|
AP_Var::erase_all();
|
|
|
|
|
|
|
|
// save the new format version
|
|
|
|
g.format_version.set_and_save(Parameters::k_format_version);
|
|
|
|
|
|
|
|
Serial.printf_P(PSTR("Please Run Setup...\n"));
|
|
|
|
while (true) {
|
2011-04-20 02:37:05 -03:00
|
|
|
delay(1000);
|
2011-04-16 17:44:44 -03:00
|
|
|
if(motor_light){
|
|
|
|
digitalWrite(A_LED_PIN, HIGH);
|
|
|
|
digitalWrite(B_LED_PIN, HIGH);
|
|
|
|
digitalWrite(C_LED_PIN, HIGH);
|
|
|
|
}else{
|
|
|
|
digitalWrite(A_LED_PIN, LOW);
|
|
|
|
digitalWrite(B_LED_PIN, LOW);
|
|
|
|
digitalWrite(C_LED_PIN, LOW);
|
|
|
|
}
|
|
|
|
motor_light = !motor_light;
|
|
|
|
}
|
|
|
|
|
|
|
|
}else{
|
2011-10-15 17:09:04 -03:00
|
|
|
|
2011-04-16 17:44:44 -03:00
|
|
|
// Load all auto-loaded EEPROM variables
|
|
|
|
AP_Var::load_all();
|
|
|
|
}
|
|
|
|
|
2011-08-01 08:39:17 -03:00
|
|
|
// Telemetry port.
|
|
|
|
//
|
|
|
|
// Not used if telemetry is going to the console.
|
|
|
|
//
|
|
|
|
// XXX for unidirectional protocols, we could (should) minimize
|
|
|
|
// the receive buffer, and the transmit buffer could also be
|
|
|
|
// shrunk for protocols that don't send large messages.
|
|
|
|
//
|
|
|
|
Serial3.begin(map_baudrate(g.serial3_baud,SERIAL3_BAUD), 128, 128);
|
|
|
|
|
2011-04-17 02:17:42 -03:00
|
|
|
#ifdef RADIO_OVERRIDE_DEFAULTS
|
2011-04-16 17:44:44 -03:00
|
|
|
{
|
|
|
|
int16_t rc_override[8] = RADIO_OVERRIDE_DEFAULTS;
|
|
|
|
APM_RC.setHIL(rc_override);
|
|
|
|
}
|
2011-04-17 02:17:42 -03:00
|
|
|
#endif
|
2011-06-16 14:03:26 -03:00
|
|
|
|
|
|
|
#if FRAME_CONFIG == HELI_FRAME
|
|
|
|
heli_init_swash(); // heli initialisation
|
|
|
|
#endif
|
2011-04-16 17:44:44 -03:00
|
|
|
|
|
|
|
init_rc_in(); // sets up rc channels from radio
|
|
|
|
init_rc_out(); // sets up the timer libs
|
2011-07-30 17:42:54 -03:00
|
|
|
init_camera();
|
2011-04-17 02:17:42 -03:00
|
|
|
|
|
|
|
#if HIL_MODE != HIL_MODE_ATTITUDE
|
2011-10-12 02:20:23 -03:00
|
|
|
// begin filtering the ADC Gyros
|
|
|
|
adc.filter_result = true;
|
2011-10-04 07:55:10 -03:00
|
|
|
|
2011-06-16 14:03:26 -03:00
|
|
|
adc.Init(); // APM ADC library initialization
|
|
|
|
barometer.Init(); // APM Abs Pressure sensor initialization
|
2011-04-17 02:17:42 -03:00
|
|
|
#endif
|
2011-04-16 17:44:44 -03:00
|
|
|
|
|
|
|
// Do GPS init
|
|
|
|
g_gps = &g_gps_driver;
|
|
|
|
g_gps->init(); // GPS Initialization
|
2011-08-01 05:08:52 -03:00
|
|
|
g_gps->callback = mavlink_delay;
|
2011-04-16 17:44:44 -03:00
|
|
|
|
|
|
|
// init the GCS
|
2011-10-11 06:12:37 -03:00
|
|
|
gcs0.init(&Serial);
|
|
|
|
gcs3.init(&Serial3);
|
2011-04-16 17:44:44 -03:00
|
|
|
|
|
|
|
if(g.compass_enabled)
|
|
|
|
init_compass();
|
|
|
|
|
2011-09-16 03:33:00 -03:00
|
|
|
#ifdef OPTFLOW_ENABLED
|
2011-07-21 20:14:53 -03:00
|
|
|
// init the optical flow sensor
|
|
|
|
if(g.optflow_enabled) {
|
|
|
|
init_optflow();
|
|
|
|
}
|
2011-09-16 03:33:00 -03:00
|
|
|
#endif
|
2011-07-30 17:42:54 -03:00
|
|
|
|
2011-10-18 03:51:47 -03:00
|
|
|
// agmatthews USERHOOKS
|
|
|
|
#ifdef USERHOOK_INIT
|
|
|
|
USERHOOK_INIT
|
|
|
|
#endif
|
2011-04-17 03:45:18 -03:00
|
|
|
// Logging:
|
|
|
|
// --------
|
2011-06-16 14:03:26 -03:00
|
|
|
// DataFlash log initialization
|
2011-10-09 08:38:49 -03:00
|
|
|
#if LOGGING_ENABLED == ENABLED
|
2011-06-16 14:03:26 -03:00
|
|
|
DataFlash.Init();
|
2011-10-09 08:38:49 -03:00
|
|
|
#endif
|
2011-06-16 14:03:26 -03:00
|
|
|
|
2011-07-17 07:34:05 -03:00
|
|
|
#if CLI_ENABLED == ENABLED
|
2011-04-16 17:44:44 -03:00
|
|
|
// If the switch is in 'menu' mode, run the main menu.
|
|
|
|
//
|
|
|
|
// Since we can't be sure that the setup or test mode won't leave
|
|
|
|
// the system in an odd state, we don't let the user exit the top
|
|
|
|
// menu; they must reset in order to fly.
|
|
|
|
//
|
2011-06-16 14:03:26 -03:00
|
|
|
if (check_startup_for_CLI()) {
|
2011-05-07 16:41:55 -03:00
|
|
|
digitalWrite(A_LED_PIN,HIGH); // turn on setup-mode LED
|
2011-10-15 17:09:04 -03:00
|
|
|
Serial.printf_P(PSTR("\nCLI:\n\n"));
|
2011-05-07 16:41:55 -03:00
|
|
|
for (;;) {
|
|
|
|
//Serial.println_P(PSTR("\nMove the slide switch and reset to FLY.\n"));
|
|
|
|
main_menu.run();
|
|
|
|
}
|
2011-04-16 17:44:44 -03:00
|
|
|
}
|
2011-07-17 07:34:05 -03:00
|
|
|
#endif // CLI_ENABLED
|
|
|
|
|
|
|
|
if(g.esc_calibrate == 1){
|
|
|
|
init_esc();
|
|
|
|
}
|
2011-04-16 17:44:44 -03:00
|
|
|
|
2011-06-16 14:03:26 -03:00
|
|
|
// Logging:
|
|
|
|
// --------
|
|
|
|
if(g.log_bitmask != 0){
|
|
|
|
// TODO - Here we will check on the length of the last log
|
|
|
|
// We don't want to create a bunch of little logs due to powering on and off
|
|
|
|
start_new_log();
|
|
|
|
}
|
|
|
|
|
2011-04-16 17:44:44 -03:00
|
|
|
GPS_enabled = false;
|
|
|
|
|
|
|
|
// Read in the GPS
|
|
|
|
for (byte counter = 0; ; counter++) {
|
|
|
|
g_gps->update();
|
|
|
|
if (g_gps->status() != 0){
|
|
|
|
GPS_enabled = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (counter >= 2) {
|
|
|
|
GPS_enabled = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-07-10 21:47:08 -03:00
|
|
|
|
2011-07-30 17:42:54 -03:00
|
|
|
// lengthen the idle timeout for gps Auto_detect
|
|
|
|
// ---------------------------------------------
|
|
|
|
g_gps->idleTimeout = 20000;
|
2011-06-16 14:03:26 -03:00
|
|
|
|
2011-07-10 21:47:08 -03:00
|
|
|
// print the GPS status
|
2011-07-30 17:42:54 -03:00
|
|
|
// --------------------
|
2011-04-16 17:44:44 -03:00
|
|
|
report_gps();
|
2011-07-10 21:47:08 -03:00
|
|
|
|
2011-07-30 17:42:54 -03:00
|
|
|
#if HIL_MODE != HIL_MODE_ATTITUDE
|
|
|
|
// read Baro pressure at ground
|
|
|
|
//-----------------------------
|
|
|
|
init_barometer();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// initialize commands
|
|
|
|
// -------------------
|
|
|
|
init_commands();
|
|
|
|
|
|
|
|
// set the correct flight mode
|
|
|
|
// ---------------------------
|
|
|
|
reset_control_switch();
|
|
|
|
|
2011-08-01 01:47:15 -03:00
|
|
|
startup_ground();
|
2011-07-30 17:42:54 -03:00
|
|
|
|
2011-06-16 14:03:26 -03:00
|
|
|
Log_Write_Startup();
|
|
|
|
|
2011-04-16 17:44:44 -03:00
|
|
|
SendDebug("\nReady to FLY ");
|
2011-07-30 17:42:54 -03:00
|
|
|
}
|
2011-06-28 03:31:18 -03:00
|
|
|
|
2011-07-30 17:42:54 -03:00
|
|
|
//********************************************************************************
|
|
|
|
//This function does all the calibrations, etc. that we need during a ground start
|
|
|
|
//********************************************************************************
|
|
|
|
static void startup_ground(void)
|
|
|
|
{
|
2011-10-11 06:12:37 -03:00
|
|
|
gcs_send_text_P(SEVERITY_LOW,PSTR("GROUND START"));
|
2011-07-30 17:42:54 -03:00
|
|
|
|
|
|
|
#if HIL_MODE != HIL_MODE_ATTITUDE
|
|
|
|
// Warm up and read Gyro offsets
|
|
|
|
// -----------------------------
|
2011-08-01 05:08:52 -03:00
|
|
|
imu.init_gyro(mavlink_delay);
|
2011-09-17 15:25:31 -03:00
|
|
|
#if CLI_ENABLED == ENABLED
|
|
|
|
report_imu();
|
|
|
|
#endif
|
2011-07-30 17:42:54 -03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// reset the leds
|
|
|
|
// ---------------------------
|
|
|
|
clear_leds();
|
2011-04-16 17:44:44 -03:00
|
|
|
}
|
|
|
|
|
2011-09-04 21:15:36 -03:00
|
|
|
/*
|
|
|
|
#define YAW_HOLD 0
|
|
|
|
#define YAW_ACRO 1
|
|
|
|
#define YAW_AUTO 2
|
|
|
|
#define YAW_LOOK_AT_HOME 3
|
|
|
|
|
|
|
|
#define ROLL_PITCH_STABLE 0
|
|
|
|
#define ROLL_PITCH_ACRO 1
|
2011-09-16 03:33:00 -03:00
|
|
|
#define ROLL_PITCH_AUTO 2
|
2011-09-04 21:15:36 -03:00
|
|
|
|
|
|
|
#define THROTTLE_MANUAL 0
|
|
|
|
#define THROTTLE_HOLD 1
|
|
|
|
#define THROTTLE_AUTO 2
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2011-07-17 07:32:00 -03:00
|
|
|
static void set_mode(byte mode)
|
2011-04-16 17:44:44 -03:00
|
|
|
{
|
|
|
|
if(control_mode == mode){
|
|
|
|
// don't switch modes if we are already in the correct mode.
|
|
|
|
return;
|
|
|
|
}
|
2011-07-30 17:42:54 -03:00
|
|
|
|
2011-07-12 17:04:15 -03:00
|
|
|
old_control_mode = control_mode;
|
2011-04-16 17:44:44 -03:00
|
|
|
|
|
|
|
control_mode = mode;
|
|
|
|
control_mode = constrain(control_mode, 0, NUM_MODES - 1);
|
|
|
|
|
|
|
|
// used to stop fly_aways
|
2011-09-22 02:31:12 -03:00
|
|
|
motor_auto_armed = (g.rc_3.control_in > 0);
|
2011-04-16 17:44:44 -03:00
|
|
|
|
2011-05-14 23:02:09 -03:00
|
|
|
Serial.println(flight_mode_strings[control_mode]);
|
|
|
|
|
2011-09-04 21:15:36 -03:00
|
|
|
// report the GPS and Motor arming status
|
2011-06-16 14:03:26 -03:00
|
|
|
led_mode = NORMAL_LEDS;
|
|
|
|
|
2011-09-14 17:58:18 -03:00
|
|
|
reset_nav();
|
2011-09-04 21:15:36 -03:00
|
|
|
|
2011-04-16 17:44:44 -03:00
|
|
|
switch(control_mode)
|
|
|
|
{
|
|
|
|
case ACRO:
|
2011-09-04 21:15:36 -03:00
|
|
|
yaw_mode = YAW_ACRO;
|
|
|
|
roll_pitch_mode = ROLL_PITCH_ACRO;
|
|
|
|
throttle_mode = THROTTLE_MANUAL;
|
2011-09-04 22:30:31 -03:00
|
|
|
reset_hold_I();
|
2011-04-16 17:44:44 -03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case STABILIZE:
|
2011-09-04 21:15:36 -03:00
|
|
|
yaw_mode = YAW_HOLD;
|
|
|
|
roll_pitch_mode = ROLL_PITCH_STABLE;
|
|
|
|
throttle_mode = THROTTLE_MANUAL;
|
2011-09-04 22:30:31 -03:00
|
|
|
reset_hold_I();
|
2011-09-04 21:15:36 -03:00
|
|
|
break;
|
|
|
|
|
2011-04-16 17:44:44 -03:00
|
|
|
case ALT_HOLD:
|
2011-09-04 21:15:36 -03:00
|
|
|
yaw_mode = ALT_HOLD_YAW;
|
|
|
|
roll_pitch_mode = ALT_HOLD_RP;
|
|
|
|
throttle_mode = ALT_HOLD_THR;
|
2011-09-07 13:43:06 -03:00
|
|
|
reset_hold_I();
|
2011-09-04 21:15:36 -03:00
|
|
|
|
2011-04-16 17:44:44 -03:00
|
|
|
init_throttle_cruise();
|
2011-09-14 17:58:18 -03:00
|
|
|
next_WP = current_loc;
|
2011-04-16 17:44:44 -03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case AUTO:
|
2011-09-04 22:30:31 -03:00
|
|
|
reset_hold_I();
|
2011-09-04 21:15:36 -03:00
|
|
|
yaw_mode = AUTO_YAW;
|
|
|
|
roll_pitch_mode = AUTO_RP;
|
|
|
|
throttle_mode = AUTO_THR;
|
|
|
|
|
2011-04-16 17:44:44 -03:00
|
|
|
init_throttle_cruise();
|
2011-09-04 21:15:36 -03:00
|
|
|
|
|
|
|
// loads the commands from where we left off
|
2011-09-12 16:57:36 -03:00
|
|
|
init_commands();
|
2011-04-16 17:44:44 -03:00
|
|
|
break;
|
|
|
|
|
2011-07-30 17:42:54 -03:00
|
|
|
case CIRCLE:
|
2011-09-04 21:15:36 -03:00
|
|
|
yaw_mode = CIRCLE_YAW;
|
|
|
|
roll_pitch_mode = CIRCLE_RP;
|
|
|
|
throttle_mode = CIRCLE_THR;
|
|
|
|
|
|
|
|
init_throttle_cruise();
|
|
|
|
next_WP = current_loc;
|
|
|
|
break;
|
|
|
|
|
2011-04-16 17:44:44 -03:00
|
|
|
case LOITER:
|
2011-09-04 21:15:36 -03:00
|
|
|
yaw_mode = LOITER_YAW;
|
|
|
|
roll_pitch_mode = LOITER_RP;
|
|
|
|
throttle_mode = LOITER_THR;
|
|
|
|
|
2011-04-16 17:44:44 -03:00
|
|
|
init_throttle_cruise();
|
2011-09-04 21:15:36 -03:00
|
|
|
next_WP = current_loc;
|
2011-04-16 17:44:44 -03:00
|
|
|
break;
|
|
|
|
|
2011-09-30 03:27:23 -03:00
|
|
|
case POSITION:
|
|
|
|
yaw_mode = YAW_HOLD;
|
|
|
|
roll_pitch_mode = ROLL_PITCH_AUTO;
|
|
|
|
throttle_mode = THROTTLE_MANUAL;
|
|
|
|
|
|
|
|
next_WP = current_loc;
|
|
|
|
break;
|
|
|
|
|
2011-07-02 19:44:59 -03:00
|
|
|
case GUIDED:
|
2011-09-04 21:15:36 -03:00
|
|
|
yaw_mode = YAW_AUTO;
|
|
|
|
roll_pitch_mode = ROLL_PITCH_AUTO;
|
|
|
|
throttle_mode = THROTTLE_AUTO;
|
|
|
|
|
2011-09-12 00:40:05 -03:00
|
|
|
//xtrack_enabled = true;
|
2011-07-12 17:04:15 -03:00
|
|
|
init_throttle_cruise();
|
2011-09-04 21:15:36 -03:00
|
|
|
next_WP = current_loc;
|
2011-09-12 16:57:36 -03:00
|
|
|
set_next_WP(&guided_WP);
|
2011-07-02 19:44:59 -03:00
|
|
|
break;
|
|
|
|
|
2011-04-16 17:44:44 -03:00
|
|
|
case RTL:
|
2011-09-04 21:15:36 -03:00
|
|
|
yaw_mode = RTL_YAW;
|
|
|
|
roll_pitch_mode = RTL_RP;
|
|
|
|
throttle_mode = RTL_THR;
|
|
|
|
|
2011-09-12 00:40:05 -03:00
|
|
|
//xtrack_enabled = true;
|
2011-07-12 17:04:15 -03:00
|
|
|
init_throttle_cruise();
|
2011-04-16 17:44:44 -03:00
|
|
|
do_RTL();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-05-29 17:27:14 -03:00
|
|
|
Log_Write_Mode(control_mode);
|
2011-04-16 17:44:44 -03:00
|
|
|
}
|
|
|
|
|
2011-07-17 07:32:00 -03:00
|
|
|
static void set_failsafe(boolean mode)
|
2011-04-16 17:44:44 -03:00
|
|
|
{
|
|
|
|
// only act on changes
|
|
|
|
// -------------------
|
|
|
|
if(failsafe != mode){
|
|
|
|
|
|
|
|
// store the value so we don't trip the gate twice
|
|
|
|
// -----------------------------------------------
|
|
|
|
failsafe = mode;
|
|
|
|
|
|
|
|
if (failsafe == false){
|
|
|
|
// We've regained radio contact
|
|
|
|
// ----------------------------
|
|
|
|
failsafe_off_event();
|
|
|
|
|
|
|
|
}else{
|
|
|
|
// We've lost radio contact
|
|
|
|
// ------------------------
|
|
|
|
failsafe_on_event();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-17 07:32:00 -03:00
|
|
|
static void
|
2011-04-16 17:44:44 -03:00
|
|
|
init_compass()
|
|
|
|
{
|
2011-08-10 09:52:53 -03:00
|
|
|
compass.set_orientation(MAG_ORIENTATION); // set compass's orientation on aircraft
|
2011-04-16 17:44:44 -03:00
|
|
|
dcm.set_compass(&compass);
|
2011-09-04 20:56:11 -03:00
|
|
|
compass.init();
|
|
|
|
compass.get_offsets(); // load offsets to account for airframe magnetic interference
|
2011-04-16 17:44:44 -03:00
|
|
|
}
|
|
|
|
|
2011-07-21 20:14:53 -03:00
|
|
|
#ifdef OPTFLOW_ENABLED
|
|
|
|
static void
|
|
|
|
init_optflow()
|
|
|
|
{
|
2011-09-16 03:33:00 -03:00
|
|
|
if( optflow.init() == false ) {
|
|
|
|
g.optflow_enabled = false;
|
|
|
|
//SendDebug("\nFailed to Init OptFlow ");
|
|
|
|
}
|
2011-07-21 20:14:53 -03:00
|
|
|
optflow.set_orientation(OPTFLOW_ORIENTATION); // set optical flow sensor's orientation on aircraft
|
|
|
|
optflow.set_field_of_view(OPTFLOW_FOV); // set optical flow sensor's field of view
|
|
|
|
}
|
|
|
|
#endif
|
2011-04-16 17:44:44 -03:00
|
|
|
|
2011-07-17 07:32:00 -03:00
|
|
|
static void
|
2011-04-16 17:44:44 -03:00
|
|
|
init_simple_bearing()
|
|
|
|
{
|
|
|
|
initial_simple_bearing = dcm.yaw_sensor;
|
|
|
|
}
|
|
|
|
|
2011-07-17 07:32:00 -03:00
|
|
|
static void
|
2011-04-16 17:44:44 -03:00
|
|
|
init_throttle_cruise()
|
|
|
|
{
|
2011-07-12 17:04:15 -03:00
|
|
|
// are we moving from manual throttle to auto_throttle?
|
2011-09-14 17:58:18 -03:00
|
|
|
if((old_control_mode <= STABILIZE) && (g.rc_3.control_in > MINIMUM_THROTTLE)){
|
2011-09-04 21:15:36 -03:00
|
|
|
g.pi_throttle.reset_I();
|
2011-07-12 17:04:15 -03:00
|
|
|
g.throttle_cruise.set_and_save(g.rc_3.control_in);
|
|
|
|
}
|
2011-05-09 14:40:32 -03:00
|
|
|
}
|
|
|
|
|
2011-10-09 08:39:23 -03:00
|
|
|
#if CLI_ENABLED == ENABLED
|
2011-06-16 14:03:26 -03:00
|
|
|
#if BROKEN_SLIDER == 1
|
|
|
|
|
2011-07-17 07:32:00 -03:00
|
|
|
static boolean
|
2011-06-16 14:03:26 -03:00
|
|
|
check_startup_for_CLI()
|
|
|
|
{
|
2011-07-02 19:44:59 -03:00
|
|
|
//return true;
|
|
|
|
if((g.rc_4.radio_max) < 1600){
|
|
|
|
// CLI mode
|
2011-06-16 14:03:26 -03:00
|
|
|
return true;
|
2011-07-02 19:44:59 -03:00
|
|
|
|
|
|
|
}else if(abs(g.rc_4.control_in) > 3000){
|
2011-06-16 14:03:26 -03:00
|
|
|
// CLI mode
|
2011-07-02 19:44:59 -03:00
|
|
|
return true;
|
|
|
|
|
|
|
|
}else{
|
|
|
|
// startup to fly
|
2011-06-16 14:03:26 -03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2011-07-17 07:32:00 -03:00
|
|
|
static boolean
|
2011-06-16 14:03:26 -03:00
|
|
|
check_startup_for_CLI()
|
|
|
|
{
|
|
|
|
return (digitalRead(SLIDE_SWITCH_PIN) == 0);
|
|
|
|
}
|
|
|
|
|
2011-10-09 08:39:23 -03:00
|
|
|
#endif // BROKEN_SLIDER
|
|
|
|
#endif // CLI_ENABLED
|
2011-08-01 08:39:17 -03:00
|
|
|
|
|
|
|
/*
|
|
|
|
map from a 8 bit EEPROM baud rate to a real baud rate
|
|
|
|
*/
|
|
|
|
static uint32_t map_baudrate(int8_t rate, uint32_t default_baud)
|
|
|
|
{
|
|
|
|
switch (rate) {
|
|
|
|
case 9: return 9600;
|
|
|
|
case 19: return 19200;
|
|
|
|
case 38: return 38400;
|
|
|
|
case 57: return 57600;
|
|
|
|
case 111: return 111100;
|
|
|
|
case 115: return 115200;
|
|
|
|
}
|
2011-10-15 17:09:04 -03:00
|
|
|
//Serial.println_P(PSTR("Invalid SERIAL3_BAUD"));
|
2011-08-01 08:39:17 -03:00
|
|
|
return default_baud;
|
|
|
|
}
|