robot_model_test.hpp
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (Apache License)
00003  *
00004  * Copyright (c) 2014, Southwest Research Institute
00005  *
00006  * Licensed under the Apache License, Version 2.0 (the "License");
00007  * you may not use this file except in compliance with the License.
00008  * You may obtain a copy of the License at
00009  *
00010  * http://www.apache.org/licenses/LICENSE-2.0
00011  *
00012  * Unless required by applicable law or agreed to in writing, software
00013  * distributed under the License is distributed on an "AS IS" BASIS,
00014  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015  * See the License for the specific language governing permissions and
00016  * limitations under the License.
00017  */
00018 
00019 #ifndef ROBOT_MODEL_TEST_HPP_
00020 #define ROBOT_MODEL_TEST_HPP_
00021 
00022 #include "descartes_core/pretty_print.hpp"
00023 #include "descartes_core/robot_model.h"
00024 #include "ros/console.h"
00025 #include <gtest/gtest.h>
00026 
00036 namespace descartes_trajectory_test
00037 {
00038 template <class T>
00039 descartes_core::RobotModelPtr CreateRobotModel();
00040 
00041 template <class T>
00042 class RobotModelTest : public ::testing::Test
00043 {
00044 public:
00045   RobotModelTest() : model_(CreateRobotModel<T>())
00046   {
00047     ROS_INFO("Instantiated RobotModelTest fixture(base) (parameterized)");
00048   }
00049 
00050   virtual void SetUp()
00051   {
00052     ROS_INFO("Setting up RobotModelTest fixture(base) (parameterized)");
00053     ASSERT_TRUE(static_cast<bool>(this->model_));
00054   }
00055 
00056   virtual void TearDown()
00057   {
00058     ROS_INFO("Tearing down RobotModelTest fixture(base) (parameterized)");
00059   }
00060 
00061   virtual ~RobotModelTest()
00062   {
00063     ROS_INFO("Desctructing RobotModelTest fixture(base) (parameterized)");
00064   }
00065 
00066   descartes_core::RobotModelPtr model_;
00067 };
00068 
00069 using namespace descartes_core;
00070 
00071 TYPED_TEST_CASE_P(RobotModelTest);
00072 
00073 const double TF_EQ_TOL = 0.001;
00074 const double JOINT_EQ_TOL = 0.001;
00075 
00076 TYPED_TEST_P(RobotModelTest, construction)
00077 {
00078   ROS_INFO_STREAM("Robot model test construction");
00079 }
00080 
00081 TYPED_TEST_P(RobotModelTest, getIK)
00082 {
00083   ROS_INFO_STREAM("Testing getIK");
00084   std::vector<double> fk_joint(6, 0.0);
00085   std::vector<double> ik_joint;
00086   Eigen::Affine3d ik_pose, fk_pose;
00087   EXPECT_TRUE(this->model_->getFK(fk_joint, ik_pose));
00088   EXPECT_TRUE(this->model_->getIK(ik_pose, fk_joint, ik_joint));
00089   // This doesn't always work, but it should.  The IKFast solution doesn't
00090   // return the "closets" solution.  Numeric IK does appear to do this.
00091   EXPECT_TRUE(this->model_->getFK(ik_joint, fk_pose));
00092   EXPECT_TRUE(ik_pose.matrix().isApprox(fk_pose.matrix(), TF_EQ_TOL));
00093   ROS_INFO_STREAM("getIK Test completed");
00094 }
00095 
00096 TYPED_TEST_P(RobotModelTest, getAllIK)
00097 {
00098   ROS_INFO_STREAM("Testing getAllIK");
00099   std::vector<double> fk_joint(6, 0.5);
00100   std::vector<std::vector<double> > joint_poses;
00101   Eigen::Affine3d ik_pose, fk_pose;
00102 
00103   EXPECT_TRUE(this->model_->getFK(fk_joint, ik_pose));
00104   EXPECT_TRUE(this->model_->getAllIK(ik_pose, joint_poses));
00105   ROS_INFO_STREAM("Get all IK returned " << joint_poses.size() << " solutions");
00106   std::vector<std::vector<double> >::iterator it;
00107   for (it = joint_poses.begin(); it != joint_poses.end(); ++it)
00108   {
00109     ROS_INFO_STREAM("GetIK joint solution: " << *it);
00110     EXPECT_TRUE(this->model_->getFK(*it, fk_pose));
00111     EXPECT_TRUE(ik_pose.matrix().isApprox(fk_pose.matrix(), TF_EQ_TOL));
00112   }
00113 }
00114 
00115 REGISTER_TYPED_TEST_CASE_P(RobotModelTest, construction, getIK, getAllIK);
00116 
00117 }  // descartes_trajectory_test
00118 
00119 #endif  // ROBOT_MODEL_TEST_HPP_


descartes_trajectory
Author(s): Jorge Nicho
autogenerated on Thu Jun 6 2019 21:36:04