trajectory_tests.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2014-2015, Fetch Robotics Inc.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the Fetch Robotics Inc. nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  * 
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL FETCH ROBOTICS INC. BE LIABLE FOR ANY
00021  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00022  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00023  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00024  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00029 // Author: Michael Ferguson
00030 
00031 #include <gtest/gtest.h>
00032 #include <robot_controllers/trajectory.h>
00033 
00034 TEST(TrajectoryTests, test_unwind)
00035 {
00036   robot_controllers::Trajectory t;
00037   t.points.resize(3);
00038   t.points[0].q.resize(3);
00039   t.points[0].q[0] = 3.0;
00040   t.points[0].q[1] = -3.0;
00041   t.points[0].q[2] = -3.0;
00042   t.points[1].q.resize(3);
00043   t.points[1].q[0] = -3.0;
00044   t.points[1].q[1] = 3.0;
00045   t.points[1].q[2] = 3.0;
00046   t.points[2].q.resize(3);
00047   t.points[2].q[0] = 3.0;
00048   t.points[2].q[1] = -3.0;
00049   t.points[2].q[2] = -3.0;
00050 
00051   std::vector<bool> continuous(3, false);
00052   continuous[0] = true;
00053   continuous[1] = true;
00054 
00055   // Test windup
00056   EXPECT_TRUE(windupTrajectory(continuous, t));
00057   // First joint should be wound up
00058   EXPECT_EQ(3.0, t.points[0].q[0]);
00059   EXPECT_EQ(3.2831853071795862, t.points[1].q[0]);
00060   EXPECT_EQ(3.0, t.points[2].q[0]);
00061   // Second joint should be wound up
00062   EXPECT_EQ(-3.0, t.points[0].q[1]);
00063   EXPECT_EQ(-3.2831853071795862, t.points[1].q[1]);
00064   EXPECT_EQ(-3.0, t.points[2].q[1]);
00065   // Third joint should be unmodified
00066   EXPECT_EQ(-3.0, t.points[0].q[2]);
00067   EXPECT_EQ(3.0, t.points[1].q[2]);
00068   EXPECT_EQ(-3.0, t.points[2].q[2]);
00069 
00070   // Test unwind
00071   EXPECT_TRUE(unwindTrajectoryPoint(continuous, t.points[0]));
00072   EXPECT_EQ(3.0,  t.points[0].q[0]);
00073   EXPECT_EQ(-3.0, t.points[0].q[1]);
00074   EXPECT_EQ(-3.0,  t.points[0].q[2]);
00075   EXPECT_TRUE(unwindTrajectoryPoint(continuous, t.points[1]));
00076   EXPECT_EQ(-3.0, t.points[1].q[0]);
00077   EXPECT_EQ(3.0,  t.points[1].q[1]);
00078   EXPECT_EQ(3.0, t.points[1].q[2]);
00079   EXPECT_TRUE(unwindTrajectoryPoint(continuous, t.points[2]));
00080   EXPECT_EQ(3.0,  t.points[2].q[0]);
00081   EXPECT_EQ(-3.0,  t.points[2].q[1]);
00082   EXPECT_EQ(-3.0, t.points[2].q[2]);
00083 
00084 
00085   // Make sure we catch mis-sized vectors
00086   t.points[1].q.resize(2);
00087   EXPECT_FALSE(windupTrajectory(continuous, t));
00088 
00089   continuous.resize(4);
00090   t.points[1].q.resize(3);
00091   EXPECT_FALSE(windupTrajectory(continuous, t));
00092 }
00093 
00094 TEST(TrajectoryTests, test_multiple_unwinds)
00095 {
00096   robot_controllers::Trajectory t;
00097   t.points.resize(10);
00098   t.points[0].q.push_back(-3.0);
00099   t.points[1].q.push_back(3.0);
00100   t.points[2].q.push_back(1.0);
00101   t.points[3].q.push_back(-1.0);
00102   t.points[4].q.push_back(-3.0);
00103   t.points[5].q.push_back(3.0);
00104   t.points[6].q.push_back(1.0);
00105   t.points[7].q.push_back(-1.0);
00106   t.points[8].q.push_back(-3.0);
00107   t.points[9].q.push_back(3.0);
00108 
00109   std::vector<bool> continuous(1, true);
00110 
00111   // Test unwind
00112   EXPECT_TRUE(windupTrajectory(continuous, t));
00113   // First joint should be unwound
00114   EXPECT_EQ(-3.0, t.points[0].q[0]);
00115   EXPECT_EQ(-3.2831853071795862, t.points[1].q[0]);
00116   EXPECT_EQ(-5.2831853071795862, t.points[2].q[0]);
00117   EXPECT_EQ(-7.2831853071795862, t.points[3].q[0]);
00118   EXPECT_EQ(-9.2831853071795862, t.points[4].q[0]);
00119   EXPECT_EQ(-9.566370614359172, t.points[5].q[0]);
00120   EXPECT_EQ(-11.566370614359172, t.points[6].q[0]);
00121   EXPECT_EQ(-13.566370614359172, t.points[7].q[0]);
00122   EXPECT_EQ(-15.566370614359172, t.points[8].q[0]);
00123   EXPECT_EQ(-15.849555921538759, t.points[9].q[0]);
00124 }
00125 
00126 // Run all the tests that were declared with TEST()
00127 int main(int argc, char **argv)
00128 {
00129   testing::InitGoogleTest(&argc, argv);
00130   return RUN_ALL_TESTS();
00131 }


robot_controllers
Author(s): Michael Ferguson
autogenerated on Wed Jun 14 2017 04:09:10