Integration Testing: Rostest with non-Catkin Packages (MAVROS and PX4)

asked 2021-10-08 06:25:04 -0500

Micha Sende gravatar image

updated 2021-10-11 02:20:25 -0500

I am trying to run an integration test of a ROS node I wrote that relies on MAVROS.

So I created a rostest which includes a launch file:

<?xml version="1.0"?>
<launch>

    <!-- PX4 SITL and Gazebo vehicle spawn URDF -->
    <include file="$(find px4)/launch/single_vehicle_spawn.launch">
        <arg name="ID" value="0" />
    </include>

    <!-- MAVROS -->
    <include file="$(find mavros)/launch/px4.launch">
        <arg name="fcu_url" value="udp://:14540@localhost:14580" />
    </include>

    <!--  My ROS node -->
    <node pkg="foo" type="bar" name="bar" />

    <!-- Node unit test -->
    <test pkg="foo" type="test_bar" test-name="test_bar" />

</launch>

My CMakeLists.txt:

if(CATKIN_ENABLE_TESTING)
  find_package(rostest REQUIRED)
  add_rostest_gtest(test_${PROJECT_NAME} test/test_${PROJECT_NAME}.test test/test_${PROJECT_NAME}.cpp)
  if(TARGET test_${PROJECT_NAME})
    target_link_libraries(test_${PROJECT_NAME} ${catkin_LIBRARIES})
  endif()
endif()

I try to run the test using catkin tools:

$ catkin run_tests

However, I'm getting a ResourceNotFound error:

rospkg.common.ResourceNotFound: px4

I guess the problem is that PX4 is neither a catkin package nor part of the ROS_PACKAGE_PATH. In order to run simulations normally, using roslaunch, I set the required environment variables in my .bashrcfile like so:

source /home/ros/workspaces/px4/Tools/setup_gazebo.bash /home/ros/workspaces/px4 /home/ros/workspaces/px4/build/px4_sitl_default > /dev/null
export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:/home/ros/workspaces/px4:/home/ros/workspaces/px4/Tools/sitl_gazebo

This allows to execute simulations:

$ roslaunch foo bar.launch

Apparently, this environment is not passed to the rostest.

Does anybody have an idea on this?

The only things I stumbled upon during my research is

Both did not help me with my problem though.

edit retag flag offensive close merge delete

Comments

My experience with catkin tests is that they have a lot of problems with external resources since they don't load paths as usual ros operation does.

Bernat Gaston gravatar image Bernat Gaston  ( 2021-10-11 05:32:21 -0500 )edit

@aau Were you able to find a solution to your problem? I'm currently facing the exact same issue.

mstampa gravatar image mstampa  ( 2022-02-23 04:26:07 -0500 )edit

@mstampa: No luck so far :( My workaround: Create a test node that publishes dummy data on the same topic as MAVROS.

Micha Sende gravatar image Micha Sende  ( 2022-06-08 08:13:30 -0500 )edit

@micha-sende I had a similar workaround, but unfortunately that's not a viable long-term solution for the parts of the system that matter most to my research. Thanks anyway for the reply! If I get back around to this problem I might post the question on the PX4 forums, maybe someone there has an idea.

mstampa gravatar image mstampa  ( 2022-06-09 03:40:40 -0500 )edit

I have the same issue when invoking "catkin run_tests", but the ResourceNotFound complaints go away when invoke rostest directly - e.g. rostest <package_name> <test_file_name>

tii1428 gravatar image tii1428  ( 2022-07-19 13:59:10 -0500 )edit