|
35 | 35 | #endif |
36 | 36 |
|
37 | 37 | #include <gtest/gtest.h> |
| 38 | +#include <geometry_msgs/msg/point.hpp> |
| 39 | +#include <geometry_msgs/msg/point_stamped.hpp> |
| 40 | +#include <geometry_msgs/msg/pose.hpp> |
| 41 | +#include <geometry_msgs/msg/pose_stamped.hpp> |
| 42 | +#include <geometry_msgs/msg/transform_stamped.hpp> |
38 | 43 | #include <rclcpp/clock.hpp> |
39 | 44 | #include <tf2/convert.h> |
| 45 | +#include <tf2/transform_datatypes.h> |
40 | 46 | #include <tf2_eigen/tf2_eigen.hpp> |
41 | 47 | #include <tf2_ros/buffer.h> |
42 | 48 | #include <tf2_ros/transform_listener.h> |
43 | 49 |
|
| 50 | +#include <Eigen/Geometry> |
| 51 | + |
44 | 52 | #include <cmath> |
45 | 53 | #include <memory> |
46 | 54 |
|
47 | | -// TODO(clalancette) Re-enable these tests once we have tf2/convert.h:convert(A, B) implemented |
48 | | -// TEST(TfEigen, ConvertVector3dStamped) |
49 | | -// { |
50 | | -// const tf2::Stamped<Eigen::Vector3d> v(Eigen::Vector3d(1,2,3), |
51 | | -// tf2::TimePoint(std::chrono::seconds(5)), "test"); |
| 55 | +TEST(TfEigen, ConvertVector3dStamped) |
| 56 | +{ |
| 57 | + const tf2::Stamped<Eigen::Vector3d> v(Eigen::Vector3d(1, 2, 3), tf2::TimePoint( |
| 58 | + std::chrono::seconds(5)), "test"); |
52 | 59 |
|
53 | | -// tf2::Stamped<Eigen::Vector3d> v1; |
54 | | -// geometry_msgs::msg::PointStamped p1; |
55 | | -// tf2::convert(v, p1); |
56 | | -// tf2::convert(p1, v1); |
| 60 | + tf2::Stamped<Eigen::Vector3d> v1; |
| 61 | + geometry_msgs::msg::PointStamped p1; |
| 62 | + tf2::convert(v, p1); |
| 63 | + tf2::convert(p1, v1); |
57 | 64 |
|
58 | | -// EXPECT_EQ(v, v1); |
59 | | -// } |
| 65 | + EXPECT_EQ(v, v1); |
| 66 | +} |
60 | 67 |
|
| 68 | +// TODO(clalancette) Re-enable these tests once we have tf2/convert.h:convert(A, B) implemented |
61 | 69 | // TEST(TfEigen, ConvertVector3d) |
62 | 70 | // { |
63 | 71 | // const Eigen::Vector3d v(1,2,3); |
|
70 | 78 | // EXPECT_EQ(v, v1); |
71 | 79 | // } |
72 | 80 |
|
73 | | -// TEST(TfEigen, ConvertAffine3dStamped) |
74 | | -// { |
75 | | -// const Eigen::Affine3d v_nonstamped( |
76 | | -// Eigen::Translation3d(1,2,3) * Eigen::AngleAxis<double>(1, Eigen::Vector3d::UnitX())); |
77 | | -// const tf2::Stamped<Eigen::Affine3d> v( |
78 | | -// v_nonstamped, tf2::TimePoint(std::chrono::seconds(42)), "test_frame"); |
79 | | - |
80 | | -// tf2::Stamped<Eigen::Affine3d> v1; |
81 | | -// geometry_msgs::msg::PoseStamped p1; |
82 | | -// tf2::convert(v, p1); |
83 | | -// tf2::convert(p1, v1); |
84 | | - |
85 | | -// EXPECT_EQ(v.translation(), v1.translation()); |
86 | | -// EXPECT_EQ(v.rotation(), v1.rotation()); |
87 | | -// EXPECT_EQ(v.frame_id_, v1.frame_id_); |
88 | | -// EXPECT_EQ(v.stamp_, v1.stamp_); |
89 | | -// } |
| 81 | +TEST(TfEigen, ConvertAffine3dStamped) |
| 82 | +{ |
| 83 | + const Eigen::Affine3d v_nonstamped(Eigen::Translation3d(1, 2, 3) * Eigen::AngleAxis<double>( |
| 84 | + 1, Eigen::Vector3d::UnitX())); |
| 85 | + const tf2::Stamped<Eigen::Affine3d> v(v_nonstamped, tf2::TimePoint( |
| 86 | + std::chrono::seconds(42)), "test_frame"); |
| 87 | + |
| 88 | + tf2::Stamped<Eigen::Affine3d> v1; |
| 89 | + geometry_msgs::msg::PoseStamped p1; |
| 90 | + tf2::convert(v, p1); |
| 91 | + tf2::convert(p1, v1); |
| 92 | + |
| 93 | + EXPECT_EQ(v.translation(), v1.translation()); |
| 94 | + EXPECT_EQ(v.rotation(), v1.rotation()); |
| 95 | + EXPECT_EQ(v.frame_id_, v1.frame_id_); |
| 96 | + EXPECT_EQ(v.stamp_, v1.stamp_); |
| 97 | +} |
90 | 98 |
|
| 99 | +// TODO(clalancette) Re-enable these tests once we have tf2/convert.h:convert(A, B) implemented |
91 | 100 | // TEST(TfEigen, ConvertAffine3d) |
92 | 101 | // { |
93 | 102 | // const Eigen::Affine3d v( |
|
0 commit comments