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
|
|
|
|
2015-05-29 23:12:49 -03:00
|
|
|
#include "Copter.h"
|
|
|
|
|
2011-07-17 07:34:05 -03:00
|
|
|
#if CLI_ENABLED == ENABLED
|
|
|
|
|
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
|
2015-10-25 14:03:46 -03:00
|
|
|
static const struct Menu::command test_menu_commands[] = {
|
2014-01-02 01:28:50 -04:00
|
|
|
#if HIL_MODE == HIL_MODE_DISABLED
|
2015-05-29 23:12:49 -03:00
|
|
|
{"baro", MENU_FUNC(test_baro)},
|
2011-12-26 04:12:05 -04:00
|
|
|
#endif
|
2015-05-29 23:12:49 -03:00
|
|
|
{"compass", MENU_FUNC(test_compass)},
|
|
|
|
{"ins", MENU_FUNC(test_ins)},
|
|
|
|
{"optflow", MENU_FUNC(test_optflow)},
|
|
|
|
{"relay", MENU_FUNC(test_relay)},
|
2014-03-31 14:57:45 -03:00
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_PX4 || CONFIG_HAL_BOARD == HAL_BOARD_VRBRAIN
|
2015-05-29 23:12:49 -03:00
|
|
|
{"shell", MENU_FUNC(test_shell)},
|
2013-03-19 22:35:50 -03:00
|
|
|
#endif
|
2014-01-02 01:28:50 -04:00
|
|
|
#if HIL_MODE == HIL_MODE_DISABLED
|
2016-04-27 08:37:04 -03:00
|
|
|
{"rangefinder", MENU_FUNC(test_rangefinder)},
|
2013-05-31 03:15:47 -03:00
|
|
|
#endif
|
2010-12-19 12:40:33 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// A Macro to create the Menu
|
|
|
|
MENU(test_menu, "test", test_menu_commands);
|
|
|
|
|
2015-05-29 23:12:49 -03:00
|
|
|
int8_t Copter::test_mode(uint8_t argc, const Menu::arg *argv)
|
2010-12-19 12:40:33 -04:00
|
|
|
{
|
2012-08-21 23:19:50 -03:00
|
|
|
test_menu.run();
|
|
|
|
return 0;
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
|
|
|
|
2014-01-02 01:28:50 -04:00
|
|
|
#if HIL_MODE == HIL_MODE_DISABLED
|
2015-05-29 23:12:49 -03:00
|
|
|
int8_t Copter::test_baro(uint8_t argc, const Menu::arg *argv)
|
2012-02-10 02:21:30 -04:00
|
|
|
{
|
2012-08-21 23:19:50 -03:00
|
|
|
print_hit_enter();
|
2014-01-15 10:18:23 -04:00
|
|
|
init_barometer(true);
|
2012-08-21 23:19:50 -03:00
|
|
|
|
|
|
|
while(1) {
|
2013-05-31 03:15:47 -03:00
|
|
|
delay(100);
|
2014-10-22 04:07:10 -03:00
|
|
|
read_barometer();
|
2012-08-21 23:19:50 -03:00
|
|
|
|
2014-08-13 10:54:41 -03:00
|
|
|
if (!barometer.healthy()) {
|
2015-10-25 16:50:51 -03:00
|
|
|
cliSerial->println("not healthy");
|
2013-05-31 03:15:47 -03:00
|
|
|
} else {
|
2015-10-25 17:10:41 -03:00
|
|
|
cliSerial->printf("Alt: %0.2fm, Raw: %f Temperature: %.1f\n",
|
2015-05-03 03:03:28 -03:00
|
|
|
(double)(baro_alt / 100.0f),
|
|
|
|
(double)barometer.get_pressure(),
|
|
|
|
(double)barometer.get_temperature());
|
2013-05-31 03:15:47 -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-05-31 03:15:47 -03:00
|
|
|
return 0;
|
2012-02-10 02:21:30 -04:00
|
|
|
}
|
2013-05-31 03:15:47 -03:00
|
|
|
#endif
|
2011-09-24 20:48:04 -03:00
|
|
|
|
2015-05-29 23:12:49 -03:00
|
|
|
int8_t Copter::test_compass(uint8_t argc, const Menu::arg *argv)
|
2011-11-12 23:51:43 -04:00
|
|
|
{
|
2013-05-31 03:15:47 -03:00
|
|
|
uint8_t delta_ms_fast_loop;
|
2013-10-11 08:40:20 -03:00
|
|
|
uint8_t medium_loopCounter = 0;
|
2013-05-31 03:15:47 -03:00
|
|
|
|
|
|
|
if (!g.compass_enabled) {
|
2015-10-25 17:10:41 -03:00
|
|
|
cliSerial->printf("Compass: ");
|
2013-05-31 03:15:47 -03:00
|
|
|
print_enabled(false);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!compass.init()) {
|
2015-10-25 16:50:51 -03:00
|
|
|
cliSerial->println("Compass initialisation failed!");
|
2013-05-31 03:15:47 -03:00
|
|
|
return 0;
|
|
|
|
}
|
2011-11-12 23:51:43 -04:00
|
|
|
|
2013-01-13 01:04:04 -04:00
|
|
|
ahrs.init();
|
2013-05-31 03:15:47 -03:00
|
|
|
ahrs.set_fly_forward(true);
|
|
|
|
ahrs.set_compass(&compass);
|
2015-01-04 16:36:40 -04:00
|
|
|
#if OPTFLOW == ENABLED
|
2015-01-02 20:15:46 -04:00
|
|
|
ahrs.set_optflow(&optflow);
|
2015-01-04 16:36:40 -04:00
|
|
|
#endif
|
2013-05-31 03:15:47 -03:00
|
|
|
report_compass();
|
|
|
|
|
|
|
|
// we need the AHRS initialised for this test
|
2015-12-26 00:00:03 -04:00
|
|
|
ins.init(scheduler.get_loop_rate_hz());
|
2013-05-31 03:15:47 -03:00
|
|
|
ahrs.reset();
|
|
|
|
int16_t counter = 0;
|
|
|
|
float heading = 0;
|
2011-11-12 23:51:43 -04:00
|
|
|
|
2013-05-31 03:15:47 -03:00
|
|
|
print_hit_enter();
|
2011-11-12 23:51:43 -04:00
|
|
|
|
2012-08-21 23:19:50 -03:00
|
|
|
while(1) {
|
2013-05-31 03:15:47 -03:00
|
|
|
delay(20);
|
|
|
|
if (millis() - fast_loopTimer > 19) {
|
|
|
|
delta_ms_fast_loop = millis() - fast_loopTimer;
|
2015-04-24 02:19:45 -03:00
|
|
|
G_Dt = (float)delta_ms_fast_loop / 1000.0f; // used by DCM integrator
|
2013-05-31 03:15:47 -03:00
|
|
|
fast_loopTimer = millis();
|
2011-11-12 23:51:43 -04:00
|
|
|
|
2013-05-31 03:15:47 -03:00
|
|
|
// INS
|
|
|
|
// ---
|
|
|
|
ahrs.update();
|
2012-07-18 15:14:13 -03:00
|
|
|
|
2013-05-31 03:15:47 -03:00
|
|
|
medium_loopCounter++;
|
|
|
|
if(medium_loopCounter == 5) {
|
|
|
|
if (compass.read()) {
|
|
|
|
// Calculate heading
|
2015-12-10 18:06:26 -04:00
|
|
|
const Matrix3f &m = ahrs.get_rotation_body_to_ned();
|
2013-05-31 03:15:47 -03:00
|
|
|
heading = compass.calculate_heading(m);
|
2014-02-15 22:22:13 -04:00
|
|
|
compass.learn_offsets();
|
2013-05-31 03:15:47 -03:00
|
|
|
}
|
|
|
|
medium_loopCounter = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
counter++;
|
|
|
|
if (counter>20) {
|
2013-12-09 02:47:22 -04:00
|
|
|
if (compass.healthy()) {
|
2015-09-28 16:57:03 -03:00
|
|
|
const Vector3f &mag_ofs = compass.get_offsets();
|
|
|
|
const Vector3f &mag = compass.get_field();
|
2015-10-26 10:05:00 -03:00
|
|
|
cliSerial->printf("Heading: %d, XYZ: %.0f, %.0f, %.0f,\tXYZoff: %6.2f, %6.2f, %6.2f\n",
|
2015-12-20 02:52:36 -04:00
|
|
|
(int)(wrap_360_cd(ToDeg(heading) * 100)) /100,
|
2015-05-03 03:03:28 -03:00
|
|
|
(double)mag.x,
|
|
|
|
(double)mag.y,
|
|
|
|
(double)mag.z,
|
|
|
|
(double)mag_ofs.x,
|
|
|
|
(double)mag_ofs.y,
|
|
|
|
(double)mag_ofs.z);
|
2013-05-31 03:15:47 -03:00
|
|
|
} else {
|
2015-10-25 16:50:51 -03:00
|
|
|
cliSerial->println("compass not healthy");
|
2013-05-31 03:15:47 -03:00
|
|
|
}
|
|
|
|
counter=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (cliSerial->available() > 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// save offsets. This allows you to get sane offset values using
|
|
|
|
// the CLI before you go flying.
|
2015-10-25 16:50:51 -03:00
|
|
|
cliSerial->println("saving offsets");
|
2013-05-31 03:15:47 -03:00
|
|
|
compass.save_offsets();
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2015-05-29 23:12:49 -03:00
|
|
|
int8_t Copter::test_ins(uint8_t argc, const Menu::arg *argv)
|
2011-04-17 20:08:16 -03:00
|
|
|
{
|
2013-05-31 03:15:47 -03:00
|
|
|
Vector3f gyro, accel;
|
2012-08-21 23:19:50 -03:00
|
|
|
print_hit_enter();
|
2015-10-25 17:10:41 -03:00
|
|
|
cliSerial->printf("INS\n");
|
2013-05-31 03:15:47 -03:00
|
|
|
delay(1000);
|
|
|
|
|
|
|
|
ahrs.init();
|
2015-12-26 00:00:03 -04:00
|
|
|
ins.init(scheduler.get_loop_rate_hz());
|
2015-10-25 17:10:41 -03:00
|
|
|
cliSerial->printf("...done\n");
|
2013-05-31 03:15:47 -03:00
|
|
|
|
|
|
|
delay(50);
|
2012-08-21 23:19:50 -03:00
|
|
|
|
|
|
|
while(1) {
|
2013-05-31 03:15:47 -03:00
|
|
|
ins.update();
|
|
|
|
gyro = ins.get_gyro();
|
|
|
|
accel = ins.get_accel();
|
|
|
|
|
|
|
|
float test = accel.length() / GRAVITY_MSS;
|
|
|
|
|
2015-10-25 17:10:41 -03:00
|
|
|
cliSerial->printf("a %7.4f %7.4f %7.4f g %7.4f %7.4f %7.4f t %7.4f \n",
|
2015-05-03 03:03:28 -03:00
|
|
|
(double)accel.x, (double)accel.y, (double)accel.z,
|
|
|
|
(double)gyro.x, (double)gyro.y, (double)gyro.z,
|
|
|
|
(double)test);
|
2012-08-21 23:19:50 -03:00
|
|
|
|
2013-05-31 03:15:47 -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-04-17 20:08:16 -03:00
|
|
|
}
|
|
|
|
|
2015-05-29 23:12:49 -03:00
|
|
|
int8_t Copter::test_optflow(uint8_t argc, const Menu::arg *argv)
|
2010-12-19 12:40:33 -04:00
|
|
|
{
|
2013-05-31 03:15:47 -03:00
|
|
|
#if OPTFLOW == ENABLED
|
2014-07-11 23:34:55 -03:00
|
|
|
if(optflow.enabled()) {
|
2015-10-25 17:10:41 -03:00
|
|
|
cliSerial->printf("dev id: %d\t",(int)optflow.device_id());
|
2013-05-31 03:15:47 -03:00
|
|
|
print_hit_enter();
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2013-05-31 03:15:47 -03:00
|
|
|
while(1) {
|
|
|
|
delay(200);
|
2013-10-23 08:42:03 -03:00
|
|
|
optflow.update();
|
2014-10-31 09:49:29 -03:00
|
|
|
const Vector2f& flowRate = optflow.flowRate();
|
2015-10-25 17:10:41 -03:00
|
|
|
cliSerial->printf("flowX : %7.4f\t flowY : %7.4f\t flow qual : %d\n",
|
2015-05-03 03:03:28 -03:00
|
|
|
(double)flowRate.x,
|
|
|
|
(double)flowRate.y,
|
2014-07-11 23:34:55 -03:00
|
|
|
(int)optflow.quality());
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2013-05-31 03:15:47 -03:00
|
|
|
if(cliSerial->available() > 0) {
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2015-10-25 17:10:41 -03:00
|
|
|
cliSerial->printf("OptFlow: ");
|
2013-05-31 03:15:47 -03:00
|
|
|
print_enabled(false);
|
|
|
|
}
|
2012-08-21 23:19:50 -03:00
|
|
|
return (0);
|
2013-05-31 03:15:47 -03:00
|
|
|
#else
|
|
|
|
return (0);
|
|
|
|
#endif // OPTFLOW == ENABLED
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
|
|
|
|
2015-05-29 23:12:49 -03:00
|
|
|
int8_t Copter::test_relay(uint8_t argc, const Menu::arg *argv)
|
2013-05-31 03:15:47 -03:00
|
|
|
{
|
2013-04-27 11:33:04 -03:00
|
|
|
print_hit_enter();
|
2013-05-31 03:15:47 -03:00
|
|
|
delay(1000);
|
2013-04-27 11:33:04 -03:00
|
|
|
|
|
|
|
while(1) {
|
2015-10-25 17:10:41 -03:00
|
|
|
cliSerial->printf("Relay on\n");
|
2014-01-19 23:54:21 -04:00
|
|
|
relay.on(0);
|
2013-05-31 03:15:47 -03:00
|
|
|
delay(3000);
|
|
|
|
if(cliSerial->available() > 0) {
|
|
|
|
return (0);
|
2013-04-27 11:33:04 -03:00
|
|
|
}
|
2013-05-31 03:15:47 -03:00
|
|
|
|
2015-10-25 17:10:41 -03:00
|
|
|
cliSerial->printf("Relay off\n");
|
2014-01-19 23:54:21 -04:00
|
|
|
relay.off(0);
|
2013-05-31 03:15:47 -03:00
|
|
|
delay(3000);
|
|
|
|
if(cliSerial->available() > 0) {
|
|
|
|
return (0);
|
2013-04-27 11:33:04 -03:00
|
|
|
}
|
|
|
|
}
|
2013-05-31 03:15:47 -03:00
|
|
|
}
|
2013-04-27 11:33:04 -03:00
|
|
|
|
2014-03-31 14:57:45 -03:00
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_PX4 || CONFIG_HAL_BOARD == HAL_BOARD_VRBRAIN
|
2013-05-31 03:15:47 -03:00
|
|
|
/*
|
|
|
|
* run a debug shell
|
|
|
|
*/
|
2015-05-29 23:12:49 -03:00
|
|
|
int8_t Copter::test_shell(uint8_t argc, const Menu::arg *argv)
|
2013-05-31 03:15:47 -03:00
|
|
|
{
|
|
|
|
hal.util->run_debug_shell(cliSerial);
|
|
|
|
return 0;
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
2013-05-31 03:15:47 -03:00
|
|
|
#endif
|
2011-12-03 19:39:02 -04:00
|
|
|
|
2014-01-02 01:28:50 -04:00
|
|
|
#if HIL_MODE == HIL_MODE_DISABLED
|
2011-03-17 22:50:27 -03:00
|
|
|
/*
|
2014-07-17 17:08:27 -03:00
|
|
|
* test the rangefinders
|
2011-03-17 22:50:27 -03:00
|
|
|
*/
|
2016-04-27 08:37:04 -03:00
|
|
|
int8_t Copter::test_rangefinder(uint8_t argc, const Menu::arg *argv)
|
2011-03-17 22:50:27 -03:00
|
|
|
{
|
2016-04-27 07:55:35 -03:00
|
|
|
#if RANGEFINDER_ENABLED == ENABLED
|
2016-04-27 08:37:04 -03:00
|
|
|
rangefinder.init();
|
2011-12-23 18:14:19 -04:00
|
|
|
|
2016-04-27 08:37:04 -03:00
|
|
|
cliSerial->printf("RangeFinder: %d devices detected\n", rangefinder.num_sensors());
|
2011-06-16 14:03:26 -03:00
|
|
|
|
2012-08-21 23:19:50 -03:00
|
|
|
print_hit_enter();
|
|
|
|
while(1) {
|
|
|
|
delay(100);
|
2016-04-27 08:37:04 -03:00
|
|
|
rangefinder.update();
|
2014-07-17 17:08:27 -03:00
|
|
|
|
2016-04-27 08:37:04 -03:00
|
|
|
cliSerial->printf("Primary: status %d distance_cm %d \n", (int)rangefinder.status(), rangefinder.distance_cm());
|
2015-10-25 17:10:41 -03:00
|
|
|
cliSerial->printf("All: device_0 type %d status %d distance_cm %d, device_1 type %d status %d distance_cm %d\n",
|
2016-04-27 08:37:04 -03:00
|
|
|
(int)rangefinder._type[0], (int)rangefinder.status(0), rangefinder.distance_cm(0), (int)rangefinder._type[1], (int)rangefinder.status(1), rangefinder.distance_cm(1));
|
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
|
|
|
|
2015-05-29 23:12:49 -03:00
|
|
|
void Copter::print_hit_enter()
|
2010-12-19 12:40:33 -04:00
|
|
|
{
|
2015-10-25 17:10:41 -03:00
|
|
|
cliSerial->printf("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
|