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
00031
00032
00033
00034
00035 #include <gtest/gtest.h>
00036 #include <dwb_local_planner/trajectory_utils.h>
00037
00038 using dwb_local_planner::getClosestPose;
00039 using dwb_local_planner::projectPose;
00040
00041 TEST(Utils, ClosestPose)
00042 {
00043 dwb_msgs::Trajectory2D traj;
00044 traj.poses.resize(4);
00045 traj.time_offsets.resize(4);
00046 for (unsigned int i=0; i < traj.poses.size(); i++)
00047 {
00048 double d = static_cast<double>(i);
00049 traj.poses[i].x = d;
00050 traj.time_offsets[i] = ros::Duration(d);
00051 }
00052
00053 EXPECT_DOUBLE_EQ(getClosestPose(traj, 0.0).x, traj.poses[0].x);
00054 EXPECT_DOUBLE_EQ(getClosestPose(traj, -1.0).x, traj.poses[0].x);
00055 EXPECT_DOUBLE_EQ(getClosestPose(traj, 0.4).x, traj.poses[0].x);
00056 EXPECT_DOUBLE_EQ(getClosestPose(traj, 0.5).x, traj.poses[0].x);
00057 EXPECT_DOUBLE_EQ(getClosestPose(traj, 0.51).x, traj.poses[1].x);
00058 EXPECT_DOUBLE_EQ(getClosestPose(traj, 1.0).x, traj.poses[1].x);
00059 EXPECT_DOUBLE_EQ(getClosestPose(traj, 1.4999).x, traj.poses[1].x);
00060 EXPECT_DOUBLE_EQ(getClosestPose(traj, 2.0).x, traj.poses[2].x);
00061 EXPECT_DOUBLE_EQ(getClosestPose(traj, 2.51).x, traj.poses[3].x);
00062 EXPECT_DOUBLE_EQ(getClosestPose(traj, 3.5).x, traj.poses[3].x);
00063 }
00064
00065 TEST(Utils, ProjectPose)
00066 {
00067 dwb_msgs::Trajectory2D traj;
00068 traj.poses.resize(4);
00069 traj.time_offsets.resize(4);
00070 for (unsigned int i=0; i < traj.poses.size(); i++)
00071 {
00072 double d = static_cast<double>(i);
00073 traj.poses[i].x = d;
00074 traj.poses[i].y = 30.0 - 2.0 * d;
00075 traj.poses[i].theta = 0.42;
00076 traj.time_offsets[i] = ros::Duration(d);
00077 }
00078
00079 EXPECT_DOUBLE_EQ(projectPose(traj, 0.0).x, 0.0);
00080 EXPECT_DOUBLE_EQ(projectPose(traj, 0.0).y, 30.0);
00081 EXPECT_DOUBLE_EQ(projectPose(traj, 0.0).theta, 0.42);
00082 EXPECT_DOUBLE_EQ(projectPose(traj, -1.0).x, 0.0);
00083 EXPECT_DOUBLE_EQ(projectPose(traj, -1.0).y, 30.0);
00084 EXPECT_DOUBLE_EQ(projectPose(traj, -1.0).theta, 0.42);
00085 EXPECT_DOUBLE_EQ(projectPose(traj, 0.4).x, 0.4);
00086 EXPECT_DOUBLE_EQ(projectPose(traj, 0.4).y, 29.2);
00087 EXPECT_DOUBLE_EQ(projectPose(traj, 0.4).theta, 0.42);
00088 EXPECT_DOUBLE_EQ(projectPose(traj, 0.5).x, 0.5);
00089 EXPECT_DOUBLE_EQ(projectPose(traj, 0.5).y, 29.0);
00090 EXPECT_DOUBLE_EQ(projectPose(traj, 0.5).theta, 0.42);
00091 EXPECT_DOUBLE_EQ(projectPose(traj, 0.51).x, 0.51);
00092 EXPECT_DOUBLE_EQ(projectPose(traj, 0.51).y, 28.98);
00093 EXPECT_DOUBLE_EQ(projectPose(traj, 0.51).theta, 0.42);
00094 EXPECT_DOUBLE_EQ(projectPose(traj, 1.0).x, 1.0);
00095 EXPECT_DOUBLE_EQ(projectPose(traj, 1.0).y, 28.0);
00096 EXPECT_DOUBLE_EQ(projectPose(traj, 1.0).theta, 0.42);
00097 EXPECT_DOUBLE_EQ(projectPose(traj, 1.4999).x, 1.4999);
00098 EXPECT_DOUBLE_EQ(projectPose(traj, 1.4999).y, 27.0002);
00099 EXPECT_DOUBLE_EQ(projectPose(traj, 1.4999).theta, 0.42);
00100 EXPECT_DOUBLE_EQ(projectPose(traj, 2.0).x, 2.0);
00101 EXPECT_DOUBLE_EQ(projectPose(traj, 2.0).y, 26.0);
00102 EXPECT_DOUBLE_EQ(projectPose(traj, 2.0).theta, 0.42);
00103 EXPECT_FLOAT_EQ(projectPose(traj, 2.51).x, 2.51);
00104 EXPECT_FLOAT_EQ(projectPose(traj, 2.51).y, 24.98);
00105 EXPECT_DOUBLE_EQ(projectPose(traj, 2.51).theta, 0.42);
00106 EXPECT_DOUBLE_EQ(projectPose(traj, 3.5).x, 3.0);
00107 EXPECT_DOUBLE_EQ(projectPose(traj, 3.5).y, 24.0);
00108 EXPECT_DOUBLE_EQ(projectPose(traj, 3.5).theta, 0.42);
00109 }
00110
00111 int main(int argc, char **argv)
00112 {
00113 testing::InitGoogleTest(&argc, argv);
00114 return RUN_ALL_TESTS();
00115 }