Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include <string>
00031
00032 #include <ros/ros.h>
00033 #include <geometry_msgs/TransformStamped.h>
00034 #include <tf2_ros/buffer.h>
00035 #include <tf2_ros/transform_listener.h>
00036
00037 #include <gtest/gtest.h>
00038
00039 class TfProjectionTest : public ::testing::TestWithParam<const char*>
00040 {
00041 public:
00042 tf2_ros::Buffer tfbuf_;
00043 tf2_ros::TransformListener tfl_;
00044
00045 std::string projected_frame_;
00046
00047 TfProjectionTest()
00048 : tfl_(tfbuf_)
00049 {
00050 }
00051 void SetUp() override
00052 {
00053 projected_frame_ = std::string(GetParam());
00054 }
00055 };
00056
00057 TEST_P(TfProjectionTest, ProjectionTransform)
00058 {
00059 EXPECT_TRUE(tfbuf_.canTransform("map", projected_frame_, ros::Time(0), ros::Duration(1.0)));
00060
00061 geometry_msgs::TransformStamped out;
00062 try
00063 {
00064 out = tfbuf_.lookupTransform("map", projected_frame_, ros::Time(0), ros::Duration(1.0));
00065 }
00066 catch (tf2::TransformException& e)
00067 {
00068 FAIL() << e.what();
00069 }
00070 ASSERT_EQ(out.transform.translation.x, 1);
00071 ASSERT_EQ(out.transform.translation.y, 2);
00072 ASSERT_EQ(out.transform.translation.z, 0);
00073 ASSERT_NEAR(out.transform.rotation.x, 0, 1e-4);
00074 ASSERT_NEAR(out.transform.rotation.y, 0, 1e-4);
00075 ASSERT_NEAR(out.transform.rotation.z, 0.7071, 1e-4);
00076 ASSERT_NEAR(out.transform.rotation.w, 0.7071, 1e-4);
00077 ASSERT_EQ(out.header.frame_id, "map");
00078 ASSERT_EQ(out.child_frame_id, projected_frame_);
00079 }
00080
00081 INSTANTIATE_TEST_CASE_P(
00082 ProjectionTransformInstance, TfProjectionTest,
00083 ::testing::Values(
00084 "base_link_projected",
00085 "base_link_projected2",
00086 "base_link_tilt_projected"));
00087
00088 int main(int argc, char** argv)
00089 {
00090 testing::InitGoogleTest(&argc, argv);
00091 ros::init(argc, argv, "test_tf_projection_node");
00092
00093 return RUN_ALL_TESTS();
00094 }