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
|
|
|
|
|
|
|
|
// These are function definitions so the Menu can be constructed before the functions
|
|
|
|
// are defined below. Order matters to the compiler.
|
2012-08-21 23:19:51 -03:00
|
|
|
static int8_t test_radio_pwm(uint8_t argc, const Menu::arg *argv);
|
|
|
|
static int8_t test_radio(uint8_t argc, const Menu::arg *argv);
|
|
|
|
static int8_t test_passthru(uint8_t argc, const Menu::arg *argv);
|
|
|
|
static int8_t test_failsafe(uint8_t argc, const Menu::arg *argv);
|
|
|
|
static int8_t test_gps(uint8_t argc, const Menu::arg *argv);
|
2013-06-02 22:40:44 -03:00
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_APM1
|
2012-08-21 23:19:51 -03:00
|
|
|
static int8_t test_adc(uint8_t argc, const Menu::arg *argv);
|
2011-11-13 05:24:05 -04:00
|
|
|
#endif
|
2012-11-05 00:32:13 -04:00
|
|
|
static int8_t test_ins(uint8_t argc, const Menu::arg *argv);
|
2012-08-21 23:19:51 -03:00
|
|
|
static int8_t test_relay(uint8_t argc, const Menu::arg *argv);
|
|
|
|
static int8_t test_wp(uint8_t argc, const Menu::arg *argv);
|
|
|
|
static int8_t test_airspeed(uint8_t argc, const Menu::arg *argv);
|
|
|
|
static int8_t test_pressure(uint8_t argc, const Menu::arg *argv);
|
|
|
|
static int8_t test_mag(uint8_t argc, const Menu::arg *argv);
|
|
|
|
static int8_t test_xbee(uint8_t argc, const Menu::arg *argv);
|
|
|
|
static int8_t test_eedump(uint8_t argc, const Menu::arg *argv);
|
|
|
|
static int8_t test_modeswitch(uint8_t argc, const Menu::arg *argv);
|
|
|
|
static int8_t test_logging(uint8_t argc, const Menu::arg *argv);
|
2014-03-31 14:58:20 -03:00
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_PX4 || CONFIG_HAL_BOARD == HAL_BOARD_VRBRAIN
|
2013-02-07 00:04:22 -04:00
|
|
|
static int8_t test_shell(uint8_t argc, const Menu::arg *argv);
|
|
|
|
#endif
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2014-03-03 09:50:45 -04:00
|
|
|
// forward declaration to keep the compiler happy
|
|
|
|
static void test_wp_print(const AP_Mission::Mission_Command& cmd);
|
|
|
|
|
2011-09-08 22:29:39 -03:00
|
|
|
// Creates a constant array of structs representing menu options
|
|
|
|
// and stores them in Flash memory, not RAM.
|
|
|
|
// User enters the string in the console to call the functions on the right.
|
|
|
|
// See class Menu in AP_Common for implementation details
|
|
|
|
static const struct Menu::command test_menu_commands[] PROGMEM = {
|
2012-08-21 23:19:51 -03:00
|
|
|
{"pwm", test_radio_pwm},
|
|
|
|
{"radio", test_radio},
|
|
|
|
{"passthru", test_passthru},
|
|
|
|
{"failsafe", test_failsafe},
|
|
|
|
{"relay", test_relay},
|
|
|
|
{"waypoints", test_wp},
|
|
|
|
{"xbee", test_xbee},
|
|
|
|
{"eedump", test_eedump},
|
|
|
|
{"modeswitch", test_modeswitch},
|
|
|
|
|
|
|
|
// Tests below here are for hardware sensors only present
|
|
|
|
// when real sensors are attached or they are emulated
|
2011-09-08 22:29:39 -03:00
|
|
|
#if HIL_MODE == HIL_MODE_DISABLED
|
2013-06-02 22:40:44 -03:00
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_APM1
|
2012-08-21 23:19:51 -03:00
|
|
|
{"adc", test_adc},
|
|
|
|
#endif
|
|
|
|
{"gps", test_gps},
|
2012-11-05 00:32:13 -04:00
|
|
|
{"ins", test_ins},
|
2012-08-21 23:19:51 -03:00
|
|
|
{"airspeed", test_airspeed},
|
|
|
|
{"airpressure", test_pressure},
|
|
|
|
{"compass", test_mag},
|
2013-04-12 04:44:40 -03:00
|
|
|
#else
|
2012-08-21 23:19:51 -03:00
|
|
|
{"gps", test_gps},
|
2012-11-05 00:32:13 -04:00
|
|
|
{"ins", test_ins},
|
2012-08-21 23:19:51 -03:00
|
|
|
{"compass", test_mag},
|
2011-09-08 22:29:39 -03:00
|
|
|
#endif
|
2012-08-21 23:19:51 -03:00
|
|
|
{"logging", test_logging},
|
2014-03-31 14:58:20 -03:00
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_PX4 || CONFIG_HAL_BOARD == HAL_BOARD_VRBRAIN
|
2013-02-07 00:04:22 -04:00
|
|
|
{"shell", test_shell},
|
|
|
|
#endif
|
2011-09-08 22:29:39 -03:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
// A Macro to create the Menu
|
|
|
|
MENU(test_menu, "test", test_menu_commands);
|
|
|
|
|
|
|
|
static int8_t
|
|
|
|
test_mode(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2012-11-21 01:19:16 -04:00
|
|
|
cliSerial->printf_P(PSTR("Test Mode\n\n"));
|
2012-08-21 23:19:51 -03:00
|
|
|
test_menu.run();
|
2011-09-08 22:29:39 -03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_hit_enter()
|
|
|
|
{
|
2012-11-21 01:19:16 -04:00
|
|
|
cliSerial->printf_P(PSTR("Hit Enter to exit.\n\n"));
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int8_t
|
|
|
|
test_eedump(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2012-12-12 17:58:28 -04:00
|
|
|
uint16_t i, j;
|
2012-08-21 23:19:51 -03:00
|
|
|
|
|
|
|
// hexdump the EEPROM
|
2014-03-12 03:20:17 -03:00
|
|
|
for (i = 0; i < HAL_STORAGE_SIZE_AVAILABLE; i += 16) {
|
2012-11-21 01:19:16 -04:00
|
|
|
cliSerial->printf_P(PSTR("%04x:"), i);
|
2012-08-21 23:19:51 -03:00
|
|
|
for (j = 0; j < 16; j++)
|
2012-12-12 17:58:28 -04:00
|
|
|
cliSerial->printf_P(PSTR(" %02x"), hal.storage->read_byte(i + j));
|
2012-11-21 01:19:16 -04:00
|
|
|
cliSerial->println();
|
2012-08-21 23:19:51 -03:00
|
|
|
}
|
|
|
|
return(0);
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int8_t
|
|
|
|
test_radio_pwm(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2012-08-21 23:19:51 -03:00
|
|
|
print_hit_enter();
|
|
|
|
delay(1000);
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
delay(20);
|
|
|
|
|
|
|
|
// Filters radio input - adjust filters in the radio.pde file
|
|
|
|
// ----------------------------------------------------------
|
|
|
|
read_radio();
|
|
|
|
|
2012-11-21 01:19:16 -04:00
|
|
|
cliSerial->printf_P(PSTR("IN:\t1: %d\t2: %d\t3: %d\t4: %d\t5: %d\t6: %d\t7: %d\t8: %d\n"),
|
2013-06-03 02:32:08 -03:00
|
|
|
(int)channel_roll->radio_in,
|
|
|
|
(int)channel_pitch->radio_in,
|
|
|
|
(int)channel_throttle->radio_in,
|
|
|
|
(int)channel_rudder->radio_in,
|
2012-08-21 23:19:51 -03:00
|
|
|
(int)g.rc_5.radio_in,
|
|
|
|
(int)g.rc_6.radio_in,
|
|
|
|
(int)g.rc_7.radio_in,
|
|
|
|
(int)g.rc_8.radio_in);
|
|
|
|
|
2012-11-21 01:19:16 -04:00
|
|
|
if(cliSerial->available() > 0) {
|
2012-08-21 23:19:51 -03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
2011-11-13 00:12:14 -04:00
|
|
|
|
|
|
|
static int8_t
|
|
|
|
test_passthru(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2012-08-21 23:19:51 -03:00
|
|
|
print_hit_enter();
|
|
|
|
delay(1000);
|
2011-11-13 00:12:14 -04:00
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
while(1) {
|
|
|
|
delay(20);
|
2011-11-13 00:12:14 -04:00
|
|
|
|
|
|
|
// New radio frame? (we could use also if((millis()- timer) > 20)
|
2014-03-25 00:41:14 -03:00
|
|
|
if (hal.rcin->new_input()) {
|
2012-11-21 01:19:16 -04:00
|
|
|
cliSerial->print_P(PSTR("CH:"));
|
2012-08-21 23:19:51 -03:00
|
|
|
for(int16_t i = 0; i < 8; i++) {
|
2012-12-04 18:22:21 -04:00
|
|
|
cliSerial->print(hal.rcin->read(i)); // Print channel values
|
2012-09-18 00:48:08 -03:00
|
|
|
print_comma();
|
2013-03-30 00:38:43 -03:00
|
|
|
servo_write(i, hal.rcin->read(i)); // Copy input to Servos
|
2011-11-13 00:12:14 -04:00
|
|
|
}
|
2012-11-21 01:19:16 -04:00
|
|
|
cliSerial->println();
|
2011-11-13 00:12:14 -04:00
|
|
|
}
|
2012-11-21 01:19:16 -04:00
|
|
|
if (cliSerial->available() > 0) {
|
2011-11-13 00:12:14 -04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-09-08 22:29:39 -03:00
|
|
|
static int8_t
|
|
|
|
test_radio(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2012-08-21 23:19:51 -03:00
|
|
|
print_hit_enter();
|
|
|
|
delay(1000);
|
|
|
|
|
|
|
|
// read the radio to set trims
|
|
|
|
// ---------------------------
|
|
|
|
trim_radio();
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
delay(20);
|
|
|
|
read_radio();
|
|
|
|
|
2013-06-03 02:32:08 -03:00
|
|
|
channel_roll->calc_pwm();
|
|
|
|
channel_pitch->calc_pwm();
|
|
|
|
channel_throttle->calc_pwm();
|
|
|
|
channel_rudder->calc_pwm();
|
2012-08-21 23:19:51 -03:00
|
|
|
|
|
|
|
// write out the servo PWM values
|
|
|
|
// ------------------------------
|
|
|
|
set_servos();
|
|
|
|
|
2012-11-21 01:19:16 -04:00
|
|
|
cliSerial->printf_P(PSTR("IN 1: %d\t2: %d\t3: %d\t4: %d\t5: %d\t6: %d\t7: %d\t8: %d\n"),
|
2013-06-03 02:32:08 -03:00
|
|
|
(int)channel_roll->control_in,
|
|
|
|
(int)channel_pitch->control_in,
|
|
|
|
(int)channel_throttle->control_in,
|
|
|
|
(int)channel_rudder->control_in,
|
2012-08-21 23:19:51 -03:00
|
|
|
(int)g.rc_5.control_in,
|
|
|
|
(int)g.rc_6.control_in,
|
|
|
|
(int)g.rc_7.control_in,
|
|
|
|
(int)g.rc_8.control_in);
|
|
|
|
|
2012-11-21 01:19:16 -04:00
|
|
|
if(cliSerial->available() > 0) {
|
2012-08-21 23:19:51 -03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int8_t
|
|
|
|
test_failsafe(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2012-12-04 18:22:21 -04:00
|
|
|
uint8_t fail_test;
|
2012-08-21 23:19:51 -03:00
|
|
|
print_hit_enter();
|
|
|
|
for(int16_t i = 0; i < 50; i++) {
|
|
|
|
delay(20);
|
|
|
|
read_radio();
|
|
|
|
}
|
|
|
|
|
|
|
|
// read the radio to set trims
|
|
|
|
// ---------------------------
|
|
|
|
trim_radio();
|
|
|
|
|
|
|
|
oldSwitchPosition = readSwitch();
|
|
|
|
|
2012-11-21 01:19:16 -04:00
|
|
|
cliSerial->printf_P(PSTR("Unplug battery, throttle in neutral, turn off radio.\n"));
|
2013-06-03 02:32:08 -03:00
|
|
|
while(channel_throttle->control_in > 0) {
|
2012-08-21 23:19:51 -03:00
|
|
|
delay(20);
|
|
|
|
read_radio();
|
|
|
|
}
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
delay(20);
|
|
|
|
read_radio();
|
|
|
|
|
2013-06-03 02:32:08 -03:00
|
|
|
if(channel_throttle->control_in > 0) {
|
|
|
|
cliSerial->printf_P(PSTR("THROTTLE CHANGED %d \n"), (int)channel_throttle->control_in);
|
2012-08-21 23:19:51 -03:00
|
|
|
fail_test++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(oldSwitchPosition != readSwitch()) {
|
2012-11-21 01:19:16 -04:00
|
|
|
cliSerial->printf_P(PSTR("CONTROL MODE CHANGED: "));
|
2013-04-20 02:18:10 -03:00
|
|
|
print_flight_mode(cliSerial, readSwitch());
|
|
|
|
cliSerial->println();
|
2012-08-21 23:19:51 -03:00
|
|
|
fail_test++;
|
|
|
|
}
|
|
|
|
|
2013-06-03 02:32:08 -03:00
|
|
|
if(g.throttle_fs_enabled && channel_throttle->get_failsafe()) {
|
|
|
|
cliSerial->printf_P(PSTR("THROTTLE FAILSAFE ACTIVATED: %d, "), (int)channel_throttle->radio_in);
|
2013-04-20 02:18:10 -03:00
|
|
|
print_flight_mode(cliSerial, readSwitch());
|
|
|
|
cliSerial->println();
|
2012-08-21 23:19:51 -03:00
|
|
|
fail_test++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(fail_test > 0) {
|
|
|
|
return (0);
|
|
|
|
}
|
2012-11-21 01:19:16 -04:00
|
|
|
if(cliSerial->available() > 0) {
|
|
|
|
cliSerial->printf_P(PSTR("LOS caused no change in APM.\n"));
|
2012-08-21 23:19:51 -03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int8_t
|
|
|
|
test_relay(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2012-08-21 23:19:51 -03:00
|
|
|
print_hit_enter();
|
|
|
|
delay(1000);
|
|
|
|
|
|
|
|
while(1) {
|
2012-11-21 01:19:16 -04:00
|
|
|
cliSerial->printf_P(PSTR("Relay on\n"));
|
2014-01-19 22:37:33 -04:00
|
|
|
relay.on(0);
|
2012-08-21 23:19:51 -03:00
|
|
|
delay(3000);
|
2012-11-21 01:19:16 -04:00
|
|
|
if(cliSerial->available() > 0) {
|
2012-08-21 23:19:51 -03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2012-11-21 01:19:16 -04:00
|
|
|
cliSerial->printf_P(PSTR("Relay off\n"));
|
2014-01-19 22:37:33 -04:00
|
|
|
relay.off(0);
|
2012-08-21 23:19:51 -03:00
|
|
|
delay(3000);
|
2012-11-21 01:19:16 -04:00
|
|
|
if(cliSerial->available() > 0) {
|
2012-08-21 23:19:51 -03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int8_t
|
|
|
|
test_wp(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2012-08-21 23:19:51 -03:00
|
|
|
delay(1000);
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
// save the alitude above home option
|
|
|
|
if (g.RTL_altitude_cm < 0) {
|
2012-11-21 01:19:16 -04:00
|
|
|
cliSerial->printf_P(PSTR("Hold current altitude\n"));
|
2012-08-21 23:19:51 -03:00
|
|
|
}else{
|
2012-11-21 01:19:16 -04:00
|
|
|
cliSerial->printf_P(PSTR("Hold altitude of %dm\n"), (int)g.RTL_altitude_cm/100);
|
2012-08-21 23:19:51 -03:00
|
|
|
}
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2014-03-03 09:50:45 -04:00
|
|
|
cliSerial->printf_P(PSTR("%d waypoints\n"), (int)mission.num_commands());
|
2012-11-21 01:19:16 -04:00
|
|
|
cliSerial->printf_P(PSTR("Hit radius: %d\n"), (int)g.waypoint_radius);
|
|
|
|
cliSerial->printf_P(PSTR("Loiter radius: %d\n\n"), (int)g.loiter_radius);
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2014-03-03 09:50:45 -04:00
|
|
|
for(uint8_t i = 0; i <= mission.num_commands(); i++) {
|
|
|
|
AP_Mission::Mission_Command temp_cmd;
|
2014-03-10 23:28:53 -03:00
|
|
|
if (mission.read_cmd_from_storage(i,temp_cmd)) {
|
|
|
|
test_wp_print(temp_cmd);
|
|
|
|
}
|
2012-08-21 23:19:51 -03:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-03-03 09:50:45 -04:00
|
|
|
test_wp_print(const AP_Mission::Mission_Command& cmd)
|
2011-09-08 22:29:39 -03:00
|
|
|
{
|
2012-11-21 01:19:16 -04:00
|
|
|
cliSerial->printf_P(PSTR("command #: %d id:%d options:%d p1:%d p2:%ld p3:%ld p4:%ld \n"),
|
2014-03-03 09:50:45 -04:00
|
|
|
(int)cmd.index,
|
|
|
|
(int)cmd.id,
|
|
|
|
(int)cmd.content.location.options,
|
|
|
|
(int)cmd.p1,
|
|
|
|
(long)cmd.content.location.alt,
|
|
|
|
(long)cmd.content.location.lat,
|
|
|
|
(long)cmd.content.location.lng);
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int8_t
|
|
|
|
test_xbee(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2012-08-21 23:19:51 -03:00
|
|
|
print_hit_enter();
|
|
|
|
delay(1000);
|
2012-11-21 01:19:16 -04:00
|
|
|
cliSerial->printf_P(PSTR("Begin XBee X-CTU Range and RSSI Test:\n"));
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
while(1) {
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2012-12-04 18:22:21 -04:00
|
|
|
if (hal.uartC->available())
|
|
|
|
hal.uartC->write(hal.uartC->read());
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2012-11-21 01:19:16 -04:00
|
|
|
if(cliSerial->available() > 0) {
|
2012-08-21 23:19:51 -03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int8_t
|
|
|
|
test_modeswitch(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2012-08-21 23:19:51 -03:00
|
|
|
print_hit_enter();
|
|
|
|
delay(1000);
|
|
|
|
|
2012-11-21 01:19:16 -04:00
|
|
|
cliSerial->printf_P(PSTR("Control CH "));
|
2012-08-21 23:19:51 -03:00
|
|
|
|
2013-09-23 01:46:58 -03:00
|
|
|
cliSerial->println(FLIGHT_MODE_CHANNEL, BASE_DEC);
|
2012-08-21 23:19:51 -03:00
|
|
|
|
|
|
|
while(1) {
|
|
|
|
delay(20);
|
2012-12-04 18:22:21 -04:00
|
|
|
uint8_t switchPosition = readSwitch();
|
2012-08-21 23:19:51 -03:00
|
|
|
if (oldSwitchPosition != switchPosition) {
|
2012-11-21 01:19:16 -04:00
|
|
|
cliSerial->printf_P(PSTR("Position %d\n"), (int)switchPosition);
|
2012-08-21 23:19:51 -03:00
|
|
|
oldSwitchPosition = switchPosition;
|
|
|
|
}
|
2012-11-21 01:19:16 -04:00
|
|
|
if(cliSerial->available() > 0) {
|
2012-08-21 23:19:51 -03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
2011-12-28 00:53:14 -04:00
|
|
|
/*
|
2012-08-21 23:19:51 -03:00
|
|
|
* test the dataflash is working
|
2011-12-28 00:53:14 -04:00
|
|
|
*/
|
|
|
|
static int8_t
|
|
|
|
test_logging(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2013-02-22 19:15:15 -04:00
|
|
|
DataFlash.ShowDeviceInfo(cliSerial);
|
2011-12-28 00:53:14 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-03-31 14:58:20 -03:00
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_PX4 || CONFIG_HAL_BOARD == HAL_BOARD_VRBRAIN
|
2013-02-07 00:04:22 -04:00
|
|
|
/*
|
|
|
|
* run a debug shell
|
|
|
|
*/
|
|
|
|
static int8_t
|
|
|
|
test_shell(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
|
|
|
hal.util->run_debug_shell(cliSerial);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-09-08 22:29:39 -03:00
|
|
|
//-------------------------------------------------------------------------------------------
|
|
|
|
// tests in this section are for real sensors or sensors that have been simulated
|
|
|
|
|
2013-09-28 11:52:51 -03:00
|
|
|
#if CONFIG_INS_TYPE == CONFIG_INS_OILPAN || CONFIG_HAL_BOARD == HAL_BOARD_APM1
|
2011-09-08 22:29:39 -03:00
|
|
|
static int8_t
|
|
|
|
test_adc(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2012-08-21 23:19:51 -03:00
|
|
|
print_hit_enter();
|
2013-06-02 22:40:44 -03:00
|
|
|
apm1_adc.Init();
|
2012-08-21 23:19:51 -03:00
|
|
|
delay(1000);
|
2012-11-21 01:19:16 -04:00
|
|
|
cliSerial->printf_P(PSTR("ADC\n"));
|
2012-08-21 23:19:51 -03:00
|
|
|
delay(1000);
|
|
|
|
|
|
|
|
while(1) {
|
2013-06-02 22:40:44 -03:00
|
|
|
for (int8_t i=0; i<9; i++) cliSerial->printf_P(PSTR("%.1f\t"),apm1_adc.Ch(i));
|
2012-11-21 01:19:16 -04:00
|
|
|
cliSerial->println();
|
2012-08-21 23:19:51 -03:00
|
|
|
delay(100);
|
2012-11-21 01:19:16 -04:00
|
|
|
if(cliSerial->available() > 0) {
|
2012-08-21 23:19:51 -03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
2013-09-28 11:52:51 -03:00
|
|
|
#endif // CONFIG_INS_TYPE
|
2011-09-08 22:29:39 -03:00
|
|
|
|
|
|
|
static int8_t
|
|
|
|
test_gps(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2012-08-21 23:19:51 -03:00
|
|
|
print_hit_enter();
|
|
|
|
delay(1000);
|
|
|
|
|
2014-03-28 16:52:48 -03:00
|
|
|
uint32_t last_message_time_ms = 0;
|
2012-08-21 23:19:51 -03:00
|
|
|
while(1) {
|
2013-03-21 08:45:17 -03:00
|
|
|
delay(100);
|
2012-08-21 23:19:51 -03:00
|
|
|
|
2014-03-28 16:52:48 -03:00
|
|
|
gps.update();
|
2012-08-21 23:19:51 -03:00
|
|
|
|
2014-03-28 16:52:48 -03:00
|
|
|
if (gps.last_message_time_ms() != last_message_time_ms) {
|
|
|
|
last_message_time_ms = gps.last_message_time_ms();
|
|
|
|
const Location &loc = gps.location();
|
2012-11-21 01:19:16 -04:00
|
|
|
cliSerial->printf_P(PSTR("Lat: %ld, Lon %ld, Alt: %ldm, #sats: %d\n"),
|
2014-03-28 16:52:48 -03:00
|
|
|
(long)loc.lat,
|
|
|
|
(long)loc.lng,
|
|
|
|
(long)loc.alt/100,
|
|
|
|
(int)gps.num_sats());
|
|
|
|
} else {
|
2012-11-21 01:19:16 -04:00
|
|
|
cliSerial->printf_P(PSTR("."));
|
2012-08-21 23:19:51 -03:00
|
|
|
}
|
2012-11-21 01:19:16 -04:00
|
|
|
if(cliSerial->available() > 0) {
|
2012-08-21 23:19:51 -03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int8_t
|
2012-11-05 00:32:13 -04:00
|
|
|
test_ins(uint8_t argc, const Menu::arg *argv)
|
2011-09-08 22:29:39 -03:00
|
|
|
{
|
2012-11-21 01:19:16 -04:00
|
|
|
//cliSerial->printf_P(PSTR("Calibrating."));
|
2013-01-13 01:04:18 -04:00
|
|
|
ahrs.init();
|
|
|
|
ahrs.set_fly_forward(true);
|
2013-05-23 22:21:32 -03:00
|
|
|
ahrs.set_wind_estimation(true);
|
2013-01-13 01:04:18 -04:00
|
|
|
|
2012-11-29 07:56:40 -04:00
|
|
|
ins.init(AP_InertialSensor::COLD_START,
|
2013-09-19 05:33:42 -03:00
|
|
|
ins_sample_rate);
|
2012-03-11 05:13:31 -03:00
|
|
|
ahrs.reset();
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
print_hit_enter();
|
|
|
|
delay(1000);
|
2013-06-04 00:34:58 -03:00
|
|
|
|
|
|
|
uint8_t counter = 0;
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
while(1) {
|
|
|
|
delay(20);
|
2013-10-11 23:30:27 -03:00
|
|
|
if (hal.scheduler->micros() - fast_loopTimer_us > 19000UL) {
|
|
|
|
fast_loopTimer_us = hal.scheduler->micros();
|
2012-08-21 23:19:51 -03:00
|
|
|
|
2012-11-05 00:32:13 -04:00
|
|
|
// INS
|
2012-08-21 23:19:51 -03:00
|
|
|
// ---
|
|
|
|
ahrs.update();
|
|
|
|
|
|
|
|
if(g.compass_enabled) {
|
2013-06-04 00:34:58 -03:00
|
|
|
counter++;
|
|
|
|
if(counter == 5) {
|
2012-08-21 23:19:51 -03:00
|
|
|
compass.read();
|
2013-06-04 00:34:58 -03:00
|
|
|
counter = 0;
|
2012-08-21 23:19:51 -03:00
|
|
|
}
|
|
|
|
}
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2012-11-05 00:32:13 -04:00
|
|
|
// We are using the INS
|
2012-08-21 23:19:51 -03:00
|
|
|
// ---------------------
|
2012-11-05 00:32:13 -04:00
|
|
|
Vector3f gyros = ins.get_gyro();
|
|
|
|
Vector3f accels = ins.get_accel();
|
2012-11-21 01:19:16 -04:00
|
|
|
cliSerial->printf_P(PSTR("r:%4d p:%4d y:%3d g=(%5.1f %5.1f %5.1f) a=(%5.1f %5.1f %5.1f)\n"),
|
2012-03-11 05:13:31 -03:00
|
|
|
(int)ahrs.roll_sensor / 100,
|
|
|
|
(int)ahrs.pitch_sensor / 100,
|
|
|
|
(uint16_t)ahrs.yaw_sensor / 100,
|
2011-12-02 23:07:19 -04:00
|
|
|
gyros.x, gyros.y, gyros.z,
|
|
|
|
accels.x, accels.y, accels.z);
|
2012-08-21 23:19:51 -03:00
|
|
|
}
|
2012-11-21 01:19:16 -04:00
|
|
|
if(cliSerial->available() > 0) {
|
2012-08-21 23:19:51 -03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int8_t
|
|
|
|
test_mag(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2012-08-21 23:19:51 -03:00
|
|
|
if (!g.compass_enabled) {
|
2012-11-21 01:19:16 -04:00
|
|
|
cliSerial->printf_P(PSTR("Compass: "));
|
2012-08-21 23:19:51 -03:00
|
|
|
print_enabled(false);
|
|
|
|
return (0);
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!compass.init()) {
|
2012-11-21 01:19:16 -04:00
|
|
|
cliSerial->println_P(PSTR("Compass initialisation failed!"));
|
2011-09-08 22:29:39 -03:00
|
|
|
return 0;
|
|
|
|
}
|
2013-01-13 01:04:18 -04:00
|
|
|
ahrs.init();
|
|
|
|
ahrs.set_fly_forward(true);
|
2013-05-23 22:21:32 -03:00
|
|
|
ahrs.set_wind_estimation(true);
|
2012-03-11 05:13:31 -03:00
|
|
|
ahrs.set_compass(&compass);
|
2011-09-08 22:29:39 -03:00
|
|
|
report_compass();
|
|
|
|
|
2012-03-11 05:13:31 -03:00
|
|
|
// we need the AHRS initialised for this test
|
2012-11-29 07:56:40 -04:00
|
|
|
ins.init(AP_InertialSensor::COLD_START,
|
2013-09-19 05:33:42 -03:00
|
|
|
ins_sample_rate);
|
2012-03-11 05:13:31 -03:00
|
|
|
ahrs.reset();
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2013-06-04 00:34:58 -03:00
|
|
|
uint16_t counter = 0;
|
2012-06-20 06:31:19 -03:00
|
|
|
float heading = 0;
|
|
|
|
|
2011-09-08 22:29:39 -03:00
|
|
|
print_hit_enter();
|
|
|
|
|
|
|
|
while(1) {
|
2012-08-21 23:19:51 -03:00
|
|
|
delay(20);
|
2013-10-11 23:30:27 -03:00
|
|
|
if (hal.scheduler->micros() - fast_loopTimer_us > 19000UL) {
|
|
|
|
fast_loopTimer_us = hal.scheduler->micros();
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2012-11-05 00:32:13 -04:00
|
|
|
// INS
|
2012-08-21 23:19:51 -03:00
|
|
|
// ---
|
|
|
|
ahrs.update();
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2013-06-04 00:34:58 -03:00
|
|
|
if(counter % 5 == 0) {
|
2011-12-28 05:33:47 -04:00
|
|
|
if (compass.read()) {
|
2012-03-03 03:33:40 -04:00
|
|
|
// Calculate heading
|
2013-05-05 02:03:05 -03:00
|
|
|
const Matrix3f &m = ahrs.get_dcm_matrix();
|
2012-06-20 06:31:19 -03:00
|
|
|
heading = compass.calculate_heading(m);
|
2014-02-15 22:22:06 -04:00
|
|
|
compass.learn_offsets();
|
2011-12-28 05:33:47 -04:00
|
|
|
}
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
counter++;
|
|
|
|
if (counter>20) {
|
2013-12-09 02:47:38 -04:00
|
|
|
if (compass.healthy()) {
|
2013-12-08 23:10:35 -04:00
|
|
|
const Vector3f &mag_ofs = compass.get_offsets();
|
|
|
|
const Vector3f &mag = compass.get_field();
|
|
|
|
cliSerial->printf_P(PSTR("Heading: %ld, XYZ: %.0f, %.0f, %.0f,\tXYZoff: %6.2f, %6.2f, %6.2f\n"),
|
|
|
|
(wrap_360_cd(ToDeg(heading) * 100)) /100,
|
|
|
|
mag.x, mag.y, mag.z,
|
|
|
|
mag_ofs.x, mag_ofs.y, mag_ofs.z);
|
2011-12-28 05:33:47 -04:00
|
|
|
} else {
|
2012-11-21 01:19:16 -04:00
|
|
|
cliSerial->println_P(PSTR("compass not healthy"));
|
2011-12-28 05:33:47 -04:00
|
|
|
}
|
2011-09-08 22:29:39 -03:00
|
|
|
counter=0;
|
|
|
|
}
|
2012-08-21 23:19:51 -03:00
|
|
|
}
|
2012-11-21 01:19:16 -04:00
|
|
|
if (cliSerial->available() > 0) {
|
2011-09-08 22:29:39 -03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// save offsets. This allows you to get sane offset values using
|
2012-08-21 23:19:51 -03:00
|
|
|
// the CLI before you go flying.
|
2012-11-21 01:19:16 -04:00
|
|
|
cliSerial->println_P(PSTR("saving offsets"));
|
2011-09-08 22:29:39 -03:00
|
|
|
compass.save_offsets();
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------------
|
|
|
|
// real sensors that have not been simulated yet go here
|
|
|
|
|
|
|
|
#if HIL_MODE == HIL_MODE_DISABLED
|
|
|
|
|
|
|
|
static int8_t
|
|
|
|
test_airspeed(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2012-08-21 23:19:51 -03:00
|
|
|
if (!airspeed.enabled()) {
|
2012-11-21 01:19:16 -04:00
|
|
|
cliSerial->printf_P(PSTR("airspeed: "));
|
2012-08-21 23:19:51 -03:00
|
|
|
print_enabled(false);
|
|
|
|
return (0);
|
|
|
|
}else{
|
|
|
|
print_hit_enter();
|
|
|
|
zero_airspeed();
|
2012-11-21 01:19:16 -04:00
|
|
|
cliSerial->printf_P(PSTR("airspeed: "));
|
2012-08-21 23:19:51 -03:00
|
|
|
print_enabled(true);
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
delay(20);
|
|
|
|
read_airspeed();
|
2012-11-21 01:19:16 -04:00
|
|
|
cliSerial->printf_P(PSTR("%.1f m/s\n"), airspeed.get_airspeed());
|
2012-08-21 23:19:51 -03:00
|
|
|
|
2012-11-21 01:19:16 -04:00
|
|
|
if(cliSerial->available() > 0) {
|
2012-08-21 23:19:51 -03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int8_t
|
|
|
|
test_pressure(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2012-11-21 01:19:16 -04:00
|
|
|
cliSerial->printf_P(PSTR("Uncalibrated relative airpressure\n"));
|
2012-08-21 23:19:51 -03:00
|
|
|
print_hit_enter();
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
init_barometer();
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
while(1) {
|
|
|
|
delay(100);
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2011-12-28 05:34:11 -04:00
|
|
|
if (!barometer.healthy) {
|
2012-11-21 01:19:16 -04:00
|
|
|
cliSerial->println_P(PSTR("not healthy"));
|
2011-12-28 05:34:11 -04:00
|
|
|
} else {
|
2013-01-20 07:11:30 -04:00
|
|
|
cliSerial->printf_P(PSTR("Alt: %0.2fm, Raw: %f Temperature: %.1f\n"),
|
2014-01-02 07:06:25 -04:00
|
|
|
barometer.get_altitude(),
|
2013-09-21 08:31:03 -03:00
|
|
|
barometer.get_pressure(),
|
|
|
|
barometer.get_temperature());
|
2011-12-28 05:34:11 -04:00
|
|
|
}
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2012-11-21 01:19:16 -04:00
|
|
|
if(cliSerial->available() > 0) {
|
2012-08-21 23:19:51 -03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // HIL_MODE == HIL_MODE_DISABLED
|
|
|
|
|
|
|
|
#endif // CLI_ENABLED
|