From e06f30bdd6625a2e38a7f3c463698546de1f561d Mon Sep 17 00:00:00 2001 From: Tomas Baca Date: Mon, 29 Apr 2024 08:25:58 +0200 Subject: [PATCH] added hover test --- test/control_manager/CMakeLists.txt | 2 + .../hover_service/CMakeLists.txt | 16 ++++ .../hover_service/config/world_config.yaml | 34 +++++++ .../hover_service/hover_service.test | 36 +++++++ test/control_manager/hover_service/test.cpp | 95 +++++++++++++++++++ 5 files changed, 183 insertions(+) create mode 100644 test/control_manager/hover_service/CMakeLists.txt create mode 100644 test/control_manager/hover_service/config/world_config.yaml create mode 100644 test/control_manager/hover_service/hover_service.test create mode 100644 test/control_manager/hover_service/test.cpp diff --git a/test/control_manager/CMakeLists.txt b/test/control_manager/CMakeLists.txt index 1c9c7d75..80faabe4 100644 --- a/test/control_manager/CMakeLists.txt +++ b/test/control_manager/CMakeLists.txt @@ -27,3 +27,5 @@ add_subdirectory(set_heading_service) add_subdirectory(set_heading_relative_service) add_subdirectory(goto_altitude_service) + +add_subdirectory(hover_service) diff --git a/test/control_manager/hover_service/CMakeLists.txt b/test/control_manager/hover_service/CMakeLists.txt new file mode 100644 index 00000000..bf8f9853 --- /dev/null +++ b/test/control_manager/hover_service/CMakeLists.txt @@ -0,0 +1,16 @@ +get_filename_component(TEST_NAME "${CMAKE_CURRENT_SOURCE_DIR}" NAME) + +catkin_add_executable_with_gtest(test_${TEST_NAME} + test.cpp + ) + +target_link_libraries(test_${TEST_NAME} + ${catkin_LIBRARIES} + ) + +add_dependencies(test_${TEST_NAME} + ${${PROJECT_NAME}_EXPORTED_TARGETS} + ${catkin_EXPORTED_TARGETS} + ) + +add_rostest(${TEST_NAME}.test) diff --git a/test/control_manager/hover_service/config/world_config.yaml b/test/control_manager/hover_service/config/world_config.yaml new file mode 100644 index 00000000..00e01eef --- /dev/null +++ b/test/control_manager/hover_service/config/world_config.yaml @@ -0,0 +1,34 @@ +world_origin: + + units: "LATLON" # {"UTM, "LATLON"} + + origin_x: 47.397743 + origin_y: 8.545594 + +safety_area: + + enabled: false + + horizontal: + + # the frame of reference in which the points are expressed + frame_name: "world_origin" + + # polygon + # + # x, y [m] for any frame_name except latlon_origin + # x = latitude, y = longitude [deg] for frame_name=="latlon_origin" + points: [ + -50, -50, + 50, -50, + 50, 50, + -50, 50, + ] + + vertical: + + # the frame of reference in which the max&min z is expressed + frame_name: "world_origin" + + max_z: 15.0 + min_z: 0.5 diff --git a/test/control_manager/hover_service/hover_service.test b/test/control_manager/hover_service/hover_service.test new file mode 100644 index 00000000..bb30842e --- /dev/null +++ b/test/control_manager/hover_service/hover_service.test @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/control_manager/hover_service/test.cpp b/test/control_manager/hover_service/test.cpp new file mode 100644 index 00000000..16336c8e --- /dev/null +++ b/test/control_manager/hover_service/test.cpp @@ -0,0 +1,95 @@ +#include + +#include + +class Tester : public mrs_uav_testing::TestGeneric { + +public: + bool test(); +}; + +bool Tester::test() { + + std::shared_ptr uh; + + { + auto [uhopt, message] = getUAVHandler(_uav_name_); + + if (!uhopt) { + ROS_ERROR("[%s]: Failed obtain handler for '%s': '%s'", ros::this_node::getName().c_str(), _uav_name_.c_str(), message.c_str()); + return false; + } + + uh = uhopt.value(); + } + + { + auto [success, message] = uh->activateMidAir(); + + if (!success) { + ROS_ERROR("[%s]: midair activation failed with message: '%s'", ros::this_node::getName().c_str(), message.c_str()); + return false; + } + } + + // | ---------------------- goto relative --------------------- | + + { + auto [success, message] = uh->gotoRelativeService(200, 0, 0, 0); + + if (!success) { + ROS_ERROR("[%s]: goto relative service failed with message: '%s'", ros::this_node::getName().c_str(), message.c_str()); + return false; + } + } + + // | -------------------------- wait -------------------------- | + + this->sleep(5.0); + + // | ---------------------- trigger hover --------------------- | + + { + auto [success, message] = uh->hover(); + + if (!success) { + ROS_ERROR("[%s]: hover service failed with message: '%s'", ros::this_node::getName().c_str(), message.c_str()); + return false; + } + } + + // | -------------------------- wait -------------------------- | + + this->sleep(5.0); + + // | --------------- check if we are stationary --------------- | + + if (uh->isFlyingNormally() && uh->isStationary()) { + return true; + } else { + ROS_ERROR("[%s]: not flying normally || not stationary", ros::this_node::getName().c_str()); + return false; + } +} + +TEST(TESTSuite, test) { + + Tester tester; + + bool result = tester.test(); + + if (result) { + GTEST_SUCCEED(); + } else { + GTEST_FAIL(); + } +} + +int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv) { + + ros::init(argc, argv, "test"); + + testing::InitGoogleTest(&argc, argv); + + return RUN_ALL_TESTS(); +}