11/*
2- * Copyright (c) Koji Terada
3- * All rights reserved.
2+ * Copyright (c) Koji Terada. All rights reserved.
43 *
54 * Redistribution and use in source and binary forms, with or without
65 * modification, are permitted provided that the following conditions are met:
3433
3534// To get M_PI, especially on Windows.
3635#include < math.h>
37- #include < memory>
3836
3937#include < tf2_eigen/tf2_eigen.h>
4038#include < gtest/gtest.h>
4139#include < rclcpp/clock.hpp>
4240#include < tf2_ros/transform_listener.h>
4341#include < tf2_ros/buffer.h>
4442#include < tf2/convert.h>
43+
44+
4545#include < geometry_msgs/msg/vector3_stamped.hpp>
4646#include < geometry_msgs/msg/quaternion_stamped.hpp>
4747
48+ #include < memory>
49+
50+
4851TEST (TfEigen, ConvertVector3dStamped)
4952{
50- const tf2::Stamped<Eigen::Vector3d> v (Eigen::Vector3d (1 ,2 ,3 ), tf2::TimePoint (std::chrono::seconds (5 )), " test" );
53+ const tf2::Stamped<Eigen::Vector3d> v (Eigen::Vector3d (1 , 2 , 3 ), tf2::TimePoint (
54+ std::chrono::seconds (
55+ 5 )), " test" );
5156
5257 tf2::Stamped<Eigen::Vector3d> v1;
5358 geometry_msgs::msg::PointStamped p1;
@@ -59,7 +64,7 @@ TEST(TfEigen, ConvertVector3dStamped)
5964
6065TEST (TfEigen, ConvertVector3d)
6166{
62- const Eigen::Vector3d v (1 ,2 , 3 );
67+ const Eigen::Vector3d v (1 , 2 , 3 );
6368
6469 Eigen::Vector3d v1;
6570 geometry_msgs::msg::Point p1;
@@ -71,8 +76,12 @@ TEST(TfEigen, ConvertVector3d)
7176
7277TEST (TfEigen, ConvertAffine3dStamped)
7378{
74- const Eigen::Affine3d v_nonstamped (Eigen::Translation3d (1 ,2 ,3 ) * Eigen::AngleAxis<double >(1 , Eigen::Vector3d::UnitX ()));
75- const tf2::Stamped<Eigen::Affine3d> v (v_nonstamped, tf2::TimePoint (std::chrono::seconds (42 )), " test_frame" );
79+ const Eigen::Affine3d v_nonstamped (Eigen::Translation3d (1 , 2 , 3 ) * Eigen::AngleAxis<double >(
80+ 1 ,
81+ Eigen::Vector3d::UnitX ()));
82+ const tf2::Stamped<Eigen::Affine3d> v (v_nonstamped, tf2::TimePoint (
83+ std::chrono::seconds (
84+ 42 )), " test_frame" );
7685
7786 tf2::Stamped<Eigen::Affine3d> v1;
7887 geometry_msgs::msg::PoseStamped p1;
@@ -87,7 +96,9 @@ TEST(TfEigen, ConvertAffine3dStamped)
8796
8897TEST (TfEigen, ConvertAffine3d)
8998{
90- const Eigen::Affine3d v (Eigen::Translation3d (1 ,2 ,3 ) * Eigen::AngleAxis<double >(1 , Eigen::Vector3d::UnitX ()));
99+ const Eigen::Affine3d v (Eigen::Translation3d (1 , 2 , 3 ) * Eigen::AngleAxis<double >(
100+ 1 ,
101+ Eigen::Vector3d::UnitX ()));
91102
92103 Eigen::Affine3d v1;
93104 geometry_msgs::msg::Pose p1;
@@ -102,14 +113,20 @@ TEST(TfEigen, ConvertTransform)
102113{
103114 Eigen::Matrix4d tm;
104115
105- double alpha = M_PI/4.0 ;
106- double theta = M_PI/6.0 ;
107- double gamma = M_PI/12.0 ;
108-
109- tm << cos (theta)*cos (gamma),-cos (theta)*sin (gamma),sin (theta), 1 , //
110- 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 , //
111- 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 , //
112- 0 , 0 , 0 , 1 ;
116+ double alpha = M_PI / 4.0 ;
117+ double theta = M_PI / 6.0 ;
118+ double gamma = M_PI / 12.0 ;
119+
120+ tm << cos (theta) * cos (gamma), -cos (theta) * sin (gamma), sin (theta), 1 , //
121+ //
122+ cos (alpha) * sin (gamma) + sin (alpha) * sin (theta) * cos (gamma), //
123+ cos (alpha) * cos (gamma) - sin (alpha) * sin (theta) * sin (gamma), //
124+ -sin (alpha) * cos (theta), 2 , //
125+ //
126+ sin (alpha) * sin (gamma) - cos (alpha) * sin (theta) * cos (gamma), //
127+ cos (alpha) * sin (theta) * sin (gamma) + sin (alpha) * cos (gamma), //
128+ cos (alpha) * cos (theta), 3 , //
129+ 0 , 0 , 0 , 1 ;
113130
114131 Eigen::Affine3d T (tm);
115132
@@ -251,24 +268,26 @@ TEST_F(EigenBufferTransform, Vector)
251268
252269TEST_F (EigenBufferTransform, Quaternion)
253270{
254- using namespace Eigen ;
255271 // rotated by -90° around y
256272 // 0, 0, -1
257273 // 0, 1, 0,
258274 // 1, 0, 0
259- const tf2::Stamped<Quaterniond> q1 {{Quaterniond (AngleAxisd (-0.5 * M_PI, Vector3d::UnitY ()))},
275+ const tf2::Stamped<Eigen::Quaterniond> q1 {{Eigen::Quaterniond (
276+ Eigen::AngleAxisd (
277+ -0.5 * M_PI,
278+ Eigen::Vector3d::UnitY ()))},
260279 tf2::toMsg (tf2::timeFromSec (2 )), " A" };
261280
262281 // simple api
263- const tf2::Stamped<Quaterniond> q_simple =
282+ const tf2::Stamped<Eigen:: Quaterniond> q_simple =
264283 tf_buffer->transform (q1, " B" , tf2::durationFromSec (2.0 ));
265284 EXPECT_NEAR (q_simple.x (), 0.707107 , EPS);
266285 EXPECT_NEAR (q_simple.y (), 0 , EPS);
267286 EXPECT_NEAR (q_simple.z (), -0.707107 , EPS);
268287 EXPECT_NEAR (q_simple.w (), 0 , EPS);
269288
270289 // advanced api
271- const tf2::Stamped<Quaterniond> q_advanced = tf_buffer->transform (
290+ const tf2::Stamped<Eigen:: Quaterniond> q_advanced = tf_buffer->transform (
272291 q1, " B" , tf2::timeFromSec (2.0 ),
273292 " A" , tf2::durationFromSec (3.0 ));
274293 EXPECT_NEAR (q_advanced.x (), 0.707107 , EPS);
0 commit comments