diff --git a/README.md b/README.md index 2417dfd..989f2d6 100644 --- a/README.md +++ b/README.md @@ -4,15 +4,36 @@ [![codecov](https://codecov.io/github/vortexntnu/vortex-utils/graph/badge.svg?token=d6D7d5xNdf)](https://codecov.io/github/vortexntnu/vortex-utils) This package contains common definitions and often-used utility functions in C++ and Python. +It consist of the packages `vortex_utils`, `vortex_utils_ros` and `vortex_utils_ros_tf` # Usage +CMake: + +```CMake +find_package(vortex_utils REQUIRED) + +# For ROS utils +find_package(vortex_utils_ros REQUIRED) +find_package(vortex_utils_ros_tf REQUIRED) +``` +For cpp packages link against the target: +```CMake +target_link_libraries(my_target vortex_utils) + +# ROS libraries +target_link_libraries(my_target vortex_utils_ros) +# ROS tf2 transform library +target_link_libraries(my_target vortex_utils_ros_tf) + +``` In Python, import your desired function/dataclass like for example: ```python from vortex_utils.python_utils import ssa ``` +To import from `vortex_utils_ros` ```python -from vortex_utils.qos_profiles import sensor_data_profile, reliable_profile +from vortex_utils_ros.qos_profiles import sensor_data_profile, reliable_profile ``` In C++, include @@ -21,10 +42,10 @@ In C++, include ``` for mathematical functions, ```C++ -#include -``` -for common QoS profile definitions, and -```C++ #include ``` for common structs like 6DOF `PoseEuler`, `Pose` and `Twist`. +```C++ +#include +``` +for common QoS profile definitions from from `vortex_utils_ros` diff --git a/cpp_test/test_main.cpp b/cpp_test/test_main.cpp deleted file mode 100644 index 5ebbc76..0000000 --- a/cpp_test/test_main.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int main(int argc, char** argv) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/CMakeLists.txt b/vortex_utils/CMakeLists.txt similarity index 80% rename from CMakeLists.txt rename to vortex_utils/CMakeLists.txt index 4a75054..62423ce 100644 --- a/CMakeLists.txt +++ b/vortex_utils/CMakeLists.txt @@ -5,15 +5,8 @@ set(CMAKE_CXX_STANDARD 20) add_compile_options(-Wall -Wextra -Wpedantic) find_package(ament_cmake REQUIRED) -find_package(rclcpp REQUIRED) find_package(ament_cmake_python REQUIRED) find_package(Eigen3 REQUIRED) -find_package(tf2 REQUIRED) -find_package(tf2_ros REQUIRED) -find_package(tf2_geometry_msgs REQUIRED) -find_package(geometry_msgs REQUIRED) - -include_directories(include) add_library(${PROJECT_NAME} SHARED src/math.cpp) @@ -23,12 +16,7 @@ target_include_directories(${PROJECT_NAME} PUBLIC $) ament_target_dependencies(${PROJECT_NAME} PUBLIC - rclcpp Eigen3 - tf2 - tf2_ros - tf2_geometry_msgs - geometry_msgs ) ament_export_targets(${PROJECT_NAME} HAS_LIBRARY_TARGET) diff --git a/cpp_test/CMakeLists.txt b/vortex_utils/cpp_test/CMakeLists.txt similarity index 54% rename from cpp_test/CMakeLists.txt rename to vortex_utils/cpp_test/CMakeLists.txt index 33f573c..b2eef42 100644 --- a/cpp_test/CMakeLists.txt +++ b/vortex_utils/cpp_test/CMakeLists.txt @@ -1,6 +1,7 @@ cmake_minimum_required(VERSION 3.8) find_package(GTest REQUIRED) +find_package(Eigen3 REQUIRED) include(GoogleTest) set(TEST_BINARY_NAME ${PROJECT_NAME}_test) @@ -9,7 +10,6 @@ add_executable( test_math.cpp test_types.cpp test_concepts.cpp - test_ros_conversions.cpp ) target_link_libraries( @@ -23,26 +23,3 @@ target_link_libraries( ament_target_dependencies(${TEST_BINARY_NAME} PUBLIC Eigen3) gtest_discover_tests(${TEST_BINARY_NAME}) - -set(TEST_BINARY_ROS_NAME ${PROJECT_NAME}_ros_test) - -add_executable( - ${TEST_BINARY_ROS_NAME} - test_ros_transforms.cpp -) - -target_link_libraries( - ${TEST_BINARY_ROS_NAME} - ${PROJECT_NAME} - GTest::GTest -) - -ament_target_dependencies( - ${TEST_BINARY_ROS_NAME} - rclcpp - tf2 - tf2_ros - tf2_geometry_msgs -) - -gtest_discover_tests(${TEST_BINARY_ROS_NAME}) diff --git a/cpp_test/test_concepts.cpp b/vortex_utils/cpp_test/test_concepts.cpp similarity index 100% rename from cpp_test/test_concepts.cpp rename to vortex_utils/cpp_test/test_concepts.cpp diff --git a/cpp_test/test_math.cpp b/vortex_utils/cpp_test/test_math.cpp similarity index 100% rename from cpp_test/test_math.cpp rename to vortex_utils/cpp_test/test_math.cpp diff --git a/cpp_test/test_types.cpp b/vortex_utils/cpp_test/test_types.cpp similarity index 100% rename from cpp_test/test_types.cpp rename to vortex_utils/cpp_test/test_types.cpp diff --git a/include/vortex/utils/concepts.hpp b/vortex_utils/include/vortex/utils/concepts.hpp similarity index 100% rename from include/vortex/utils/concepts.hpp rename to vortex_utils/include/vortex/utils/concepts.hpp diff --git a/include/vortex/utils/math.hpp b/vortex_utils/include/vortex/utils/math.hpp similarity index 100% rename from include/vortex/utils/math.hpp rename to vortex_utils/include/vortex/utils/math.hpp diff --git a/include/vortex/utils/types.hpp b/vortex_utils/include/vortex/utils/types.hpp similarity index 100% rename from include/vortex/utils/types.hpp rename to vortex_utils/include/vortex/utils/types.hpp diff --git a/package.xml b/vortex_utils/package.xml similarity index 83% rename from package.xml rename to vortex_utils/package.xml index 61ae562..22d8452 100644 --- a/package.xml +++ b/vortex_utils/package.xml @@ -10,15 +10,9 @@ ament_cmake ament_cmake_python - rclcpp eigen python3-numpy python3-scipy - tf2 - tf2_ros - tf2_geometry_msgs - geometry_msgs - ament_cmake_pytest ament_cmake_gtest diff --git a/py_test/CMakeLists.txt b/vortex_utils/py_test/CMakeLists.txt similarity index 100% rename from py_test/CMakeLists.txt rename to vortex_utils/py_test/CMakeLists.txt diff --git a/py_test/resources/test_video.h264 b/vortex_utils/py_test/resources/test_video.h264 similarity index 100% rename from py_test/resources/test_video.h264 rename to vortex_utils/py_test/resources/test_video.h264 diff --git a/py_test/test_utils.py b/vortex_utils/py_test/test_utils.py similarity index 88% rename from py_test/test_utils.py rename to vortex_utils/py_test/test_utils.py index 764a11d..f6064a0 100644 --- a/py_test/test_utils.py +++ b/vortex_utils/py_test/test_utils.py @@ -3,7 +3,6 @@ import numpy as np import pytest -from geometry_msgs.msg import Pose, Twist from gi.repository import Gst from vortex_utils.gst_utils import H264Decoder @@ -15,7 +14,6 @@ quat_to_euler, ssa, ) -from vortex_utils.ros_converter import pose_from_ros, twist_from_ros def test_ssa_zero(): @@ -285,39 +283,3 @@ def test_h264_decoder_stops_cleanly(decoder): assert decoder._pipeline.get_state(0)[1] == Gst.State.NULL, ( "Decoder did not shut down properly." ) - - -def test_pose_from_ros(): - pose_msg = Pose() - pose_msg.position.x = 1.0 - pose_msg.position.y = 2.0 - pose_msg.position.z = 3.0 - pose_msg.orientation.x = 0.1 - pose_msg.orientation.y = 0.2 - pose_msg.orientation.z = 0.3 - pose_msg.orientation.w = 0.4 - euler = quat_to_euler(0.1, 0.2, 0.3, 0.4) - pose = pose_from_ros(pose_msg) - assert pose.x == 1.0 - assert pose.y == 2.0 - assert pose.z == 3.0 - assert pose.roll == pytest.approx(euler[0], abs=0.01) - assert pose.pitch == pytest.approx(euler[1], abs=0.01) - assert pose.yaw == pytest.approx(euler[2], abs=0.01) - - -def test_twist_from_ros(): - twist_msg = Twist() - twist_msg.linear.x = 1.0 - twist_msg.linear.y = 2.0 - twist_msg.linear.z = 3.0 - twist_msg.angular.x = 0.1 - twist_msg.angular.y = 0.2 - twist_msg.angular.z = 0.3 - twist = twist_from_ros(twist_msg) - assert twist.linear_x == 1.0 - assert twist.linear_y == 2.0 - assert twist.linear_z == 3.0 - assert twist.angular_x == 0.1 - assert twist.angular_y == 0.2 - assert twist.angular_z == 0.3 diff --git a/src/math.cpp b/vortex_utils/src/math.cpp similarity index 100% rename from src/math.cpp rename to vortex_utils/src/math.cpp diff --git a/vortex_utils/README.md b/vortex_utils/vortex_utils/README.md similarity index 100% rename from vortex_utils/README.md rename to vortex_utils/vortex_utils/README.md diff --git a/vortex_utils/__init__.py b/vortex_utils/vortex_utils/__init__.py similarity index 100% rename from vortex_utils/__init__.py rename to vortex_utils/vortex_utils/__init__.py diff --git a/vortex_utils/gst_utils.py b/vortex_utils/vortex_utils/gst_utils.py similarity index 100% rename from vortex_utils/gst_utils.py rename to vortex_utils/vortex_utils/gst_utils.py diff --git a/vortex_utils/python_utils.py b/vortex_utils/vortex_utils/python_utils.py similarity index 100% rename from vortex_utils/python_utils.py rename to vortex_utils/vortex_utils/python_utils.py diff --git a/vortex_utils_ros/CMakeLists.txt b/vortex_utils_ros/CMakeLists.txt new file mode 100644 index 0000000..d52800b --- /dev/null +++ b/vortex_utils_ros/CMakeLists.txt @@ -0,0 +1,49 @@ +cmake_minimum_required(VERSION 3.8) +project(vortex_utils_ros) + +set(CMAKE_CXX_STANDARD 20) +add_compile_options(-Wall -Wextra -Wpedantic) + +find_package(ament_cmake REQUIRED) +find_package(vortex_utils REQUIRED) +find_package(rclcpp REQUIRED) +find_package(ament_cmake_python REQUIRED) +find_package(Eigen3 REQUIRED) +find_package(geometry_msgs REQUIRED) + +add_library(vortex_utils_ros INTERFACE) + +target_include_directories(vortex_utils_ros INTERFACE + $ + $ +) + +ament_target_dependencies(vortex_utils_ros INTERFACE + vortex_utils + rclcpp + Eigen3 + geometry_msgs +) + +install( + DIRECTORY include/ + DESTINATION include +) + +install( + TARGETS vortex_utils_ros + EXPORT vortex_utils_ros_targets +) + +ament_export_targets(vortex_utils_ros_targets) + +ament_export_dependencies() +ament_export_include_directories(include) +ament_python_install_package(${PROJECT_NAME}) + +if(BUILD_TESTING) + add_subdirectory(py_test) + add_subdirectory(cpp_test) +endif() + +ament_package() diff --git a/vortex_utils_ros/cpp_test/CMakeLists.txt b/vortex_utils_ros/cpp_test/CMakeLists.txt new file mode 100644 index 0000000..dd4b874 --- /dev/null +++ b/vortex_utils_ros/cpp_test/CMakeLists.txt @@ -0,0 +1,23 @@ +cmake_minimum_required(VERSION 3.8) + +find_package(GTest REQUIRED) +include(GoogleTest) + +set(TEST_BINARY_NAME ${PROJECT_NAME}_test) + +add_executable(${TEST_BINARY_NAME} + test_ros_conversions.cpp +) + +target_link_libraries(${TEST_BINARY_NAME} + PRIVATE + ${PROJECT_NAME} + GTest::GTest + GTest::gtest_main +) + +ament_target_dependencies(${TEST_BINARY_NAME} PUBLIC + rclcpp +) + +gtest_discover_tests(${TEST_BINARY_NAME}) diff --git a/cpp_test/test_ros_conversions.cpp b/vortex_utils_ros/cpp_test/test_ros_conversions.cpp similarity index 98% rename from cpp_test/test_ros_conversions.cpp rename to vortex_utils_ros/cpp_test/test_ros_conversions.cpp index 69c7714..9eec425 100644 --- a/cpp_test/test_ros_conversions.cpp +++ b/vortex_utils_ros/cpp_test/test_ros_conversions.cpp @@ -8,9 +8,9 @@ #include #include -#include "vortex/utils/math.hpp" -#include "vortex/utils/ros_conversions.hpp" -#include "vortex/utils/types.hpp" +#include +#include +#include "vortex/utils/ros/ros_conversions.hpp" struct HasEulerPose { double x = 0, y = 0, z = 0; diff --git a/include/vortex/utils/qos_profiles.hpp b/vortex_utils_ros/include/vortex/utils/ros/qos_profiles.hpp similarity index 100% rename from include/vortex/utils/qos_profiles.hpp rename to vortex_utils_ros/include/vortex/utils/ros/qos_profiles.hpp diff --git a/include/vortex/utils/ros_conversions.hpp b/vortex_utils_ros/include/vortex/utils/ros/ros_conversions.hpp similarity index 98% rename from include/vortex/utils/ros_conversions.hpp rename to vortex_utils_ros/include/vortex/utils/ros/ros_conversions.hpp index 3dc7a31..eb3999c 100644 --- a/include/vortex/utils/ros_conversions.hpp +++ b/vortex_utils_ros/include/vortex/utils/ros/ros_conversions.hpp @@ -14,9 +14,9 @@ #include #include -#include "concepts.hpp" -#include "math.hpp" -#include "types.hpp" +#include +#include +#include namespace vortex::utils::ros_conversions { diff --git a/vortex_utils_ros/package.xml b/vortex_utils_ros/package.xml new file mode 100644 index 0000000..087735b --- /dev/null +++ b/vortex_utils_ros/package.xml @@ -0,0 +1,27 @@ + + + + vortex_utils_ros + 0.0.0 + Package containing ROS utility functions and data structures. + jorgenfj + MIT + + ament_cmake + ament_cmake_python + + rclcpp + vortex_utils + eigen + python3-numpy + python3-scipy + geometry_msgs + + + ament_cmake_pytest + ament_cmake_gtest + + + ament_cmake + + diff --git a/vortex_utils_ros/py_test/CMakeLists.txt b/vortex_utils_ros/py_test/CMakeLists.txt new file mode 100644 index 0000000..eed0cdf --- /dev/null +++ b/vortex_utils_ros/py_test/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.8) + +find_package(ament_cmake_pytest REQUIRED) +set(_pytest_tests + test_utils_ros.py +) +foreach(_test_path ${_pytest_tests}) + get_filename_component(_test_name ${_test_path} NAME_WE) + ament_add_pytest_test(${_test_name} ${_test_path} + APPEND_ENV PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR} + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + ) +endforeach() diff --git a/vortex_utils_ros/py_test/resources/test_video.h264 b/vortex_utils_ros/py_test/resources/test_video.h264 new file mode 100644 index 0000000..a56ce6a Binary files /dev/null and b/vortex_utils_ros/py_test/resources/test_video.h264 differ diff --git a/vortex_utils_ros/py_test/test_utils_ros.py b/vortex_utils_ros/py_test/test_utils_ros.py new file mode 100644 index 0000000..03ecbd5 --- /dev/null +++ b/vortex_utils_ros/py_test/test_utils_ros.py @@ -0,0 +1,41 @@ +import pytest +from geometry_msgs.msg import Pose, Twist + +from vortex_utils.python_utils import quat_to_euler +from vortex_utils_ros.ros_converter import pose_from_ros, twist_from_ros + + +def test_pose_from_ros(): + pose_msg = Pose() + pose_msg.position.x = 1.0 + pose_msg.position.y = 2.0 + pose_msg.position.z = 3.0 + pose_msg.orientation.x = 0.1 + pose_msg.orientation.y = 0.2 + pose_msg.orientation.z = 0.3 + pose_msg.orientation.w = 0.4 + euler = quat_to_euler(0.1, 0.2, 0.3, 0.4) + pose = pose_from_ros(pose_msg) + assert pose.x == 1.0 + assert pose.y == 2.0 + assert pose.z == 3.0 + assert pose.roll == pytest.approx(euler[0], abs=0.01) + assert pose.pitch == pytest.approx(euler[1], abs=0.01) + assert pose.yaw == pytest.approx(euler[2], abs=0.01) + + +def test_twist_from_ros(): + twist_msg = Twist() + twist_msg.linear.x = 1.0 + twist_msg.linear.y = 2.0 + twist_msg.linear.z = 3.0 + twist_msg.angular.x = 0.1 + twist_msg.angular.y = 0.2 + twist_msg.angular.z = 0.3 + twist = twist_from_ros(twist_msg) + assert twist.linear_x == 1.0 + assert twist.linear_y == 2.0 + assert twist.linear_z == 3.0 + assert twist.angular_x == 0.1 + assert twist.angular_y == 0.2 + assert twist.angular_z == 0.3 diff --git a/vortex_utils_ros/vortex_utils_ros/__init__.py b/vortex_utils_ros/vortex_utils_ros/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/vortex_utils/qos_profiles.py b/vortex_utils_ros/vortex_utils_ros/qos_profiles.py similarity index 100% rename from vortex_utils/qos_profiles.py rename to vortex_utils_ros/vortex_utils_ros/qos_profiles.py diff --git a/vortex_utils/ros_converter.py b/vortex_utils_ros/vortex_utils_ros/ros_converter.py similarity index 100% rename from vortex_utils/ros_converter.py rename to vortex_utils_ros/vortex_utils_ros/ros_converter.py diff --git a/vortex_utils_ros_tf/CMakeLists.txt b/vortex_utils_ros_tf/CMakeLists.txt new file mode 100644 index 0000000..6b21759 --- /dev/null +++ b/vortex_utils_ros_tf/CMakeLists.txt @@ -0,0 +1,51 @@ +cmake_minimum_required(VERSION 3.8) +project(vortex_utils_ros_tf) + +set(CMAKE_CXX_STANDARD 20) +add_compile_options(-Wall -Wextra -Wpedantic) + +find_package(ament_cmake REQUIRED) +find_package(vortex_utils REQUIRED) +find_package(rclcpp REQUIRED) +find_package(ament_cmake_python REQUIRED) +find_package(geometry_msgs REQUIRED) +find_package(tf2 REQUIRED) +find_package(tf2_ros REQUIRED) +find_package(tf2_geometry_msgs REQUIRED) + +add_library(vortex_utils_ros_tf INTERFACE) + +target_include_directories(vortex_utils_ros_tf INTERFACE + $ + $ +) + +ament_target_dependencies(vortex_utils_ros_tf INTERFACE + vortex_utils + rclcpp + tf2 + tf2_ros + tf2_geometry_msgs + geometry_msgs +) + +install( + DIRECTORY include/ + DESTINATION include +) + +install( + TARGETS vortex_utils_ros_tf + EXPORT vortex_utils_ros_targets +) + +ament_export_targets(vortex_utils_ros_targets) + +ament_export_dependencies() +ament_export_include_directories(include) + +if(BUILD_TESTING) + add_subdirectory(cpp_test) +endif() + +ament_package() diff --git a/vortex_utils_ros_tf/cpp_test/CMakeLists.txt b/vortex_utils_ros_tf/cpp_test/CMakeLists.txt new file mode 100644 index 0000000..1e15427 --- /dev/null +++ b/vortex_utils_ros_tf/cpp_test/CMakeLists.txt @@ -0,0 +1,25 @@ +cmake_minimum_required(VERSION 3.8) + +find_package(GTest REQUIRED) +include(GoogleTest) + +set(TEST_BINARY_TF_NAME ${PROJECT_NAME}_test) + + +add_executable(${TEST_BINARY_TF_NAME} + test_ros_transforms.cpp +) + +target_link_libraries(${TEST_BINARY_TF_NAME} + ${PROJECT_NAME} + GTest::GTest +) + +ament_target_dependencies(${TEST_BINARY_TF_NAME} + rclcpp + tf2 + tf2_ros + tf2_geometry_msgs +) + +gtest_discover_tests(${TEST_BINARY_TF_NAME}) diff --git a/cpp_test/test_ros_transforms.cpp b/vortex_utils_ros_tf/cpp_test/test_ros_transforms.cpp similarity index 98% rename from cpp_test/test_ros_transforms.cpp rename to vortex_utils_ros_tf/cpp_test/test_ros_transforms.cpp index 9335be3..f87feac 100644 --- a/cpp_test/test_ros_transforms.cpp +++ b/vortex_utils_ros_tf/cpp_test/test_ros_transforms.cpp @@ -12,7 +12,7 @@ #include #include -#include "vortex/utils/ros_transforms.hpp" +#include "vortex/utils/ros/ros_transforms.hpp" class RosTransformsTest : public ::testing::Test { protected: diff --git a/include/vortex/utils/ros_transforms.hpp b/vortex_utils_ros_tf/include/vortex/utils/ros/ros_transforms.hpp similarity index 100% rename from include/vortex/utils/ros_transforms.hpp rename to vortex_utils_ros_tf/include/vortex/utils/ros/ros_transforms.hpp diff --git a/vortex_utils_ros_tf/package.xml b/vortex_utils_ros_tf/package.xml new file mode 100644 index 0000000..e478262 --- /dev/null +++ b/vortex_utils_ros_tf/package.xml @@ -0,0 +1,25 @@ + + + + vortex_utils_ros_tf + 0.0.0 + Package containing ROS tf2 utility functions. + jorgenfj + MIT + + ament_cmake + + rclcpp + vortex_utils + eigen + tf2 + tf2_ros + tf2_geometry_msgs + geometry_msgs + + ament_cmake_gtest + + + ament_cmake + +