pr2_low_spheres_speed_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 <planning_models/robot_model.h>
00038 #include <planning_models/kinematic_state.h>
00039 #include <gtest/gtest.h>
00040 #include <sstream>
00041 #include <algorithm>
00042 #include <ctype.h>
00043 #include <planning_models/robot_model.h>
00044 #include <planning_models/kinematic_state.h>
00045 #include <planning_models/transforms.h>
00046 #include <geometric_shapes/shape_operations.h>
00047 #include <collision_distance_field/collision_distance_field_types.h>
00048 #include <collision_distance_field/collision_robot_distance_field.h>
00049 #include <collision_distance_field/collision_world_distance_field.h>
00050 #include <collision_distance_field_ros/collision_distance_field_ros_helpers.h>
00051 #include <collision_detection_fcl/collision_world_fcl.h>
00052 #include <collision_detection_fcl/collision_robot_fcl.h>
00053 #include <rdf_loader/rdf_loader.h>
00054 
00055 #include <boost/filesystem.hpp>
00056 #include <ros/console.h>
00057 
00058 static const unsigned int TRIALS = 10000;
00059 
00060 class Pr2DistanceFieldCollisionDetectionTester : public testing::Test{
00061 
00062 protected:
00063 
00064   virtual void SetUp()
00065   {
00066 
00067     rml_.reset(new rdf_loader::RDFLoader("robot_description"));
00068     kmodel_.reset(new planning_models::RobotModel(rml_->getURDF(), rml_->getSRDF()));
00069 
00070     acm_.reset(new collision_detection::AllowedCollisionMatrix());
00071 
00072     ros::NodeHandle nh;
00073 
00074     XmlRpc::XmlRpcValue coll_ops;
00075     nh.getParam("robot_description_planning/default_collision_operations", coll_ops);
00076 
00077     if (coll_ops.getType() != XmlRpc::XmlRpcValue::TypeArray)
00078     {
00079       ROS_WARN("default_collision_operations is not an array");
00080       return;
00081     }
00082 
00083     if (coll_ops.size() == 0)
00084     {
00085       ROS_WARN("No collision operations in default collision operations");
00086       return;
00087     }
00088 
00089     for (int i = 0 ; i < coll_ops.size() ; ++i)
00090     {
00091       if (!coll_ops[i].hasMember("object1") || !coll_ops[i].hasMember("object2") || !coll_ops[i].hasMember("operation"))
00092       {
00093         ROS_WARN("All collision operations must have two objects and an operation");
00094         continue;
00095       }
00096       acm_->setEntry(std::string(coll_ops[i]["object1"]), std::string(coll_ops[i]["object2"]), std::string(coll_ops[i]["operation"]) == "disable");
00097     }
00098 
00099     std::map<std::string, std::vector<collision_detection::CollisionSphere> > coll_spheres;
00100     collision_detection::loadLinkBodySphereDecompositions(nh,
00101                                                           kmodel_,
00102                                                           coll_spheres);
00103 
00104     crobot_df_.reset(new collision_detection::CollisionRobotDistanceField(kmodel_, coll_spheres));
00105     cworld_df_.reset(new collision_detection::CollisionWorldDistanceField());
00106 
00107     crobot_fcl_.reset(new collision_detection::CollisionRobotFCL(kmodel_));
00108     cworld_fcl_.reset(new collision_detection::CollisionWorldFCL());
00109   }
00110 
00111   virtual void TearDown()
00112   {
00113 
00114   }
00115 
00116 protected:
00117 
00118   boost::shared_ptr<rdf_loader::RDFLoader> rml_;
00119 
00120   planning_models::RobotModelPtr             kmodel_;
00121 
00122   planning_models::TransformsPtr                 ftf_;
00123   planning_models::TransformsConstPtr            ftf_const_;
00124 
00125   boost::shared_ptr<collision_detection::CollisionRobotDistanceField> crobot_df_;
00126   boost::shared_ptr<collision_detection::CollisionWorldDistanceField> cworld_df_;
00127 
00128   boost::shared_ptr<collision_detection::CollisionRobot> crobot_fcl_;
00129   boost::shared_ptr<collision_detection::CollisionWorld> cworld_fcl_;
00130 
00131 
00132   collision_detection::AllowedCollisionMatrixPtr acm_;
00133 
00134 };
00135 
00136 TEST_F(Pr2DistanceFieldCollisionDetectionTester, SpeedTest)
00137 {
00138   planning_models::RobotState *kstate(kmodel_);
00139   kstate.setToDefaultValues();
00140 
00141   planning_models::RobotState *::JointStateGroup* jsg = kstate.getJointStateGroup("right_arm");
00142 
00143   ros::WallDuration total_speed_df;
00144   ros::WallDuration total_speed_fcl;
00145 
00146   unsigned int in_collision_df = 0;
00147   unsigned int in_collision_fcl = 0;
00148   unsigned int fcl_in_coll_df_not = 0;
00149 
00150   collision_detection::CollisionRequest req;
00151   req.group_name = "right_arm";
00152   req.contacts = true;
00153 
00154   collision_detection::CollisionResult res1;
00155   //first check with this group doesn't count
00156   boost::shared_ptr<collision_detection::GroupStateRepresentation> gsr;
00157   crobot_df_->checkSelfCollision(req, res1, kstate, *acm_, gsr);
00158   crobot_fcl_->checkSelfCollision(req, res1, kstate, *acm_);
00159 
00160   for(unsigned int i = 0; i < TRIALS; i++) {
00161     jsg->setToRandomValues();
00162     collision_detection::CollisionResult res;
00163     ros::WallTime before = ros::WallTime::now();
00164     crobot_df_->checkSelfCollision(req, res, kstate, gsr);
00165     total_speed_df += (ros::WallTime::now()-before);
00166     bool df_in_collision = false;
00167     if(res.collision) {
00168       in_collision_df++;
00169       df_in_collision = true;
00170     }
00171     res = collision_detection::CollisionResult();
00172     before = ros::WallTime::now();
00173     crobot_fcl_->checkSelfCollision(req, res, kstate, *acm_);
00174     total_speed_fcl += (ros::WallTime::now()-before);
00175     if(res.collision) {
00176       in_collision_fcl++;
00177       if(!df_in_collision) {
00178         fcl_in_coll_df_not++;
00179       }
00180     }
00181   }
00182   std::cerr << "Average time df " << total_speed_df.toSec()/(1.0*TRIALS) << " hz " << (1.0/(total_speed_df.toSec()/(1.0*TRIALS))) << std::endl;
00183   std::cerr << "In collision df " << in_collision_df << std::endl;
00184   std::cerr << "Average time fcl " << total_speed_fcl.toSec()/(1.0*TRIALS) << " hz " << (1.0/(total_speed_fcl.toSec()/(1.0*TRIALS))) << std::endl;
00185   std::cerr << "In collision fcl " << in_collision_fcl << std::endl;
00186   std::cerr << "Fcl in collision df not " << fcl_in_coll_df_not << std::endl;
00187 }
00188 
00189 int main(int argc, char **argv)
00190 {
00191   ros::init(argc, argv, "pr2_moveit_cd_speed_test");
00192   testing::InitGoogleTest(&argc, argv);
00193   return RUN_ALL_TESTS();
00194 }


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