2011-09-08 22:29:39 -03:00
|
|
|
// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
|
|
|
#if CLI_ENABLED == ENABLED
|
|
|
|
|
|
|
|
// Functions called from the setup menu
|
2012-08-21 23:19:51 -03:00
|
|
|
static int8_t setup_radio (uint8_t argc, const Menu::arg *argv);
|
|
|
|
static int8_t setup_show (uint8_t argc, const Menu::arg *argv);
|
|
|
|
static int8_t setup_factory (uint8_t argc, const Menu::arg *argv);
|
|
|
|
static int8_t setup_flightmodes (uint8_t argc, const Menu::arg *argv);
|
|
|
|
static int8_t setup_level (uint8_t argc, const Menu::arg *argv);
|
|
|
|
static int8_t setup_erase (uint8_t argc, const Menu::arg *argv);
|
|
|
|
static int8_t setup_compass (uint8_t argc, const Menu::arg *argv);
|
|
|
|
static int8_t setup_declination (uint8_t argc, const Menu::arg *argv);
|
|
|
|
static int8_t setup_batt_monitor (uint8_t argc, const Menu::arg *argv);
|
2011-09-08 22:29:39 -03:00
|
|
|
|
|
|
|
// Command/function table for the setup menu
|
|
|
|
static const struct Menu::command setup_menu_commands[] PROGMEM = {
|
2012-08-21 23:19:51 -03:00
|
|
|
// command function called
|
|
|
|
// ======= ===============
|
|
|
|
{"reset", setup_factory},
|
|
|
|
{"radio", setup_radio},
|
|
|
|
{"modes", setup_flightmodes},
|
|
|
|
{"level", setup_level},
|
|
|
|
{"compass", setup_compass},
|
|
|
|
{"declination", setup_declination},
|
|
|
|
{"battery", setup_batt_monitor},
|
|
|
|
{"show", setup_show},
|
|
|
|
{"erase", setup_erase},
|
2011-09-08 22:29:39 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
// Create the setup menu object.
|
|
|
|
MENU(setup_menu, "setup", setup_menu_commands);
|
|
|
|
|
|
|
|
// Called from the top-level menu to run the setup menu.
|
|
|
|
static int8_t
|
|
|
|
setup_mode(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2012-08-21 23:19:51 -03:00
|
|
|
// Give the user some guidance
|
|
|
|
Serial.printf_P(PSTR("Setup Mode\n"
|
|
|
|
"\n"
|
|
|
|
"IMPORTANT: if you have not previously set this system up, use the\n"
|
|
|
|
"'reset' command to initialize the EEPROM to sensible default values\n"
|
|
|
|
"and then the 'radio' command to configure for your radio.\n"
|
|
|
|
"\n"));
|
|
|
|
|
|
|
|
// Run the setup menu. When the menu exits, we will return to the main menu.
|
|
|
|
setup_menu.run();
|
2011-09-08 22:29:39 -03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Print the current configuration.
|
|
|
|
// Called by the setup menu 'show' command.
|
|
|
|
static int8_t
|
|
|
|
setup_show(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2012-08-21 23:19:51 -03:00
|
|
|
// clear the area
|
|
|
|
print_blanks(8);
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
report_radio();
|
|
|
|
report_batt_monitor();
|
|
|
|
report_gains();
|
|
|
|
report_xtrack();
|
|
|
|
report_throttle();
|
|
|
|
report_flight_modes();
|
|
|
|
report_imu();
|
|
|
|
report_compass();
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
Serial.printf_P(PSTR("Raw Values\n"));
|
|
|
|
print_divider();
|
2012-02-12 04:21:22 -04:00
|
|
|
|
2012-02-12 19:16:55 -04:00
|
|
|
AP_Param::show_all();
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
return(0);
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Initialise the EEPROM to 'factory' settings (mostly defined in APM_Config.h or via defaults).
|
|
|
|
// Called by the setup menu 'factoryreset' command.
|
|
|
|
static int8_t
|
|
|
|
setup_factory(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2012-08-21 23:19:51 -03:00
|
|
|
int c;
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
Serial.printf_P(PSTR("\nType 'Y' and hit Enter to perform factory reset, any other key to abort: "));
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
do {
|
|
|
|
c = Serial.read();
|
|
|
|
} while (-1 == c);
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
if (('y' != c) && ('Y' != c))
|
|
|
|
return(-1);
|
|
|
|
AP_Param::erase_all();
|
|
|
|
Serial.printf_P(PSTR("\nFACTORY RESET complete - please reset APM to continue"));
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
//default_flight_modes(); // This will not work here. Replacement code located in init_ardupilot()
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
for (;; ) {
|
|
|
|
}
|
|
|
|
// note, cannot actually return here
|
|
|
|
return(0);
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Perform radio setup.
|
|
|
|
// Called by the setup menu 'radio' command.
|
|
|
|
static int8_t
|
|
|
|
setup_radio(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2012-08-21 23:19:51 -03:00
|
|
|
Serial.printf_P(PSTR("\n\nRadio Setup:\n"));
|
|
|
|
uint8_t i;
|
|
|
|
|
|
|
|
for(i = 0; i < 100; i++) {
|
|
|
|
delay(20);
|
|
|
|
read_radio();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(g.channel_roll.radio_in < 500) {
|
|
|
|
while(1) {
|
|
|
|
Serial.printf_P(PSTR("\nNo radio; Check connectors."));
|
|
|
|
delay(1000);
|
|
|
|
// stop here
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g.channel_roll.radio_min = g.channel_roll.radio_in;
|
|
|
|
g.channel_pitch.radio_min = g.channel_pitch.radio_in;
|
|
|
|
g.channel_throttle.radio_min = g.channel_throttle.radio_in;
|
|
|
|
g.channel_rudder.radio_min = g.channel_rudder.radio_in;
|
|
|
|
g.rc_5.radio_min = g.rc_5.radio_in;
|
|
|
|
g.rc_6.radio_min = g.rc_6.radio_in;
|
|
|
|
g.rc_7.radio_min = g.rc_7.radio_in;
|
|
|
|
g.rc_8.radio_min = g.rc_8.radio_in;
|
|
|
|
|
|
|
|
g.channel_roll.radio_max = g.channel_roll.radio_in;
|
|
|
|
g.channel_pitch.radio_max = g.channel_pitch.radio_in;
|
|
|
|
g.channel_throttle.radio_max = g.channel_throttle.radio_in;
|
|
|
|
g.channel_rudder.radio_max = g.channel_rudder.radio_in;
|
|
|
|
g.rc_5.radio_max = g.rc_5.radio_in;
|
|
|
|
g.rc_6.radio_max = g.rc_6.radio_in;
|
|
|
|
g.rc_7.radio_max = g.rc_7.radio_in;
|
|
|
|
g.rc_8.radio_max = g.rc_8.radio_in;
|
|
|
|
|
|
|
|
g.channel_roll.radio_trim = g.channel_roll.radio_in;
|
|
|
|
g.channel_pitch.radio_trim = g.channel_pitch.radio_in;
|
|
|
|
g.channel_rudder.radio_trim = g.channel_rudder.radio_in;
|
|
|
|
g.rc_5.radio_trim = 1500;
|
|
|
|
g.rc_6.radio_trim = 1500;
|
|
|
|
g.rc_7.radio_trim = 1500;
|
|
|
|
g.rc_8.radio_trim = 1500;
|
|
|
|
|
|
|
|
Serial.printf_P(PSTR("\nMove all controls to each extreme. Hit Enter to save: \n"));
|
|
|
|
while(1) {
|
|
|
|
|
|
|
|
delay(20);
|
|
|
|
// Filters radio input - adjust filters in the radio.pde file
|
|
|
|
// ----------------------------------------------------------
|
|
|
|
read_radio();
|
|
|
|
|
|
|
|
g.channel_roll.update_min_max();
|
|
|
|
g.channel_pitch.update_min_max();
|
|
|
|
g.channel_throttle.update_min_max();
|
|
|
|
g.channel_rudder.update_min_max();
|
|
|
|
g.rc_5.update_min_max();
|
|
|
|
g.rc_6.update_min_max();
|
|
|
|
g.rc_7.update_min_max();
|
|
|
|
g.rc_8.update_min_max();
|
|
|
|
|
|
|
|
if(Serial.available() > 0) {
|
|
|
|
Serial.flush();
|
|
|
|
g.channel_roll.save_eeprom();
|
|
|
|
g.channel_pitch.save_eeprom();
|
|
|
|
g.channel_throttle.save_eeprom();
|
|
|
|
g.channel_rudder.save_eeprom();
|
|
|
|
g.rc_5.save_eeprom();
|
|
|
|
g.rc_6.save_eeprom();
|
|
|
|
g.rc_7.save_eeprom();
|
|
|
|
g.rc_8.save_eeprom();
|
|
|
|
print_done();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
trim_radio();
|
|
|
|
report_radio();
|
|
|
|
return(0);
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int8_t
|
|
|
|
setup_flightmodes(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2012-08-21 23:19:51 -03:00
|
|
|
byte switchPosition, mode = 0;
|
|
|
|
|
|
|
|
Serial.printf_P(PSTR("\nMove RC toggle switch to each position to edit, move aileron stick to select modes."));
|
|
|
|
print_hit_enter();
|
|
|
|
trim_radio();
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
delay(20);
|
|
|
|
read_radio();
|
|
|
|
switchPosition = readSwitch();
|
|
|
|
|
|
|
|
|
|
|
|
// look for control switch change
|
|
|
|
if (oldSwitchPosition != switchPosition) {
|
|
|
|
// force position 5 to MANUAL
|
|
|
|
if (switchPosition > 4) {
|
|
|
|
flight_modes[switchPosition] = MANUAL;
|
|
|
|
}
|
|
|
|
// update our current mode
|
|
|
|
mode = flight_modes[switchPosition];
|
|
|
|
|
|
|
|
// update the user
|
|
|
|
print_switch(switchPosition, mode);
|
|
|
|
|
|
|
|
// Remember switch position
|
|
|
|
oldSwitchPosition = switchPosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
// look for stick input
|
|
|
|
int16_t radioInputSwitch = radio_input_switch();
|
|
|
|
|
|
|
|
if (radioInputSwitch != 0) {
|
|
|
|
|
|
|
|
mode += radioInputSwitch;
|
|
|
|
|
|
|
|
while (
|
|
|
|
mode != MANUAL &&
|
|
|
|
mode != CIRCLE &&
|
|
|
|
mode != STABILIZE &&
|
|
|
|
mode != FLY_BY_WIRE_A &&
|
|
|
|
mode != FLY_BY_WIRE_B &&
|
|
|
|
mode != AUTO &&
|
|
|
|
mode != RTL &&
|
|
|
|
mode != LOITER)
|
|
|
|
{
|
|
|
|
if (mode < MANUAL)
|
|
|
|
mode = LOITER;
|
|
|
|
else if (mode >LOITER)
|
|
|
|
mode = MANUAL;
|
|
|
|
else
|
|
|
|
mode += radioInputSwitch;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Override position 5
|
|
|
|
if(switchPosition > 4)
|
|
|
|
mode = MANUAL;
|
|
|
|
|
|
|
|
// save new mode
|
|
|
|
flight_modes[switchPosition] = mode;
|
|
|
|
|
|
|
|
// print new mode
|
|
|
|
print_switch(switchPosition, mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
// escape hatch
|
|
|
|
if(Serial.available() > 0) {
|
|
|
|
// save changes
|
2011-09-08 22:29:39 -03:00
|
|
|
for (mode=0; mode<6; mode++)
|
|
|
|
flight_modes[mode].save();
|
2012-08-21 23:19:51 -03:00
|
|
|
report_flight_modes();
|
|
|
|
print_done();
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int8_t
|
|
|
|
setup_declination(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2012-08-21 23:19:51 -03:00
|
|
|
compass.set_declination(radians(argv[1].f));
|
|
|
|
report_compass();
|
2011-09-08 22:29:39 -03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int8_t
|
|
|
|
setup_erase(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2012-08-21 23:19:51 -03:00
|
|
|
int c;
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
Serial.printf_P(PSTR("\nType 'Y' and hit Enter to erase all waypoint and parameter data, any other key to abort: "));
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
do {
|
|
|
|
c = Serial.read();
|
|
|
|
} while (-1 == c);
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
if (('y' != c) && ('Y' != c))
|
|
|
|
return(-1);
|
|
|
|
zero_eeprom();
|
|
|
|
return 0;
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
2012-06-12 03:01:25 -03:00
|
|
|
static int8_t
|
|
|
|
setup_level(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2012-08-21 23:19:51 -03:00
|
|
|
startup_IMU_ground(true);
|
|
|
|
return 0;
|
2012-06-12 03:01:25 -03:00
|
|
|
}
|
|
|
|
|
2011-09-08 22:29:39 -03:00
|
|
|
static int8_t
|
|
|
|
setup_compass(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2012-08-21 23:19:51 -03:00
|
|
|
if (!strcmp_P(argv[1].str, PSTR("on"))) {
|
|
|
|
compass.set_orientation(MAG_ORIENTATION); // set compass's orientation on aircraft
|
|
|
|
if (!compass.init()) {
|
2011-09-08 22:29:39 -03:00
|
|
|
Serial.println_P(PSTR("Compass initialisation failed!"));
|
|
|
|
g.compass_enabled = false;
|
|
|
|
} else {
|
|
|
|
g.compass_enabled = true;
|
|
|
|
}
|
2012-08-21 23:19:51 -03:00
|
|
|
} else if (!strcmp_P(argv[1].str, PSTR("off"))) {
|
|
|
|
g.compass_enabled = false;
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
} else if (!strcmp_P(argv[1].str, PSTR("reset"))) {
|
|
|
|
compass.set_offsets(0,0,0);
|
2012-01-15 19:15:08 -04:00
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
} else {
|
|
|
|
Serial.printf_P(PSTR("\nOptions:[on,off,reset]\n"));
|
|
|
|
report_compass();
|
|
|
|
return 0;
|
|
|
|
}
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
g.compass_enabled.save();
|
|
|
|
report_compass();
|
|
|
|
return 0;
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int8_t
|
|
|
|
setup_batt_monitor(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2012-08-21 23:19:51 -03:00
|
|
|
if(argv[1].i >= 0 && argv[1].i <= 4) {
|
|
|
|
g.battery_monitoring.set_and_save(argv[1].i);
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
} else {
|
|
|
|
Serial.printf_P(PSTR("\nOptions: 3-4"));
|
|
|
|
}
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
report_batt_monitor();
|
|
|
|
return 0;
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
// CLI reports
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
|
|
static void report_batt_monitor()
|
|
|
|
{
|
2012-08-21 23:19:51 -03:00
|
|
|
//print_blanks(2);
|
|
|
|
Serial.printf_P(PSTR("Batt Mointor\n"));
|
|
|
|
print_divider();
|
|
|
|
if(g.battery_monitoring == 0) Serial.printf_P(PSTR("Batt monitoring disabled"));
|
|
|
|
if(g.battery_monitoring == 3) Serial.printf_P(PSTR("Monitoring batt volts"));
|
|
|
|
if(g.battery_monitoring == 4) Serial.printf_P(PSTR("Monitoring volts and current"));
|
|
|
|
print_blanks(2);
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
static void report_radio()
|
|
|
|
{
|
2012-08-21 23:19:51 -03:00
|
|
|
//print_blanks(2);
|
|
|
|
Serial.printf_P(PSTR("Radio\n"));
|
|
|
|
print_divider();
|
|
|
|
// radio
|
|
|
|
print_radio_values();
|
|
|
|
print_blanks(2);
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void report_gains()
|
|
|
|
{
|
2012-08-21 23:19:51 -03:00
|
|
|
//print_blanks(2);
|
|
|
|
Serial.printf_P(PSTR("Gains\n"));
|
|
|
|
print_divider();
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2012-08-21 23:34:40 -03:00
|
|
|
#if APM_CONTROL == DISABLED
|
|
|
|
Serial.printf_P(PSTR("servo roll:\n"));
|
|
|
|
print_PID(&g.pidServoRoll);
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
Serial.printf_P(PSTR("servo pitch:\n"));
|
|
|
|
print_PID(&g.pidServoPitch);
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2012-08-21 23:34:40 -03:00
|
|
|
Serial.printf_P(PSTR("servo rudder:\n"));
|
|
|
|
print_PID(&g.pidServoRudder);
|
|
|
|
#endif
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
Serial.printf_P(PSTR("nav roll:\n"));
|
|
|
|
print_PID(&g.pidNavRoll);
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
Serial.printf_P(PSTR("nav pitch airspeed:\n"));
|
|
|
|
print_PID(&g.pidNavPitchAirspeed);
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
Serial.printf_P(PSTR("energry throttle:\n"));
|
|
|
|
print_PID(&g.pidTeThrottle);
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
Serial.printf_P(PSTR("nav pitch alt:\n"));
|
|
|
|
print_PID(&g.pidNavPitchAltitude);
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
print_blanks(2);
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void report_xtrack()
|
|
|
|
{
|
2012-08-21 23:19:51 -03:00
|
|
|
//print_blanks(2);
|
|
|
|
Serial.printf_P(PSTR("Crosstrack\n"));
|
|
|
|
print_divider();
|
|
|
|
// radio
|
|
|
|
Serial.printf_P(PSTR("XTRACK: %4.2f\n"
|
|
|
|
"XTRACK angle: %d\n"),
|
|
|
|
(float)g.crosstrack_gain,
|
|
|
|
(int)g.crosstrack_entry_angle);
|
|
|
|
print_blanks(2);
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void report_throttle()
|
|
|
|
{
|
2012-08-21 23:19:51 -03:00
|
|
|
//print_blanks(2);
|
|
|
|
Serial.printf_P(PSTR("Throttle\n"));
|
|
|
|
print_divider();
|
|
|
|
|
|
|
|
Serial.printf_P(PSTR("min: %d\n"
|
|
|
|
"max: %d\n"
|
|
|
|
"cruise: %d\n"
|
|
|
|
"failsafe_enabled: %d\n"
|
|
|
|
"failsafe_value: %d\n"),
|
|
|
|
(int)g.throttle_min,
|
|
|
|
(int)g.throttle_max,
|
|
|
|
(int)g.throttle_cruise,
|
|
|
|
(int)g.throttle_fs_enabled,
|
|
|
|
(int)g.throttle_fs_value);
|
|
|
|
print_blanks(2);
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void report_imu()
|
|
|
|
{
|
2012-08-21 23:19:51 -03:00
|
|
|
//print_blanks(2);
|
|
|
|
Serial.printf_P(PSTR("IMU\n"));
|
|
|
|
print_divider();
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
print_gyro_offsets();
|
|
|
|
print_accel_offsets();
|
|
|
|
print_blanks(2);
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void report_compass()
|
|
|
|
{
|
2012-08-21 23:19:51 -03:00
|
|
|
//print_blanks(2);
|
|
|
|
Serial.printf_P(PSTR("Compass: "));
|
2011-09-08 22:29:39 -03:00
|
|
|
|
|
|
|
switch (compass.product_id) {
|
|
|
|
case AP_COMPASS_TYPE_HMC5883L:
|
|
|
|
Serial.println_P(PSTR("HMC5883L"));
|
|
|
|
break;
|
|
|
|
case AP_COMPASS_TYPE_HMC5843:
|
|
|
|
Serial.println_P(PSTR("HMC5843"));
|
|
|
|
break;
|
|
|
|
case AP_COMPASS_TYPE_HIL:
|
|
|
|
Serial.println_P(PSTR("HIL"));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Serial.println_P(PSTR("??"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
print_divider();
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
print_enabled(g.compass_enabled);
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
// mag declination
|
|
|
|
Serial.printf_P(PSTR("Mag Declination: %4.4f\n"),
|
|
|
|
degrees(compass.get_declination()));
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
Vector3f offsets = compass.get_offsets();
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
// mag offsets
|
|
|
|
Serial.printf_P(PSTR("Mag offsets: %4.4f, %4.4f, %4.4f\n"),
|
|
|
|
offsets.x,
|
|
|
|
offsets.y,
|
|
|
|
offsets.z);
|
|
|
|
print_blanks(2);
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void report_flight_modes()
|
|
|
|
{
|
2012-08-21 23:19:51 -03:00
|
|
|
//print_blanks(2);
|
|
|
|
Serial.printf_P(PSTR("Flight modes\n"));
|
|
|
|
print_divider();
|
|
|
|
|
|
|
|
for(int16_t i = 0; i < 6; i++ ) {
|
|
|
|
print_switch(i, flight_modes[i]);
|
|
|
|
}
|
|
|
|
print_blanks(2);
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
// CLI utilities
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_PID(PID * pid)
|
|
|
|
{
|
2012-08-21 23:19:51 -03:00
|
|
|
Serial.printf_P(PSTR("P: %4.3f, I:%4.3f, D:%4.3f, IMAX:%ld\n"),
|
|
|
|
pid->kP(),
|
|
|
|
pid->kI(),
|
|
|
|
pid->kD(),
|
|
|
|
(long)pid->imax());
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_radio_values()
|
|
|
|
{
|
2012-08-21 23:19:51 -03:00
|
|
|
Serial.printf_P(PSTR("CH1: %d | %d | %d\n"), (int)g.channel_roll.radio_min, (int)g.channel_roll.radio_trim, (int)g.channel_roll.radio_max);
|
|
|
|
Serial.printf_P(PSTR("CH2: %d | %d | %d\n"), (int)g.channel_pitch.radio_min, (int)g.channel_pitch.radio_trim, (int)g.channel_pitch.radio_max);
|
|
|
|
Serial.printf_P(PSTR("CH3: %d | %d | %d\n"), (int)g.channel_throttle.radio_min, (int)g.channel_throttle.radio_trim, (int)g.channel_throttle.radio_max);
|
|
|
|
Serial.printf_P(PSTR("CH4: %d | %d | %d\n"), (int)g.channel_rudder.radio_min, (int)g.channel_rudder.radio_trim, (int)g.channel_rudder.radio_max);
|
|
|
|
Serial.printf_P(PSTR("CH5: %d | %d | %d\n"), (int)g.rc_5.radio_min, (int)g.rc_5.radio_trim, (int)g.rc_5.radio_max);
|
|
|
|
Serial.printf_P(PSTR("CH6: %d | %d | %d\n"), (int)g.rc_6.radio_min, (int)g.rc_6.radio_trim, (int)g.rc_6.radio_max);
|
|
|
|
Serial.printf_P(PSTR("CH7: %d | %d | %d\n"), (int)g.rc_7.radio_min, (int)g.rc_7.radio_trim, (int)g.rc_7.radio_max);
|
|
|
|
Serial.printf_P(PSTR("CH8: %d | %d | %d\n"), (int)g.rc_8.radio_min, (int)g.rc_8.radio_trim, (int)g.rc_8.radio_max);
|
2011-09-08 22:29:39 -03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_switch(byte p, byte m)
|
|
|
|
{
|
2012-08-21 23:19:51 -03:00
|
|
|
Serial.printf_P(PSTR("Pos %d: "),p);
|
2012-09-18 00:38:56 -03:00
|
|
|
print_flight_mode(m);
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_done()
|
|
|
|
{
|
2012-08-21 23:19:51 -03:00
|
|
|
Serial.printf_P(PSTR("\nSaved Settings\n\n"));
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-08-18 06:26:13 -03:00
|
|
|
print_blanks(int16_t num)
|
2011-09-08 22:29:39 -03:00
|
|
|
{
|
2012-08-21 23:19:51 -03:00
|
|
|
while(num > 0) {
|
|
|
|
num--;
|
|
|
|
Serial.println("");
|
|
|
|
}
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_divider(void)
|
|
|
|
{
|
2012-08-21 23:19:51 -03:00
|
|
|
for (int16_t i = 0; i < 40; i++) {
|
|
|
|
Serial.printf_P(PSTR("-"));
|
|
|
|
}
|
|
|
|
Serial.println("");
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int8_t
|
|
|
|
radio_input_switch(void)
|
|
|
|
{
|
2012-08-21 23:19:51 -03:00
|
|
|
static int8_t bouncer = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (int16_t(g.channel_roll.radio_in - g.channel_roll.radio_trim) > 100) {
|
|
|
|
bouncer = 10;
|
|
|
|
}
|
|
|
|
if (int16_t(g.channel_roll.radio_in - g.channel_roll.radio_trim) < -100) {
|
|
|
|
bouncer = -10;
|
|
|
|
}
|
|
|
|
if (bouncer >0) {
|
|
|
|
bouncer--;
|
|
|
|
}
|
|
|
|
if (bouncer <0) {
|
|
|
|
bouncer++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bouncer == 1 || bouncer == -1) {
|
|
|
|
return bouncer;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void zero_eeprom(void)
|
|
|
|
{
|
2012-08-21 23:19:51 -03:00
|
|
|
byte b = 0;
|
|
|
|
Serial.printf_P(PSTR("\nErasing EEPROM\n"));
|
|
|
|
for (intptr_t i = 0; i < EEPROM_MAX_ADDR; i++) {
|
|
|
|
eeprom_write_byte((uint8_t *) i, b);
|
|
|
|
}
|
|
|
|
Serial.printf_P(PSTR("done\n"));
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void print_enabled(bool b)
|
|
|
|
{
|
2012-08-21 23:19:51 -03:00
|
|
|
if(b)
|
|
|
|
Serial.printf_P(PSTR("en"));
|
|
|
|
else
|
|
|
|
Serial.printf_P(PSTR("dis"));
|
|
|
|
Serial.printf_P(PSTR("abled\n"));
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_accel_offsets(void)
|
|
|
|
{
|
2012-08-21 23:19:51 -03:00
|
|
|
Serial.printf_P(PSTR("Accel offsets: %4.2f, %4.2f, %4.2f\n"),
|
|
|
|
(float)imu.ax(),
|
|
|
|
(float)imu.ay(),
|
|
|
|
(float)imu.az());
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_gyro_offsets(void)
|
|
|
|
{
|
2012-08-21 23:19:51 -03:00
|
|
|
Serial.printf_P(PSTR("Gyro offsets: %4.2f, %4.2f, %4.2f\n"),
|
|
|
|
(float)imu.gx(),
|
|
|
|
(float)imu.gy(),
|
|
|
|
(float)imu.gz());
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif // CLI_ENABLED
|