compare_pose.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-2017, the mcl_3dl 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 <cmath>
31 
32 #include <ros/ros.h>
33 
34 #include <nav_msgs/Path.h>
35 #include <geometry_msgs/PoseWithCovarianceStamped.h>
36 #include <tf2/utils.h>
37 
38 #include <gtest/gtest.h>
39 
40 TEST(ComparePose, Compare)
41 {
42  ros::NodeHandle nh("~");
43 
44  nav_msgs::Path path;
45  size_t i_path;
46 
47  double error_limit;
48  nh.param("error_limit", error_limit, 0.3);
49 
50  const boost::function<void(const nav_msgs::Path::ConstPtr&)> cb_path =
51  [&path, &i_path](const nav_msgs::Path::ConstPtr& msg) -> void
52  {
53  path = *msg;
54  i_path = 0;
55  fprintf(stderr, "compare_pose: reference received\n");
56  };
57  const boost::function<void(const geometry_msgs::PoseWithCovarianceStamped::ConstPtr&)> cb_pose =
58  [&path, &i_path, &error_limit](const geometry_msgs::PoseWithCovarianceStamped::ConstPtr& msg) -> void
59  {
60  if (path.poses.size() > 0 && path.poses[i_path].header.stamp < ros::Time::now())
61  {
62  const float x_error = path.poses[i_path].pose.position.x - msg->pose.pose.position.x;
63  const float y_error = path.poses[i_path].pose.position.y - msg->pose.pose.position.y;
64  const float z_error = path.poses[i_path].pose.position.z - msg->pose.pose.position.z;
65  float yaw_error =
66  tf2::getYaw(path.poses[i_path].pose.orientation) - tf2::getYaw(msg->pose.pose.orientation);
67  while (yaw_error > M_PI)
68  yaw_error -= 2 * M_PI;
69  while (yaw_error < -M_PI)
70  yaw_error += 2 * M_PI;
71  const float error = std::sqrt(std::pow(x_error, 2) + std::pow(y_error, 2) + std::pow(z_error, 2));
72  const float x_sigma = std::sqrt(msg->pose.covariance[0 * 6 + 0]);
73  const float y_sigma = std::sqrt(msg->pose.covariance[1 * 6 + 1]);
74  const float z_sigma = std::sqrt(msg->pose.covariance[2 * 6 + 2]);
75  const float yaw_sigma = std::sqrt(msg->pose.covariance[5 * 6 + 5]);
76 
77  fprintf(stderr, "compare_pose[%lu/%lu]:\n",
78  i_path, path.poses.size());
79  fprintf(stderr, " position error/limit=%0.3f/%0.3f\n", error, error_limit);
80  fprintf(stderr, " x error/3sigma=%0.3f/%0.3f\n", x_error, x_sigma * 3.0);
81  fprintf(stderr, " y error/3sigma=%0.3f/%0.3f\n", y_error, y_sigma * 3.0);
82  fprintf(stderr, " z error/3sigma=%0.3f/%0.3f\n", z_error, z_sigma * 3.0);
83  fprintf(stderr, " yaw error/3sigma=%0.3f/%0.3f\n", yaw_error, yaw_sigma * 3.0);
84 
85  i_path++;
86  if (i_path >= path.poses.size())
87  ros::shutdown();
88 
89  ASSERT_FALSE(error > error_limit)
90  << "Position error is larger then expected.";
91  ASSERT_FALSE(fabs(x_error) > x_sigma * 3.0)
92  << "Estimated variance is too small to continue tracking. (x)";
93  ASSERT_FALSE(fabs(y_error) > y_sigma * 3.0)
94  << "Estimated variance is too small to continue tracking. (y)";
95  ASSERT_FALSE(fabs(z_error) > z_sigma * 3.0)
96  << "Estimated variance is too small to continue tracking. (z)";
97  ASSERT_FALSE(fabs(yaw_error) > yaw_sigma * 3.0)
98  << "Estimated variance is too small to continue tracking. (yaw)";
99  }
100  };
101 
102  ros::Subscriber sub_pose = nh.subscribe("/amcl_pose", 1, cb_pose);
103  ros::Subscriber sub_path = nh.subscribe("poses_ref", 1, cb_path);
104 
105  ros::Rate wait(10);
106 
107  while (ros::ok())
108  {
109  ros::spinOnce();
110  wait.sleep();
111  }
112  fprintf(stderr, "compare_pose finished\n");
113 }
114 
115 int main(int argc, char** argv)
116 {
117  testing::InitGoogleTest(&argc, argv);
118  ros::init(argc, argv, "compare_pose");
119 
120  return RUN_ALL_TESTS();
121 }
msg
msg
ros::init
ROSCPP_DECL void init(const M_string &remappings, const std::string &name, uint32_t options=0)
tf2::getYaw
double getYaw(const A &a)
utils.h
ros.h
ros::spinOnce
ROSCPP_DECL void spinOnce()
ros::shutdown
ROSCPP_DECL void shutdown()
wait
void wait(int seconds)
main
int main(int argc, char **argv)
Definition: compare_pose.cpp:115
ros::ok
ROSCPP_DECL bool ok()
ros::NodeHandle::subscribe
Subscriber subscribe(const std::string &topic, uint32_t queue_size, const boost::function< void(C)> &callback, const VoidConstPtr &tracked_object=VoidConstPtr(), const TransportHints &transport_hints=TransportHints())
TEST
TEST(ComparePose, Compare)
Definition: compare_pose.cpp:40
ros::NodeHandle::param
T param(const std::string &param_name, const T &default_val) const
ros::Rate
ros::NodeHandle
ros::Subscriber
ros::Time::now
static Time now()


mcl_3dl
Author(s): Atsushi Watanabe
autogenerated on Thu Oct 17 2024 02:18:04