2015-05-13 00:16:45 -03:00
|
|
|
#include "Rover.h"
|
|
|
|
|
2012-04-30 04:17:14 -03:00
|
|
|
#if CLI_ENABLED == ENABLED
|
|
|
|
|
|
|
|
// 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[] = {
|
2016-12-20 09:34:16 -04:00
|
|
|
{"passthru", MENU_FUNC(test_passthru)},
|
|
|
|
{"failsafe", MENU_FUNC(test_failsafe)},
|
|
|
|
{"relay", MENU_FUNC(test_relay)},
|
|
|
|
{"waypoints", MENU_FUNC(test_wp)},
|
|
|
|
{"modeswitch", MENU_FUNC(test_modeswitch)},
|
|
|
|
|
|
|
|
// Tests below here are for hardware sensors only present
|
|
|
|
// when real sensors are attached or they are emulated
|
|
|
|
{"gps", MENU_FUNC(test_gps)},
|
|
|
|
{"ins", MENU_FUNC(test_ins)},
|
|
|
|
{"sonartest", MENU_FUNC(test_sonar)},
|
|
|
|
{"compass", MENU_FUNC(test_mag)},
|
|
|
|
{"logging", MENU_FUNC(test_logging)},
|
2014-03-31 14:58:48 -03:00
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_PX4 || CONFIG_HAL_BOARD == HAL_BOARD_VRBRAIN
|
2016-12-20 09:34:16 -04:00
|
|
|
{"shell", MENU_FUNC(test_shell)},
|
2013-03-19 22:35:56 -03:00
|
|
|
#endif
|
2012-04-30 04:17:14 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
// A Macro to create the Menu
|
|
|
|
MENU(test_menu, "test", test_menu_commands);
|
|
|
|
|
2015-05-12 04:00:25 -03:00
|
|
|
int8_t Rover::test_mode(uint8_t argc, const Menu::arg *argv)
|
2012-04-30 04:17:14 -03:00
|
|
|
{
|
2016-12-20 09:34:16 -04:00
|
|
|
cliSerial->printf("Test Mode\n\n");
|
|
|
|
test_menu.run();
|
2012-04-30 04:17:14 -03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-05-12 02:03:23 -03:00
|
|
|
void Rover::print_hit_enter()
|
2012-04-30 04:17:14 -03:00
|
|
|
{
|
2016-12-20 09:34:16 -04:00
|
|
|
cliSerial->printf("Hit Enter to exit.\n\n");
|
2012-04-30 04:17:14 -03:00
|
|
|
}
|
|
|
|
|
2015-05-12 04:00:25 -03:00
|
|
|
int8_t Rover::test_passthru(uint8_t argc, const Menu::arg *argv)
|
2012-04-30 04:17:14 -03:00
|
|
|
{
|
2016-12-20 09:34:16 -04:00
|
|
|
print_hit_enter();
|
|
|
|
delay(1000);
|
2012-04-30 04:17:14 -03:00
|
|
|
|
2016-12-20 09:34:16 -04:00
|
|
|
while (1) {
|
|
|
|
delay(20);
|
2012-04-30 04:17:14 -03:00
|
|
|
|
|
|
|
// New radio frame? (we could use also if((millis()- timer) > 20)
|
2014-03-25 00:47:02 -03:00
|
|
|
if (hal.rcin->new_input()) {
|
2017-01-21 00:33:27 -04:00
|
|
|
cliSerial->printf("CH:");
|
2016-12-20 09:34:16 -04:00
|
|
|
for (int i = 0; i < 8; i++) {
|
2017-01-21 00:33:27 -04:00
|
|
|
cliSerial->printf("%u", hal.rcin->read(i)); // Print channel values
|
|
|
|
cliSerial->printf(",");
|
2016-12-20 09:34:16 -04:00
|
|
|
hal.rcout->write(i, hal.rcin->read(i)); // Copy input to Servos
|
2012-04-30 04:17:14 -03:00
|
|
|
}
|
2017-01-21 00:33:27 -04:00
|
|
|
cliSerial->printf("\n");
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-12 04:00:25 -03:00
|
|
|
int8_t Rover::test_failsafe(uint8_t argc, const Menu::arg *argv)
|
2012-04-30 04:17:14 -03:00
|
|
|
{
|
2016-12-20 09:34:16 -04:00
|
|
|
uint8_t fail_test = 0;
|
|
|
|
print_hit_enter();
|
|
|
|
for (int i = 0; i < 50; i++) {
|
|
|
|
delay(20);
|
|
|
|
read_radio();
|
|
|
|
}
|
|
|
|
|
|
|
|
// read the radio to set trims
|
|
|
|
// ---------------------------
|
|
|
|
trim_radio();
|
|
|
|
|
|
|
|
oldSwitchPosition = readSwitch();
|
|
|
|
|
2017-01-21 00:33:27 -04:00
|
|
|
cliSerial->printf("Unplug battery, throttle in neutral, turn off radio.\n");
|
2016-12-20 09:34:16 -04:00
|
|
|
while (channel_throttle->get_control_in() > 0) {
|
|
|
|
delay(20);
|
|
|
|
read_radio();
|
|
|
|
}
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
delay(20);
|
|
|
|
read_radio();
|
|
|
|
|
|
|
|
if (channel_throttle->get_control_in() > 0) {
|
|
|
|
cliSerial->printf("THROTTLE CHANGED %d \n", channel_throttle->get_control_in());
|
|
|
|
fail_test++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (oldSwitchPosition != readSwitch()){
|
2017-01-21 00:33:27 -04:00
|
|
|
cliSerial->printf("CONTROL MODE CHANGED: ");
|
2013-04-20 02:18:42 -03:00
|
|
|
print_mode(cliSerial, readSwitch());
|
2017-01-21 00:33:27 -04:00
|
|
|
cliSerial->printf("\n");
|
2016-12-20 09:34:16 -04:00
|
|
|
fail_test++;
|
|
|
|
}
|
2012-04-30 04:17:14 -03:00
|
|
|
|
2016-12-20 09:34:16 -04:00
|
|
|
if (throttle_failsafe_active()) {
|
|
|
|
cliSerial->printf("THROTTLE FAILSAFE ACTIVATED: %d, ", channel_throttle->get_radio_in());
|
2013-04-20 02:18:42 -03:00
|
|
|
print_mode(cliSerial, readSwitch());
|
2017-01-21 00:33:27 -04:00
|
|
|
cliSerial->printf("\n");
|
2016-12-20 09:34:16 -04:00
|
|
|
fail_test++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fail_test > 0) {
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
if (cliSerial->available() > 0) {
|
2017-01-21 00:33:27 -04:00
|
|
|
cliSerial->printf("LOS caused no change in APM.\n");
|
2016-12-20 09:34:16 -04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
2012-04-30 04:17:14 -03:00
|
|
|
}
|
|
|
|
|
2015-05-12 04:00:25 -03:00
|
|
|
int8_t Rover::test_relay(uint8_t argc, const Menu::arg *argv)
|
2012-04-30 04:17:14 -03:00
|
|
|
{
|
2016-12-20 09:34:16 -04:00
|
|
|
print_hit_enter();
|
|
|
|
delay(1000);
|
|
|
|
|
|
|
|
while (1) {
|
2017-01-21 00:33:27 -04:00
|
|
|
cliSerial->printf("Relay on\n");
|
2016-12-20 09:34:16 -04:00
|
|
|
relay.on(0);
|
|
|
|
delay(3000);
|
|
|
|
if (cliSerial->available() > 0) {
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2017-01-21 00:33:27 -04:00
|
|
|
cliSerial->printf("Relay off\n");
|
2016-12-20 09:34:16 -04:00
|
|
|
relay.off(0);
|
|
|
|
delay(3000);
|
|
|
|
if (cliSerial->available() > 0) {
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
2012-04-30 04:17:14 -03:00
|
|
|
}
|
|
|
|
|
2015-05-12 04:00:25 -03:00
|
|
|
int8_t Rover::test_wp(uint8_t argc, const Menu::arg *argv)
|
2012-04-30 04:17:14 -03:00
|
|
|
{
|
2016-12-20 09:34:16 -04:00
|
|
|
delay(1000);
|
2012-04-30 04:17:14 -03:00
|
|
|
|
2016-12-20 09:34:16 -04:00
|
|
|
cliSerial->printf("%u waypoints\n", (unsigned)mission.num_commands());
|
|
|
|
cliSerial->printf("Hit radius: %f\n", (double)g.waypoint_radius.get());
|
2012-04-30 04:17:14 -03:00
|
|
|
|
2016-12-20 09:34:16 -04:00
|
|
|
for (uint8_t i = 0; i < mission.num_commands(); i++) {
|
2014-03-10 05:46:21 -03:00
|
|
|
AP_Mission::Mission_Command temp_cmd;
|
2016-12-20 09:34:16 -04:00
|
|
|
if (mission.read_cmd_from_storage(i, temp_cmd)) {
|
2014-03-10 23:29:53 -03:00
|
|
|
test_wp_print(temp_cmd);
|
|
|
|
}
|
2016-12-20 09:34:16 -04:00
|
|
|
}
|
2012-04-30 04:17:14 -03:00
|
|
|
|
2016-12-20 09:34:16 -04:00
|
|
|
return (0);
|
2012-04-30 04:17:14 -03:00
|
|
|
}
|
|
|
|
|
2015-05-12 04:00:25 -03:00
|
|
|
void Rover::test_wp_print(const AP_Mission::Mission_Command& cmd)
|
2012-04-30 04:17:14 -03:00
|
|
|
{
|
2015-10-25 17:10:41 -03:00
|
|
|
cliSerial->printf("command #: %d id:%d options:%d p1:%d p2:%ld p3:%ld p4:%ld \n",
|
2014-03-10 05:46:21 -03: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);
|
2012-04-30 04:17:14 -03:00
|
|
|
}
|
|
|
|
|
2015-05-12 04:00:25 -03:00
|
|
|
int8_t Rover::test_modeswitch(uint8_t argc, const Menu::arg *argv)
|
2012-04-30 04:17:14 -03:00
|
|
|
{
|
2016-12-20 09:34:16 -04:00
|
|
|
print_hit_enter();
|
|
|
|
delay(1000);
|
|
|
|
|
2017-01-21 00:33:27 -04:00
|
|
|
cliSerial->printf("Control CH ");
|
2016-12-20 09:34:16 -04:00
|
|
|
|
2017-01-21 00:33:27 -04:00
|
|
|
cliSerial->printf("%d\n", MODE_CHANNEL);
|
2016-12-20 09:34:16 -04:00
|
|
|
|
|
|
|
while (1) {
|
|
|
|
delay(20);
|
|
|
|
uint8_t switchPosition = readSwitch();
|
|
|
|
if (oldSwitchPosition != switchPosition){
|
|
|
|
cliSerial->printf("Position %d\n", switchPosition);
|
|
|
|
oldSwitchPosition = switchPosition;
|
|
|
|
}
|
|
|
|
if (cliSerial->available() > 0) {
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
2012-04-30 04:17:14 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
test the dataflash is working
|
|
|
|
*/
|
2015-05-12 04:00:25 -03:00
|
|
|
int8_t Rover::test_logging(uint8_t argc, const Menu::arg *argv)
|
2012-04-30 04:17:14 -03:00
|
|
|
{
|
2017-01-21 00:33:27 -04:00
|
|
|
cliSerial->printf("Testing dataflash logging\n");
|
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
|
|
|
|
|
2015-05-12 04:00:25 -03:00
|
|
|
int8_t Rover::test_gps(uint8_t argc, const Menu::arg *argv)
|
2012-04-30 04:17:14 -03:00
|
|
|
{
|
2014-03-30 22:01:54 -03:00
|
|
|
print_hit_enter();
|
|
|
|
delay(1000);
|
|
|
|
|
|
|
|
uint32_t last_message_time_ms = 0;
|
2016-12-20 09:34:16 -04:00
|
|
|
while (1) {
|
2014-03-30 22:01:54 -03:00
|
|
|
delay(100);
|
|
|
|
|
|
|
|
gps.update();
|
|
|
|
|
|
|
|
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-30 22:01:54 -03:00
|
|
|
(long)loc.lat,
|
|
|
|
(long)loc.lng,
|
|
|
|
(long)loc.alt/100,
|
|
|
|
(int)gps.num_sats());
|
|
|
|
} else {
|
2017-01-21 00:33:27 -04:00
|
|
|
cliSerial->printf(".");
|
2014-03-30 22:01:54 -03:00
|
|
|
}
|
2016-12-20 09:34:16 -04:00
|
|
|
if (cliSerial->available() > 0) {
|
2014-03-30 22:01:54 -03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
2012-04-30 04:17:14 -03:00
|
|
|
}
|
|
|
|
|
2015-05-12 04:00:25 -03:00
|
|
|
int8_t Rover::test_ins(uint8_t argc, const Menu::arg *argv)
|
2012-04-30 04:17:14 -03:00
|
|
|
{
|
2017-01-21 00:33:27 -04:00
|
|
|
// cliSerial->printf("Calibrating.");
|
2016-12-20 09:34:16 -04:00
|
|
|
ahrs.init();
|
2013-01-13 01:03:54 -04:00
|
|
|
ahrs.set_fly_forward(true);
|
2015-10-21 18:22:45 -03:00
|
|
|
|
|
|
|
ins.init(scheduler.get_loop_rate_hz());
|
2012-04-30 04:17:14 -03:00
|
|
|
ahrs.reset();
|
|
|
|
|
2016-12-20 09:34:16 -04:00
|
|
|
print_hit_enter();
|
|
|
|
delay(1000);
|
2012-04-30 04:17:14 -03:00
|
|
|
|
2013-06-03 21:37:05 -03:00
|
|
|
uint8_t medium_loopCounter = 0;
|
|
|
|
|
2016-12-20 09:34:16 -04:00
|
|
|
while (1) {
|
2014-10-15 20:33:46 -03:00
|
|
|
ins.wait_for_sample();
|
2013-10-28 03:21:35 -03:00
|
|
|
|
|
|
|
ahrs.update();
|
|
|
|
|
2016-12-20 09:34:16 -04:00
|
|
|
if (g.compass_enabled) {
|
2013-10-28 03:21:35 -03:00
|
|
|
medium_loopCounter++;
|
2016-12-20 09:34:16 -04:00
|
|
|
if (medium_loopCounter >= 5) {
|
2013-10-28 03:21:35 -03:00
|
|
|
compass.read();
|
|
|
|
medium_loopCounter = 0;
|
|
|
|
}
|
|
|
|
}
|
2016-12-20 09:34:16 -04:00
|
|
|
|
2013-10-28 03:21:35 -03:00
|
|
|
// We are using the IMU
|
|
|
|
// ---------------------
|
2016-12-20 09:34:16 -04:00
|
|
|
Vector3f gyros = ins.get_gyro();
|
2013-10-28 03:21:35 -03:00
|
|
|
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-04-30 04:17:14 -03:00
|
|
|
(int)ahrs.roll_sensor / 100,
|
|
|
|
(int)ahrs.pitch_sensor / 100,
|
|
|
|
(uint16_t)ahrs.yaw_sensor / 100,
|
2015-05-03 03:01:05 -03:00
|
|
|
(double)gyros.x, (double)gyros.y, (double)gyros.z,
|
|
|
|
(double)accels.x, (double)accels.y, (double)accels.z);
|
2016-12-20 09:34:16 -04:00
|
|
|
if (cliSerial->available() > 0) {
|
2014-11-14 22:29:25 -04:00
|
|
|
return (0);
|
|
|
|
}
|
2013-10-28 03:21:35 -03:00
|
|
|
}
|
2012-04-30 04:17:14 -03:00
|
|
|
}
|
|
|
|
|
2015-05-12 04:00:25 -03:00
|
|
|
void Rover::print_enabled(bool b)
|
|
|
|
{
|
2016-12-20 09:34:16 -04:00
|
|
|
if (b) {
|
2017-01-21 00:33:27 -04:00
|
|
|
cliSerial->printf("en");
|
2016-12-20 09:34:16 -04:00
|
|
|
} else {
|
2017-01-21 00:33:27 -04:00
|
|
|
cliSerial->printf("dis");
|
2016-12-20 09:34:16 -04:00
|
|
|
}
|
2017-01-21 00:33:27 -04:00
|
|
|
cliSerial->printf("abled\n");
|
2015-05-12 04:00:25 -03:00
|
|
|
}
|
2012-04-30 04:17:14 -03:00
|
|
|
|
2015-05-12 04:00:25 -03:00
|
|
|
int8_t Rover::test_mag(uint8_t argc, const Menu::arg *argv)
|
2012-04-30 04:17:14 -03:00
|
|
|
{
|
2016-12-20 09:34:16 -04:00
|
|
|
if (!g.compass_enabled) {
|
2017-01-21 00:33:27 -04:00
|
|
|
cliSerial->printf("Compass: ");
|
2016-12-20 09:34:16 -04:00
|
|
|
print_enabled(false);
|
|
|
|
return (0);
|
2012-04-30 04:17:14 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!compass.init()) {
|
2017-01-21 00:33:27 -04:00
|
|
|
cliSerial->printf("Compass initialisation failed!\n");
|
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);
|
|
|
|
|
|
|
|
// we need the AHRS initialised for this test
|
2015-10-21 18:22:45 -03:00
|
|
|
ins.init(scheduler.get_loop_rate_hz());
|
2012-04-30 04:17:14 -03:00
|
|
|
ahrs.reset();
|
|
|
|
|
2016-12-20 09:34:16 -04:00
|
|
|
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;
|
|
|
|
|
2016-12-20 09:34:16 -04:00
|
|
|
while (1) {
|
2014-10-15 20:33:46 -03:00
|
|
|
ins.wait_for_sample();
|
2013-10-28 03:21:35 -03:00
|
|
|
ahrs.update();
|
|
|
|
|
|
|
|
medium_loopCounter++;
|
2016-12-20 09:34:16 -04:00
|
|
|
if (medium_loopCounter >= 5) {
|
2013-10-28 03:21:35 -03:00
|
|
|
if (compass.read()) {
|
|
|
|
// Calculate heading
|
2015-12-10 18:05:31 -04:00
|
|
|
Matrix3f m = ahrs.get_rotation_body_to_ned();
|
2013-10-28 03:21:35 -03:00
|
|
|
heading = compass.calculate_heading(m);
|
2014-02-15 22:22:20 -04:00
|
|
|
compass.learn_offsets();
|
2012-04-30 04:17:14 -03:00
|
|
|
}
|
2013-10-28 03:21:35 -03:00
|
|
|
medium_loopCounter = 0;
|
|
|
|
}
|
2016-12-20 09:34:16 -04:00
|
|
|
|
2013-10-28 03:21:35 -03:00
|
|
|
counter++;
|
2016-12-20 09:34:16 -04:00
|
|
|
if (counter > 20) {
|
2013-12-09 02:46:57 -04:00
|
|
|
if (compass.healthy()) {
|
2015-09-28 16:57:00 -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-11-23 03:14:40 -04:00
|
|
|
(double)(wrap_360_cd(ToDeg(heading) * 100)) /100,
|
2015-05-03 03:01:05 -03:00
|
|
|
(double)mag.x, (double)mag.y, (double)mag.z,
|
|
|
|
(double)mag_ofs.x, (double)mag_ofs.y, (double)mag_ofs.z);
|
2013-10-28 03:21:35 -03:00
|
|
|
} else {
|
2017-01-21 00:33:27 -04:00
|
|
|
cliSerial->printf("compass not healthy\n");
|
2012-04-30 04:17:14 -03:00
|
|
|
}
|
2016-12-20 09:34:16 -04:00
|
|
|
counter = 0;
|
2013-10-28 03:21:35 -03:00
|
|
|
}
|
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
|
2016-12-20 09:34:16 -04:00
|
|
|
// the CLI before you go flying.
|
2017-01-21 00:33:27 -04:00
|
|
|
cliSerial->printf("saving offsets\n");
|
2012-04-30 04:17:14 -03:00
|
|
|
compass.save_offsets();
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------------
|
|
|
|
// real sensors that have not been simulated yet go here
|
|
|
|
|
2015-05-12 04:00:25 -03:00
|
|
|
int8_t Rover::test_sonar(uint8_t argc, const Menu::arg *argv)
|
2012-06-13 03:29:32 -03:00
|
|
|
{
|
2014-11-10 20:33:51 -04:00
|
|
|
init_sonar();
|
|
|
|
delay(20);
|
|
|
|
sonar.update();
|
|
|
|
|
2017-02-09 07:48:39 -04:00
|
|
|
if (sonar.status(0) == RangeFinder::RangeFinder_NotConnected && sonar.status(1) == RangeFinder::RangeFinder_NotConnected) {
|
2017-01-21 00:33:27 -04:00
|
|
|
cliSerial->printf("WARNING: Sonar is not enabled\n");
|
2013-02-28 16:14:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
print_hit_enter();
|
2016-12-20 09:34:16 -04:00
|
|
|
|
2013-03-28 18:07:24 -03:00
|
|
|
float sonar_dist_cm_min = 0.0f;
|
|
|
|
float sonar_dist_cm_max = 0.0f;
|
2016-12-20 09:34:16 -04:00
|
|
|
float voltage_min = 0.0f, voltage_max = 0.0f;
|
2013-03-28 18:07:24 -03:00
|
|
|
float sonar2_dist_cm_min = 0.0f;
|
|
|
|
float sonar2_dist_cm_max = 0.0f;
|
2016-12-20 09:34:16 -04:00
|
|
|
float voltage2_min = 0.0f, voltage2_max = 0.0f;
|
2013-03-28 18:07:24 -03:00
|
|
|
uint32_t last_print = 0;
|
2012-06-13 03:29:32 -03:00
|
|
|
|
2016-12-20 09:34:16 -04:00
|
|
|
while (true) {
|
2013-03-28 18:07:24 -03:00
|
|
|
delay(20);
|
2014-11-10 20:33:51 -04:00
|
|
|
sonar.update();
|
2013-03-28 18:07:24 -03:00
|
|
|
uint32_t now = millis();
|
2016-12-20 09:34:16 -04:00
|
|
|
|
2014-06-27 00:18:20 -03:00
|
|
|
float dist_cm = sonar.distance_cm(0);
|
|
|
|
float voltage = sonar.voltage_mv(0);
|
2015-05-04 23:34:02 -03:00
|
|
|
if (is_zero(sonar_dist_cm_min)) {
|
2013-03-28 18:07:24 -03:00
|
|
|
sonar_dist_cm_min = dist_cm;
|
|
|
|
voltage_min = voltage;
|
|
|
|
}
|
2015-11-27 13:11:58 -04:00
|
|
|
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);
|
2013-03-28 18:07:24 -03:00
|
|
|
|
2014-06-27 00:18:20 -03:00
|
|
|
dist_cm = sonar.distance_cm(1);
|
|
|
|
voltage = sonar.voltage_mv(1);
|
2015-05-04 23:34:02 -03:00
|
|
|
if (is_zero(sonar2_dist_cm_min)) {
|
2013-03-28 18:07:24 -03:00
|
|
|
sonar2_dist_cm_min = dist_cm;
|
|
|
|
voltage2_min = voltage;
|
|
|
|
}
|
2015-11-27 13:11:58 -04:00
|
|
|
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);
|
2013-03-28 18:07:24 -03:00
|
|
|
|
|
|
|
if (now - last_print >= 200) {
|
2015-10-25 17:10:41 -03:00
|
|
|
cliSerial->printf("sonar1 dist=%.1f:%.1fcm volt1=%.2f:%.2f sonar2 dist=%.1f:%.1fcm volt2=%.2f:%.2f\n",
|
2015-05-03 03:01:05 -03:00
|
|
|
(double)sonar_dist_cm_min,
|
|
|
|
(double)sonar_dist_cm_max,
|
|
|
|
(double)voltage_min,
|
|
|
|
(double)voltage_max,
|
|
|
|
(double)sonar2_dist_cm_min,
|
|
|
|
(double)sonar2_dist_cm_max,
|
|
|
|
(double)voltage2_min,
|
|
|
|
(double)voltage2_max);
|
2013-03-28 18:07:24 -03:00
|
|
|
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;
|
2016-12-20 09:34:16 -04: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
|
|
|
|
2014-03-31 14:58:48 -03:00
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_PX4 || CONFIG_HAL_BOARD == HAL_BOARD_VRBRAIN
|
2013-03-19 22:35:56 -03:00
|
|
|
/*
|
|
|
|
* run a debug shell
|
|
|
|
*/
|
2015-05-12 04:00:25 -03:00
|
|
|
int8_t Rover::test_shell(uint8_t argc, const Menu::arg *argv)
|
2013-03-19 22:35:56 -03:00
|
|
|
{
|
|
|
|
hal.util->run_debug_shell(cliSerial);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-12-20 09:34:16 -04:00
|
|
|
#endif // CLI_ENABLED
|