pr2_chomp_planner_test.cpp
Go to the documentation of this file.
00001 /*********************************************************************
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2012, Willow Garage, Inc.
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 Willow Garage 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 OWNER 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 /* Author: E. Gil Jones */
00036 
00037 #include <gtest/gtest.h>
00038 #include <urdf_parser/urdf_parser.h>
00039 #include <chomp_motion_planner/chomp_planner.h>
00040 #include <chomp_motion_planner/chomp_parameters.h>
00041 #include <moveit_msgs/GetMotionPlan.h>
00042 #include <kinematic_constraints/utils.h>
00043 #include <planning_models/conversions.h>
00044 #include <collision_distance_field/collision_detector_allocator_distance_field.h>
00045 #include <rdf_loader/rdf_loader.h>
00046 
00047 class Pr2ChompPlannerTester : public testing::Test{
00048 
00049 protected:
00050 
00051   virtual void SetUp()
00052   {
00053 
00054     rml_.reset(new rdf_loader::RDFLoader("robot_description"));
00055 
00056     acm_.reset(new collision_detection::AllowedCollisionMatrix());
00057 
00058     ros::NodeHandle nh;
00059 
00060     XmlRpc::XmlRpcValue coll_ops;
00061     nh.getParam("robot_description_planning/default_collision_operations", coll_ops);
00062 
00063     if (coll_ops.getType() != XmlRpc::XmlRpcValue::TypeArray)
00064     {
00065       ROS_WARN("default_collision_operations is not an array");
00066       return;
00067     }
00068 
00069     if (coll_ops.size() == 0)
00070     {
00071       ROS_WARN("No collision operations in default collision operations");
00072       return;
00073     }
00074 
00075     for (int i = 0 ; i < coll_ops.size() ; ++i)
00076     {
00077       if (!coll_ops[i].hasMember("object1") || !coll_ops[i].hasMember("object2") || !coll_ops[i].hasMember("operation"))
00078       {
00079         ROS_WARN("All collision operations must have two objects and an operation");
00080         continue;
00081       }
00082       acm_->setEntry(std::string(coll_ops[i]["object1"]), std::string(coll_ops[i]["object2"]), std::string(coll_ops[i]["operation"]) == "disable");
00083     }
00084   }
00085 
00086   virtual void TearDown()
00087   {
00088 
00089   }
00090 
00091 protected:
00092 
00093   boost::shared_ptr<rdf_loader::RDFLoader> rml_;
00094   collision_detection::AllowedCollisionMatrixPtr acm_;
00095 
00096 };
00097 
00098 TEST_F(Pr2ChompPlannerTester, SimplePlan)
00099 {
00100   planning_scene::PlanningScenePtr ps(new planning_scene::PlanningScene());
00101   ps->setActiveCollisionDetector(collision_detection::CollisionDetectorAllocatorDistanceField::create());
00102   ps->configure(rml_->getURDF(), rml_->getSRDF());
00103   ASSERT_TRUE(ps->isConfigured());
00104   ps->getAllowedCollisionMatrixNonConst() = *acm_;
00105 
00106   chomp::ChompPlanner chomp_planner(ps->getRobotModel());
00107 
00108   moveit_msgs::GetMotionPlan::Request mplan_req;
00109   moveit_msgs::GetMotionPlan::Response mplan_res;
00110   mplan_req.motion_plan_request.group_name = "right_arm";
00111   mplan_req.motion_plan_request.num_planning_attempts = 5;
00112   mplan_req.motion_plan_request.allowed_planning_time = ros::Duration(5.0);
00113   const std::vector<std::string>& joint_names = ps->getRobotModel()->getJointModelGroup("right_arm")->getJointModelNames();
00114   mplan_req.motion_plan_request.goal_constraints.resize(1);
00115   mplan_req.motion_plan_request.goal_constraints[0].joint_constraints.resize(joint_names.size());
00116   for(unsigned int i = 0; i < joint_names.size(); i++)
00117   {
00118     mplan_req.motion_plan_request.goal_constraints[0].joint_constraints[i].joint_name = joint_names[i];
00119     mplan_req.motion_plan_request.goal_constraints[0].joint_constraints[i].position = 0.0;
00120     mplan_req.motion_plan_request.goal_constraints[0].joint_constraints[i].tolerance_above = 0.001;
00121     mplan_req.motion_plan_request.goal_constraints[0].joint_constraints[i].tolerance_below = 0.001;
00122     mplan_req.motion_plan_request.goal_constraints[0].joint_constraints[i].weight = 1.0;
00123   }
00124   mplan_req.motion_plan_request.goal_constraints[0].joint_constraints[0].position = -2.0;
00125   mplan_req.motion_plan_request.goal_constraints[0].joint_constraints[3].position = -.2;
00126   mplan_req.motion_plan_request.goal_constraints[0].joint_constraints[5].position = -.2;
00127 
00128   chomp::ChompParameters params;
00129   chomp_planner.solve(ps,
00130                       mplan_req,
00131                       params,
00132                       mplan_res);
00133 
00134   ASSERT_EQ(mplan_res.error_code.val, mplan_res.error_code.SUCCESS);
00135   EXPECT_GT(mplan_res.trajectory.joint_trajectory.points.size(), 0);
00136 }
00137 
00138 int main(int argc, char **argv)
00139 {
00140   testing::InitGoogleTest(&argc, argv);
00141   ros::init(argc, argv, "test_chomp_planning");
00142 
00143   return RUN_ALL_TESTS();
00144 }


pr2_test_chomp_planner
Author(s): E. Gil Jones
autogenerated on Mon Sep 14 2015 14:18:22