-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
723 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,20 @@ | ||
find_package(rostest REQUIRED) | ||
find_package(mrs_uav_testing REQUIRED) | ||
find_package(catkin REQUIRED COMPONENTS mrs_uav_testing) | ||
|
||
# will test takeoff in mrs simulator | ||
add_subdirectory(takeoff) | ||
|
||
# will test takeoff in gazebo | ||
add_subdirectory(gazebo_takeoff) | ||
|
||
# will test if takeoff is not allowed outside of safety area | ||
add_subdirectory(outside_safety_area) | ||
|
||
# will test the "handle_takeoff: false" option | ||
add_subdirectory(without_takeoff) | ||
|
||
# will test if takeoff is not allowed when UAV is moving | ||
add_subdirectory(moving_drone) | ||
|
||
# will test if takeoff is not allowed if topic check fails | ||
add_subdirectory(topic_check) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/bash | ||
|
||
PACKAGE_NAME=mrs_uav_autostart | ||
|
||
while [ ! -e ".catkin_tools" ]; do | ||
cd .. | ||
if [[ `pwd` == "/" ]]; then | ||
# we reached the root and didn't find the build/COLCON_IGNORE file - that's a fail! | ||
echo "$0: could not find the root of the current workspace". | ||
return 1 | ||
fi | ||
done | ||
|
||
cd build | ||
|
||
lcov --capture --directory . --output-file coverage.info | ||
lcov --remove coverage.info "*/test/*" --output-file coverage.info.removed | ||
lcov --extract coverage.info.removed "*/mrs_uav_autostart/*" --output-file coverage.info.cleaned | ||
genhtml -o coverage_html coverage.info.cleaned | tee /tmp/genhtml.log | ||
|
||
COVERAGE_PCT=`cat /tmp/genhtml.log | tail -n 1 | awk '{print $2}'` | ||
|
||
echo "Coverage: $COVERAGE_PCT" | ||
|
||
xdg-open coverage_html/index.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
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 | ||
ARGS | ||
test_path:=${CMAKE_CURRENT_SOURCE_DIR} | ||
package_name:=${PROJECT_NAME} | ||
test_name:=${TEST_NAME} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<launch> | ||
|
||
<arg name="UAV_NAME" default="uav1" /> | ||
<arg name="UAV_TYPE" default="x500" /> | ||
|
||
<!-- these will be filled in from the CMakeLists --> | ||
<arg name="test_path" default="" /> | ||
<arg name="test_name" default="" /> | ||
<arg name="package_name" default="" /> | ||
|
||
<include file="$(find mrs_uav_testing)/launch/gazebo_simulator.launch" /> | ||
|
||
<include file="$(find mrs_uav_px4_api)/launch/api.launch"> | ||
<arg name="UAV_NAME" default="$(arg UAV_NAME)" /> | ||
<arg name="RUN_TYPE" default="simulation" /> | ||
</include> | ||
|
||
<include file="$(find mrs_uav_testing)/launch/mrs_uav_system.launch"> | ||
<arg name="automatic_start" default="true" /> | ||
<arg name="platform_config" default="$(find mrs_uav_gazebo_simulation)/config/mrs_uav_system/$(arg UAV_TYPE).yaml" /> | ||
<arg name="UAV_NAME" default="$(arg UAV_NAME)" /> | ||
</include> | ||
|
||
<test pkg="$(arg package_name)" type="test_$(arg test_name)" test-name="$(arg test_name)" time-limit="60.0"> | ||
<param name="test_name" value="$(arg test_name)" /> | ||
<param name="uav_name" value="$(arg UAV_NAME)" /> | ||
<param name="gazebo_spawner_params" value="1 --$(arg UAV_TYPE) --enable-rangefinder" /> | ||
</test> | ||
|
||
</launch> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include <gtest/gtest.h> | ||
|
||
#include <mrs_uav_testing/test_generic.h> | ||
|
||
class Tester : public mrs_uav_testing::TestGeneric { | ||
|
||
public: | ||
bool test(); | ||
}; | ||
|
||
bool Tester::test() { | ||
|
||
{ | ||
auto [success, message] = spawnGazeboUav(); | ||
|
||
if (!success) { | ||
ROS_ERROR("[%s]: gazebo UAV spawning failed with message: '%s'", ros::this_node::getName().c_str(), message.c_str()); | ||
return false; | ||
} | ||
} | ||
|
||
{ | ||
auto [success, message] = takeoff(); | ||
|
||
if (!success) { | ||
ROS_ERROR("[%s]: midair activation failed with message: '%s'", ros::this_node::getName().c_str(), message.c_str()); | ||
return false; | ||
} | ||
} | ||
|
||
this->sleep(5.0); | ||
|
||
if (this->isFlyingNormally()) { | ||
return true; | ||
} else { | ||
ROS_ERROR("[%s]: not flying normally", 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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
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 | ||
ARGS | ||
test_path:=${CMAKE_CURRENT_SOURCE_DIR} | ||
package_name:=${PROJECT_NAME} | ||
test_name:=${TEST_NAME} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<launch> | ||
|
||
<arg name="UAV_NAME" default="uav1" /> | ||
<arg name="UAV_TYPE" default="x500" /> | ||
|
||
<!-- these will be filled in from the CMakeLists --> | ||
<arg name="test_path" default="" /> | ||
<arg name="test_name" default="" /> | ||
<arg name="package_name" default="" /> | ||
|
||
<include file="$(find mrs_uav_testing)/launch/mrs_simulator.launch"> | ||
<arg name="UAV_NAME" default="$(arg UAV_NAME)" /> | ||
</include> | ||
|
||
<include file="$(find mrs_multirotor_simulator)/launch/hw_api.launch"> | ||
<arg name="UAV_NAME" default="$(arg UAV_NAME)" /> | ||
</include> | ||
|
||
<include file="$(find mrs_uav_testing)/launch/mrs_uav_system.launch"> | ||
<arg name="automatic_start" default="true" /> | ||
<arg name="platform_config" default="$(find mrs_multirotor_simulator)/config/mrs_uav_system/$(arg UAV_TYPE).yaml" /> | ||
<arg name="UAV_NAME" default="$(arg UAV_NAME)" /> | ||
</include> | ||
|
||
<test pkg="$(arg package_name)" type="test_$(arg test_name)" test-name="$(arg test_name)" time-limit="60.0"> | ||
<param name="test_name" value="$(arg test_name)" /> | ||
<param name="uav_name" value="$(arg UAV_NAME)" /> | ||
</test> | ||
|
||
</launch> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#include <gtest/gtest.h> | ||
|
||
#include <mrs_uav_testing/test_generic.h> | ||
|
||
#include <mrs_msgs/HwApiVelocityHdgCmd.h> | ||
|
||
class Tester : public mrs_uav_testing::TestGeneric { | ||
|
||
public: | ||
Tester(); | ||
|
||
bool test(); | ||
|
||
mrs_lib::PublisherHandler<mrs_msgs::HwApiVelocityHdgCmd> ph_velocity_; | ||
|
||
ros::Timer timer_main_; | ||
void timerMain(const ros::TimerEvent& event); | ||
}; | ||
|
||
Tester::Tester() : mrs_uav_testing::TestGeneric() { | ||
|
||
ph_velocity_ = mrs_lib::PublisherHandler<mrs_msgs::HwApiVelocityHdgCmd>(nh_, "/multirotor_simulator/" + _uav_name_ + "/velocity_hdg_cmd"); | ||
|
||
timer_main_ = nh_.createTimer(ros::Rate(100.0), &Tester::timerMain, this, false, true); | ||
} | ||
|
||
void Tester::timerMain(const ros::TimerEvent& event) { | ||
|
||
mrs_msgs::HwApiVelocityHdgCmd msg; | ||
|
||
msg.velocity.x = 0.5; | ||
msg.velocity.z = 0.1; | ||
|
||
ph_velocity_.publish(msg); | ||
} | ||
|
||
bool Tester::test() { | ||
|
||
auto [success, message] = takeoff(); | ||
|
||
if (!success) { | ||
return true; | ||
} else { | ||
ROS_ERROR("[%s]: takeoff initiated, this should not be possible", 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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
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 | ||
ARGS | ||
test_path:=${CMAKE_CURRENT_SOURCE_DIR} | ||
package_name:=${PROJECT_NAME} | ||
test_name:=${TEST_NAME} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
individual_takeoff_platform: | ||
enabled: false | ||
|
||
uav_names: [ | ||
"uav1", | ||
] | ||
|
||
uav1: | ||
type: "x500" | ||
spawn: | ||
x: 500.0 | ||
y: 500.0 | ||
z: 0.0 | ||
heading: 0 |
Oops, something went wrong.