$search
00001 /********************************************************************* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2008, 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 the 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 00037 #include <ros/ros.h> 00038 #include <planning_environment/monitors/collision_space_monitor.h> 00039 #include <visualization_msgs/Marker.h> 00040 #include <boost/thread.hpp> 00041 00042 class CollisionTestSpeed 00043 { 00044 public: 00045 00046 CollisionTestSpeed(void) 00047 { 00048 vmPub_ = nh_.advertise<visualization_msgs::Marker>("visualization_marker", 10240); 00049 cm_ = new planning_environment::CollisionModels("robot_description"); 00050 id_ = 1; 00051 } 00052 00053 virtual ~CollisionTestSpeed(void) 00054 { 00055 delete cm_; 00056 } 00057 00058 void testPointCloud(void) 00059 { 00060 if (!cm_->loadedModels()) 00061 return; 00062 00063 planning_models::KinematicState state(cm_->getKinematicModel()); 00064 00065 state.setKinematicStateToDefault(); 00066 00067 ROS_INFO("Collision (should be 0): %d", cm_->isKinematicStateInEnvironmentCollision(state)); 00068 00069 const int n = 10000; 00070 00071 std::vector<shapes::Shape*> spheres; 00072 std::vector<btTransform> poses; 00073 00074 for (int i = 0 ; i < n ; ++i) 00075 { 00076 btTransform pos; 00077 pos.setIdentity(); 00078 do 00079 { 00080 std::vector<shapes::Shape*> spheres_one; 00081 std::vector<btTransform> poses_one; 00082 00083 shapes::Sphere* obj = new shapes::Sphere(0.02); 00084 spheres_one.push_back(obj); 00085 cm_->deleteAllStaticObjects(); 00086 pos.setOrigin(btVector3(uniform(1.5), uniform(1.5), uniform(1.5))); 00087 poses_one.push_back(pos); 00088 cm_->addStaticObject("points", spheres_one, poses_one, 0.02); 00089 } 00090 while(cm_->isKinematicStateInEnvironmentCollision(state)); 00091 spheres.push_back(new shapes::Sphere(0.02)); 00092 poses.push_back(pos); 00093 } 00094 00095 cm_->deleteAllStaticObjects(); 00096 cm_->addStaticObject("points", spheres, poses, 0.02); 00097 ROS_INFO("Added %d spheres", n); 00098 00099 ROS_INFO("Collision (should be 0): %d", cm_->isKinematicStateInEnvironmentCollision(state)); 00100 00101 const unsigned int K = 10000; 00102 00103 ros::WallTime tm = ros::WallTime::now(); 00104 for (unsigned int i = 0 ; i < K ; ++i) 00105 cm_->isKinematicStateInEnvironmentCollision(state); 00106 ROS_INFO("%f collision tests per second (without self collision checking)", (double)K/(ros::WallTime::now() - tm).toSec()); 00107 00108 tm = ros::WallTime::now(); 00109 for (unsigned int i = 0 ; i < K ; ++i) 00110 cm_->isKinematicStateInCollision(state); 00111 ROS_INFO("%f collision tests per second (with self collision checking)", (double)K/(ros::WallTime::now() - tm).toSec()); 00112 00113 tm = ros::WallTime::now(); 00114 for (unsigned int i = 0 ; i < K ; ++i) 00115 cm_->isKinematicStateInSelfCollision(state); 00116 ROS_INFO("%f collision tests per second (only self collision checking)", (double)K/(ros::WallTime::now() - tm).toSec()); 00117 } 00118 00119 protected: 00120 00121 void sendPoint(double x, double y, double z) 00122 { 00123 visualization_msgs::Marker mk; 00124 00125 mk.header.stamp = ros::Time::now(); 00126 00127 mk.header.frame_id = "base_link"; 00128 00129 mk.ns = "test_self_filter"; 00130 mk.id = id_++; 00131 mk.type = visualization_msgs::Marker::SPHERE; 00132 mk.action = visualization_msgs::Marker::ADD; 00133 mk.pose.position.x = x; 00134 mk.pose.position.y = y; 00135 mk.pose.position.z = z; 00136 mk.pose.orientation.w = 1.0; 00137 00138 mk.scale.x = mk.scale.y = mk.scale.z = 0.01; 00139 00140 mk.color.a = 1.0; 00141 mk.color.r = 1.0; 00142 mk.color.g = 0.04; 00143 mk.color.b = 0.04; 00144 00145 vmPub_.publish(mk); 00146 } 00147 00148 // return a random number (uniform distribution) 00149 // between -magnitude and magnitude 00150 double uniform(double magnitude) 00151 { 00152 return (2.0 * drand48() - 1.0) * magnitude; 00153 } 00154 00155 ros::Publisher vmPub_; 00156 ros::NodeHandle nh_; 00157 planning_environment::CollisionModels *cm_; 00158 int id_; 00159 00160 }; 00161 00162 00163 int main(int argc, char **argv) 00164 { 00165 ros::init(argc, argv, "CollisionTestSpeed"); 00166 00167 CollisionTestSpeed cts; 00168 00169 cts.testPointCloud(); 00170 // cts.testCollision(); 00171 // cts.testThreads(); 00172 00173 ROS_INFO("Done"); 00174 00175 return 0; 00176 }