2012-04-30 04:17:14 -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
|
|
|
|
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);
|
2012-11-27 19:42:34 -04:00
|
|
|
#if !defined( __AVR_ATmega1280__ )
|
2013-02-21 16:49:07 -04:00
|
|
|
static int8_t setup_accel_scale (uint8_t argc, const Menu::arg *argv);
|
2013-03-18 07:24:34 -03:00
|
|
|
static int8_t setup_set (uint8_t argc, const Menu::arg *argv);
|
2012-11-27 19:42:34 -04:00
|
|
|
#endif
|
2013-02-21 16:49:07 -04:00
|
|
|
static int8_t setup_level (uint8_t argc, const Menu::arg *argv);
|
2012-04-30 04:17:14 -03:00
|
|
|
static int8_t setup_erase (uint8_t argc, const Menu::arg *argv);
|
2013-02-21 16:49:07 -04:00
|
|
|
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);
|
2012-04-30 04:17:14 -03:00
|
|
|
|
|
|
|
// Command/function table for the setup menu
|
|
|
|
static const struct Menu::command setup_menu_commands[] PROGMEM = {
|
|
|
|
// command function called
|
|
|
|
// ======= ===============
|
|
|
|
{"reset", setup_factory},
|
|
|
|
{"radio", setup_radio},
|
|
|
|
{"modes", setup_flightmodes},
|
2013-02-21 16:49:07 -04:00
|
|
|
{"level", setup_level},
|
2012-11-27 19:42:34 -04:00
|
|
|
#if !defined( __AVR_ATmega1280__ )
|
2012-11-07 03:28:20 -04:00
|
|
|
{"accel", setup_accel_scale},
|
2012-11-27 19:42:34 -04:00
|
|
|
#endif
|
2012-04-30 04:17:14 -03:00
|
|
|
{"compass", setup_compass},
|
|
|
|
{"declination", setup_declination},
|
|
|
|
{"battery", setup_batt_monitor},
|
|
|
|
{"show", setup_show},
|
2013-03-18 07:24:34 -03:00
|
|
|
#if !defined( __AVR_ATmega1280__ )
|
|
|
|
{"set", setup_set},
|
|
|
|
#endif
|
2012-04-30 04:17:14 -03:00
|
|
|
{"erase", setup_erase},
|
|
|
|
};
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
{
|
|
|
|
// Give the user some guidance
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->printf_P(PSTR("Setup Mode\n"
|
2012-04-30 04:17:14 -03:00
|
|
|
"\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();
|
|
|
|
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)
|
|
|
|
{
|
2013-03-18 07:24:34 -03:00
|
|
|
|
|
|
|
#if !defined( __AVR_ATmega1280__ )
|
|
|
|
AP_Param *param;
|
|
|
|
ap_var_type type;
|
|
|
|
|
|
|
|
//If a parameter name is given as an argument to show, print only that parameter
|
|
|
|
if(argc>=2)
|
|
|
|
{
|
|
|
|
|
|
|
|
param=AP_Param::find(argv[1].str, &type);
|
|
|
|
|
|
|
|
if(!param)
|
|
|
|
{
|
|
|
|
cliSerial->printf_P(PSTR("Parameter not found: '%s'\n"), argv[1]);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Print differently for different types, and include parameter type in output.
|
|
|
|
switch (type) {
|
|
|
|
case AP_PARAM_INT8:
|
|
|
|
cliSerial->printf_P(PSTR("INT8 %s: %d\n"), argv[1].str, (int)((AP_Int8 *)param)->get());
|
|
|
|
break;
|
|
|
|
case AP_PARAM_INT16:
|
|
|
|
cliSerial->printf_P(PSTR("INT16 %s: %d\n"), argv[1].str, (int)((AP_Int16 *)param)->get());
|
|
|
|
break;
|
|
|
|
case AP_PARAM_INT32:
|
|
|
|
cliSerial->printf_P(PSTR("INT32 %s: %ld\n"), argv[1].str, (long)((AP_Int32 *)param)->get());
|
|
|
|
break;
|
|
|
|
case AP_PARAM_FLOAT:
|
|
|
|
cliSerial->printf_P(PSTR("FLOAT %s: %f\n"), argv[1].str, ((AP_Float *)param)->get());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
cliSerial->printf_P(PSTR("Unhandled parameter type for %s: %d.\n"), argv[1].str, type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-04-30 04:17:14 -03:00
|
|
|
// clear the area
|
|
|
|
print_blanks(8);
|
|
|
|
|
|
|
|
report_radio();
|
|
|
|
report_batt_monitor();
|
|
|
|
report_gains();
|
|
|
|
report_xtrack();
|
|
|
|
report_throttle();
|
2013-02-07 18:21:22 -04:00
|
|
|
report_modes();
|
2012-04-30 04:17:14 -03:00
|
|
|
report_compass();
|
|
|
|
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->printf_P(PSTR("Raw Values\n"));
|
2012-04-30 04:17:14 -03:00
|
|
|
print_divider();
|
|
|
|
|
2013-04-19 04:53:07 -03:00
|
|
|
AP_Param::show_all(cliSerial);
|
2012-04-30 04:17:14 -03:00
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2013-03-18 07:24:34 -03:00
|
|
|
|
|
|
|
#if !defined( __AVR_ATmega1280__ )
|
|
|
|
|
|
|
|
//Set a parameter to a specified value. It will cast the value to the current type of the
|
|
|
|
//parameter and make sure it fits in case of INT8 and INT16
|
|
|
|
static int8_t setup_set(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
|
|
|
int8_t value_int8;
|
|
|
|
int16_t value_int16;
|
|
|
|
|
|
|
|
AP_Param *param;
|
|
|
|
enum ap_var_type p_type;
|
|
|
|
|
|
|
|
if(argc!=3)
|
|
|
|
{
|
|
|
|
cliSerial->printf_P(PSTR("Invalid command. Usage: set <name> <value>\n"));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
param = AP_Param::find(argv[1].str, &p_type);
|
|
|
|
if(!param)
|
|
|
|
{
|
|
|
|
cliSerial->printf_P(PSTR("Param not found: %s\n"), argv[1].str);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(p_type)
|
|
|
|
{
|
|
|
|
case AP_PARAM_INT8:
|
|
|
|
value_int8 = (int8_t)(argv[2].i);
|
|
|
|
if(argv[2].i!=value_int8)
|
|
|
|
{
|
|
|
|
cliSerial->printf_P(PSTR("Value out of range for type INT8\n"));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
((AP_Int8*)param)->set_and_save(value_int8);
|
|
|
|
break;
|
|
|
|
case AP_PARAM_INT16:
|
|
|
|
value_int16 = (int16_t)(argv[2].i);
|
|
|
|
if(argv[2].i!=value_int16)
|
|
|
|
{
|
|
|
|
cliSerial->printf_P(PSTR("Value out of range for type INT16\n"));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
((AP_Int16*)param)->set_and_save(value_int16);
|
|
|
|
break;
|
|
|
|
|
|
|
|
//int32 and float don't need bounds checking, just use the value provoded by Menu::arg
|
|
|
|
case AP_PARAM_INT32:
|
|
|
|
((AP_Int32*)param)->set_and_save(argv[2].i);
|
|
|
|
break;
|
|
|
|
case AP_PARAM_FLOAT:
|
|
|
|
((AP_Float*)param)->set_and_save(argv[2].f);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
cliSerial->printf_P(PSTR("Cannot set parameter of type %d.\n"), p_type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2012-04-30 04:17:14 -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)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->printf_P(PSTR("\nType 'Y' and hit Enter to perform factory reset, any other key to abort: "));
|
2012-04-30 04:17:14 -03:00
|
|
|
|
|
|
|
do {
|
2012-11-21 02:25:11 -04:00
|
|
|
c = cliSerial->read();
|
2012-04-30 04:17:14 -03:00
|
|
|
} while (-1 == c);
|
|
|
|
|
|
|
|
if (('y' != c) && ('Y' != c))
|
|
|
|
return(-1);
|
|
|
|
AP_Param::erase_all();
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->printf_P(PSTR("\nFACTORY RESET complete - please reset APM to continue"));
|
2012-04-30 04:17:14 -03:00
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
}
|
|
|
|
// note, cannot actually return here
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Perform radio setup.
|
|
|
|
// Called by the setup menu 'radio' command.
|
|
|
|
static int8_t
|
|
|
|
setup_radio(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->printf_P(PSTR("\n\nRadio Setup:\n"));
|
2012-04-30 04:17:14 -03:00
|
|
|
uint8_t i;
|
|
|
|
|
|
|
|
for(i = 0; i < 100;i++){
|
|
|
|
delay(20);
|
|
|
|
read_radio();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-07 18:21:22 -04:00
|
|
|
if(g.channel_steer.radio_in < 500){
|
2012-04-30 04:17:14 -03:00
|
|
|
while(1){
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->printf_P(PSTR("\nNo radio; Check connectors."));
|
2012-04-30 04:17:14 -03:00
|
|
|
delay(1000);
|
|
|
|
// stop here
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-07 18:21:22 -04:00
|
|
|
g.channel_steer.radio_min = g.channel_steer.radio_in;
|
2012-04-30 04:17:14 -03:00
|
|
|
g.channel_throttle.radio_min = g.channel_throttle.radio_in;
|
2013-02-07 18:21:22 -04:00
|
|
|
g.rc_2.radio_min = g.rc_2.radio_in;
|
|
|
|
g.rc_4.radio_min = g.rc_4.radio_in;
|
2012-04-30 04:17:14 -03:00
|
|
|
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;
|
|
|
|
|
2013-02-07 18:21:22 -04:00
|
|
|
g.channel_steer.radio_max = g.channel_steer.radio_in;
|
2012-04-30 04:17:14 -03:00
|
|
|
g.channel_throttle.radio_max = g.channel_throttle.radio_in;
|
2013-02-07 18:21:22 -04:00
|
|
|
g.rc_2.radio_max = g.rc_2.radio_in;
|
|
|
|
g.rc_4.radio_max = g.rc_4.radio_in;
|
2012-04-30 04:17:14 -03:00
|
|
|
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;
|
|
|
|
|
2013-02-07 18:21:22 -04:00
|
|
|
g.channel_steer.radio_trim = g.channel_steer.radio_in;
|
|
|
|
g.rc_2.radio_trim = 1500;
|
|
|
|
g.rc_4.radio_trim = 1500;
|
2012-04-30 04:17:14 -03:00
|
|
|
g.rc_5.radio_trim = 1500;
|
|
|
|
g.rc_6.radio_trim = 1500;
|
|
|
|
g.rc_7.radio_trim = 1500;
|
|
|
|
g.rc_8.radio_trim = 1500;
|
|
|
|
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->printf_P(PSTR("\nMove all controls to each extreme. Hit Enter to save: \n"));
|
2012-04-30 04:17:14 -03:00
|
|
|
while(1){
|
|
|
|
|
|
|
|
delay(20);
|
|
|
|
// Filters radio input - adjust filters in the radio.pde file
|
|
|
|
// ----------------------------------------------------------
|
|
|
|
read_radio();
|
|
|
|
|
2013-02-07 18:21:22 -04:00
|
|
|
g.channel_steer.update_min_max();
|
2012-04-30 04:17:14 -03:00
|
|
|
g.channel_throttle.update_min_max();
|
2013-02-07 18:21:22 -04:00
|
|
|
g.rc_2.update_min_max();
|
|
|
|
g.rc_4.update_min_max();
|
2012-04-30 04:17:14 -03:00
|
|
|
g.rc_5.update_min_max();
|
|
|
|
g.rc_6.update_min_max();
|
|
|
|
g.rc_7.update_min_max();
|
|
|
|
g.rc_8.update_min_max();
|
|
|
|
|
2012-11-21 02:25:11 -04:00
|
|
|
if(cliSerial->available() > 0){
|
2012-12-18 07:44:12 -04:00
|
|
|
while (cliSerial->available() > 0) {
|
|
|
|
cliSerial->read();
|
|
|
|
}
|
2013-02-07 18:21:22 -04:00
|
|
|
g.channel_steer.save_eeprom();
|
2012-04-30 04:17:14 -03:00
|
|
|
g.channel_throttle.save_eeprom();
|
2013-02-07 18:21:22 -04:00
|
|
|
g.rc_2.save_eeprom();
|
|
|
|
g.rc_4.save_eeprom();
|
2012-04-30 04:17:14 -03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int8_t
|
|
|
|
setup_flightmodes(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2012-12-18 07:44:12 -04:00
|
|
|
uint8_t switchPosition, mode = 0;
|
2012-04-30 04:17:14 -03:00
|
|
|
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->printf_P(PSTR("\nMove RC toggle switch to each position to edit, move aileron stick to select modes."));
|
2012-04-30 04:17:14 -03:00
|
|
|
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) {
|
2013-02-07 18:21:22 -04:00
|
|
|
modes[switchPosition] = MANUAL;
|
2012-04-30 04:17:14 -03:00
|
|
|
}
|
|
|
|
// update our current mode
|
2013-02-07 18:21:22 -04:00
|
|
|
mode = modes[switchPosition];
|
2012-04-30 04:17:14 -03:00
|
|
|
|
|
|
|
// update the user
|
|
|
|
print_switch(switchPosition, mode);
|
|
|
|
|
|
|
|
// Remember switch position
|
|
|
|
oldSwitchPosition = switchPosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
// look for stick input
|
|
|
|
int radioInputSwitch = radio_input_switch();
|
|
|
|
|
|
|
|
if (radioInputSwitch != 0){
|
|
|
|
|
|
|
|
mode += radioInputSwitch;
|
|
|
|
|
|
|
|
while (
|
|
|
|
mode != MANUAL &&
|
2013-03-28 18:53:20 -03:00
|
|
|
mode != HOLD &&
|
2012-05-14 16:21:29 -03:00
|
|
|
mode != LEARNING &&
|
2013-03-01 07:32:57 -04:00
|
|
|
mode != STEERING &&
|
2012-04-30 04:17:14 -03:00
|
|
|
mode != AUTO &&
|
2012-11-27 18:20:20 -04:00
|
|
|
mode != RTL)
|
2012-04-30 04:17:14 -03:00
|
|
|
{
|
|
|
|
if (mode < MANUAL)
|
2012-11-27 18:20:20 -04:00
|
|
|
mode = RTL;
|
|
|
|
else if (mode > RTL)
|
2012-04-30 04:17:14 -03:00
|
|
|
mode = MANUAL;
|
|
|
|
else
|
|
|
|
mode += radioInputSwitch;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Override position 5
|
|
|
|
if(switchPosition > 4)
|
|
|
|
mode = MANUAL;
|
|
|
|
|
|
|
|
// save new mode
|
2013-02-07 18:21:22 -04:00
|
|
|
modes[switchPosition] = mode;
|
2012-04-30 04:17:14 -03:00
|
|
|
|
|
|
|
// print new mode
|
|
|
|
print_switch(switchPosition, mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
// escape hatch
|
2012-11-21 02:25:11 -04:00
|
|
|
if(cliSerial->available() > 0){
|
2012-04-30 04:17:14 -03:00
|
|
|
// save changes
|
|
|
|
for (mode=0; mode<6; mode++)
|
2013-02-07 18:21:22 -04:00
|
|
|
modes[mode].save();
|
|
|
|
report_modes();
|
2012-04-30 04:17:14 -03:00
|
|
|
print_done();
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int8_t
|
|
|
|
setup_declination(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
|
|
|
compass.set_declination(radians(argv[1].f));
|
|
|
|
report_compass();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int8_t
|
|
|
|
setup_erase(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->printf_P(PSTR("\nType 'Y' and hit Enter to erase all waypoint and parameter data, any other key to abort: "));
|
2012-04-30 04:17:14 -03:00
|
|
|
|
|
|
|
do {
|
2012-11-21 02:25:11 -04:00
|
|
|
c = cliSerial->read();
|
2012-04-30 04:17:14 -03:00
|
|
|
} while (-1 == c);
|
|
|
|
|
|
|
|
if (('y' != c) && ('Y' != c))
|
|
|
|
return(-1);
|
|
|
|
zero_eeprom();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-21 02:25:11 -04:00
|
|
|
/*
|
|
|
|
handle full accelerometer calibration via user dialog
|
|
|
|
*/
|
2012-11-27 19:42:34 -04:00
|
|
|
#if !defined( __AVR_ATmega1280__ )
|
2012-11-07 03:28:20 -04:00
|
|
|
static int8_t
|
|
|
|
setup_accel_scale(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2013-02-19 00:31:03 -04:00
|
|
|
float trim_roll, trim_pitch;
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->println_P(PSTR("Initialising gyros"));
|
2013-01-13 01:03:54 -04:00
|
|
|
ahrs.init();
|
2012-11-29 07:57:10 -04:00
|
|
|
ins.init(AP_InertialSensor::COLD_START,
|
|
|
|
ins_sample_rate,
|
2012-12-18 07:44:12 -04:00
|
|
|
flash_leds);
|
2012-12-19 18:31:34 -04:00
|
|
|
AP_InertialSensor_UserInteractStream interact(hal.console);
|
2013-02-19 00:31:03 -04:00
|
|
|
if(ins.calibrate_accel(flash_leds, &interact, trim_roll, trim_pitch)) {
|
|
|
|
// reset ahrs's trim to suggested values from calibration routine
|
|
|
|
ahrs.set_trim(Vector3f(trim_roll, trim_pitch, 0));
|
|
|
|
}
|
2012-11-07 03:28:20 -04:00
|
|
|
return(0);
|
|
|
|
}
|
2012-11-27 19:42:34 -04:00
|
|
|
#endif
|
2012-11-07 03:28:20 -04:00
|
|
|
|
2013-02-21 16:49:07 -04:00
|
|
|
static int8_t
|
|
|
|
setup_level(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
|
|
|
cliSerial->println_P(PSTR("Initialising gyros"));
|
|
|
|
ahrs.init();
|
|
|
|
ins.init(AP_InertialSensor::COLD_START,
|
|
|
|
ins_sample_rate,
|
|
|
|
flash_leds);
|
|
|
|
ins.init_accel(flash_leds);
|
|
|
|
ahrs.set_trim(Vector3f(0, 0, 0));
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2012-04-30 04:17:14 -03:00
|
|
|
static int8_t
|
|
|
|
setup_compass(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
|
|
|
if (!strcmp_P(argv[1].str, PSTR("on"))) {
|
|
|
|
if (!compass.init()) {
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->println_P(PSTR("Compass initialisation failed!"));
|
2012-04-30 04:17:14 -03:00
|
|
|
g.compass_enabled = false;
|
|
|
|
} else {
|
|
|
|
g.compass_enabled = true;
|
|
|
|
}
|
|
|
|
} else if (!strcmp_P(argv[1].str, PSTR("off"))) {
|
|
|
|
g.compass_enabled = false;
|
|
|
|
|
|
|
|
} else if (!strcmp_P(argv[1].str, PSTR("reset"))) {
|
|
|
|
compass.set_offsets(0,0,0);
|
|
|
|
|
|
|
|
} else {
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->printf_P(PSTR("\nOptions:[on,off,reset]\n"));
|
2012-04-30 04:17:14 -03:00
|
|
|
report_compass();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
g.compass_enabled.save();
|
|
|
|
report_compass();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int8_t
|
|
|
|
setup_batt_monitor(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
|
|
|
if(argv[1].i >= 0 && argv[1].i <= 4){
|
|
|
|
g.battery_monitoring.set_and_save(argv[1].i);
|
|
|
|
|
|
|
|
} else {
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->printf_P(PSTR("\nOptions: 3-4"));
|
2012-04-30 04:17:14 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
report_batt_monitor();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
// CLI reports
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
|
|
static void report_batt_monitor()
|
|
|
|
{
|
|
|
|
//print_blanks(2);
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->printf_P(PSTR("Batt Mointor\n"));
|
2012-04-30 04:17:14 -03:00
|
|
|
print_divider();
|
2012-11-21 02:25:11 -04:00
|
|
|
if(g.battery_monitoring == 0) cliSerial->printf_P(PSTR("Batt monitoring disabled"));
|
|
|
|
if(g.battery_monitoring == 3) cliSerial->printf_P(PSTR("Monitoring batt volts"));
|
|
|
|
if(g.battery_monitoring == 4) cliSerial->printf_P(PSTR("Monitoring volts and current"));
|
2012-04-30 04:17:14 -03:00
|
|
|
print_blanks(2);
|
|
|
|
}
|
|
|
|
static void report_radio()
|
|
|
|
{
|
|
|
|
//print_blanks(2);
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->printf_P(PSTR("Radio\n"));
|
2012-04-30 04:17:14 -03:00
|
|
|
print_divider();
|
|
|
|
// radio
|
|
|
|
print_radio_values();
|
|
|
|
print_blanks(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void report_gains()
|
|
|
|
{
|
|
|
|
//print_blanks(2);
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->printf_P(PSTR("Gains\n"));
|
2012-04-30 04:17:14 -03:00
|
|
|
print_divider();
|
|
|
|
|
2013-02-07 18:21:22 -04:00
|
|
|
cliSerial->printf_P(PSTR("servo steer:\n"));
|
|
|
|
print_PID(&g.pidServoSteer);
|
2012-04-30 04:17:14 -03:00
|
|
|
|
2013-02-07 18:21:22 -04:00
|
|
|
cliSerial->printf_P(PSTR("nav steer:\n"));
|
|
|
|
print_PID(&g.pidNavSteer);
|
2012-04-30 04:17:14 -03:00
|
|
|
|
2013-02-07 18:21:22 -04:00
|
|
|
cliSerial->printf_P(PSTR("speed throttle:\n"));
|
|
|
|
print_PID(&g.pidSpeedThrottle);
|
2012-04-30 04:17:14 -03:00
|
|
|
|
|
|
|
print_blanks(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void report_xtrack()
|
|
|
|
{
|
|
|
|
//print_blanks(2);
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->printf_P(PSTR("Crosstrack\n"));
|
2012-04-30 04:17:14 -03:00
|
|
|
print_divider();
|
|
|
|
// radio
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->printf_P(PSTR("XTRACK: %4.2f\n"
|
2012-04-30 04:17:14 -03:00
|
|
|
"XTRACK angle: %d\n"),
|
|
|
|
(float)g.crosstrack_gain,
|
|
|
|
(int)g.crosstrack_entry_angle);
|
|
|
|
print_blanks(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void report_throttle()
|
|
|
|
{
|
|
|
|
//print_blanks(2);
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->printf_P(PSTR("Throttle\n"));
|
2012-04-30 04:17:14 -03:00
|
|
|
print_divider();
|
|
|
|
|
2013-02-08 06:17:54 -04:00
|
|
|
cliSerial->printf_P(PSTR("min: %u\n"
|
|
|
|
"max: %u\n"
|
|
|
|
"cruise: %u\n"
|
|
|
|
"failsafe_enabled: %u\n"
|
|
|
|
"failsafe_value: %u\n"),
|
|
|
|
(unsigned)g.throttle_min,
|
|
|
|
(unsigned)g.throttle_max,
|
|
|
|
(unsigned)g.throttle_cruise,
|
|
|
|
(unsigned)g.fs_throttle_enabled,
|
|
|
|
(unsigned)g.fs_throttle_value);
|
2012-04-30 04:17:14 -03:00
|
|
|
print_blanks(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void report_compass()
|
|
|
|
{
|
|
|
|
//print_blanks(2);
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->printf_P(PSTR("Compass: "));
|
2012-04-30 04:17:14 -03:00
|
|
|
|
|
|
|
switch (compass.product_id) {
|
|
|
|
case AP_COMPASS_TYPE_HMC5883L:
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->println_P(PSTR("HMC5883L"));
|
2012-04-30 04:17:14 -03:00
|
|
|
break;
|
|
|
|
case AP_COMPASS_TYPE_HMC5843:
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->println_P(PSTR("HMC5843"));
|
2012-04-30 04:17:14 -03:00
|
|
|
break;
|
|
|
|
case AP_COMPASS_TYPE_HIL:
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->println_P(PSTR("HIL"));
|
2012-04-30 04:17:14 -03:00
|
|
|
break;
|
|
|
|
default:
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->println_P(PSTR("??"));
|
2012-04-30 04:17:14 -03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
print_divider();
|
|
|
|
|
|
|
|
print_enabled(g.compass_enabled);
|
|
|
|
|
|
|
|
// mag declination
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->printf_P(PSTR("Mag Declination: %4.4f\n"),
|
2012-04-30 04:17:14 -03:00
|
|
|
degrees(compass.get_declination()));
|
|
|
|
|
|
|
|
Vector3f offsets = compass.get_offsets();
|
|
|
|
|
|
|
|
// mag offsets
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->printf_P(PSTR("Mag offsets: %4.4f, %4.4f, %4.4f\n"),
|
2012-04-30 04:17:14 -03:00
|
|
|
offsets.x,
|
|
|
|
offsets.y,
|
|
|
|
offsets.z);
|
|
|
|
print_blanks(2);
|
|
|
|
}
|
|
|
|
|
2013-02-07 18:21:22 -04:00
|
|
|
static void report_modes()
|
2012-04-30 04:17:14 -03:00
|
|
|
{
|
|
|
|
//print_blanks(2);
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->printf_P(PSTR("Flight modes\n"));
|
2012-04-30 04:17:14 -03:00
|
|
|
print_divider();
|
|
|
|
|
|
|
|
for(int i = 0; i < 6; i++ ){
|
2013-02-07 18:21:22 -04:00
|
|
|
print_switch(i, modes[i]);
|
2012-04-30 04:17:14 -03:00
|
|
|
}
|
|
|
|
print_blanks(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
// CLI utilities
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_PID(PID * pid)
|
|
|
|
{
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->printf_P(PSTR("P: %4.3f, I:%4.3f, D:%4.3f, IMAX:%ld\n"),
|
2012-04-30 04:17:14 -03:00
|
|
|
pid->kP(),
|
|
|
|
pid->kI(),
|
|
|
|
pid->kD(),
|
|
|
|
(long)pid->imax());
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_radio_values()
|
|
|
|
{
|
2013-02-07 18:21:22 -04:00
|
|
|
cliSerial->printf_P(PSTR("CH1: %d | %d | %d\n"), (int)g.channel_steer.radio_min, (int)g.channel_steer.radio_trim, (int)g.channel_steer.radio_max);
|
|
|
|
cliSerial->printf_P(PSTR("CH2: %d | %d | %d\n"), (int)g.rc_2.radio_min, (int)g.rc_2.radio_trim, (int)g.rc_2.radio_max);
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->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);
|
2013-02-07 18:21:22 -04:00
|
|
|
cliSerial->printf_P(PSTR("CH4: %d | %d | %d\n"), (int)g.rc_4.radio_min, (int)g.rc_4.radio_trim, (int)g.rc_4.radio_max);
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->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);
|
|
|
|
cliSerial->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);
|
|
|
|
cliSerial->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);
|
|
|
|
cliSerial->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);
|
2012-04-30 04:17:14 -03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-12-18 07:44:12 -04:00
|
|
|
print_switch(uint8_t p, uint8_t m)
|
2012-04-30 04:17:14 -03:00
|
|
|
{
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->printf_P(PSTR("Pos %d: "),p);
|
2013-04-20 02:18:42 -03:00
|
|
|
print_mode(cliSerial, m);
|
|
|
|
cliSerial->println();
|
2012-04-30 04:17:14 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_done()
|
|
|
|
{
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->printf_P(PSTR("\nSaved Settings\n\n"));
|
2012-04-30 04:17:14 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_blanks(int num)
|
|
|
|
{
|
|
|
|
while(num > 0){
|
|
|
|
num--;
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->println("");
|
2012-04-30 04:17:14 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_divider(void)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 40; i++) {
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->printf_P(PSTR("-"));
|
2012-04-30 04:17:14 -03:00
|
|
|
}
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->println("");
|
2012-04-30 04:17:14 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int8_t
|
|
|
|
radio_input_switch(void)
|
|
|
|
{
|
|
|
|
static int8_t bouncer = 0;
|
|
|
|
|
|
|
|
|
2013-02-07 18:21:22 -04:00
|
|
|
if (int16_t(g.channel_steer.radio_in - g.channel_steer.radio_trim) > 100) {
|
2012-04-30 04:17:14 -03:00
|
|
|
bouncer = 10;
|
|
|
|
}
|
2013-02-07 18:21:22 -04:00
|
|
|
if (int16_t(g.channel_steer.radio_in - g.channel_steer.radio_trim) < -100) {
|
2012-04-30 04:17:14 -03:00
|
|
|
bouncer = -10;
|
|
|
|
}
|
|
|
|
if (bouncer >0) {
|
|
|
|
bouncer --;
|
|
|
|
}
|
|
|
|
if (bouncer <0) {
|
|
|
|
bouncer ++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bouncer == 1 || bouncer == -1) {
|
|
|
|
return bouncer;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void zero_eeprom(void)
|
|
|
|
{
|
2012-12-18 07:44:12 -04:00
|
|
|
uint8_t b = 0;
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->printf_P(PSTR("\nErasing EEPROM\n"));
|
2012-12-18 07:44:12 -04:00
|
|
|
for (uint16_t i = 0; i < EEPROM_MAX_ADDR; i++) {
|
|
|
|
hal.storage->write_byte(i, b);
|
2012-04-30 04:17:14 -03:00
|
|
|
}
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->printf_P(PSTR("done\n"));
|
2012-04-30 04:17:14 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void print_enabled(bool b)
|
|
|
|
{
|
|
|
|
if(b)
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->printf_P(PSTR("en"));
|
2012-04-30 04:17:14 -03:00
|
|
|
else
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->printf_P(PSTR("dis"));
|
|
|
|
cliSerial->printf_P(PSTR("abled\n"));
|
2012-04-30 04:17:14 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // CLI_ENABLED
|