Skip to content

Commit 20a0753

Browse files
committed
landmark array to pose vector
1 parent 9f26976 commit 20a0753

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

vortex_utils_ros/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ find_package(rclcpp REQUIRED)
1010
find_package(ament_cmake_python REQUIRED)
1111
find_package(Eigen3 REQUIRED)
1212
find_package(geometry_msgs REQUIRED)
13+
find_package(vortex_msgs REQUIRED)
1314

1415
add_library(vortex_utils_ros INTERFACE)
1516

@@ -23,6 +24,7 @@ ament_target_dependencies(vortex_utils_ros INTERFACE
2324
rclcpp
2425
Eigen3
2526
geometry_msgs
27+
vortex_msgs
2628
)
2729

2830
install(

vortex_utils_ros/cpp_test/test_ros_conversions.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <geometry_msgs/msg/pose_array.hpp>
88
#include <geometry_msgs/msg/pose_stamped.hpp>
99
#include <geometry_msgs/msg/pose_with_covariance_stamped.hpp>
10+
#include <vortex_msgs/msg/landmark_array.hpp>
1011

1112
#include <vortex/utils/math.hpp>
1213
#include <vortex/utils/types.hpp>
@@ -214,3 +215,17 @@ TEST(ros_to_pose_vec, pose_array) {
214215
EXPECT_NEAR(v[0].x, 1.0, 1e-6);
215216
EXPECT_NEAR(v[1].x, 2.0, 1e-6);
216217
}
218+
219+
TEST(ros_to_pose_vec, landmark_array) {
220+
vortex_msgs::msg::LandmarkArray arr;
221+
arr.landmarks.resize(2);
222+
223+
arr.landmarks[0].pose.pose.position.x = 1;
224+
arr.landmarks[1].pose.pose.position.x = 2;
225+
226+
auto v = vortex::utils::ros_conversions::ros_to_pose_vec(arr);
227+
228+
ASSERT_EQ(v.size(), 2);
229+
EXPECT_NEAR(v[0].x, 1.0, 1e-6);
230+
EXPECT_NEAR(v[1].x, 2.0, 1e-6);
231+
}

vortex_utils_ros/include/vortex/utils/ros/ros_conversions.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <geometry_msgs/msg/pose_stamped.hpp>
1414
#include <geometry_msgs/msg/pose_with_covariance.hpp>
1515
#include <geometry_msgs/msg/pose_with_covariance_stamped.hpp>
16+
#include <vortex_msgs/msg/landmark_array.hpp>
1617

1718
#include <vortex/utils/concepts.hpp>
1819
#include <vortex/utils/math.hpp>
@@ -159,6 +160,22 @@ inline std::vector<vortex::utils::types::Pose> ros_to_pose_vec(
159160
return poses;
160161
}
161162

163+
/**
164+
* @brief Converts a ROS vortex_msgs::msg::LandmarkArray to an internal Pose
165+
* vector type.
166+
* @param pose vortex_msgs::msg::LandmarkArray
167+
* @return std::vector<vortex::utils::types::Pose> Internal pose representation
168+
*/
169+
inline std::vector<vortex::utils::types::Pose> ros_to_pose_vec(
170+
const vortex_msgs::msg::LandmarkArray& msg) {
171+
std::vector<vortex::utils::types::Pose> poses;
172+
poses.reserve(msg.landmarks.size());
173+
for (const auto& landmark : msg.landmarks) {
174+
poses.push_back(ros_pose_to_pose(landmark.pose.pose));
175+
}
176+
return poses;
177+
}
178+
162179
} // namespace vortex::utils::ros_conversions
163180

164181
#endif // VORTEX_UTILS__ROS_CONVERSIONS_HPP_

vortex_utils_ros/package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<depend>python3-numpy</depend>
1717
<depend>python3-scipy</depend>
1818
<depend>geometry_msgs</depend>
19+
<depend>vortex_msgs</depend>
1920

2021

2122
<test_depend>ament_cmake_pytest</test_depend>

0 commit comments

Comments
 (0)