collision_robot_distance_field.h
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2012, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the Willow Garage nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 /* Author: E. Gil Jones */
36 
37 #ifndef MOVEIT_COLLISION_DISTANCE_FIELD_COLLISION_ROBOT_DISTANCE_FIELD_
38 #define MOVEIT_COLLISION_DISTANCE_FIELD_COLLISION_ROBOT_DISTANCE_FIELD_
39 
45 #include <boost/thread/mutex.hpp>
46 
47 namespace collision_detection
48 {
49 static const double DEFAULT_SIZE_X = 3.0;
50 static const double DEFAULT_SIZE_Y = 3.0;
51 static const double DEFAULT_SIZE_Z = 4.0;
52 static const bool DEFAULT_USE_SIGNED_DISTANCE_FIELD = false;
53 static const double DEFAULT_RESOLUTION = .02;
54 static const double DEFAULT_COLLISION_TOLERANCE = 0.0;
55 static const double DEFAULT_MAX_PROPOGATION_DISTANCE = .25;
56 
58 
60 {
62 
63 public:
65 
66  CollisionRobotDistanceField(const robot_model::RobotModelConstPtr& kmodel);
67 
68  CollisionRobotDistanceField(const CollisionRobot& col_robot, const Eigen::Vector3d& size,
69  const Eigen::Vector3d& origin, bool use_signed_distance_field, double resolution,
70  double collision_tolerance, double max_propogation_distance, double padding);
71 
72  CollisionRobotDistanceField(const robot_model::RobotModelConstPtr& kmodel,
73  const std::map<std::string, std::vector<CollisionSphere>>& link_body_decompositions,
74  double size_x = DEFAULT_SIZE_X, double size_y = DEFAULT_SIZE_Y,
75  double size_z = DEFAULT_SIZE_Z,
76  bool use_signed_distance_field = DEFAULT_USE_SIGNED_DISTANCE_FIELD,
77  double resolution = DEFAULT_RESOLUTION,
78  double collision_tolerance = DEFAULT_COLLISION_TOLERANCE,
79  double max_propogation_distance = DEFAULT_MAX_PROPOGATION_DISTANCE, double padding = 0.0,
80  double scale = 1.0);
81 
83 
84  void initialize(const std::map<std::string, std::vector<CollisionSphere>>& link_body_decompositions,
85  const Eigen::Vector3d& size, const Eigen::Vector3d& origin, bool use_signed_distance_field,
86  double resolution, double collision_tolerance, double max_propogation_distance);
87 
90  const moveit::core::RobotState& state) const;
91 
93  const moveit::core::RobotState& state, GroupStateRepresentationPtr& gsr) const;
94 
98 
101  GroupStateRepresentationPtr& gsr) const;
102 
105  const moveit::core::RobotState& state2) const
106  {
107  ROS_ERROR_NAMED("collision_distance_field", "Not implemented");
108  };
109 
112  const moveit::core::RobotState& state2,
114  {
115  ROS_ERROR_NAMED("collision_distance_field", "Not implemented");
116  };
117 
120  const CollisionRobot& other_robot, const moveit::core::RobotState& other_state) const
121  {
122  ROS_ERROR_NAMED("collision_distance_field", "Not implemented");
123  };
124 
127  const CollisionRobot& other_robot, const moveit::core::RobotState& other_state,
129  {
130  ROS_ERROR_NAMED("collision_distance_field", "Not implemented");
131  };
132 
135  const moveit::core::RobotState& state2, const CollisionRobot& other_robot,
136  const moveit::core::RobotState& other_state1,
137  const moveit::core::RobotState& other_state2) const
138  {
139  ROS_ERROR_NAMED("collision_distance_field", "Not implemented");
140  };
141 
144  const moveit::core::RobotState& state2, const CollisionRobot& other_robot,
145  const moveit::core::RobotState& other_state1,
146  const moveit::core::RobotState& other_state2,
148  {
149  ROS_ERROR_NAMED("collision_distance_field", "Not implemented");
150  };
151 
153  visualization_msgs::MarkerArray& model_markers) const;
154 
155  virtual double distanceSelf(const moveit::core::RobotState& state) const
156  {
157  return 0.0;
158  };
159  virtual double distanceSelf(const moveit::core::RobotState& state,
161  {
162  return 0.0;
163  };
164  virtual double distanceOther(const moveit::core::RobotState& state, const CollisionRobot& other_robot,
165  const moveit::core::RobotState& other_state) const
166  {
167  return 0.0;
168  };
169  virtual double distanceOther(const moveit::core::RobotState& state, const CollisionRobot& other_robot,
170  const moveit::core::RobotState& other_state,
172  {
173  return 0.0;
174  };
175 
176  virtual void distanceSelf(const DistanceRequest& req, DistanceResult& res, const robot_state::RobotState& state) const
177  {
178  ROS_ERROR_NAMED("collision_distance_field", "Not implemented");
179  }
180 
181  virtual void distanceOther(const DistanceRequest& req, DistanceResult& res, const robot_state::RobotState& state,
182  const CollisionRobot& other_robot, const robot_state::RobotState& other_state) const
183  {
184  ROS_ERROR_NAMED("collision_distance_field", "Not implemented");
185  }
186 
187  DistanceFieldCacheEntryConstPtr getLastDistanceFieldEntry() const
188  {
190  }
191 
192  // void getSelfCollisionsGradients(const collision_detection::CollisionRequest
193  // &req,
194  // collision_detection::CollisionResult &res,
195  // const moveit::core::RobotState &state,
196  // const
197  // collision_detection::AllowedCollisionMatrix
198  // &acm) const;
199 protected:
200  bool getSelfProximityGradients(GroupStateRepresentationPtr& gsr) const;
201 
202  bool getIntraGroupProximityGradients(GroupStateRepresentationPtr& gsr) const;
203 
205  GroupStateRepresentationPtr& gsr) const;
206 
208  collision_detection::CollisionResult& res, GroupStateRepresentationPtr& gsr) const;
209 
213  GroupStateRepresentationPtr& gsr) const;
214 
216  GroupStateRepresentationPtr& gsr) const;
217 
218  void generateCollisionCheckingStructures(const std::string& group_name, const moveit::core::RobotState& state,
220  GroupStateRepresentationPtr& gsr, bool generate_distance_field) const;
221 
222  DistanceFieldCacheEntryConstPtr
223  getDistanceFieldCacheEntry(const std::string& group_name, const moveit::core::RobotState& state,
225 
226  DistanceFieldCacheEntryPtr generateDistanceFieldCacheEntry(const std::string& group_name,
227  const moveit::core::RobotState& state,
229  bool generate_distance_field) const;
230 
232 
233  void addLinkBodyDecompositions(double resolution,
234  const std::map<std::string, std::vector<CollisionSphere>>& link_body_decompositions);
235 
236  PosedBodySphereDecompositionPtr getPosedLinkBodySphereDecomposition(const moveit::core::LinkModel* ls,
237  unsigned int ind) const;
238 
239  PosedBodyPointDecompositionPtr getPosedLinkBodyPointDecomposition(const moveit::core::LinkModel* ls) const;
240 
241  void getGroupStateRepresentation(const DistanceFieldCacheEntryConstPtr& dfce, const moveit::core::RobotState& state,
242  GroupStateRepresentationPtr& gsr) const;
243 
244  bool compareCacheEntryToState(const DistanceFieldCacheEntryConstPtr& dfce,
245  const moveit::core::RobotState& state) const;
246 
247  bool compareCacheEntryToAllowedCollisionMatrix(const DistanceFieldCacheEntryConstPtr& dfce,
249 
250  virtual void updatedPaddingOrScaling(const std::vector<std::string>& links){};
251 
252  Eigen::Vector3d size_;
253  Eigen::Vector3d origin_;
255  double resolution_;
258 
259  std::vector<BodyDecompositionConstPtr> link_body_decomposition_vector_;
260  std::map<std::string, unsigned int> link_body_decomposition_index_map_;
261 
262  mutable boost::mutex update_cache_lock_;
263  DistanceFieldCacheEntryPtr distance_field_cache_entry_;
264  std::map<std::string, std::map<std::string, bool>> in_group_update_map_;
265  std::map<std::string, GroupStateRepresentationPtr> pregenerated_group_state_representation_map_;
266 
267  planning_scene::PlanningScenePtr planning_scene_;
268 };
269 }
270 
271 #endif
bool getIntraGroupProximityGradients(GroupStateRepresentationPtr &gsr) const
bool compareCacheEntryToState(const DistanceFieldCacheEntryConstPtr &dfce, const moveit::core::RobotState &state) const
void generateCollisionCheckingStructures(const std::string &group_name, const moveit::core::RobotState &state, const collision_detection::AllowedCollisionMatrix *acm, GroupStateRepresentationPtr &gsr, bool generate_distance_field) const
DistanceFieldCacheEntryConstPtr getLastDistanceFieldEntry() const
static const double DEFAULT_RESOLUTION
virtual void checkSelfCollision(const collision_detection::CollisionRequest &req, collision_detection::CollisionResult &res, const moveit::core::RobotState &state1, const moveit::core::RobotState &state2, const collision_detection::AllowedCollisionMatrix &acm) const
Check for self collision. Allowed collisions specified by the allowed collision matrix are taken into...
void createCollisionModelMarker(const moveit::core::RobotState &state, visualization_msgs::MarkerArray &model_markers) const
virtual void distanceOther(const DistanceRequest &req, DistanceResult &res, const robot_state::RobotState &state, const CollisionRobot &other_robot, const robot_state::RobotState &other_state) const
The distance to self-collision given the robot is at state state.
virtual void distanceSelf(const DistanceRequest &req, DistanceResult &res, const robot_state::RobotState &state) const
The distance to self-collision given the robot is at state state.
void initialize(const std::map< std::string, std::vector< CollisionSphere >> &link_body_decompositions, const Eigen::Vector3d &size, const Eigen::Vector3d &origin, bool use_signed_distance_field, double resolution, double collision_tolerance, double max_propogation_distance)
MOVEIT_CLASS_FORWARD(AllowedCollisionMatrix)
std::map< std::string, unsigned int > link_body_decomposition_index_map_
EIGEN_MAKE_ALIGNED_OPERATOR_NEW CollisionRobotDistanceField(const robot_model::RobotModelConstPtr &kmodel)
virtual double distanceSelf(const moveit::core::RobotState &state) const
virtual double distanceSelf(const moveit::core::RobotState &state, const collision_detection::AllowedCollisionMatrix &acm) const
static const double DEFAULT_MAX_PROPOGATION_DISTANCE
virtual double distanceOther(const moveit::core::RobotState &state, const CollisionRobot &other_robot, const moveit::core::RobotState &other_state, const collision_detection::AllowedCollisionMatrix &acm) const
Generic interface to collision detection.
static const double DEFAULT_COLLISION_TOLERANCE
bool compareCacheEntryToAllowedCollisionMatrix(const DistanceFieldCacheEntryConstPtr &dfce, const collision_detection::AllowedCollisionMatrix &acm) const
static const double resolution
std::map< std::string, std::map< std::string, bool > > in_group_update_map_
void updateGroupStateRepresentationState(const moveit::core::RobotState &state, GroupStateRepresentationPtr &gsr) const
Definition of a structure for the allowed collision matrix. All elements in the collision world are r...
PosedBodySphereDecompositionPtr getPosedLinkBodySphereDecomposition(const moveit::core::LinkModel *ls, unsigned int ind) const
This class represents a collision model of the robot and can be used for self collision checks (to ch...
ROS/KDL based interface for the inverse kinematics of the PR2 arm.
virtual void updatedPaddingOrScaling(const std::vector< std::string > &links)
When the scale or padding is changed for a set of links by any of the functions in this class...
bool getIntraGroupCollisions(const collision_detection::CollisionRequest &req, collision_detection::CollisionResult &res, GroupStateRepresentationPtr &gsr) const
virtual void checkSelfCollision(const collision_detection::CollisionRequest &req, collision_detection::CollisionResult &res, const moveit::core::RobotState &state1, const moveit::core::RobotState &state2) const
Check for self collision in a continuous manner. Any collision between any pair of links is checked f...
DistanceFieldCacheEntryPtr generateDistanceFieldCacheEntry(const std::string &group_name, const moveit::core::RobotState &state, const collision_detection::AllowedCollisionMatrix *acm, bool generate_distance_field) const
virtual void checkOtherCollision(const collision_detection::CollisionRequest &req, collision_detection::CollisionResult &res, const moveit::core::RobotState &state1, const moveit::core::RobotState &state2, const CollisionRobot &other_robot, const moveit::core::RobotState &other_state1, const moveit::core::RobotState &other_state2, const collision_detection::AllowedCollisionMatrix &acm) const
Check for collision with a different robot (possibly a different kinematic model as well)...
virtual double distanceOther(const moveit::core::RobotState &state, const CollisionRobot &other_robot, const moveit::core::RobotState &other_state) const
virtual void checkOtherCollision(const collision_detection::CollisionRequest &req, collision_detection::CollisionResult &res, const moveit::core::RobotState &state, const CollisionRobot &other_robot, const moveit::core::RobotState &other_state, const collision_detection::AllowedCollisionMatrix &acm) const
Check for collision with a different robot (possibly a different kinematic model as well)...
void getGroupStateRepresentation(const DistanceFieldCacheEntryConstPtr &dfce, const moveit::core::RobotState &state, GroupStateRepresentationPtr &gsr) const
std::vector< BodyDecompositionConstPtr > link_body_decomposition_vector_
virtual void checkOtherCollision(const collision_detection::CollisionRequest &req, collision_detection::CollisionResult &res, const moveit::core::RobotState &state, const CollisionRobot &other_robot, const moveit::core::RobotState &other_state) const
Check for collision with a different robot (possibly a different kinematic model as well)...
static const bool DEFAULT_USE_SIGNED_DISTANCE_FIELD
#define ROS_ERROR_NAMED(name,...)
DistanceFieldCacheEntryConstPtr getDistanceFieldCacheEntry(const std::string &group_name, const moveit::core::RobotState &state, const collision_detection::AllowedCollisionMatrix *acm) const
virtual void checkOtherCollision(const collision_detection::CollisionRequest &req, collision_detection::CollisionResult &res, const moveit::core::RobotState &state1, const moveit::core::RobotState &state2, const CollisionRobot &other_robot, const moveit::core::RobotState &other_state1, const moveit::core::RobotState &other_state2) const
Check for collision with a different robot (possibly a different kinematic model as well)...
Representation of a robot&#39;s state. This includes position, velocity, acceleration and effort...
Definition: robot_state.h:123
A link from the robot. Contains the constant transform applied to the link and its geometry...
Definition: link_model.h:72
std::map< std::string, GroupStateRepresentationPtr > pregenerated_group_state_representation_map_
bool getSelfProximityGradients(GroupStateRepresentationPtr &gsr) const
void checkSelfCollisionHelper(const collision_detection::CollisionRequest &req, collision_detection::CollisionResult &res, const moveit::core::RobotState &state, const collision_detection::AllowedCollisionMatrix *acm, GroupStateRepresentationPtr &gsr) const
PosedBodyPointDecompositionPtr getPosedLinkBodyPointDecomposition(const moveit::core::LinkModel *ls) const
virtual void checkSelfCollision(const collision_detection::CollisionRequest &req, collision_detection::CollisionResult &res, const moveit::core::RobotState &state) const
Check for self collision. Any collision between any pair of links is checked for, NO collisions are i...
bool getSelfCollisions(const collision_detection::CollisionRequest &req, collision_detection::CollisionResult &res, GroupStateRepresentationPtr &gsr) const


moveit_core
Author(s): Ioan Sucan , Sachin Chitta , Acorn Pooley
autogenerated on Mon Jun 10 2019 14:07:15