2017-09-08 23:44:31 -03:00
|
|
|
#include "SmartRTL_test.h"
|
2017-07-31 02:13:27 -03:00
|
|
|
#include <AP_AHRS/AP_AHRS.h>
|
|
|
|
#include <AP_Baro/AP_Baro.h>
|
|
|
|
#include <AP_Compass/AP_Compass.h>
|
|
|
|
#include <AP_GPS/AP_GPS.h>
|
|
|
|
#include <AP_InertialSensor/AP_InertialSensor.h>
|
|
|
|
#include <AP_NavEKF2/AP_NavEKF2.h>
|
|
|
|
#include <AP_NavEKF3/AP_NavEKF3.h>
|
|
|
|
#include <AP_RangeFinder/AP_RangeFinder.h>
|
|
|
|
#include <AP_SerialManager/AP_SerialManager.h>
|
|
|
|
|
|
|
|
const AP_HAL::HAL &hal = AP_HAL::get_HAL();
|
|
|
|
|
|
|
|
// INS and Baro declaration
|
2017-12-12 21:06:14 -04:00
|
|
|
static AP_InertialSensor ins;
|
|
|
|
static Compass compass;
|
|
|
|
static AP_GPS gps;
|
|
|
|
static AP_Baro barometer;
|
|
|
|
static AP_SerialManager serial_manager;
|
2017-07-31 02:13:27 -03:00
|
|
|
|
|
|
|
class DummyVehicle {
|
|
|
|
public:
|
2021-07-20 09:16:31 -03:00
|
|
|
AP_AHRS ahrs{AP_AHRS::FLAG_ALWAYS_USE_EKF};
|
2017-07-31 02:13:27 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
static DummyVehicle vehicle;
|
|
|
|
|
2021-07-20 09:16:31 -03:00
|
|
|
AP_AHRS &ahrs(vehicle.ahrs);
|
2018-03-31 09:31:51 -03:00
|
|
|
AP_SmartRTL smart_rtl{true};
|
2017-12-12 21:06:14 -04:00
|
|
|
AP_BoardConfig board_config;
|
2017-07-31 02:13:27 -03:00
|
|
|
|
|
|
|
void setup();
|
|
|
|
void loop();
|
|
|
|
void reset();
|
|
|
|
void check_path(const std::vector<Vector3f> &correct_path, const char* test_name, uint32_t time_us);
|
|
|
|
|
|
|
|
void setup()
|
|
|
|
{
|
2017-09-14 10:19:28 -03:00
|
|
|
hal.console->printf("SmartRTL test\n");
|
2017-09-11 20:07:33 -03:00
|
|
|
board_config.init();
|
2017-09-08 23:44:31 -03:00
|
|
|
smart_rtl.init();
|
2017-07-31 02:13:27 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop()
|
|
|
|
{
|
|
|
|
if (!hal.console->is_initialized()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uint32_t reference_time, run_time;
|
|
|
|
|
|
|
|
hal.console->printf("--------------------\n");
|
|
|
|
|
2017-09-08 23:44:31 -03:00
|
|
|
// reset path and upload "test_path_before" to smart_rtl
|
2017-07-31 02:13:27 -03:00
|
|
|
reference_time = AP_HAL::micros();
|
|
|
|
reset();
|
|
|
|
run_time = AP_HAL::micros() - reference_time;
|
|
|
|
|
|
|
|
// check path after initial load (no simplification or pruning)
|
|
|
|
check_path(test_path_after_adding, "append", run_time);
|
|
|
|
|
|
|
|
// test simplifications
|
|
|
|
reference_time = AP_HAL::micros();
|
2017-09-08 23:44:31 -03:00
|
|
|
while (!smart_rtl.request_thorough_cleanup(AP_SmartRTL::THOROUGH_CLEAN_SIMPLIFY_ONLY)) {
|
|
|
|
smart_rtl.run_background_cleanup();
|
2017-07-31 02:13:27 -03:00
|
|
|
}
|
|
|
|
run_time = AP_HAL::micros() - reference_time;
|
|
|
|
check_path(test_path_after_simplifying, "simplify", run_time);
|
|
|
|
|
|
|
|
// test both simplification and pruning
|
|
|
|
hal.scheduler->delay(5); // delay 5 milliseconds because request_through_cleanup uses millisecond timestamps
|
|
|
|
reset();
|
|
|
|
reference_time = AP_HAL::micros();
|
2017-09-08 23:44:31 -03:00
|
|
|
while (!smart_rtl.request_thorough_cleanup(AP_SmartRTL::THOROUGH_CLEAN_ALL)) {
|
|
|
|
smart_rtl.run_background_cleanup();
|
2017-07-31 02:13:27 -03:00
|
|
|
}
|
|
|
|
run_time = AP_HAL::micros() - reference_time;
|
2017-09-08 23:24:58 -03:00
|
|
|
check_path(test_path_complete, "simplify and pruning", run_time);
|
2017-07-31 02:13:27 -03:00
|
|
|
|
|
|
|
// delay before next display
|
|
|
|
hal.scheduler->delay(5e3); // 5 seconds
|
|
|
|
}
|
|
|
|
|
2017-09-08 23:44:31 -03:00
|
|
|
// reset path (i.e. clear path and add home) and upload "test_path_before" to smart_rtl
|
2017-07-31 02:13:27 -03:00
|
|
|
void reset()
|
|
|
|
{
|
2018-01-15 12:08:06 -04:00
|
|
|
smart_rtl.set_home(true, Vector3f{0.0f, 0.0f, 0.0f});
|
2017-07-31 02:13:27 -03:00
|
|
|
for (Vector3f v : test_path_before) {
|
2017-09-08 23:44:31 -03:00
|
|
|
smart_rtl.update(true, v);
|
2017-07-31 02:13:27 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-08 23:44:31 -03:00
|
|
|
// compare the vector array passed in with the path held in the smart_rtl object
|
2017-07-31 02:13:27 -03:00
|
|
|
void check_path(const std::vector<Vector3f>& correct_path, const char* test_name, uint32_t time_us)
|
|
|
|
{
|
|
|
|
// check number of points
|
2017-09-08 23:44:31 -03:00
|
|
|
bool num_points_match = correct_path.size() == smart_rtl.get_num_points();
|
|
|
|
uint16_t points_to_compare = MIN(correct_path.size(), smart_rtl.get_num_points());
|
2017-07-31 02:13:27 -03:00
|
|
|
|
|
|
|
// check all points match
|
|
|
|
bool points_match = true;
|
|
|
|
uint16_t failure_index = 0;
|
|
|
|
for (uint16_t i = 0; i < points_to_compare; i++) {
|
2017-09-08 23:44:31 -03:00
|
|
|
if (smart_rtl.get_point(i) != correct_path[i]) {
|
2017-07-31 02:13:27 -03:00
|
|
|
failure_index = i;
|
|
|
|
points_match = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// display overall results
|
2018-05-03 22:41:05 -03:00
|
|
|
hal.console->printf("%s: %s time:%u us\n", test_name, (num_points_match && points_match) ? "success" : "fail", (unsigned)time_us);
|
2017-07-31 02:13:27 -03:00
|
|
|
|
|
|
|
// display number of points
|
2017-09-08 23:44:31 -03:00
|
|
|
hal.console->printf(" expected %u points, got %u\n", (unsigned)correct_path.size(), (unsigned)smart_rtl.get_num_points());
|
2017-07-31 02:13:27 -03:00
|
|
|
|
|
|
|
// display the first failed point and all subsequent points
|
|
|
|
if (!points_match) {
|
|
|
|
for (uint16_t j = failure_index; j < points_to_compare; j++) {
|
2017-09-14 10:19:28 -03:00
|
|
|
const Vector3f& smartrtl_point = smart_rtl.get_point(j);
|
2017-07-31 02:13:27 -03:00
|
|
|
hal.console->printf(" expected point %d to be %4.2f,%4.2f,%4.2f, got %4.2f,%4.2f,%4.2f\n",
|
|
|
|
(int)j,
|
|
|
|
(double)correct_path[j].x,
|
|
|
|
(double)correct_path[j].y,
|
|
|
|
(double)correct_path[j].z,
|
2017-09-14 10:19:28 -03:00
|
|
|
(double)smartrtl_point.x,
|
|
|
|
(double)smartrtl_point.y,
|
|
|
|
(double)smartrtl_point.z
|
2017-07-31 02:13:27 -03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-20 22:06:45 -03:00
|
|
|
// gcc9 produces a large frame
|
|
|
|
#pragma GCC diagnostic ignored "-Wframe-larger-than="
|
|
|
|
|
2017-07-31 02:13:27 -03:00
|
|
|
AP_HAL_MAIN();
|