test_trajectory_recorder.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018, the neonavigation authors
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the copyright holder nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include <ros/ros.h>
33 #include <nav_msgs/Path.h>
34 
35 #include <algorithm>
36 #include <string>
37 
38 #include <gtest/gtest.h>
39 
40 TEST(TrajectoryRecorder, TfToPath)
41 {
42  ros::NodeHandle nh("");
43 
44  nav_msgs::Path::ConstPtr path;
45  const boost::function<void(const nav_msgs::Path::ConstPtr&)> cb_path =
46  [&path](const nav_msgs::Path::ConstPtr& msg) -> void
47  {
48  path = msg;
49  };
50  ros::Subscriber sub_path = nh.subscribe("path", 1, cb_path);
52 
53  const tf2::Transform points[] =
54  {
55  tf2::Transform(tf2::Quaternion(0, 0, 0, 1), tf2::Vector3(0, 0, 0)),
56  tf2::Transform(tf2::Quaternion(0, 0, 1, 0), tf2::Vector3(2, 0, 0)),
57  tf2::Transform(tf2::Quaternion(0, 0, 0, -1), tf2::Vector3(3, 5, 0)),
58  tf2::Transform(tf2::Quaternion(0, 0, -1, 0), tf2::Vector3(-1, 5, 1))
59  };
60  const size_t len = sizeof(points) / sizeof(tf2::Transform);
61 
62  ros::Duration(1.0).sleep();
63  for (auto& p : points)
64  {
65  for (size_t i = 0; i < 3; ++i)
66  {
67  geometry_msgs::TransformStamped trans =
69  p, ros::Time::now() + ros::Duration(0.1), "map"));
70  trans.child_frame_id = "base_link";
71  tfb.sendTransform(trans);
72  ros::Duration(0.1).sleep();
73  }
74  }
75  ros::spinOnce();
76  ASSERT_TRUE(static_cast<bool>(path));
77  sub_path.shutdown();
78 
79  ASSERT_EQ(path->poses.size(), len);
80  for (size_t i = 0; i < len; ++i)
81  {
82  ASSERT_EQ(path->poses[i].pose.position.x, points[i].getOrigin().x());
83  ASSERT_EQ(path->poses[i].pose.position.y, points[i].getOrigin().y());
84  ASSERT_EQ(path->poses[i].pose.position.z, points[i].getOrigin().z());
85  ASSERT_EQ(path->poses[i].pose.orientation.x, points[i].getRotation().x());
86  ASSERT_EQ(path->poses[i].pose.orientation.y, points[i].getRotation().y());
87  ASSERT_EQ(path->poses[i].pose.orientation.z, points[i].getRotation().z());
88  ASSERT_EQ(path->poses[i].pose.orientation.w, points[i].getRotation().w());
89  }
90 }
91 
92 int main(int argc, char** argv)
93 {
94  testing::InitGoogleTest(&argc, argv);
95  ros::init(argc, argv, "test_trajectory_recorder");
96 
97  return RUN_ALL_TESTS();
98 }
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
bool sleep() const
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void sendTransform(const geometry_msgs::TransformStamped &transform)
B toMsg(const A &a)
int main(int argc, char **argv)
static Time now()
ROSCPP_DECL void spinOnce()
TEST(TrajectoryRecorder, TfToPath)


trajectory_tracker
Author(s): Atsushi Watanabe
autogenerated on Tue Jul 9 2019 05:00:09