Skip to content

Commit 5701c29

Browse files
committed
Reenable Eigen unit tests
1 parent d65b7eb commit 5701c29

File tree

1 file changed

+69
-60
lines changed

1 file changed

+69
-60
lines changed

tf2_eigen/test/tf2_eigen-test.cpp

Lines changed: 69 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -39,72 +39,81 @@
3939
#include <gtest/gtest.h>
4040
#include <tf2/convert.h>
4141

42-
// TODO(clalancette) Re-enable these tests once we have tf2/convert.h:convert(A, B) implemented
43-
// TEST(TfEigen, ConvertVector3dStamped)
44-
// {
45-
// const tf2::Stamped<Eigen::Vector3d> v(Eigen::Vector3d(1,2,3), tf2::TimePoint(std::chrono::seconds(5)), "test");
46-
47-
// tf2::Stamped<Eigen::Vector3d> v1;
48-
// geometry_msgs::msg::PointStamped p1;
49-
// tf2::convert(v, p1);
50-
// tf2::convert(p1, v1);
51-
52-
// EXPECT_EQ(v, v1);
53-
// }
54-
55-
// TEST(TfEigen, ConvertVector3d)
56-
// {
57-
// const Eigen::Vector3d v(1,2,3);
58-
59-
// Eigen::Vector3d v1;
60-
// geometry_msgs::msg::Point p1;
61-
// tf2::convert(v, p1);
62-
// tf2::convert(p1, v1);
63-
64-
// EXPECT_EQ(v, v1);
65-
// }
66-
67-
// TEST(TfEigen, ConvertAffine3dStamped)
68-
// {
69-
// const Eigen::Affine3d v_nonstamped(Eigen::Translation3d(1,2,3) * Eigen::AngleAxis<double>(1, Eigen::Vector3d::UnitX()));
70-
// const tf2::Stamped<Eigen::Affine3d> v(v_nonstamped, tf2::TimePoint(std::chrono::seconds(42)), "test_frame");
71-
72-
// tf2::Stamped<Eigen::Affine3d> v1;
73-
// geometry_msgs::msg::PoseStamped p1;
74-
// tf2::convert(v, p1);
75-
// tf2::convert(p1, v1);
76-
77-
// EXPECT_EQ(v.translation(), v1.translation());
78-
// EXPECT_EQ(v.rotation(), v1.rotation());
79-
// EXPECT_EQ(v.frame_id_, v1.frame_id_);
80-
// EXPECT_EQ(v.stamp_, v1.stamp_);
81-
// }
82-
83-
// TEST(TfEigen, ConvertAffine3d)
84-
// {
85-
// const Eigen::Affine3d v(Eigen::Translation3d(1,2,3) * Eigen::AngleAxis<double>(1, Eigen::Vector3d::UnitX()));
86-
87-
// Eigen::Affine3d v1;
88-
// geometry_msgs::msg::Pose p1;
89-
// tf2::convert(v, p1);
90-
// tf2::convert(p1, v1);
91-
92-
// EXPECT_EQ(v.translation(), v1.translation());
93-
// EXPECT_EQ(v.rotation(), v1.rotation());
94-
// }
42+
TEST(TfEigen, ConvertVector3dStamped)
43+
{
44+
const tf2::Stamped<Eigen::Vector3d> v(Eigen::Vector3d(1, 2, 3), tf2::TimePoint(
45+
std::chrono::seconds(
46+
5)), "test");
47+
48+
tf2::Stamped<Eigen::Vector3d> v1;
49+
geometry_msgs::msg::PointStamped p1;
50+
tf2::convert(v, p1);
51+
tf2::convert(p1, v1);
52+
53+
EXPECT_EQ(v, v1);
54+
}
55+
56+
TEST(TfEigen, ConvertVector3d)
57+
{
58+
const Eigen::Vector3d v(1, 2, 3);
59+
60+
Eigen::Vector3d v1;
61+
geometry_msgs::msg::Point p1;
62+
tf2::convert(v, p1);
63+
tf2::convert(p1, v1);
64+
65+
EXPECT_EQ(v, v1);
66+
}
67+
68+
TEST(TfEigen, ConvertAffine3dStamped)
69+
{
70+
const Eigen::Affine3d v_nonstamped(Eigen::Translation3d(1, 2, 3) * Eigen::AngleAxis<double>(
71+
1,
72+
Eigen::Vector3d::UnitX()));
73+
const tf2::Stamped<Eigen::Affine3d> v(v_nonstamped, tf2::TimePoint(
74+
std::chrono::seconds(
75+
42)), "test_frame");
76+
77+
tf2::Stamped<Eigen::Affine3d> v1;
78+
geometry_msgs::msg::PoseStamped p1;
79+
tf2::convert(v, p1);
80+
tf2::convert(p1, v1);
81+
82+
EXPECT_EQ(v.translation(), v1.translation());
83+
EXPECT_EQ(v.rotation(), v1.rotation());
84+
EXPECT_EQ(v.frame_id_, v1.frame_id_);
85+
EXPECT_EQ(v.stamp_, v1.stamp_);
86+
}
87+
88+
TEST(TfEigen, ConvertAffine3d)
89+
{
90+
const Eigen::Affine3d v(Eigen::Translation3d(1, 2, 3) * Eigen::AngleAxis<double>(
91+
1,
92+
Eigen::Vector3d::UnitX()));
93+
94+
Eigen::Affine3d v1;
95+
geometry_msgs::msg::Pose p1;
96+
tf2::convert(v, p1);
97+
tf2::convert(p1, v1);
98+
99+
EXPECT_EQ(v.translation(), v1.translation());
100+
EXPECT_EQ(v.rotation(), v1.rotation());
101+
}
95102

96103
TEST(TfEigen, ConvertTransform)
97104
{
98105
Eigen::Matrix4d tm;
99106

100-
double alpha = M_PI/4.0;
101-
double theta = M_PI/6.0;
102-
double gamma = M_PI/12.0;
107+
double alpha = M_PI / 4.0;
108+
double theta = M_PI / 6.0;
109+
double gamma = M_PI / 12.0;
103110

104-
tm << cos(theta)*cos(gamma),-cos(theta)*sin(gamma),sin(theta), 1, //
105-
cos(alpha)*sin(gamma)+sin(alpha)*sin(theta)*cos(gamma),cos(alpha)*cos(gamma)-sin(alpha)*sin(theta)*sin(gamma),-sin(alpha)*cos(theta), 2, //
106-
sin(alpha)*sin(gamma)-cos(alpha)*sin(theta)*cos(gamma),cos(alpha)*sin(theta)*sin(gamma)+sin(alpha)*cos(gamma),cos(alpha)*cos(theta), 3, //
107-
0, 0, 0, 1;
111+
tm << cos(theta) * cos(gamma), -cos(theta) * sin(gamma), sin(theta), 1, //
112+
cos(alpha) * sin(gamma) + sin(alpha) * sin(theta) * cos(gamma), cos(alpha) * cos(gamma) - sin(
113+
alpha) * sin(theta) * sin(gamma), -sin(alpha) * cos(theta), 2, //
114+
sin(alpha) * sin(gamma) - cos(alpha) * sin(theta) * cos(gamma), cos(alpha) * sin(theta) * sin(
115+
gamma) + sin(alpha) * cos(gamma), cos(alpha) * cos(theta), 3, //
116+
0, 0, 0, 1;
108117

109118
Eigen::Affine3d T(tm);
110119

0 commit comments

Comments
 (0)