2015-05-13 03:09:36 -03:00
|
|
|
#include "Plane.h"
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2015-05-13 03:09:36 -03:00
|
|
|
#if CLI_ENABLED == ENABLED
|
2014-03-03 09:50:45 -04:00
|
|
|
|
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
|
2015-10-25 14:03:46 -03:00
|
|
|
static const struct Menu::command test_menu_commands[] = {
|
2012-08-21 23:19:51 -03:00
|
|
|
// Tests below here are for hardware sensors only present
|
|
|
|
// when real sensors are attached or they are emulated
|
2015-05-13 03:09:36 -03:00
|
|
|
{"gps", MENU_FUNC(test_gps)},
|
|
|
|
{"ins", MENU_FUNC(test_ins)},
|
|
|
|
{"airspeed", MENU_FUNC(test_airspeed)},
|
|
|
|
{"airpressure", MENU_FUNC(test_pressure)},
|
|
|
|
{"compass", MENU_FUNC(test_mag)},
|
|
|
|
{"logging", MENU_FUNC(test_logging)},
|
2014-03-31 14:58:20 -03:00
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_PX4 || CONFIG_HAL_BOARD == HAL_BOARD_VRBRAIN
|
2015-05-13 03:09:36 -03:00
|
|
|
{"shell", MENU_FUNC(test_shell)},
|
2013-02-07 00:04:22 -04:00
|
|
|
#endif
|
2011-09-08 22:29:39 -03:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
// A Macro to create the Menu
|
|
|
|
MENU(test_menu, "test", test_menu_commands);
|
|
|
|
|
2015-05-13 03:09:36 -03:00
|
|
|
int8_t Plane::test_mode(uint8_t argc, const Menu::arg *argv)
|
2011-09-08 22:29:39 -03:00
|
|
|
{
|
2015-10-25 17:10:41 -03:00
|
|
|
cliSerial->printf("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;
|
|
|
|
}
|
|
|
|
|
2015-05-13 03:09:36 -03:00
|
|
|
void Plane::print_hit_enter()
|
2011-09-08 22:29:39 -03:00
|
|
|
{
|
2015-10-25 17:10:41 -03:00
|
|
|
cliSerial->printf("Hit Enter to exit.\n\n");
|
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
|
|
|
*/
|
2015-05-13 03:09:36 -03:00
|
|
|
int8_t Plane::test_logging(uint8_t argc, const Menu::arg *argv)
|
2011-12-28 00:53:14 -04:00
|
|
|
{
|
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
|
|
|
|
*/
|
2015-05-13 03:09:36 -03:00
|
|
|
int8_t Plane::test_shell(uint8_t argc, const Menu::arg *argv)
|
2013-02-07 00:04:22 -04:00
|
|
|
{
|
|
|
|
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
|
|
|
|
|
2015-05-13 03:09:36 -03:00
|
|
|
int8_t Plane::test_gps(uint8_t argc, const Menu::arg *argv)
|
2011-09-08 22:29:39 -03:00
|
|
|
{
|
2012-08-21 23:19:51 -03:00
|
|
|
print_hit_enter();
|
2014-11-11 06:54:25 -04:00
|
|
|
hal.scheduler->delay(1000);
|
2012-08-21 23:19:51 -03:00
|
|
|
|
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) {
|
2014-11-11 06:54:25 -04:00
|
|
|
hal.scheduler->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();
|
2015-10-25 17:10:41 -03:00
|
|
|
cliSerial->printf("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 {
|
2017-01-21 00:35:24 -04:00
|
|
|
cliSerial->printf(".");
|
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
|
|
|
}
|
|
|
|
|
2015-05-13 03:09:36 -03:00
|
|
|
int8_t Plane::test_ins(uint8_t argc, const Menu::arg *argv)
|
2011-09-08 22:29:39 -03:00
|
|
|
{
|
2017-01-21 00:35:24 -04:00
|
|
|
//cliSerial->printf("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
|
|
|
|
2015-12-25 23:12:39 -04:00
|
|
|
ins.init(scheduler.get_loop_rate_hz());
|
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();
|
2014-11-11 06:54:25 -04:00
|
|
|
hal.scheduler->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) {
|
2014-11-11 06:54:25 -04:00
|
|
|
hal.scheduler->delay(20);
|
2016-04-20 22:50:13 -03:00
|
|
|
if (micros() - perf.fast_loopTimer_us > 19000UL) {
|
|
|
|
perf.fast_loopTimer_us = 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();
|
2015-10-25 17:10:41 -03:00
|
|
|
cliSerial->printf("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,
|
2015-05-03 03:00:05 -03:00
|
|
|
(double)gyros.x, (double)gyros.y, (double)gyros.z,
|
|
|
|
(double)accels.x, (double)accels.y, (double)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
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-13 03:09:36 -03:00
|
|
|
int8_t Plane::test_mag(uint8_t argc, const Menu::arg *argv)
|
2011-09-08 22:29:39 -03:00
|
|
|
{
|
2012-08-21 23:19:51 -03:00
|
|
|
if (!g.compass_enabled) {
|
2017-01-21 00:35:24 -04:00
|
|
|
cliSerial->printf("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()) {
|
2017-01-21 00:35:24 -04:00
|
|
|
cliSerial->printf("Compass initialisation failed!\n");
|
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
|
|
|
|
2012-03-11 05:13:31 -03:00
|
|
|
// we need the AHRS initialised for this test
|
2015-12-25 23:12:39 -04:00
|
|
|
ins.init(scheduler.get_loop_rate_hz());
|
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) {
|
2014-11-11 06:54:25 -04:00
|
|
|
hal.scheduler->delay(20);
|
2016-04-20 22:50:13 -03:00
|
|
|
if (micros() - perf.fast_loopTimer_us > 19000UL) {
|
|
|
|
perf.fast_loopTimer_us = 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
|
2015-12-10 18:06:37 -04:00
|
|
|
const Matrix3f &m = ahrs.get_rotation_body_to_ned();
|
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()) {
|
2015-09-28 16:57:09 -03:00
|
|
|
const Vector3f &mag_ofs = compass.get_offsets();
|
|
|
|
const Vector3f &mag = compass.get_field();
|
2016-04-27 06:35:18 -03:00
|
|
|
cliSerial->printf("Heading: %f, XYZ: %.0f, %.0f, %.0f,\tXYZoff: %6.2f, %6.2f, %6.2f\n",
|
2016-05-17 19:57:26 -03:00
|
|
|
(double)((wrap_360_cd(ToDeg(heading) * 100)) /100),
|
2015-05-03 03:00:05 -03:00
|
|
|
(double)mag.x, (double)mag.y, (double)mag.z,
|
|
|
|
(double)mag_ofs.x, (double)mag_ofs.y, (double)mag_ofs.z);
|
2011-12-28 05:33:47 -04:00
|
|
|
} else {
|
2017-01-21 00:35:24 -04:00
|
|
|
cliSerial->printf("compass not healthy\n");
|
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.
|
2017-01-21 00:35:24 -04:00
|
|
|
cliSerial->printf("saving offsets\n");
|
2011-09-08 22:29:39 -03:00
|
|
|
compass.save_offsets();
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------------
|
|
|
|
// real sensors that have not been simulated yet go here
|
|
|
|
|
2015-05-13 03:09:36 -03:00
|
|
|
int8_t Plane::test_airspeed(uint8_t argc, const Menu::arg *argv)
|
2011-09-08 22:29:39 -03:00
|
|
|
{
|
2012-08-21 23:19:51 -03:00
|
|
|
if (!airspeed.enabled()) {
|
2017-01-21 00:35:24 -04:00
|
|
|
cliSerial->printf("airspeed: ");
|
2012-08-21 23:19:51 -03:00
|
|
|
print_enabled(false);
|
|
|
|
return (0);
|
|
|
|
}else{
|
|
|
|
print_hit_enter();
|
2014-11-13 06:12:59 -04:00
|
|
|
zero_airspeed(false);
|
2017-01-21 00:35:24 -04:00
|
|
|
cliSerial->printf("airspeed: ");
|
2012-08-21 23:19:51 -03:00
|
|
|
print_enabled(true);
|
|
|
|
|
|
|
|
while(1) {
|
2014-11-11 06:54:25 -04:00
|
|
|
hal.scheduler->delay(20);
|
2012-08-21 23:19:51 -03:00
|
|
|
read_airspeed();
|
2015-10-25 17:10:41 -03:00
|
|
|
cliSerial->printf("%.1f m/s\n", (double)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
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-13 03:09:36 -03:00
|
|
|
int8_t Plane::test_pressure(uint8_t argc, const Menu::arg *argv)
|
2011-09-08 22:29:39 -03:00
|
|
|
{
|
2017-01-21 00:35:24 -04:00
|
|
|
cliSerial->printf("Uncalibrated relative airpressure\n");
|
2012-08-21 23:19:51 -03:00
|
|
|
print_hit_enter();
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2016-05-23 22:31:53 -03:00
|
|
|
init_barometer(true);
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
while(1) {
|
2014-11-11 06:54:25 -04:00
|
|
|
hal.scheduler->delay(100);
|
2015-01-05 00:56:18 -04:00
|
|
|
barometer.update();
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2014-08-13 10:55:48 -03:00
|
|
|
if (!barometer.healthy()) {
|
2017-01-21 00:35:24 -04:00
|
|
|
cliSerial->printf("not healthy\n");
|
2011-12-28 05:34:11 -04:00
|
|
|
} else {
|
2015-10-25 17:10:41 -03:00
|
|
|
cliSerial->printf("Alt: %0.2fm, Raw: %f Temperature: %.1f\n",
|
2015-05-03 03:00:05 -03:00
|
|
|
(double)barometer.get_altitude(),
|
|
|
|
(double)barometer.get_pressure(),
|
|
|
|
(double)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
|
|
|
}
|
|
|
|
|
2015-05-13 03:09:36 -03:00
|
|
|
void Plane::print_enabled(bool b)
|
|
|
|
{
|
|
|
|
if (b) {
|
2017-01-21 00:35:24 -04:00
|
|
|
cliSerial->printf("en");
|
2015-05-13 03:09:36 -03:00
|
|
|
} else {
|
2017-01-21 00:35:24 -04:00
|
|
|
cliSerial->printf("dis");
|
2015-05-13 03:09:36 -03:00
|
|
|
}
|
2017-01-21 00:35:24 -04:00
|
|
|
cliSerial->printf("abled\n");
|
2015-05-13 03:09:36 -03:00
|
|
|
}
|
|
|
|
|
2011-09-08 22:29:39 -03:00
|
|
|
#endif // CLI_ENABLED
|