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


dwb_local_planner
Author(s): David V. Lu!!
autogenerated on Wed Jun 26 2019 20:09:38