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
|
|
|
|
|
|
|
|
// These are function definitions so the Menu can be constructed before the functions
|
|
|
|
// are defined below. Order matters to the compiler.
|
|
|
|
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);
|
2012-11-07 03:28:20 -04:00
|
|
|
static int8_t test_ins(uint8_t argc, const Menu::arg *argv);
|
2012-04-30 04:17:14 -03:00
|
|
|
static int8_t test_battery(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);
|
2012-06-13 03:29:32 -03:00
|
|
|
static int8_t test_sonar(uint8_t argc, const Menu::arg *argv);
|
2012-04-30 04:17:14 -03:00
|
|
|
static int8_t test_mag(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);
|
2013-03-19 22:35:56 -03:00
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_PX4
|
|
|
|
static int8_t test_shell(uint8_t argc, const Menu::arg *argv);
|
|
|
|
#endif
|
2012-04-30 04:17:14 -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 = {
|
|
|
|
{"pwm", test_radio_pwm},
|
|
|
|
{"radio", test_radio},
|
|
|
|
{"passthru", test_passthru},
|
|
|
|
{"failsafe", test_failsafe},
|
|
|
|
{"battery", test_battery},
|
|
|
|
{"relay", test_relay},
|
|
|
|
{"waypoints", test_wp},
|
|
|
|
{"modeswitch", test_modeswitch},
|
|
|
|
|
|
|
|
// Tests below here are for hardware sensors only present
|
|
|
|
// when real sensors are attached or they are emulated
|
|
|
|
{"gps", test_gps},
|
2012-11-07 03:28:20 -04:00
|
|
|
{"ins", test_ins},
|
2012-06-13 03:29:32 -03:00
|
|
|
{"sonartest", test_sonar},
|
2012-04-30 04:17:14 -03:00
|
|
|
{"compass", test_mag},
|
|
|
|
{"logging", test_logging},
|
2013-03-19 22:35:56 -03:00
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_PX4
|
|
|
|
{"shell", test_shell},
|
|
|
|
#endif
|
2012-04-30 04:17:14 -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 02:25:11 -04:00
|
|
|
cliSerial->printf_P(PSTR("Test Mode\n\n"));
|
2012-04-30 04:17:14 -03:00
|
|
|
test_menu.run();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_hit_enter()
|
|
|
|
{
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->printf_P(PSTR("Hit Enter to exit.\n\n"));
|
2012-04-30 04:17:14 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int8_t
|
|
|
|
test_radio_pwm(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
|
|
|
print_hit_enter();
|
|
|
|
delay(1000);
|
|
|
|
|
|
|
|
while(1){
|
|
|
|
delay(20);
|
|
|
|
|
|
|
|
// Filters radio input - adjust filters in the radio.pde file
|
|
|
|
// ----------------------------------------------------------
|
|
|
|
read_radio();
|
|
|
|
|
2012-11-21 02:25:11 -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 06:33:59 -03:00
|
|
|
channel_steer->radio_in,
|
2013-02-07 18:21:22 -04:00
|
|
|
g.rc_2.radio_in,
|
2013-06-03 06:33:59 -03:00
|
|
|
channel_throttle->radio_in,
|
2013-02-07 18:21:22 -04:00
|
|
|
g.rc_4.radio_in,
|
2012-04-30 04:17:14 -03:00
|
|
|
g.rc_5.radio_in,
|
|
|
|
g.rc_6.radio_in,
|
|
|
|
g.rc_7.radio_in,
|
|
|
|
g.rc_8.radio_in);
|
|
|
|
|
2012-11-21 02:25:11 -04:00
|
|
|
if(cliSerial->available() > 0){
|
2012-04-30 04:17:14 -03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int8_t
|
|
|
|
test_passthru(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
|
|
|
print_hit_enter();
|
|
|
|
delay(1000);
|
|
|
|
|
|
|
|
while(1){
|
|
|
|
delay(20);
|
|
|
|
|
|
|
|
// New radio frame? (we could use also if((millis()- timer) > 20)
|
2013-04-29 03:07:22 -03:00
|
|
|
if (hal.rcin->valid_channels() > 0) {
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->print("CH:");
|
2012-04-30 04:17:14 -03:00
|
|
|
for(int i = 0; i < 8; i++){
|
2012-12-18 17:00:32 -04:00
|
|
|
cliSerial->print(hal.rcin->read(i)); // Print channel values
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->print(",");
|
2012-12-18 17:00:32 -04:00
|
|
|
hal.rcout->write(i, hal.rcin->read(i)); // Copy input to Servos
|
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
|
|
|
}
|
2012-11-21 02:25:11 -04:00
|
|
|
if (cliSerial->available() > 0){
|
2012-04-30 04:17:14 -03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int8_t
|
|
|
|
test_radio(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
|
|
|
print_hit_enter();
|
|
|
|
delay(1000);
|
|
|
|
|
|
|
|
// read the radio to set trims
|
|
|
|
// ---------------------------
|
|
|
|
trim_radio();
|
|
|
|
|
|
|
|
while(1){
|
|
|
|
delay(20);
|
|
|
|
read_radio();
|
|
|
|
|
2013-06-03 06:33:59 -03:00
|
|
|
channel_steer->calc_pwm();
|
|
|
|
channel_throttle->calc_pwm();
|
2012-04-30 04:17:14 -03:00
|
|
|
|
|
|
|
// write out the servo PWM values
|
|
|
|
// ------------------------------
|
|
|
|
set_servos();
|
|
|
|
|
2013-06-30 21:10:38 -03: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 06:33:59 -03:00
|
|
|
channel_steer->control_in,
|
2013-02-07 18:21:22 -04:00
|
|
|
g.rc_2.control_in,
|
2013-06-03 06:33:59 -03:00
|
|
|
channel_throttle->control_in,
|
2013-02-07 18:21:22 -04:00
|
|
|
g.rc_4.control_in,
|
2012-04-30 04:17:14 -03:00
|
|
|
g.rc_5.control_in,
|
|
|
|
g.rc_6.control_in,
|
|
|
|
g.rc_7.control_in,
|
2013-06-30 21:10:38 -03:00
|
|
|
g.rc_8.control_in);
|
2012-04-30 04:17:14 -03:00
|
|
|
|
2012-11-21 02:25:11 -04:00
|
|
|
if(cliSerial->available() > 0){
|
2012-04-30 04:17:14 -03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int8_t
|
|
|
|
test_failsafe(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2012-12-18 07:44:12 -04:00
|
|
|
uint8_t fail_test;
|
2012-04-30 04:17:14 -03:00
|
|
|
print_hit_enter();
|
|
|
|
for(int i = 0; i < 50; i++){
|
|
|
|
delay(20);
|
|
|
|
read_radio();
|
|
|
|
}
|
|
|
|
|
|
|
|
// read the radio to set trims
|
|
|
|
// ---------------------------
|
|
|
|
trim_radio();
|
|
|
|
|
|
|
|
oldSwitchPosition = readSwitch();
|
|
|
|
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->printf_P(PSTR("Unplug battery, throttle in neutral, turn off radio.\n"));
|
2013-06-03 06:33:59 -03:00
|
|
|
while(channel_throttle->control_in > 0){
|
2012-04-30 04:17:14 -03:00
|
|
|
delay(20);
|
|
|
|
read_radio();
|
|
|
|
}
|
|
|
|
|
|
|
|
while(1){
|
|
|
|
delay(20);
|
|
|
|
read_radio();
|
|
|
|
|
2013-06-03 06:33:59 -03:00
|
|
|
if(channel_throttle->control_in > 0){
|
|
|
|
cliSerial->printf_P(PSTR("THROTTLE CHANGED %d \n"), channel_throttle->control_in);
|
2012-04-30 04:17:14 -03:00
|
|
|
fail_test++;
|
|
|
|
}
|
|
|
|
|
2012-11-28 07:44:03 -04:00
|
|
|
if (oldSwitchPosition != readSwitch()){
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->printf_P(PSTR("CONTROL MODE CHANGED: "));
|
2013-04-20 02:18:42 -03:00
|
|
|
print_mode(cliSerial, readSwitch());
|
|
|
|
cliSerial->println();
|
2012-04-30 04:17:14 -03:00
|
|
|
fail_test++;
|
|
|
|
}
|
|
|
|
|
2013-06-03 06:33:59 -03:00
|
|
|
if (g.fs_throttle_enabled && channel_throttle->get_failsafe()){
|
|
|
|
cliSerial->printf_P(PSTR("THROTTLE FAILSAFE ACTIVATED: %d, "), channel_throttle->radio_in);
|
2013-04-20 02:18:42 -03:00
|
|
|
print_mode(cliSerial, readSwitch());
|
|
|
|
cliSerial->println();
|
2012-04-30 04:17:14 -03:00
|
|
|
fail_test++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(fail_test > 0){
|
|
|
|
return (0);
|
|
|
|
}
|
2012-11-21 02:25:11 -04:00
|
|
|
if(cliSerial->available() > 0){
|
|
|
|
cliSerial->printf_P(PSTR("LOS caused no change in APM.\n"));
|
2012-04-30 04:17:14 -03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int8_t
|
|
|
|
test_battery(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
|
|
|
if (g.battery_monitoring == 3 || g.battery_monitoring == 4) {
|
|
|
|
print_hit_enter();
|
|
|
|
|
|
|
|
while(1){
|
|
|
|
delay(100);
|
|
|
|
read_radio();
|
|
|
|
read_battery();
|
|
|
|
if (g.battery_monitoring == 3){
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->printf_P(PSTR("V: %4.4f\n"),
|
2012-04-30 04:17:14 -03:00
|
|
|
battery_voltage1,
|
|
|
|
current_amps1,
|
|
|
|
current_total1);
|
|
|
|
} else {
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->printf_P(PSTR("V: %4.4f, A: %4.4f, mAh: %4.4f\n"),
|
2012-04-30 04:17:14 -03:00
|
|
|
battery_voltage1,
|
|
|
|
current_amps1,
|
|
|
|
current_total1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// write out the servo PWM values
|
|
|
|
// ------------------------------
|
|
|
|
set_servos();
|
|
|
|
|
2012-11-21 02:25:11 -04:00
|
|
|
if(cliSerial->available() > 0){
|
2012-04-30 04:17:14 -03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->printf_P(PSTR("Not enabled\n"));
|
2012-04-30 04:17:14 -03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static int8_t
|
|
|
|
test_relay(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
|
|
|
print_hit_enter();
|
|
|
|
delay(1000);
|
|
|
|
|
|
|
|
while(1){
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->printf_P(PSTR("Relay on\n"));
|
2012-04-30 04:17:14 -03:00
|
|
|
relay.on();
|
|
|
|
delay(3000);
|
2012-11-21 02:25:11 -04:00
|
|
|
if(cliSerial->available() > 0){
|
2012-04-30 04:17:14 -03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->printf_P(PSTR("Relay off\n"));
|
2012-04-30 04:17:14 -03:00
|
|
|
relay.off();
|
|
|
|
delay(3000);
|
2012-11-21 02:25:11 -04:00
|
|
|
if(cliSerial->available() > 0){
|
2012-04-30 04:17:14 -03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int8_t
|
|
|
|
test_wp(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
|
|
|
delay(1000);
|
|
|
|
|
2013-02-07 18:21:22 -04:00
|
|
|
cliSerial->printf_P(PSTR("%u waypoints\n"), (unsigned)g.command_total);
|
|
|
|
cliSerial->printf_P(PSTR("Hit radius: %f\n"), g.waypoint_radius);
|
2012-04-30 04:17:14 -03:00
|
|
|
|
2012-12-18 07:44:12 -04:00
|
|
|
for(uint8_t i = 0; i <= g.command_total; i++){
|
2012-04-30 04:17:14 -03:00
|
|
|
struct Location temp = get_cmd_with_index(i);
|
|
|
|
test_wp_print(&temp, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-03-26 08:58:54 -03:00
|
|
|
test_wp_print(const struct Location *cmd, uint8_t wp_index)
|
2012-04-30 04:17:14 -03:00
|
|
|
{
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->printf_P(PSTR("command #: %d id:%d options:%d p1:%d p2:%ld p3:%ld p4:%ld \n"),
|
2012-04-30 04:17:14 -03:00
|
|
|
(int)wp_index,
|
|
|
|
(int)cmd->id,
|
|
|
|
(int)cmd->options,
|
|
|
|
(int)cmd->p1,
|
|
|
|
cmd->alt,
|
|
|
|
cmd->lat,
|
|
|
|
cmd->lng);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int8_t
|
|
|
|
test_modeswitch(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
|
|
|
print_hit_enter();
|
|
|
|
delay(1000);
|
|
|
|
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->printf_P(PSTR("Control CH "));
|
2012-04-30 04:17:14 -03:00
|
|
|
|
2013-02-07 18:21:22 -04:00
|
|
|
cliSerial->println(MODE_CHANNEL, DEC);
|
2012-04-30 04:17:14 -03:00
|
|
|
|
|
|
|
while(1){
|
|
|
|
delay(20);
|
2012-12-18 07:44:12 -04:00
|
|
|
uint8_t switchPosition = readSwitch();
|
2012-04-30 04:17:14 -03:00
|
|
|
if (oldSwitchPosition != switchPosition){
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->printf_P(PSTR("Position %d\n"), switchPosition);
|
2012-04-30 04:17:14 -03:00
|
|
|
oldSwitchPosition = switchPosition;
|
|
|
|
}
|
2012-11-21 02:25:11 -04:00
|
|
|
if(cliSerial->available() > 0){
|
2012-04-30 04:17:14 -03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
test the dataflash is working
|
|
|
|
*/
|
|
|
|
static int8_t
|
|
|
|
test_logging(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->println_P(PSTR("Testing dataflash logging"));
|
2013-02-22 19:14:35 -04:00
|
|
|
DataFlash.ShowDeviceInfo(cliSerial);
|
2012-04-30 04:17:14 -03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------------
|
|
|
|
// tests in this section are for real sensors or sensors that have been simulated
|
|
|
|
|
|
|
|
static int8_t
|
|
|
|
test_gps(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
|
|
|
print_hit_enter();
|
|
|
|
delay(1000);
|
|
|
|
|
|
|
|
while(1){
|
2013-03-21 08:45:29 -03:00
|
|
|
delay(100);
|
2012-04-30 04:17:14 -03:00
|
|
|
|
|
|
|
g_gps->update();
|
|
|
|
|
|
|
|
if (g_gps->new_data){
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->printf_P(PSTR("Lat: %ld, Lon %ld, Alt: %ldm, #sats: %d\n"),
|
2012-04-30 04:17:14 -03:00
|
|
|
g_gps->latitude,
|
|
|
|
g_gps->longitude,
|
2013-07-10 01:02:40 -03:00
|
|
|
g_gps->altitude_cm/100,
|
2012-04-30 04:17:14 -03:00
|
|
|
g_gps->num_sats);
|
|
|
|
}else{
|
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
|
|
|
if(cliSerial->available() > 0){
|
2012-04-30 04:17:14 -03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int8_t
|
2012-11-07 03:28:20 -04:00
|
|
|
test_ins(uint8_t argc, const Menu::arg *argv)
|
2012-04-30 04:17:14 -03:00
|
|
|
{
|
2012-11-21 02:25:11 -04:00
|
|
|
//cliSerial->printf_P(PSTR("Calibrating."));
|
2013-01-13 01:03:54 -04:00
|
|
|
ahrs.init();
|
|
|
|
ahrs.set_fly_forward(true);
|
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-04-30 04:17:14 -03:00
|
|
|
ahrs.reset();
|
|
|
|
|
|
|
|
print_hit_enter();
|
|
|
|
delay(1000);
|
|
|
|
|
2013-06-03 21:37:05 -03:00
|
|
|
uint8_t medium_loopCounter = 0;
|
|
|
|
|
2012-04-30 04:17:14 -03:00
|
|
|
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();
|
|
|
|
|
2012-11-07 03:28:20 -04:00
|
|
|
// INS
|
2012-04-30 04:17:14 -03:00
|
|
|
// ---
|
|
|
|
ahrs.update();
|
|
|
|
|
|
|
|
if(g.compass_enabled) {
|
|
|
|
medium_loopCounter++;
|
2013-06-03 21:37:05 -03:00
|
|
|
if(medium_loopCounter >= 5){
|
2012-06-20 06:31:56 -03:00
|
|
|
compass.read();
|
2012-04-30 04:17:14 -03:00
|
|
|
medium_loopCounter = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We are using the IMU
|
|
|
|
// ---------------------
|
2012-11-07 03:28:20 -04:00
|
|
|
Vector3f gyros = ins.get_gyro();
|
|
|
|
Vector3f accels = ins.get_accel();
|
2012-11-21 02:25:11 -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-04-30 04:17:14 -03:00
|
|
|
(int)ahrs.roll_sensor / 100,
|
|
|
|
(int)ahrs.pitch_sensor / 100,
|
|
|
|
(uint16_t)ahrs.yaw_sensor / 100,
|
|
|
|
gyros.x, gyros.y, gyros.z,
|
|
|
|
accels.x, accels.y, accels.z);
|
|
|
|
}
|
2012-11-21 02:25:11 -04:00
|
|
|
if(cliSerial->available() > 0){
|
2012-04-30 04:17:14 -03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int8_t
|
|
|
|
test_mag(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
|
|
|
if (!g.compass_enabled) {
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->printf_P(PSTR("Compass: "));
|
2012-04-30 04:17:14 -03:00
|
|
|
print_enabled(false);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
return 0;
|
|
|
|
}
|
2013-01-13 01:03:54 -04:00
|
|
|
ahrs.init();
|
|
|
|
ahrs.set_fly_forward(true);
|
2012-04-30 04:17:14 -03:00
|
|
|
ahrs.set_compass(&compass);
|
|
|
|
report_compass();
|
|
|
|
|
|
|
|
// we need the AHRS initialised for this test
|
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-04-30 04:17:14 -03:00
|
|
|
ahrs.reset();
|
|
|
|
|
|
|
|
int counter = 0;
|
2012-06-20 06:31:56 -03:00
|
|
|
float heading = 0;
|
|
|
|
|
2012-04-30 04:17:14 -03:00
|
|
|
print_hit_enter();
|
|
|
|
|
2013-06-03 21:37:05 -03:00
|
|
|
uint8_t medium_loopCounter = 0;
|
|
|
|
|
2012-04-30 04:17:14 -03:00
|
|
|
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();
|
|
|
|
|
|
|
|
// IMU
|
|
|
|
// ---
|
|
|
|
ahrs.update();
|
|
|
|
|
|
|
|
medium_loopCounter++;
|
2013-06-03 21:37:05 -03:00
|
|
|
if(medium_loopCounter >= 5){
|
2012-04-30 04:17:14 -03:00
|
|
|
if (compass.read()) {
|
|
|
|
// Calculate heading
|
|
|
|
Matrix3f m = ahrs.get_dcm_matrix();
|
2012-06-20 06:31:56 -03:00
|
|
|
heading = compass.calculate_heading(m);
|
2012-04-30 04:17:14 -03:00
|
|
|
compass.null_offsets();
|
|
|
|
}
|
|
|
|
medium_loopCounter = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
counter++;
|
|
|
|
if (counter>20) {
|
|
|
|
if (compass.healthy) {
|
|
|
|
Vector3f maggy = compass.get_offsets();
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->printf_P(PSTR("Heading: %ld, XYZ: %d, %d, %d,\tXYZoff: %6.2f, %6.2f, %6.2f\n"),
|
2013-03-28 23:14:14 -03:00
|
|
|
(wrap_360_cd(ToDeg(heading) * 100)) /100,
|
2012-04-30 04:17:14 -03:00
|
|
|
(int)compass.mag_x,
|
|
|
|
(int)compass.mag_y,
|
|
|
|
(int)compass.mag_z,
|
|
|
|
maggy.x,
|
|
|
|
maggy.y,
|
|
|
|
maggy.z);
|
|
|
|
} else {
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->println_P(PSTR("compass not healthy"));
|
2012-04-30 04:17:14 -03:00
|
|
|
}
|
|
|
|
counter=0;
|
|
|
|
}
|
|
|
|
}
|
2012-11-21 02:25:11 -04:00
|
|
|
if (cliSerial->available() > 0) {
|
2012-04-30 04:17:14 -03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// save offsets. This allows you to get sane offset values using
|
|
|
|
// the CLI before you go flying.
|
2012-11-21 02:25:11 -04:00
|
|
|
cliSerial->println_P(PSTR("saving offsets"));
|
2012-04-30 04:17:14 -03:00
|
|
|
compass.save_offsets();
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------------
|
|
|
|
// real sensors that have not been simulated yet go here
|
|
|
|
|
2012-06-13 03:29:32 -03:00
|
|
|
static int8_t
|
|
|
|
test_sonar(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2013-03-21 17:53:16 -03:00
|
|
|
if (!sonar.enabled()) {
|
2013-02-28 21:29:29 -04:00
|
|
|
cliSerial->println_P(PSTR("WARNING: Sonar is not enabled"));
|
2013-02-28 16:14:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
print_hit_enter();
|
2013-02-28 21:00:48 -04:00
|
|
|
init_sonar();
|
2013-03-28 18:07:24 -03:00
|
|
|
|
|
|
|
float sonar_dist_cm_min = 0.0f;
|
|
|
|
float sonar_dist_cm_max = 0.0f;
|
|
|
|
float voltage_min=0.0f, voltage_max = 0.0f;
|
|
|
|
float sonar2_dist_cm_min = 0.0f;
|
|
|
|
float sonar2_dist_cm_max = 0.0f;
|
|
|
|
float voltage2_min=0.0f, voltage2_max = 0.0f;
|
|
|
|
uint32_t last_print = 0;
|
2012-06-13 03:29:32 -03:00
|
|
|
|
2013-02-28 16:14:08 -04:00
|
|
|
while (true) {
|
2013-03-28 18:07:24 -03:00
|
|
|
delay(20);
|
|
|
|
uint32_t now = millis();
|
|
|
|
|
|
|
|
float dist_cm = sonar.distance_cm();
|
2013-02-28 21:00:48 -04:00
|
|
|
float voltage = sonar.voltage();
|
2013-03-28 18:07:24 -03:00
|
|
|
if (sonar_dist_cm_min == 0.0f) {
|
|
|
|
sonar_dist_cm_min = dist_cm;
|
|
|
|
voltage_min = voltage;
|
|
|
|
}
|
|
|
|
sonar_dist_cm_max = max(sonar_dist_cm_max, dist_cm);
|
|
|
|
sonar_dist_cm_min = min(sonar_dist_cm_min, dist_cm);
|
|
|
|
voltage_min = min(voltage_min, voltage);
|
|
|
|
voltage_max = max(voltage_max, voltage);
|
|
|
|
|
|
|
|
dist_cm = sonar2.distance_cm();
|
|
|
|
voltage = sonar2.voltage();
|
|
|
|
if (sonar2_dist_cm_min == 0.0f) {
|
|
|
|
sonar2_dist_cm_min = dist_cm;
|
|
|
|
voltage2_min = voltage;
|
|
|
|
}
|
|
|
|
sonar2_dist_cm_max = max(sonar2_dist_cm_max, dist_cm);
|
|
|
|
sonar2_dist_cm_min = min(sonar2_dist_cm_min, dist_cm);
|
|
|
|
voltage2_min = min(voltage2_min, voltage);
|
|
|
|
voltage2_max = max(voltage2_max, voltage);
|
|
|
|
|
|
|
|
if (now - last_print >= 200) {
|
|
|
|
cliSerial->printf_P(PSTR("sonar1 dist=%.1f:%.1fcm volt1=%.2f:%.2f sonar2 dist=%.1f:%.1fcm volt2=%.2f:%.2f\n"),
|
|
|
|
sonar_dist_cm_min,
|
|
|
|
sonar_dist_cm_max,
|
|
|
|
voltage_min,
|
|
|
|
voltage_max,
|
|
|
|
sonar2_dist_cm_min,
|
|
|
|
sonar2_dist_cm_max,
|
|
|
|
voltage2_min,
|
|
|
|
voltage2_max);
|
|
|
|
voltage_min = voltage_max = 0.0f;
|
|
|
|
voltage2_min = voltage2_max = 0.0f;
|
|
|
|
sonar_dist_cm_min = sonar_dist_cm_max = 0.0f;
|
|
|
|
sonar2_dist_cm_min = sonar2_dist_cm_max = 0.0f;
|
|
|
|
last_print = now;
|
|
|
|
}
|
2013-02-28 16:14:08 -04:00
|
|
|
if (cliSerial->available() > 0) {
|
|
|
|
break;
|
2012-06-13 03:29:32 -03:00
|
|
|
}
|
2013-02-28 16:14:08 -04:00
|
|
|
}
|
|
|
|
return (0);
|
2012-06-13 03:29:32 -03:00
|
|
|
}
|
2012-04-30 04:17:14 -03:00
|
|
|
|
2013-03-19 22:35:56 -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
|
|
|
|
|
2012-04-30 04:17:14 -03:00
|
|
|
#endif // CLI_ENABLED
|