5 #include <boost/bind.hpp> 6 #include <gazebo/gazebo.hh> 7 #include <gazebo/physics/physics.hh> 8 #include <gazebo/physics/ContactManager.hh> 9 #include <gazebo/physics/Contact.hh> 10 #include <gazebo/common/common.hh> 17 #define DEFAULT_FORCES_ANGLE_TOLERANCE 120 18 #define DEFAULT_UPDATE_RATE 5 19 #define DEFAULT_MAX_GRIP_COUNT 10 20 #define DEFAULT_RELEASE_TOLERANCE 0.005 21 #define DEFAULT_DISABLE_COLLISIONS_ON_ATTACH false 23 GazeboGraspGripper::GazeboGraspGripper():
47 const std::string& _gripperName,
48 const std::string& palmLinkName,
49 const std::vector<std::string>& fingerLinkNames,
50 bool _disableCollisionsOnAttach,
51 std::map<std::string, physics::CollisionPtr>& _collisionElems)
57 physics::PhysicsEnginePtr physics = this->
model->GetWorld()->GetPhysicsEngine();
58 this->
fixedJoint = physics->CreateJoint(
"revolute");
63 gzerr <<
"GazeboGraspGripper: Palm link "<<palmLinkName<<
" not found. The gazebo grasp plugin will not work."<<std::endl;
66 for (std::vector<std::string>::const_iterator fingerIt=fingerLinkNames.begin();
67 fingerIt!=fingerLinkNames.end(); ++fingerIt)
69 physics::LinkPtr link = this->
model->GetLink(*fingerIt);
72 gzerr <<
"GazeboGraspGripper ERROR: Link "<<*fingerIt<<
" can't be found in gazebo for GazeboGraspGripper model plugin. Skipping."<<std::endl;
75 for (
unsigned int j = 0; j < link->GetChildCount(); ++j)
77 physics::CollisionPtr collision = link->GetCollision(j);
78 std::string collName = collision->GetScopedName();
80 std::map<std::string, physics::CollisionPtr>::iterator collIter =
collisionElems.find(collName);
82 gzwarn <<
"GazeboGraspGripper: Adding Gazebo collision link element "<<collName<<
" multiple times, the gazebo grasp handler may not work properly"<<std::endl;
86 _collisionElems[collName] = collision;
101 for (std::vector<std::string>::const_iterator it=
linkNames.begin(); it!=
linkNames.end(); ++it)
103 if (*it==linkName)
return true;
132 gzwarn <<
"GazeboGraspGripper: palm link not found, not enforcing grasp hack!\n"<<std::endl;
135 physics::WorldPtr world = this->
model->GetWorld();
138 gzerr <<
"GazeboGraspGripper: world is NULL"<<std::endl;
141 #ifdef USE_MODEL_ATTACH 142 physics::ModelPtr obj = world->GetModel(objName);
144 std::cerr<<
"ERROR: Object ModelPtr "<<objName<<
" not found in world, can't attach it"<<std::endl;
147 gazebo::math::Pose
diff = obj->GetLink()->GetWorldPose() - this->
palmLink->GetWorldPose();
148 this->
palmLink->AttachStaticModel(obj,diff);
150 physics::CollisionPtr obj = boost::dynamic_pointer_cast<physics::Collision>(world->GetEntity(objName));
152 std::cerr<<
"ERROR: Object "<<objName<<
" not found in world, can't attach it"<<std::endl;
155 gazebo::math::Pose diff = obj->GetLink()->GetWorldPose() - this->
palmLink->GetWorldPose();
163 obj->GetLink()->SetCollideMode(
"none");
165 #endif // USE_MODEL_ATTACH 173 physics::WorldPtr world = this->
model->GetWorld();
176 gzerr <<
"GazeboGraspGripper: world is NULL"<<std::endl<<std::endl;
179 #ifdef USE_MODEL_ATTACH 180 physics::ModelPtr obj = world->GetModel(objName);
182 std::cerr<<
"ERROR: Object ModelPtr "<<objName<<
" not found in world, can't detach it"<<std::endl;
185 this->
palmLink->DetachStaticModel(objName);
187 physics::CollisionPtr obj = boost::dynamic_pointer_cast<physics::Collision>(world->GetEntity(objName));
189 std::cerr<<
"ERROR: Object "<<objName<<
" not found in world, can't attach it"<<std::endl;
194 obj->GetLink()->SetCollideMode(
"all");
197 #endif // USE_MODEL_ATTACH
bool disableCollisionsOnAttach
const std::string & getGripperName() const
bool isObjectAttached() const
void HandleDetach(const std::string &objName)
std::map< std::string, physics::CollisionPtr > collisionElems
std::vector< std::string > linkNames
bool hasLink(const std::string &linkName) const
const std::string & attachedObject() const
std::string attachedObjName
virtual ~GazeboGraspGripper()
physics::LinkPtr palmLink
Helper class for GazeboGraspFix which holds information for one arm. Attaches /detaches objects to th...
bool HandleAttach(const std::string &objName)
physics::JointPtr fixedJoint
bool Init(physics::ModelPtr &_model, const std::string &_gripperName, const std::string &palmLinkName, const std::vector< std::string > &fingerLinkNames, bool _disableCollisionsOnAttach, std::map< std::string, physics::CollisionPtr > &_collisions)
bool hasCollisionLink(const std::string &linkName) const
int ALVAR_EXPORT diff(const std::vector< C > &v, std::vector< C > &ret)