2011-03-19 07:20:11 -03:00
|
|
|
// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
2011-02-24 01:56:59 -04:00
|
|
|
|
2011-07-17 07:34:05 -03:00
|
|
|
#if CLI_ENABLED == ENABLED
|
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
// 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:50 -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_failsafe(uint8_t argc, const Menu::arg *argv);
|
|
|
|
//static int8_t test_stabilize(uint8_t argc, const Menu::arg *argv);
|
|
|
|
static int8_t test_gps(uint8_t argc, const Menu::arg *argv);
|
|
|
|
//static int8_t test_tri(uint8_t argc, const Menu::arg *argv);
|
|
|
|
//static int8_t test_adc(uint8_t argc, const Menu::arg *argv);
|
|
|
|
static int8_t test_ins(uint8_t argc, const Menu::arg *argv);
|
|
|
|
//static int8_t test_imu(uint8_t argc, const Menu::arg *argv);
|
|
|
|
//static int8_t test_dcm_eulers(uint8_t argc, const Menu::arg *argv);
|
|
|
|
//static int8_t test_dcm(uint8_t argc, const Menu::arg *argv);
|
|
|
|
//static int8_t test_omega(uint8_t argc, const Menu::arg *argv);
|
|
|
|
//static int8_t test_stab_d(uint8_t argc, const Menu::arg *argv);
|
|
|
|
static int8_t test_battery(uint8_t argc, const Menu::arg *argv);
|
|
|
|
//static int8_t test_toy(uint8_t argc, const Menu::arg *argv);
|
|
|
|
static int8_t test_wp_nav(uint8_t argc, const Menu::arg *argv);
|
|
|
|
//static int8_t test_reverse(uint8_t argc, const Menu::arg *argv);
|
|
|
|
static int8_t test_tuning(uint8_t argc, const Menu::arg *argv);
|
|
|
|
static int8_t test_relay(uint8_t argc, const Menu::arg *argv);
|
|
|
|
static int8_t test_wp(uint8_t argc, const Menu::arg *argv);
|
2013-03-18 01:40:43 -03:00
|
|
|
#if HIL_MODE != HIL_MODE_ATTITUDE && HIL_MODE != HIL_MODE_SENSORS
|
2012-08-21 23:19:50 -03:00
|
|
|
static int8_t test_baro(uint8_t argc, const Menu::arg *argv);
|
|
|
|
static int8_t test_sonar(uint8_t argc, const Menu::arg *argv);
|
2011-12-26 04:12:05 -04:00
|
|
|
#endif
|
2012-08-21 23:19:50 -03:00
|
|
|
static int8_t test_mag(uint8_t argc, const Menu::arg *argv);
|
|
|
|
static int8_t test_optflow(uint8_t argc, const Menu::arg *argv);
|
|
|
|
static int8_t test_logging(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);
|
2013-04-05 10:25:58 -03:00
|
|
|
//static int8_t test_rawgps(uint8_t argc, const Menu::arg *argv);
|
2012-08-21 23:19:50 -03:00
|
|
|
//static int8_t test_mission(uint8_t argc, const Menu::arg *argv);
|
2013-03-19 22:35:50 -03:00
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_PX4
|
|
|
|
static int8_t test_shell(uint8_t argc, const Menu::arg *argv);
|
|
|
|
#endif
|
2010-12-19 12:40:33 -04:00
|
|
|
|
|
|
|
// This is the help function
|
|
|
|
// PSTR is an AVR macro to read strings from flash memory
|
|
|
|
// printf_P is a version of printf that reads from flash memory
|
2012-08-21 23:19:50 -03:00
|
|
|
/*static int8_t help_test(uint8_t argc, const Menu::arg *argv)
|
|
|
|
* {
|
2012-11-21 02:08:03 -04:00
|
|
|
* cliSerial->printf_P(PSTR("\n"
|
2012-08-21 23:19:50 -03:00
|
|
|
* "Commands:\n"
|
|
|
|
* " radio\n"
|
|
|
|
* " servos\n"
|
|
|
|
* " g_gps\n"
|
|
|
|
* " imu\n"
|
|
|
|
* " battery\n"
|
|
|
|
* "\n"));
|
|
|
|
* }*/
|
2010-12-19 12:40:33 -04: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_Coommon for implementation details
|
|
|
|
const struct Menu::command test_menu_commands[] PROGMEM = {
|
2012-08-21 23:19:50 -03:00
|
|
|
{"pwm", test_radio_pwm},
|
|
|
|
{"radio", test_radio},
|
|
|
|
{"gps", test_gps},
|
|
|
|
{"ins", test_ins},
|
|
|
|
{"battery", test_battery},
|
|
|
|
{"tune", test_tuning},
|
|
|
|
{"relay", test_relay},
|
|
|
|
{"wp", test_wp},
|
2013-05-25 00:21:29 -03:00
|
|
|
// {"toy", test_toy},
|
2013-03-18 01:40:43 -03:00
|
|
|
#if HIL_MODE != HIL_MODE_ATTITUDE && HIL_MODE != HIL_MODE_SENSORS
|
2013-05-25 00:21:29 -03:00
|
|
|
{"baro", test_baro},
|
2012-08-21 23:19:50 -03:00
|
|
|
{"sonar", test_sonar},
|
2011-12-26 04:12:05 -04:00
|
|
|
#endif
|
2012-08-21 23:19:50 -03:00
|
|
|
{"compass", test_mag},
|
|
|
|
{"optflow", test_optflow},
|
|
|
|
//{"xbee", test_xbee},
|
|
|
|
{"eedump", test_eedump},
|
|
|
|
{"logging", test_logging},
|
|
|
|
{"nav", test_wp_nav},
|
2013-03-19 22:35:50 -03:00
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_PX4
|
|
|
|
{"shell", test_shell},
|
|
|
|
#endif
|
2010-12-19 12:40:33 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// A Macro to create the Menu
|
|
|
|
MENU(test_menu, "test", test_menu_commands);
|
|
|
|
|
2011-07-17 07:32:00 -03:00
|
|
|
static int8_t
|
2010-12-19 12:40:33 -04:00
|
|
|
test_mode(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2012-11-21 02:08:03 -04:00
|
|
|
//cliSerial->printf_P(PSTR("Test Mode\n\n"));
|
2012-08-21 23:19:50 -03:00
|
|
|
test_menu.run();
|
|
|
|
return 0;
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int8_t
|
|
|
|
test_eedump(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2012-08-21 23:19:50 -03:00
|
|
|
|
|
|
|
// hexdump the EEPROM
|
2012-12-13 15:48:01 -04:00
|
|
|
for (uint16_t i = 0; i < EEPROM_MAX_ADDR; i += 16) {
|
2012-11-21 02:08:03 -04:00
|
|
|
cliSerial->printf_P(PSTR("%04x:"), i);
|
2012-12-13 15:48:01 -04:00
|
|
|
for (uint16_t j = 0; j < 16; j++) {
|
|
|
|
int b = hal.storage->read_byte(i+j);
|
|
|
|
cliSerial->printf_P(PSTR(" %02x"), b);
|
|
|
|
}
|
2012-11-21 02:08:03 -04:00
|
|
|
cliSerial->println();
|
2012-08-21 23:19:50 -03:00
|
|
|
}
|
|
|
|
return(0);
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-10 02:21:30 -04:00
|
|
|
static int8_t
|
|
|
|
test_radio_pwm(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2012-08-21 23:19:50 -03:00
|
|
|
print_hit_enter();
|
|
|
|
delay(1000);
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
delay(20);
|
|
|
|
|
|
|
|
// Filters radio input - adjust filters in the radio.pde file
|
|
|
|
// ----------------------------------------------------------
|
|
|
|
read_radio();
|
|
|
|
|
|
|
|
// servo Yaw
|
|
|
|
//APM_RC.OutputCh(CH_7, g.rc_4.radio_out);
|
|
|
|
|
2012-11-21 02:08:03 -04:00
|
|
|
cliSerial->printf_P(PSTR("IN: 1: %d\t2: %d\t3: %d\t4: %d\t5: %d\t6: %d\t7: %d\t8: %d\n"),
|
2012-08-21 23:19:50 -03:00
|
|
|
g.rc_1.radio_in,
|
|
|
|
g.rc_2.radio_in,
|
|
|
|
g.rc_3.radio_in,
|
|
|
|
g.rc_4.radio_in,
|
|
|
|
g.rc_5.radio_in,
|
|
|
|
g.rc_6.radio_in,
|
|
|
|
g.rc_7.radio_in,
|
|
|
|
g.rc_8.radio_in);
|
|
|
|
|
2012-11-21 02:08:03 -04:00
|
|
|
if(cliSerial->available() > 0) {
|
2012-08-21 23:19:50 -03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
2012-02-10 02:21:30 -04:00
|
|
|
}
|
2010-12-19 12:40:33 -04:00
|
|
|
|
2012-10-21 18:32:39 -03:00
|
|
|
/*
|
|
|
|
//static int8_t
|
|
|
|
//test_toy(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2012-11-10 01:55:51 -04:00
|
|
|
|
|
|
|
for(altitude_error = 2000; altitude_error > -100; altitude_error--){
|
|
|
|
int16_t temp = get_desired_climb_rate();
|
2012-11-21 02:08:03 -04:00
|
|
|
cliSerial->printf("%ld, %d\n", altitude_error, temp);
|
2012-11-10 01:55:51 -04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
{ wp_distance = 0;
|
2012-10-21 18:32:39 -03:00
|
|
|
int16_t max_speed = 0;
|
|
|
|
|
|
|
|
for(int16_t i = 0; i < 200; i++){
|
2013-04-14 01:27:37 -03:00
|
|
|
int32_t temp = 2 * 100 * (wp_distance - wp_nav.get_waypoint_radius());
|
2013-01-10 14:42:24 -04:00
|
|
|
max_speed = sqrtf((float)temp);
|
2013-04-14 01:27:37 -03:00
|
|
|
max_speed = min(max_speed, wp_nav.get_horizontal_speed());
|
2012-11-21 02:08:03 -04:00
|
|
|
cliSerial->printf("Zspeed: %ld, %d, %ld\n", temp, max_speed, wp_distance);
|
2012-10-21 18:32:39 -03:00
|
|
|
wp_distance += 100;
|
|
|
|
}
|
|
|
|
return 0;
|
2012-11-10 01:55:51 -04:00
|
|
|
}
|
2012-10-21 18:32:39 -03:00
|
|
|
//*/
|
|
|
|
|
2012-07-19 21:50:42 -03:00
|
|
|
/*static int8_t
|
2012-08-21 23:19:50 -03:00
|
|
|
* //test_toy(uint8_t argc, const Menu::arg *argv)
|
|
|
|
* {
|
|
|
|
* int16_t yaw_rate;
|
|
|
|
* int16_t roll_rate;
|
|
|
|
* g.rc_1.control_in = -2500;
|
|
|
|
* g.rc_2.control_in = 2500;
|
|
|
|
*
|
|
|
|
* g.toy_yaw_rate = 3;
|
|
|
|
* yaw_rate = g.rc_1.control_in / g.toy_yaw_rate;
|
|
|
|
* roll_rate = ((int32_t)g.rc_2.control_in * (yaw_rate/100)) /40;
|
2012-11-21 02:08:03 -04:00
|
|
|
* cliSerial->printf("yaw_rate, %d, roll_rate, %d\n", yaw_rate, roll_rate);
|
2012-08-21 23:19:50 -03:00
|
|
|
*
|
|
|
|
* g.toy_yaw_rate = 2;
|
|
|
|
* yaw_rate = g.rc_1.control_in / g.toy_yaw_rate;
|
|
|
|
* roll_rate = ((int32_t)g.rc_2.control_in * (yaw_rate/100)) /40;
|
2012-11-21 02:08:03 -04:00
|
|
|
* cliSerial->printf("yaw_rate, %d, roll_rate, %d\n", yaw_rate, roll_rate);
|
2012-08-21 23:19:50 -03:00
|
|
|
*
|
|
|
|
* g.toy_yaw_rate = 1;
|
|
|
|
* yaw_rate = g.rc_1.control_in / g.toy_yaw_rate;
|
|
|
|
* roll_rate = ((int32_t)g.rc_2.control_in * (yaw_rate/100)) /40;
|
2012-11-21 02:08:03 -04:00
|
|
|
* cliSerial->printf("yaw_rate, %d, roll_rate, %d\n", yaw_rate, roll_rate);
|
2012-08-21 23:19:50 -03:00
|
|
|
* }*/
|
2011-09-24 20:48:04 -03:00
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
static int8_t
|
|
|
|
test_radio(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2012-08-21 23:19:50 -03:00
|
|
|
print_hit_enter();
|
|
|
|
delay(1000);
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
delay(20);
|
|
|
|
read_radio();
|
|
|
|
|
|
|
|
|
2012-11-21 02:08:03 -04:00
|
|
|
cliSerial->printf_P(PSTR("IN 1: %d\t2: %d\t3: %d\t4: %d\t5: %d\t6: %d\t7: %d\n"),
|
2012-08-21 23:19:50 -03:00
|
|
|
g.rc_1.control_in,
|
|
|
|
g.rc_2.control_in,
|
|
|
|
g.rc_3.control_in,
|
|
|
|
g.rc_4.control_in,
|
|
|
|
g.rc_5.control_in,
|
|
|
|
g.rc_6.control_in,
|
|
|
|
g.rc_7.control_in);
|
|
|
|
|
2012-11-21 02:08:03 -04:00
|
|
|
//cliSerial->printf_P(PSTR("OUT 1: %d\t2: %d\t3: %d\t4: %d\n"), (g.rc_1.servo_out / 100), (g.rc_2.servo_out / 100), g.rc_3.servo_out, (g.rc_4.servo_out / 100));
|
2012-08-21 23:19:50 -03:00
|
|
|
|
2012-11-21 02:08:03 -04:00
|
|
|
/*cliSerial->printf_P(PSTR( "min: %d"
|
2012-08-21 23:19:50 -03:00
|
|
|
* "\t in: %d"
|
|
|
|
* "\t pwm_in: %d"
|
|
|
|
* "\t sout: %d"
|
|
|
|
* "\t pwm_out %d\n"),
|
|
|
|
* g.rc_3.radio_min,
|
|
|
|
* g.rc_3.control_in,
|
|
|
|
* g.rc_3.radio_in,
|
|
|
|
* g.rc_3.servo_out,
|
|
|
|
* g.rc_3.pwm_out
|
|
|
|
* );
|
|
|
|
*/
|
2012-11-21 02:08:03 -04:00
|
|
|
if(cliSerial->available() > 0) {
|
2012-08-21 23:19:50 -03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
|
|
|
|
2011-11-12 23:51:43 -04:00
|
|
|
static int8_t
|
|
|
|
test_ins(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2012-11-05 00:32:38 -04:00
|
|
|
Vector3f gyro, accel;
|
2012-08-21 23:19:50 -03:00
|
|
|
print_hit_enter();
|
2012-11-21 02:08:03 -04:00
|
|
|
cliSerial->printf_P(PSTR("INS\n"));
|
2012-08-21 23:19:50 -03:00
|
|
|
delay(1000);
|
2011-11-12 23:51:43 -04:00
|
|
|
|
2013-01-13 01:04:04 -04:00
|
|
|
ahrs.init();
|
2012-11-29 07:56:54 -04:00
|
|
|
ins.init(AP_InertialSensor::COLD_START,
|
|
|
|
ins_sample_rate,
|
2012-12-13 15:48:01 -04:00
|
|
|
flash_leds);
|
2011-11-12 23:51:43 -04:00
|
|
|
|
2012-08-21 23:19:50 -03:00
|
|
|
delay(50);
|
2011-11-12 23:51:43 -04:00
|
|
|
|
2012-08-21 23:19:50 -03:00
|
|
|
while(1) {
|
|
|
|
ins.update();
|
2012-11-05 00:32:38 -04:00
|
|
|
gyro = ins.get_gyro();
|
|
|
|
accel = ins.get_accel();
|
2011-11-12 23:51:43 -04:00
|
|
|
|
2013-01-01 22:52:53 -04:00
|
|
|
float test = accel.length() / GRAVITY_MSS;
|
2011-11-12 23:51:43 -04:00
|
|
|
|
2012-11-21 02:08:03 -04:00
|
|
|
cliSerial->printf_P(PSTR("a %7.4f %7.4f %7.4f g %7.4f %7.4f %7.4f t %74f | %7.4f\n"),
|
2012-11-05 00:32:38 -04:00
|
|
|
accel.x, accel.y, accel.z,
|
|
|
|
gyro.x, gyro.y, gyro.z,
|
2013-02-07 00:05:47 -04:00
|
|
|
test);
|
2012-07-18 15:14:13 -03:00
|
|
|
|
2012-08-21 23:19:50 -03:00
|
|
|
delay(40);
|
2012-11-21 02:08:03 -04:00
|
|
|
if(cliSerial->available() > 0) {
|
2012-08-21 23:19:50 -03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
2011-11-12 23:51:43 -04:00
|
|
|
}
|
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
static int8_t
|
|
|
|
test_gps(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2012-08-21 23:19:50 -03:00
|
|
|
print_hit_enter();
|
|
|
|
delay(1000);
|
|
|
|
|
|
|
|
while(1) {
|
2013-03-21 08:45:07 -03:00
|
|
|
delay(100);
|
2012-08-21 23:19:50 -03:00
|
|
|
|
|
|
|
// Blink GPS LED if we don't have a fix
|
|
|
|
// ------------------------------------
|
|
|
|
update_GPS_light();
|
|
|
|
|
|
|
|
g_gps->update();
|
|
|
|
|
|
|
|
if (g_gps->new_data) {
|
2012-11-21 02:08:03 -04:00
|
|
|
cliSerial->printf_P(PSTR("Lat: "));
|
2012-12-13 15:48:01 -04:00
|
|
|
print_latlon(cliSerial, g_gps->latitude);
|
2012-11-21 02:08:03 -04:00
|
|
|
cliSerial->printf_P(PSTR(", Lon "));
|
2012-12-13 15:48:01 -04:00
|
|
|
print_latlon(cliSerial, g_gps->longitude);
|
2012-11-21 02:08:03 -04:00
|
|
|
cliSerial->printf_P(PSTR(", Alt: %ldm, #sats: %d\n"),
|
2012-08-21 23:19:50 -03:00
|
|
|
g_gps->altitude/100,
|
|
|
|
g_gps->num_sats);
|
|
|
|
g_gps->new_data = false;
|
|
|
|
}else{
|
2012-11-21 02:08:03 -04:00
|
|
|
cliSerial->print_P(PSTR("."));
|
2012-08-21 23:19:50 -03:00
|
|
|
}
|
2012-11-21 02:08:03 -04:00
|
|
|
if(cliSerial->available() > 0) {
|
2012-08-21 23:19:50 -03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
|
|
|
|
2011-04-17 20:08:16 -03:00
|
|
|
static int8_t
|
|
|
|
test_tuning(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2012-08-21 23:19:50 -03:00
|
|
|
print_hit_enter();
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
delay(200);
|
|
|
|
read_radio();
|
|
|
|
tuning();
|
2012-11-21 02:08:03 -04:00
|
|
|
cliSerial->printf_P(PSTR("tune: %1.3f\n"), tuning_value);
|
2012-08-21 23:19:50 -03:00
|
|
|
|
2012-11-21 02:08:03 -04:00
|
|
|
if(cliSerial->available() > 0) {
|
2012-08-21 23:19:50 -03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
2011-04-17 20:08:16 -03:00
|
|
|
}
|
|
|
|
|
2011-01-16 23:44:12 -04:00
|
|
|
static int8_t
|
2012-01-15 20:10:02 -04:00
|
|
|
test_battery(uint8_t argc, const Menu::arg *argv)
|
2011-01-16 23:44:12 -04:00
|
|
|
{
|
2013-05-16 04:32:00 -03:00
|
|
|
// check if radio is calibration
|
|
|
|
pre_arm_rc_checks();
|
|
|
|
if(!ap.pre_arm_rc_check) {
|
|
|
|
cliSerial->print_P(PSTR("radio not calibrated, exiting"));
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2012-11-21 02:08:03 -04:00
|
|
|
cliSerial->printf_P(PSTR("\nCareful! Motors will spin! Press Enter to start.\n"));
|
2012-12-13 15:48:01 -04:00
|
|
|
while (cliSerial->read() != -1); /* flush */
|
|
|
|
while(!cliSerial->available()) { /* wait for input */
|
2012-08-21 23:19:50 -03:00
|
|
|
delay(100);
|
|
|
|
}
|
2012-12-13 15:48:01 -04:00
|
|
|
while (cliSerial->read() != -1); /* flush */
|
2012-08-21 23:19:50 -03:00
|
|
|
print_hit_enter();
|
|
|
|
|
|
|
|
// allow motors to spin
|
2013-05-16 04:32:00 -03:00
|
|
|
output_min();
|
2012-08-21 23:19:50 -03:00
|
|
|
motors.armed(true);
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
delay(100);
|
|
|
|
read_radio();
|
|
|
|
read_battery();
|
2013-03-03 10:02:36 -04:00
|
|
|
if (g.battery_monitoring == BATT_MONITOR_VOLTAGE_ONLY) {
|
2012-11-21 02:08:03 -04:00
|
|
|
cliSerial->printf_P(PSTR("V: %4.4f\n"),
|
2012-08-21 23:19:50 -03:00
|
|
|
battery_voltage1,
|
|
|
|
current_amps1,
|
|
|
|
current_total1);
|
|
|
|
} else {
|
2012-11-21 02:08:03 -04:00
|
|
|
cliSerial->printf_P(PSTR("V: %4.4f, A: %4.4f, Ah: %4.4f\n"),
|
2012-08-21 23:19:50 -03:00
|
|
|
battery_voltage1,
|
|
|
|
current_amps1,
|
|
|
|
current_total1);
|
|
|
|
}
|
|
|
|
motors.throttle_pass_through();
|
|
|
|
|
2012-11-21 02:08:03 -04:00
|
|
|
if(cliSerial->available() > 0) {
|
2012-08-21 23:19:50 -03:00
|
|
|
motors.armed(false);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
motors.armed(false);
|
|
|
|
return (0);
|
2011-01-16 23:44:12 -04:00
|
|
|
}
|
|
|
|
|
2012-01-13 12:55:02 -04:00
|
|
|
static int8_t test_relay(uint8_t argc, const Menu::arg *argv)
|
2010-12-19 12:40:33 -04:00
|
|
|
{
|
2012-08-21 23:19:50 -03:00
|
|
|
print_hit_enter();
|
|
|
|
delay(1000);
|
|
|
|
|
|
|
|
while(1) {
|
2012-11-21 02:08:03 -04:00
|
|
|
cliSerial->printf_P(PSTR("Relay on\n"));
|
2012-08-21 23:19:50 -03:00
|
|
|
relay.on();
|
|
|
|
delay(3000);
|
2012-11-21 02:08:03 -04:00
|
|
|
if(cliSerial->available() > 0) {
|
2012-08-21 23:19:50 -03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2012-11-21 02:08:03 -04:00
|
|
|
cliSerial->printf_P(PSTR("Relay off\n"));
|
2012-08-21 23:19:50 -03:00
|
|
|
relay.off();
|
|
|
|
delay(3000);
|
2012-11-21 02:08:03 -04:00
|
|
|
if(cliSerial->available() > 0) {
|
2012-08-21 23:19:50 -03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
2012-01-13 12:55:02 -04:00
|
|
|
|
2012-01-29 02:16:24 -04:00
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
static int8_t
|
|
|
|
test_wp(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2012-08-21 23:19:50 -03:00
|
|
|
delay(1000);
|
|
|
|
|
|
|
|
// save the alitude above home option
|
2012-11-21 02:08:03 -04:00
|
|
|
cliSerial->printf_P(PSTR("Hold alt "));
|
2012-11-29 08:08:19 -04:00
|
|
|
if(g.rtl_altitude < 0) {
|
2012-11-21 02:08:03 -04:00
|
|
|
cliSerial->printf_P(PSTR("\n"));
|
2012-08-21 23:19:50 -03:00
|
|
|
}else{
|
2012-11-29 08:08:19 -04:00
|
|
|
cliSerial->printf_P(PSTR("of %dm\n"), (int)g.rtl_altitude / 100);
|
2012-08-21 23:19:50 -03:00
|
|
|
}
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2012-11-21 02:08:03 -04:00
|
|
|
cliSerial->printf_P(PSTR("%d wp\n"), (int)g.command_total);
|
2013-04-14 01:27:37 -03:00
|
|
|
cliSerial->printf_P(PSTR("Hit rad: %dm\n"), (int)wp_nav.get_waypoint_radius());
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2012-08-21 23:19:50 -03:00
|
|
|
report_wp();
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2012-08-21 23:19:50 -03:00
|
|
|
return (0);
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
|
|
|
|
2013-03-18 01:40:43 -03:00
|
|
|
#if HIL_MODE != HIL_MODE_ATTITUDE && HIL_MODE != HIL_MODE_SENSORS
|
2010-12-19 12:40:33 -04:00
|
|
|
static int8_t
|
2011-06-03 15:49:13 -03:00
|
|
|
test_baro(uint8_t argc, const Menu::arg *argv)
|
2010-12-19 12:40:33 -04:00
|
|
|
{
|
2013-05-25 00:21:29 -03:00
|
|
|
int32_t alt;
|
2012-08-21 23:19:50 -03:00
|
|
|
print_hit_enter();
|
|
|
|
init_barometer();
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
delay(100);
|
2013-05-25 00:21:29 -03:00
|
|
|
alt = read_barometer();
|
|
|
|
|
|
|
|
if (!barometer.healthy) {
|
|
|
|
cliSerial->println_P(PSTR("not healthy"));
|
|
|
|
} else {
|
|
|
|
cliSerial->printf_P(PSTR("Alt: %0.2fm, Raw: %f Temperature: %.1f\n"),
|
|
|
|
alt / 100.0,
|
|
|
|
barometer.get_pressure(), 0.1*barometer.get_temperature());
|
|
|
|
}
|
2012-11-21 02:08:03 -04:00
|
|
|
if(cliSerial->available() > 0) {
|
2012-08-21 23:19:50 -03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
2011-12-26 04:12:05 -04:00
|
|
|
#endif
|
2010-12-19 12:40:33 -04:00
|
|
|
|
2011-12-03 19:39:02 -04:00
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
static int8_t
|
2011-12-03 19:39:02 -04:00
|
|
|
test_mag(uint8_t argc, const Menu::arg *argv)
|
2011-04-08 16:13:31 -03:00
|
|
|
{
|
2013-04-27 11:33:04 -03:00
|
|
|
uint8_t delta_ms_fast_loop;
|
2012-08-21 23:19:50 -03:00
|
|
|
|
2013-04-27 11:33:04 -03:00
|
|
|
if (!g.compass_enabled) {
|
2012-11-21 02:08:03 -04:00
|
|
|
cliSerial->printf_P(PSTR("Compass: "));
|
2012-08-21 23:19:50 -03:00
|
|
|
print_enabled(false);
|
|
|
|
return (0);
|
|
|
|
}
|
2013-04-27 11:33:04 -03:00
|
|
|
|
|
|
|
if (!compass.init()) {
|
|
|
|
cliSerial->println_P(PSTR("Compass initialisation failed!"));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ahrs.init();
|
|
|
|
ahrs.set_fly_forward(true);
|
|
|
|
ahrs.set_compass(&compass);
|
|
|
|
report_compass();
|
|
|
|
|
|
|
|
// we need the AHRS initialised for this test
|
|
|
|
ins.init(AP_InertialSensor::COLD_START,
|
|
|
|
ins_sample_rate,
|
|
|
|
flash_leds);
|
|
|
|
ahrs.reset();
|
|
|
|
int16_t counter = 0;
|
|
|
|
float heading = 0;
|
|
|
|
|
|
|
|
print_hit_enter();
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
delay(20);
|
|
|
|
if (millis() - fast_loopTimer > 19) {
|
|
|
|
delta_ms_fast_loop = millis() - fast_loopTimer;
|
|
|
|
G_Dt = (float)delta_ms_fast_loop / 1000.f; // used by DCM integrator
|
|
|
|
fast_loopTimer = millis();
|
|
|
|
|
|
|
|
// INS
|
|
|
|
// ---
|
|
|
|
ahrs.update();
|
|
|
|
|
|
|
|
medium_loopCounter++;
|
|
|
|
if(medium_loopCounter == 5) {
|
|
|
|
if (compass.read()) {
|
|
|
|
// Calculate heading
|
2013-05-05 02:02:51 -03:00
|
|
|
const Matrix3f &m = ahrs.get_dcm_matrix();
|
2013-04-27 11:33:04 -03:00
|
|
|
heading = compass.calculate_heading(m);
|
|
|
|
compass.null_offsets();
|
|
|
|
}
|
|
|
|
medium_loopCounter = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
counter++;
|
|
|
|
if (counter>20) {
|
|
|
|
if (compass.healthy) {
|
|
|
|
Vector3f maggy = compass.get_offsets();
|
|
|
|
cliSerial->printf_P(PSTR("Heading: %ld, XYZ: %d, %d, %d,\tXYZoff: %6.2f, %6.2f, %6.2f\n"),
|
|
|
|
(wrap_360_cd(ToDeg(heading) * 100)) /100,
|
|
|
|
(int)compass.mag_x,
|
|
|
|
(int)compass.mag_y,
|
|
|
|
(int)compass.mag_z,
|
|
|
|
maggy.x,
|
|
|
|
maggy.y,
|
|
|
|
maggy.z);
|
|
|
|
} else {
|
|
|
|
cliSerial->println_P(PSTR("compass not healthy"));
|
|
|
|
}
|
|
|
|
counter=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (cliSerial->available() > 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// save offsets. This allows you to get sane offset values using
|
|
|
|
// the CLI before you go flying.
|
|
|
|
cliSerial->println_P(PSTR("saving offsets"));
|
|
|
|
compass.save_offsets();
|
2012-08-21 23:19:50 -03:00
|
|
|
return (0);
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
2011-12-03 19:39:02 -04:00
|
|
|
|
2013-03-18 01:40:43 -03:00
|
|
|
#if HIL_MODE != HIL_MODE_ATTITUDE && HIL_MODE != HIL_MODE_SENSORS
|
2011-03-17 22:50:27 -03:00
|
|
|
/*
|
2012-08-21 23:19:50 -03:00
|
|
|
* test the sonar
|
2011-03-17 22:50:27 -03:00
|
|
|
*/
|
2011-06-03 15:49:13 -03:00
|
|
|
static int8_t
|
2011-03-17 22:50:27 -03:00
|
|
|
test_sonar(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2013-03-18 01:40:43 -03:00
|
|
|
#if CONFIG_SONAR == ENABLED
|
2012-08-21 23:19:50 -03:00
|
|
|
if(g.sonar_enabled == false) {
|
2012-11-21 02:08:03 -04:00
|
|
|
cliSerial->printf_P(PSTR("Sonar disabled\n"));
|
2012-08-21 23:19:50 -03:00
|
|
|
return (0);
|
|
|
|
}
|
2011-12-23 18:14:19 -04:00
|
|
|
|
2012-08-21 23:19:50 -03:00
|
|
|
// make sure sonar is initialised
|
|
|
|
init_sonar();
|
2011-06-16 14:03:26 -03:00
|
|
|
|
2012-08-21 23:19:50 -03:00
|
|
|
print_hit_enter();
|
|
|
|
while(1) {
|
|
|
|
delay(100);
|
2011-06-03 15:49:13 -03:00
|
|
|
|
2012-12-13 15:48:01 -04:00
|
|
|
cliSerial->printf_P(PSTR("Sonar: %d cm\n"), sonar->read());
|
2011-06-03 15:49:13 -03:00
|
|
|
|
2012-11-21 02:08:03 -04:00
|
|
|
if(cliSerial->available() > 0) {
|
2012-08-21 23:19:50 -03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
2013-03-18 01:40:43 -03:00
|
|
|
#endif
|
2012-08-21 23:19:50 -03:00
|
|
|
return (0);
|
2011-03-17 22:50:27 -03:00
|
|
|
}
|
2011-12-26 04:12:05 -04:00
|
|
|
#endif
|
2011-03-17 22:50:27 -03:00
|
|
|
|
2011-12-23 18:14:19 -04:00
|
|
|
|
2011-07-21 20:14:53 -03:00
|
|
|
static int8_t
|
|
|
|
test_optflow(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2012-11-18 12:16:07 -04:00
|
|
|
#if OPTFLOW == ENABLED
|
2012-08-21 23:19:50 -03:00
|
|
|
if(g.optflow_enabled) {
|
2012-11-21 02:08:03 -04:00
|
|
|
cliSerial->printf_P(PSTR("man id: %d\t"),optflow.read_register(ADNS3080_PRODUCT_ID));
|
2012-08-21 23:19:50 -03:00
|
|
|
print_hit_enter();
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
delay(200);
|
2012-09-14 09:05:20 -03:00
|
|
|
optflow.update(millis());
|
2012-08-21 23:19:50 -03:00
|
|
|
Log_Write_Optflow();
|
2012-11-21 02:08:03 -04:00
|
|
|
cliSerial->printf_P(PSTR("x/dx: %d/%d\t y/dy %d/%d\t squal:%d\n"),
|
2012-08-21 23:19:50 -03:00
|
|
|
optflow.x,
|
|
|
|
optflow.dx,
|
|
|
|
optflow.y,
|
|
|
|
optflow.dy,
|
|
|
|
optflow.surface_quality);
|
|
|
|
|
2012-11-21 02:08:03 -04:00
|
|
|
if(cliSerial->available() > 0) {
|
2012-08-21 23:19:50 -03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2012-11-21 02:08:03 -04:00
|
|
|
cliSerial->printf_P(PSTR("OptFlow: "));
|
2012-08-21 23:19:50 -03:00
|
|
|
print_enabled(false);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
#else
|
|
|
|
return (0);
|
2012-11-18 12:16:07 -04:00
|
|
|
#endif // OPTFLOW == ENABLED
|
2011-07-21 20:14:53 -03:00
|
|
|
}
|
2011-12-23 18:14:19 -04:00
|
|
|
|
2011-07-21 20:14:53 -03:00
|
|
|
|
2012-08-16 01:03:32 -03:00
|
|
|
static int8_t
|
|
|
|
test_wp_nav(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2012-08-21 23:19:50 -03:00
|
|
|
current_loc.lat = 389539260;
|
|
|
|
current_loc.lng = -1199540200;
|
2012-08-16 01:03:32 -03:00
|
|
|
|
2013-03-22 09:59:17 -03:00
|
|
|
wp_nav.set_destination(pv_latlon_to_vector(389538528,-1199541248,0));
|
2012-08-16 01:03:32 -03:00
|
|
|
|
2012-08-21 23:19:50 -03:00
|
|
|
// got 23506;, should be 22800
|
2012-11-07 06:03:30 -04:00
|
|
|
update_navigation();
|
2012-12-08 01:23:32 -04:00
|
|
|
cliSerial->printf_P(PSTR("bear: %ld\n"), wp_bearing);
|
2012-08-21 23:19:50 -03:00
|
|
|
return 0;
|
2012-08-16 01:03:32 -03:00
|
|
|
}
|
|
|
|
|
2011-12-28 00:53:05 -04:00
|
|
|
/*
|
2012-08-21 23:19:50 -03:00
|
|
|
* test the dataflash is working
|
2011-12-28 00:53:05 -04:00
|
|
|
*/
|
2012-01-29 02:16:24 -04:00
|
|
|
|
2011-12-28 00:53:05 -04:00
|
|
|
static int8_t
|
|
|
|
test_logging(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2012-11-21 02:08:03 -04:00
|
|
|
cliSerial->println_P(PSTR("Testing dataflash logging"));
|
2013-02-22 19:15:01 -04:00
|
|
|
DataFlash.ShowDeviceInfo(cliSerial);
|
2012-08-21 23:19:50 -03:00
|
|
|
return 0;
|
2011-12-28 00:53:05 -04:00
|
|
|
}
|
|
|
|
|
2013-03-19 22:35:50 -03:00
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_PX4
|
|
|
|
/*
|
|
|
|
* 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-07-17 07:32:00 -03:00
|
|
|
static void print_hit_enter()
|
2010-12-19 12:40:33 -04:00
|
|
|
{
|
2012-11-21 02:08:03 -04:00
|
|
|
cliSerial->printf_P(PSTR("Hit Enter to exit.\n\n"));
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
2011-09-10 19:16:51 -03:00
|
|
|
|
2011-07-17 07:34:05 -03:00
|
|
|
#endif // CLI_ENABLED
|