34 #include <nav_msgs/Path.h>
35 #include <geometry_msgs/PoseWithCovarianceStamped.h>
38 #include <gtest/gtest.h>
48 nh.
param(
"error_limit", error_limit, 0.3);
50 const boost::function<void(
const nav_msgs::Path::ConstPtr&)> cb_path =
51 [&path, &i_path](
const nav_msgs::Path::ConstPtr&
msg) ->
void
55 fprintf(stderr,
"compare_pose: reference received\n");
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
60 if (path.poses.size() > 0 && path.poses[i_path].header.stamp <
ros::Time::now())
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;
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]);
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);
86 if (i_path >= path.poses.size())
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)";
112 fprintf(stderr,
"compare_pose finished\n");
115 int main(
int argc,
char** argv)
117 testing::InitGoogleTest(&argc, argv);
120 return RUN_ALL_TESTS();