ardupilot/ArduCopter/system.pde

745 lines
20 KiB
Plaintext
Raw Normal View History

// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
/*****************************************************************************
2012-08-21 23:19:50 -03:00
* 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.
*
*****************************************************************************/
#if CLI_ENABLED == ENABLED
// Functions called from the top-level menu
2012-08-21 23:19:50 -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 reboot_board(uint8_t argc, const Menu::arg *argv);
// 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
2012-08-21 23:19:50 -03:00
static int8_t main_menu_help(uint8_t argc, const Menu::arg *argv)
{
cliSerial->printf_P(PSTR("Commands:\n"
2012-08-21 23:19:50 -03:00
" logs\n"
" setup\n"
" test\n"
" reboot\n"
2012-08-21 23:19:50 -03:00
"\n"));
return(0);
}
// Command/function table for the top-level menu.
const struct Menu::command main_menu_commands[] PROGMEM = {
// command function called
// ======= ===============
2012-08-21 23:19:50 -03:00
{"logs", process_logs},
{"setup", setup_mode},
{"test", test_mode},
{"reboot", reboot_board},
2012-08-21 23:19:50 -03:00
{"help", main_menu_help},
};
// Create the top-level menu object.
MENU(main_menu, THISFIRMWARE, main_menu_commands);
static int8_t reboot_board(uint8_t argc, const Menu::arg *argv)
{
reboot_apm();
return 0;
}
// the user wants the CLI. It never exits
static void run_cli(FastSerial *port)
{
cliSerial = port;
Menu::set_port(port);
port->set_blocking_writes(true);
while (1) {
main_menu.run();
}
}
#endif // CLI_ENABLED
static void init_ardupilot()
{
#if USB_MUX_PIN > 0
2011-11-25 19:11:25 -04:00
// on the APM2 board we have a mux thet switches UART0 between
// USB and the board header. If the right ArduPPM firmware is
// installed we can detect if USB is connected using the
// USB_MUX_PIN
pinMode(USB_MUX_PIN, INPUT);
ap_system.usb_connected = !digitalReadFast(USB_MUX_PIN);
if (!ap_system.usb_connected) {
// USB is not connected, this means UART0 may be a Xbee, with
// its darned bricking problem. We can't write to it for at
// least one second after powering up. Simplest solution for
// now is to delay for 1 second. Something more elegant may be
// added later
delay(1000);
}
#endif
2012-08-21 23:19:50 -03:00
// Console serial port
//
// The console port buffers are defined to be sufficiently large to support
// the MAVLink protocol efficiently
//
cliSerial->begin(SERIAL0_BAUD, 128, 256);
2012-08-21 23:19:50 -03:00
// GPS serial port.
//
#if GPS_PROTOCOL != GPS_PROTOCOL_IMU
// standard gps running. Note that we need a 256 byte buffer for some
// GPS types (eg. UBLOX)
Serial1.begin(38400, 256, 16);
2012-08-21 23:19:50 -03:00
#endif
cliSerial->printf_P(PSTR("\n\nInit " THISFIRMWARE
2012-08-21 23:19:50 -03:00
"\n\nFree RAM: %u\n"),
memcheck_available_memory());
2012-08-21 23:19:50 -03:00
//
// Initialize Wire and SPI libraries
//
#ifndef DESKTOP_BUILD
2011-12-28 05:34:59 -04:00
I2c.begin();
I2c.timeOut(5);
// initially set a fast I2c speed, and drop it on first failures
I2c.setSpeed(true);
#endif
SPI.begin();
SPI.setClockDivider(SPI_CLOCK_DIV16); // 1MHZ SPI rate
#if CONFIG_APM_HARDWARE == APM_HARDWARE_APM2
SPI3.begin();
SPI3.setSpeed(SPI3_SPEED_2MHZ);
#endif
2012-08-21 23:19:50 -03:00
//
// Initialize the isr_registry.
//
isr_registry.init();
2012-08-21 23:19:50 -03:00
//
// Report firmware version code expect on console (check of actual EEPROM format version is done in load_parameters function)
2012-08-21 23:19:50 -03:00
//
report_version();
2012-08-21 23:19:50 -03:00
// setup IO pins
pinMode(A_LED_PIN, OUTPUT); // GPS status LED
digitalWrite(A_LED_PIN, LED_OFF);
2012-08-21 23:19:50 -03:00
pinMode(B_LED_PIN, OUTPUT); // GPS status LED
digitalWrite(B_LED_PIN, LED_OFF);
2012-08-21 23:19:50 -03:00
pinMode(C_LED_PIN, OUTPUT); // GPS status LED
digitalWrite(C_LED_PIN, LED_OFF);
#if SLIDE_SWITCH_PIN > 0
2012-08-21 23:19:50 -03:00
pinMode(SLIDE_SWITCH_PIN, INPUT); // To enter interactive mode
#endif
#if CONFIG_PUSHBUTTON == ENABLED
2012-08-21 23:19:50 -03:00
pinMode(PUSHBUTTON_PIN, INPUT); // unused
#endif
#if CONFIG_RELAY == ENABLED
2012-08-21 23:19:50 -03:00
DDRL |= B00000100; // Set Port L, pin 2 to output for the relay
#endif
#if COPTER_LEDS == ENABLED
2012-08-21 23:19:50 -03:00
pinMode(COPTER_LED_1, OUTPUT); //Motor LED
pinMode(COPTER_LED_2, OUTPUT); //Motor LED
pinMode(COPTER_LED_3, OUTPUT); //Motor LED
pinMode(COPTER_LED_4, OUTPUT); //Motor LED
pinMode(COPTER_LED_5, OUTPUT); //Motor or Aux LED
pinMode(COPTER_LED_6, OUTPUT); //Motor or Aux LED
pinMode(COPTER_LED_7, OUTPUT); //Motor or GPS LED
pinMode(COPTER_LED_8, OUTPUT); //Motor or GPS LED
if ( !bitRead(g.copter_leds_mode, 3) ) {
piezo_beep();
}
#endif
2011-09-18 21:12:28 -03:00
2012-02-12 07:27:51 -04:00
// load parameters from EEPROM
load_parameters();
2012-08-21 23:19:50 -03:00
// init the GCS
gcs0.init(&Serial);
#if USB_MUX_PIN > 0
if (!ap_system.usb_connected) {
// we are not connected via USB, re-init UART0 with right
// baud rate
cliSerial->begin(map_baudrate(g.serial3_baud, SERIAL3_BAUD));
}
#else
// we have a 2nd serial port for telemetry
Serial3.begin(map_baudrate(g.serial3_baud, SERIAL3_BAUD), 128, 256);
2012-08-21 23:19:50 -03:00
gcs3.init(&Serial3);
#endif
// identify ourselves correctly with the ground station
2012-08-21 23:19:50 -03:00
mavlink_system.sysid = g.sysid_this_mav;
mavlink_system.type = 2; //MAV_QUADROTOR;
2012-02-11 02:25:24 -04:00
2011-12-28 00:53:05 -04:00
#if LOGGING_ENABLED == ENABLED
DataFlash.Init();
if (!DataFlash.CardInserted()) {
gcs_send_text_P(SEVERITY_LOW, PSTR("No dataflash inserted"));
g.log_bitmask.set(0);
} else if (DataFlash.NeedErase()) {
gcs_send_text_P(SEVERITY_LOW, PSTR("ERASING LOGS"));
2012-08-21 23:19:50 -03:00
do_erase_logs();
}
if (g.log_bitmask != 0) {
DataFlash.start_new_log();
}
2011-12-28 00:53:05 -04:00
#endif
2012-11-10 01:55:51 -04:00
/*
2012-08-21 23:19:50 -03:00
#ifdef RADIO_OVERRIDE_DEFAULTS
{
int16_t rc_override[8] = RADIO_OVERRIDE_DEFAULTS;
APM_RC.setHIL(rc_override);
}
#endif
2012-11-10 01:55:51 -04:00
*/
2012-08-21 23:19:50 -03:00
#if FRAME_CONFIG == HELI_FRAME
motors.servo_manual = false;
motors.init_swash(); // heli initialisation
#endif
RC_Channel::set_apm_rc(&APM_RC);
2012-08-21 23:19:50 -03:00
init_rc_in(); // sets up rc channels from radio
init_rc_out(); // sets up the timer libs
timer_scheduler.init( &isr_registry );
/*
* setup the 'main loop is dead' check. Note that this relies on
* the RC library being initialised.
*/
timer_scheduler.set_failsafe(failsafe_check);
// initialise the analog port reader
AP_AnalogSource_Arduino::init_timer(&timer_scheduler);
2011-11-12 22:47:54 -04:00
#if HIL_MODE != HIL_MODE_ATTITUDE
2012-08-21 23:19:50 -03:00
#if CONFIG_ADC == ENABLED
// begin filtering the ADC Gyros
adc.Init(&timer_scheduler); // APM ADC library initialization
#endif // CONFIG_ADC
2011-10-04 07:55:10 -03:00
2012-08-21 23:19:50 -03:00
barometer.init(&timer_scheduler);
2011-11-12 22:47:54 -04:00
#endif // HIL_MODE
2012-08-21 23:19:50 -03:00
// Do GPS init
g_gps = &g_gps_driver;
// GPS Initialization
2012-08-21 23:19:50 -03:00
g_gps->init(GPS::GPS_ENGINE_AIRBORNE_1G);
2012-08-21 23:19:50 -03:00
if(g.compass_enabled)
init_compass();
2012-08-21 23:19:50 -03:00
// init the optical flow sensor
if(g.optflow_enabled) {
init_optflow();
}
#if INERTIAL_NAV_XY == ENABLED || INERTIAL_NAV_Z == ENABLED
// initialise inertial nav
inertial_nav.init();
#endif
2011-10-18 03:51:47 -03:00
// agmatthews USERHOOKS
#ifdef USERHOOK_INIT
2012-08-21 23:19:50 -03:00
USERHOOK_INIT
2011-10-18 03:51:47 -03:00
#endif
#if CLI_ENABLED == ENABLED && CLI_SLIDER_ENABLED == ENABLED
2012-08-21 23:19:50 -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.
//
if (check_startup_for_CLI()) {
digitalWrite(A_LED_PIN, LED_ON); // turn on setup-mode LED
cliSerial->printf_P(PSTR("\nCLI:\n\n"));
run_cli(cliSerial);
2012-08-21 23:19:50 -03:00
}
#else
const prog_char_t *msg = PSTR("\nPress ENTER 3 times to start interactive setup\n");
cliSerial->println_P(msg);
#if USB_MUX_PIN == 0
Serial3.println_P(msg);
#endif
#endif // CLI_ENABLED
2012-08-21 23:19:50 -03:00
#if HIL_MODE != HIL_MODE_ATTITUDE
// read Baro pressure at ground
//-----------------------------
init_barometer();
#endif
// initialise sonar
#if CONFIG_SONAR == ENABLED
init_sonar();
#endif
#if FRAME_CONIG == HELI_FRAME
// initialise controller filters
init_rate_controllers();
#endif // HELI_FRAME
2012-08-21 23:19:50 -03:00
// initialize commands
// -------------------
init_commands();
// set the correct flight mode
// ---------------------------
reset_control_switch();
startup_ground();
// now that initialisation of IMU has occurred increase SPI to 2MHz
SPI.setClockDivider(SPI_CLOCK_DIV8); // 2MHZ SPI rate
#if LOGGING_ENABLED == ENABLED
2012-08-21 23:19:50 -03:00
Log_Write_Startup();
#endif
///////////////////////////////////////////////////////////////////////////////
// Experimental AP_Limits library - set constraints, limits, fences, minima, maxima on various parameters
////////////////////////////////////////////////////////////////////////////////
#ifdef AP_LIMITS
2012-08-21 23:19:50 -03:00
// AP_Limits modules are stored as a _linked list_. That allows us to define an infinite number of modules
// and also to allocate no space until we actually need to.
2012-08-21 23:19:50 -03:00
// The linked list looks (logically) like this
// [limits module] -> [first limit module] -> [second limit module] -> [third limit module] -> NULL
2012-08-21 23:19:50 -03:00
// The details of the linked list are handled by the methods
// modules_first, modules_current, modules_next, modules_last, modules_add
// in limits
2012-08-21 23:19:50 -03:00
limits.modules_add(&gpslock_limit);
limits.modules_add(&geofence_limit);
limits.modules_add(&altitude_limit);
2012-08-21 23:19:50 -03:00
if (limits.debug()) {
gcs_send_text_P(SEVERITY_LOW,PSTR("Limits Modules Loaded"));
2012-08-21 23:19:50 -03:00
AP_Limit_Module *m = limits.modules_first();
while (m) {
gcs_send_text_P(SEVERITY_LOW, get_module_name(m->get_module_id()));
m = limits.modules_next();
}
}
#endif
cliSerial->print_P(PSTR("\nReady to FLY "));
}
//********************************************************************************
//This function does all the calibrations, etc. that we need during a ground start
//********************************************************************************
static void startup_ground(void)
{
2012-08-21 23:19:50 -03:00
gcs_send_text_P(SEVERITY_LOW,PSTR("GROUND START"));
2012-08-21 23:19:50 -03:00
// Warm up and read Gyro offsets
// -----------------------------
2012-12-14 00:12:39 -04:00
ins.init(AP_InertialSensor::COLD_START,
ins_sample_rate,
mavlink_delay, flash_leds, &timer_scheduler);
2012-08-21 23:19:50 -03:00
#if CLI_ENABLED == ENABLED
report_ins();
2012-08-21 23:19:50 -03:00
#endif
// initialise ahrs (may push imu calibration into the mpu6000 if using that device).
ahrs.init(&timer_scheduler);
// setup fast AHRS gains to get right attitude
ahrs.set_fast_gains(true);
#if SECONDARY_DMP_ENABLED == ENABLED
ahrs2.init(&timer_scheduler);
ahrs2.set_as_secondary(true);
ahrs2.set_fast_gains(true);
#endif
2012-08-21 23:19:50 -03:00
// reset the leds
// ---------------------------
clear_leds();
// when we re-calibrate the gyros,
// all previous I values are invalid
reset_I_all();
}
// set_mode - change flight mode and perform any necessary initialisation
2012-08-21 23:19:50 -03:00
static void set_mode(byte mode)
{
// Switch to stabilize mode if requested mode requires a GPS lock
if(!ap.home_is_set) {
if (mode > ALT_HOLD && mode != TOY_A && mode != TOY_M && mode != OF_LOITER && mode != LAND) {
2012-08-21 23:19:50 -03:00
mode = STABILIZE;
}
}
// Switch to stabilize if OF_LOITER requested but no optical flow sensor
if (mode == OF_LOITER && !g.optflow_enabled ) {
mode = STABILIZE;
2012-08-21 23:19:50 -03:00
}
2012-12-14 00:12:39 -04:00
control_mode = mode;
control_mode = constrain(control_mode, 0, NUM_MODES - 1);
2012-08-21 23:19:50 -03:00
// used to stop fly_aways
// set to false if we have low throttle
motors.auto_armed(g.rc_3.control_in > 0);
2012-11-10 01:55:51 -04:00
set_auto_armed(g.rc_3.control_in > 0);
2012-08-21 23:19:50 -03:00
// if we change modes, we must clear landed flag
2012-11-10 01:55:51 -04:00
set_land_complete(false);
2012-08-21 23:19:50 -03:00
// debug to Serial terminal
//cliSerial->println(flight_mode_strings[control_mode]);
2012-08-21 23:19:50 -03:00
2012-11-10 01:55:51 -04:00
ap.loiter_override = false;
2012-08-21 23:19:50 -03:00
// report the GPS and Motor arming status
led_mode = NORMAL_LEDS;
switch(control_mode)
{
case ACRO:
2012-11-10 01:55:51 -04:00
ap.manual_throttle = true;
ap.manual_attitude = true;
set_yaw_mode(YAW_ACRO);
set_roll_pitch_mode(ROLL_PITCH_ACRO);
set_throttle_mode(THROTTLE_MANUAL);
// reset acro axis targets to current attitude
2012-11-10 01:55:51 -04:00
if(g.axis_enabled){
2012-10-27 18:13:46 -03:00
roll_axis = ahrs.roll_sensor;
pitch_axis = ahrs.pitch_sensor;
nav_yaw = ahrs.yaw_sensor;
}
2012-08-21 23:19:50 -03:00
break;
case STABILIZE:
2012-11-10 01:55:51 -04:00
ap.manual_throttle = true;
ap.manual_attitude = true;
set_yaw_mode(YAW_HOLD);
set_roll_pitch_mode(ROLL_PITCH_STABLE);
set_throttle_mode(STABILIZE_THROTTLE);
2012-08-21 23:19:50 -03:00
break;
case ALT_HOLD:
2012-11-10 01:55:51 -04:00
ap.manual_throttle = false;
ap.manual_attitude = true;
set_yaw_mode(ALT_HOLD_YAW);
set_roll_pitch_mode(ALT_HOLD_RP);
set_throttle_mode(ALT_HOLD_THR);
2012-08-21 23:19:50 -03:00
break;
case AUTO:
2012-11-10 01:55:51 -04:00
ap.manual_throttle = false;
ap.manual_attitude = false;
set_yaw_mode(AUTO_YAW);
set_roll_pitch_mode(AUTO_RP);
set_throttle_mode(AUTO_THR);
2012-08-21 23:19:50 -03:00
// loads the commands from where we left off
init_commands();
break;
case CIRCLE:
2012-11-10 01:55:51 -04:00
ap.manual_throttle = false;
ap.manual_attitude = false;
// start circling around current location
2012-08-21 23:19:50 -03:00
set_next_WP(&current_loc);
2012-10-27 18:13:46 -03:00
circle_WP = next_WP;
// set yaw to point to center of circle
yaw_look_at_WP = circle_WP;
set_yaw_mode(YAW_LOOK_AT_LOCATION);
set_roll_pitch_mode(CIRCLE_RP);
set_throttle_mode(CIRCLE_THR);
2012-08-21 23:19:50 -03:00
circle_angle = 0;
break;
case LOITER:
2012-11-10 01:55:51 -04:00
ap.manual_throttle = false;
ap.manual_attitude = false;
set_yaw_mode(LOITER_YAW);
set_roll_pitch_mode(LOITER_RP);
set_throttle_mode(LOITER_THR);
2012-08-21 23:19:50 -03:00
set_next_WP(&current_loc);
break;
case POSITION:
2012-11-10 01:55:51 -04:00
ap.manual_throttle = true;
ap.manual_attitude = false;
set_yaw_mode(YAW_HOLD);
set_roll_pitch_mode(ROLL_PITCH_AUTO);
set_throttle_mode(THROTTLE_MANUAL);
2012-08-21 23:19:50 -03:00
set_next_WP(&current_loc);
break;
case GUIDED:
2012-11-10 01:55:51 -04:00
ap.manual_throttle = false;
ap.manual_attitude = false;
set_yaw_mode(YAW_LOOK_AT_NEXT_WP);
set_roll_pitch_mode(ROLL_PITCH_AUTO);
set_throttle_mode(THROTTLE_AUTO);
next_WP = current_loc;
2012-08-21 23:19:50 -03:00
set_next_WP(&guided_WP);
break;
case LAND:
if( ap.home_is_set ) {
// switch to loiter if we have gps
ap.manual_attitude = false;
set_yaw_mode(LOITER_YAW);
set_roll_pitch_mode(LOITER_RP);
}else{
// otherwise remain with stabilize roll and pitch
ap.manual_attitude = true;
set_yaw_mode(YAW_HOLD);
set_roll_pitch_mode(ROLL_PITCH_STABLE);
}
2012-11-10 01:55:51 -04:00
ap.manual_throttle = false;
2012-08-21 23:19:50 -03:00
do_land();
break;
case RTL:
2012-11-10 01:55:51 -04:00
ap.manual_throttle = false;
ap.manual_attitude = false;
do_RTL();
2012-08-21 23:19:50 -03:00
break;
case OF_LOITER:
2012-11-10 01:55:51 -04:00
ap.manual_throttle = false;
ap.manual_attitude = false;
set_yaw_mode(OF_LOITER_YAW);
set_roll_pitch_mode(OF_LOITER_RP);
set_throttle_mode(OF_LOITER_THR);
2012-08-21 23:19:50 -03:00
set_next_WP(&current_loc);
break;
// THOR
// These are the flight modes for Toy mode
// See the defines for the enumerated values
case TOY_A:
2012-11-10 01:55:51 -04:00
ap.manual_throttle = false;
ap.manual_attitude = true;
set_yaw_mode(YAW_TOY);
set_roll_pitch_mode(ROLL_PITCH_TOY);
set_throttle_mode(THROTTLE_AUTO);
2012-11-10 01:55:51 -04:00
wp_control = NO_NAV_MODE;
2012-08-21 23:19:50 -03:00
// save throttle for fast exit of Alt hold
saved_toy_throttle = g.rc_3.control_in;
break;
case TOY_M:
2012-11-10 01:55:51 -04:00
ap.manual_throttle = false;
ap.manual_attitude = true;
set_yaw_mode(YAW_TOY);
set_roll_pitch_mode(ROLL_PITCH_TOY);
2012-11-10 01:55:51 -04:00
wp_control = NO_NAV_MODE;
set_throttle_mode(THROTTLE_HOLD);
2012-08-21 23:19:50 -03:00
break;
default:
break;
}
2012-11-10 01:55:51 -04:00
if(ap.failsafe) {
2012-08-21 23:19:50 -03:00
// this is to allow us to fly home without interactive throttle control
set_throttle_mode(THROTTLE_AUTO);
2012-11-10 01:55:51 -04:00
ap.manual_throttle = false;
2012-08-21 23:19:50 -03:00
// does not wait for us to be in high throttle, since the
// Receiver will be outputting low throttle
motors.auto_armed(true);
2012-11-10 01:55:51 -04:00
set_auto_armed(true);
2012-08-21 23:19:50 -03:00
}
2012-11-10 01:55:51 -04:00
if(ap.manual_attitude) {
2012-08-21 23:19:50 -03:00
// We are under manual attitude control
// remove the navigation from roll and pitch command
reset_nav_params();
// remove the wind compenstaion
reset_wind_I();
}
Log_Write_Mode(control_mode);
}
static void
init_simple_bearing()
{
2012-08-21 23:19:50 -03:00
initial_simple_bearing = ahrs.yaw_sensor;
2012-11-10 01:55:51 -04:00
Log_Write_Data(DATA_INIT_SIMPLE_BEARING, initial_simple_bearing);
}
#if CLI_SLIDER_ENABLED == ENABLED && CLI_ENABLED == ENABLED
static boolean
check_startup_for_CLI()
{
return (digitalReadFast(SLIDE_SWITCH_PIN) == 0);
}
#endif // CLI_ENABLED
/*
2012-08-21 23:19:50 -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 1: return 1200;
case 2: return 2400;
case 4: return 4800;
case 9: return 9600;
case 19: return 19200;
case 38: return 38400;
case 57: return 57600;
case 111: return 111100;
case 115: return 115200;
}
//cliSerial->println_P(PSTR("Invalid SERIAL3_BAUD"));
return default_baud;
}
#if USB_MUX_PIN > 0
static void check_usb_mux(void)
{
bool usb_check = !digitalReadFast(USB_MUX_PIN);
if (usb_check == ap_system.usb_connected) {
return;
}
// the user has switched to/from the telemetry port
ap_system.usb_connected = usb_check;
if (ap_system.usb_connected) {
cliSerial->begin(SERIAL0_BAUD);
} else {
cliSerial->begin(map_baudrate(g.serial3_baud, SERIAL3_BAUD));
}
}
#endif
/*
2012-08-21 23:19:50 -03:00
* called by gyro/accel init to flash LEDs so user
* has some mesmerising lights to watch while waiting
*/
void flash_leds(bool on)
{
2012-08-21 23:19:50 -03:00
digitalWrite(A_LED_PIN, on ? LED_OFF : LED_ON);
digitalWrite(C_LED_PIN, on ? LED_ON : LED_OFF);
}
2012-03-01 08:36:51 -04:00
#ifndef DESKTOP_BUILD
/*
* Read Vcc vs 1.1v internal reference
*/
uint16_t board_voltage(void)
{
static AP_AnalogSource_Arduino vcc(ANALOG_PIN_VCC);
return vcc.read_vcc();
2012-03-01 08:36:51 -04:00
}
#endif
/*
force a software reset of the APM
*/
static void reboot_apm(void)
{
cliSerial->printf_P(PSTR("REBOOTING\n"));
delay(100); // let serial flush
// see http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1250663814/
// for the method
#if CONFIG_APM_HARDWARE == APM_HARDWARE_APM2
// this relies on the bootloader resetting the watchdog, which
// APM1 doesn't do
cli();
wdt_enable(WDTO_15MS);
#else
// this works on APM1
void (*fn)(void) = NULL;
fn();
#endif
while (1);
}
//
// print_flight_mode - prints flight mode to serial port.
//
static void
print_flight_mode(uint8_t mode)
{
switch (mode) {
case STABILIZE:
cliSerial->print_P(PSTR("STABILIZE"));
break;
case ACRO:
cliSerial->print_P(PSTR("ACRO"));
break;
case ALT_HOLD:
cliSerial->print_P(PSTR("ALT_HOLD"));
break;
case AUTO:
cliSerial->print_P(PSTR("AUTO"));
break;
case GUIDED:
cliSerial->print_P(PSTR("GUIDED"));
break;
case LOITER:
cliSerial->print_P(PSTR("LOITER"));
break;
case RTL:
cliSerial->print_P(PSTR("RTL"));
break;
case CIRCLE:
cliSerial->print_P(PSTR("CIRCLE"));
break;
case POSITION:
cliSerial->print_P(PSTR("POSITION"));
break;
case LAND:
cliSerial->print_P(PSTR("LAND"));
break;
case OF_LOITER:
cliSerial->print_P(PSTR("OF_LOITER"));
break;
case TOY_M:
cliSerial->print_P(PSTR("TOY_M"));
break;
case TOY_A:
cliSerial->print_P(PSTR("TOY_A"));
break;
default:
cliSerial->print_P(PSTR("---"));
break;
}
}