Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,10 +42,10 @@ In C++, include
```
for mathematical functions,
```C++
#include <vortex/utils/qos_profiles.hpp>
```
for common QoS profile definitions, and
```C++
#include <vortex/utils/types.hpp>
```
for common structs like 6DOF `PoseEuler`, `Pose` and `Twist`.
```C++
#include <vortex/utils/ros/qos_profiles.hpp>
```
for common QoS profile definitions from from `vortex_utils_ros`
6 changes: 0 additions & 6 deletions cpp_test/test_main.cpp

This file was deleted.

12 changes: 0 additions & 12 deletions CMakeLists.txt → vortex_utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -23,12 +16,7 @@ target_include_directories(${PROJECT_NAME} PUBLIC
$<INSTALL_INTERFACE:include>)

ament_target_dependencies(${PROJECT_NAME} PUBLIC
rclcpp
Eigen3
tf2
tf2_ros
tf2_geometry_msgs
geometry_msgs
)

ament_export_targets(${PROJECT_NAME} HAS_LIBRARY_TARGET)
Expand Down
25 changes: 1 addition & 24 deletions cpp_test/CMakeLists.txt → vortex_utils/cpp_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -9,7 +10,6 @@ add_executable(
test_math.cpp
test_types.cpp
test_concepts.cpp
test_ros_conversions.cpp
)

target_link_libraries(
Expand All @@ -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})
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 0 additions & 6 deletions package.xml → vortex_utils/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,9 @@
<buildtool_depend>ament_cmake</buildtool_depend>
<buildtool_depend>ament_cmake_python</buildtool_depend>

<depend>rclcpp</depend>
<depend>eigen</depend>
<depend>python3-numpy</depend>
<depend>python3-scipy</depend>
<depend>tf2</depend>
<depend>tf2_ros</depend>
<depend>tf2_geometry_msgs</depend>
<depend>geometry_msgs</depend>


<test_depend>ament_cmake_pytest</test_depend>
<test_depend>ament_cmake_gtest</test_depend>
Expand Down
File renamed without changes.
38 changes: 0 additions & 38 deletions py_test/test_utils.py → vortex_utils/py_test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,7 +14,6 @@
quat_to_euler,
ssa,
)
from vortex_utils.ros_converter import pose_from_ros, twist_from_ros


def test_ssa_zero():
Expand Down Expand Up @@ -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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
49 changes: 49 additions & 0 deletions vortex_utils_ros/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)

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()
23 changes: 23 additions & 0 deletions vortex_utils_ros/cpp_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#include <geometry_msgs/msg/pose_stamped.hpp>
#include <geometry_msgs/msg/pose_with_covariance_stamped.hpp>

#include "vortex/utils/math.hpp"
#include "vortex/utils/ros_conversions.hpp"
#include "vortex/utils/types.hpp"
#include <vortex/utils/math.hpp>
#include <vortex/utils/types.hpp>
#include "vortex/utils/ros/ros_conversions.hpp"

struct HasEulerPose {
double x = 0, y = 0, z = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
#include <geometry_msgs/msg/pose_with_covariance.hpp>
#include <geometry_msgs/msg/pose_with_covariance_stamped.hpp>

#include "concepts.hpp"
#include "math.hpp"
#include "types.hpp"
#include <vortex/utils/concepts.hpp>
#include <vortex/utils/math.hpp>
#include <vortex/utils/types.hpp>

namespace vortex::utils::ros_conversions {

Expand Down
27 changes: 27 additions & 0 deletions vortex_utils_ros/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>vortex_utils_ros</name>
<version>0.0.0</version>
<description>Package containing ROS utility functions and data structures.</description>
<maintainer email="jorgen.fjermedal@hotmail.com">jorgenfj</maintainer>
<license>MIT</license>

<buildtool_depend>ament_cmake</buildtool_depend>
<buildtool_depend>ament_cmake_python</buildtool_depend>

<depend>rclcpp</depend>
<depend>vortex_utils</depend>
<depend>eigen</depend>
<depend>python3-numpy</depend>
<depend>python3-scipy</depend>
<depend>geometry_msgs</depend>


<test_depend>ament_cmake_pytest</test_depend>
<test_depend>ament_cmake_gtest</test_depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
13 changes: 13 additions & 0 deletions vortex_utils_ros/py_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
Binary file not shown.
41 changes: 41 additions & 0 deletions vortex_utils_ros/py_test/test_utils_ros.py
Original file line number Diff line number Diff line change
@@ -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
Empty file.
Loading