test_tf_projection_node.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2019, the neonavigation authors
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the copyright holder nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
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 }


track_odometry
Author(s): Atsushi Watanabe
autogenerated on Sat Jun 22 2019 20:07:23