00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00037 #ifndef COLLISION_SPACE_ENVIRONMENT_MODEL_
00038 #define COLLISION_SPACE_ENVIRONMENT_MODEL_
00039
00040 #include "collision_space/environment_objects.h"
00041 #include <planning_models/kinematic_model.h>
00042 #include <planning_models/kinematic_state.h>
00043 #include <geometric_shapes/bodies.h>
00044 #include <LinearMath/btVector3.h>
00045 #include <boost/thread/recursive_mutex.hpp>
00046 #include <boost/shared_ptr.hpp>
00047 #include <vector>
00048 #include <string>
00049
00050
00052 namespace collision_space
00053 {
00054
00061 class EnvironmentModel
00062 {
00063 public:
00064
00066 struct Contact
00067 {
00069 btVector3 pos;
00071 btVector3 normal;
00073 double depth;
00075 const planning_models::KinematicModel::LinkModel *link1;
00076
00078 unsigned int link1_attached_body_index;
00079
00081 const planning_models::KinematicModel::LinkModel *link2;
00082
00084 unsigned int link2_attached_body_index;
00085
00086
00087 std::string object_name;
00088 };
00089
00091 struct AllowedContact
00092 {
00094 boost::shared_ptr<bodies::Body> bound;
00095
00097 std::vector<std::string> links;
00098
00100 double depth;
00101 };
00102
00103 EnvironmentModel(void)
00104 {
00105 m_selfCollision = true;
00106 m_verbose = false;
00107 m_objects = new EnvironmentObjects();
00108 use_set_collision_matrix_ = false;
00109 }
00110
00111 virtual ~EnvironmentModel(void)
00112 {
00113 if (m_objects)
00114 delete m_objects;
00115 }
00116
00117
00118
00119
00120
00122 void setSelfCollision(bool selfCollision);
00123
00125 bool getSelfCollision(void) const;
00126
00128 virtual void addSelfCollisionGroup(const std::vector<std::string> &group1,
00129 const std::vector<std::string> &group2);
00130
00132 virtual void removeSelfCollisionGroup(const std::vector<std::string> &group1,
00133 const std::vector<std::string> &group2);
00134
00136 virtual int setCollisionCheck(const std::string &link, bool state) = 0;
00137
00139 virtual void setCollisionCheckLinks(const std::vector<std::string> &links, bool state) = 0;
00140
00142 virtual void setCollisionCheckOnlyLinks(const std::vector<std::string> &links, bool state) = 0;
00143
00145 virtual void setCollisionCheckAll(bool state) = 0;
00146
00153 virtual void setRobotModel(const boost::shared_ptr<const planning_models::KinematicModel> &model,
00154 const std::vector<std::string> &links,
00155 const std::map<std::string, double>& link_padding_map,
00156 double default_padding = 0.0,
00157 double scale = 1.0);
00158
00160 double getRobotScale(void) const;
00161
00163 double getRobotPadding(void) const;
00164
00166 virtual void updateRobotModel(const planning_models::KinematicState* state) = 0;
00167
00169 virtual void updateAttachedBodies() = 0;
00170
00172 const boost::shared_ptr<const planning_models::KinematicModel>& getRobotModel(void) const;
00173
00174
00175
00176
00177
00178
00180 virtual bool isCollision(void) = 0;
00181
00183 virtual bool isSelfCollision(void) = 0;
00184
00186 virtual bool getCollisionContacts(const std::vector<AllowedContact> &allowedContacts, std::vector<Contact> &contacts, unsigned int max_count = 1) = 0;
00187 bool getCollisionContacts(std::vector<Contact> &contacts, unsigned int max_count = 1);
00188
00189
00190
00191
00192
00194 virtual void clearObjects(void) = 0;
00195
00197 virtual void clearObjects(const std::string &ns) = 0;
00198
00200 virtual void addObject(const std::string &ns, shapes::StaticShape *shape) = 0;
00201
00203 virtual void addObject(const std::string &ns, shapes::Shape* shape, const btTransform &pose) = 0;
00204
00206 virtual void addObjects(const std::string &ns, const std::vector<shapes::Shape*> &shapes, const std::vector<btTransform> &poses) = 0;
00207
00209 virtual void removeCollidingObjects(const shapes::StaticShape *shape) = 0;
00210
00212 virtual void removeCollidingObjects(const shapes::Shape *shape, const btTransform &pose) = 0;
00213
00215 virtual const std::vector<const planning_models::KinematicModel::AttachedBodyModel*> getAttachedBodies(void) const = 0;
00216
00218 virtual const std::vector<const planning_models::KinematicModel::AttachedBodyModel*> getAttachedBodies(const std::string link_name) const = 0;
00219
00221 virtual void setRobotLinkPadding(const std::map<std::string, double>& link_padding_map);
00222
00224 virtual void revertRobotLinkPadding();
00225
00226 double getCurrentLinkPadding(std::string name) const;
00227
00229 const EnvironmentObjects* getObjects(void) const;
00230
00231 virtual void getDefaultAllowedCollisionMatrix(std::vector<std::vector<bool> > &matrix,
00232 std::map<std::string, unsigned int> &ind) const = 0;
00233
00234 virtual void getCurrentAllowedCollisionMatrix(std::vector<std::vector<bool> > &matrix,
00235 std::map<std::string, unsigned int> &ind) const;
00236
00238 virtual void setAllowedCollisionMatrix(const std::vector<std::vector<bool> > &matrix,
00239 const std::map<std::string, unsigned int > &ind);
00240
00242 virtual void revertAllowedCollisionMatrix();
00243
00244
00245
00246
00247
00249 void lock(void);
00250
00252 void unlock(void);
00253
00255 void setVerbose(bool verbose);
00256
00258 bool getVerbose(void) const;
00259
00261 virtual EnvironmentModel* clone(void) const = 0;
00262
00263 protected:
00264
00266 boost::recursive_mutex m_lock;
00267
00269 std::vector<std::string> m_collisionLinks;
00270
00272 std::map<std::string, unsigned int> m_collisionLinkIndex;
00273
00275
00276 std::vector< std::vector<bool> > m_selfCollisionTest;
00277
00279 bool m_selfCollision;
00280
00282 bool m_verbose;
00283
00285 boost::shared_ptr<const planning_models::KinematicModel> m_robotModel;
00286
00288 EnvironmentObjects *m_objects;
00289
00291 double m_robotScale;
00292
00294 double m_robotPadd;
00295
00296 std::vector<std::vector<bool> > set_collision_matrix_;
00297 std::map<std::string, unsigned int> set_collision_ind_;
00298
00299 bool use_set_collision_matrix_;
00300
00301 std::map<std::string, double> link_padding_map_;
00302 std::map<std::string, double> altered_link_padding_;
00303
00304 };
00305 }
00306
00307 #endif
00308