GazeboGraspFix.h
Go to the documentation of this file.
00001 #ifndef GAZEBO_GAZEBOGRASPFIX_H
00002 #define GAZEBO_GAZEBOGRASPFIX_H
00003 
00004 #include <boost/bind.hpp>
00005 #include <gazebo/gazebo.hh>
00006 #include <gazebo/physics/physics.hh>
00007 #include <gazebo/common/common.hh>
00008 #include <gazebo/transport/TransportTypes.hh>
00009 #include <stdio.h>
00010 #include <gazebo_grasp_plugin/GazeboGraspGripper.h>
00011 
00012 namespace gazebo
00013 {
00014 
00092 class GazeboGraspFix : public ModelPlugin
00093 {
00094   public:
00095     GazeboGraspFix();
00096     GazeboGraspFix(physics::ModelPtr _model);
00097     virtual ~GazeboGraspFix();
00098 
00102     virtual void OnAttach(const std::string &objectName,
00103                           const std::string &armName) {}
00107     virtual void OnDetach(const std::string &objectName,
00108                           const std::string &armName) {}
00109 
00110   private:
00111     virtual void Init();
00112     virtual void Load(physics::ModelPtr _parent, sdf::ElementPtr _sdf);
00135     void OnUpdate();
00136 
00137     void InitValues();
00138 
00139 
00152     void OnContact(const ConstContactsPtr &ptr);
00153 
00154 //    bool CheckGrip(const std::vector<GzVector3> &forces, float minAngleDiff,
00155 //                   float lengthRatio);
00156 
00157     bool IsGripperLink(const std::string &linkName, std::string &gripperName) const;
00158 
00162     std::map<std::string, std::string> GetAttachedObjects() const;
00163 
00168     class ObjectContactInfo;
00169 
00173     bool ObjectAttachedToGripper(const ObjectContactInfo &objContInfo,
00174                                  std::string &attachedToGripper) const;
00175 
00179     bool ObjectAttachedToGripper(const std::string &gripperName,
00180                                  std::string &attachedToGripper) const;
00181 
00182 
00183     // physics::ModelPtr model;
00184     // physics::PhysicsEnginePtr physics;
00185     physics::WorldPtr world;
00186 
00187     // sorted by their name, all grippers of the robot
00188     std::map<std::string, GazeboGraspGripper> grippers;
00189 
00190     event::ConnectionPtr update_connection;
00191     transport::NodePtr node;
00192     transport::SubscriberPtr contactSub; //subscriber to contact updates
00193 
00194     // tolerance (in degrees) between force vectors to
00195     // beconsidered "opposing"
00196     float forcesAngleTolerance;
00197 
00198     // when an object is attached, collisions with it may be disabled, in case the
00199     // robot still keeps wobbling.
00200     bool disableCollisionsOnAttach;
00201 
00202     // all collisions per gazebo collision link (each entry
00203     // belongs to a physics::CollisionPtr element). The key
00204     // is the collision link name, the value is the gripper name
00205     // this collision link belongs to.
00206     std::map<std::string, std::string> collisions;
00207 
00208 
00212     class CollidingPoint;
00213 
00214     // Contact forces sorted by object name the gripper collides with (first key)
00215     // and the link colliding (second key).
00216     std::map<std::string, std::map<std::string, CollidingPoint> > contacts;
00217     boost::mutex mutexContacts; //mutex protects contacts
00218 
00219     // when an object was first attached, it had these colliding points.
00220     // First key is object name, second is the link colliding, as in \e contacts.
00221     // Only the links of *one* gripper are stored here. This indirectly imposes the
00222     // limitation that no two grippers can grasp the object (while it would be
00223     // possible, the release condition is tied to only one link, so the object may
00224     // not be released properly).
00225     std::map<std::string, std::map<std::string, CollidingPoint> >
00226     attachGripContacts;
00227 
00228 
00229     // Records how many subsequent update calls the grip on that object has been recorded
00230     // as "holding". Every loop, if a grip is not recorded, this number decreases.
00231     // When it reaches \e grip_count_threshold, it will be attached.
00232     // The number won't increase above max_grip_count once it has reached that number.
00233     std::map<std::string, int> gripCounts;
00234 
00235     // *maximum* number in \e gripCounts to be recorded.
00236     int maxGripCount;
00237 
00238     // number of recorded "grips" in the past (in gripCount) which, when it is exceeded, counts
00239     // as the object grasped, and when it is lower, as released.
00240     int gripCountThreshold;
00241 
00242     // once an object is gripped, the relative position of the collision link surface to the
00243     // object is remembered. As soon as this distance changes more than release_tolerance,
00244     // the object is released.
00245     float releaseTolerance;
00246 
00247     //nano seconds between two updates
00248     common::Time updateRate;
00249 
00250     //last time OnUpdate() was called
00251     common::Time prevUpdateTime;
00252 };
00253 
00254 }
00255 
00256 #endif  // GAZEBO_GAZEBOGRASPFIX_H


gazebo_grasp_plugin
Author(s): Jennifer Buehler
autogenerated on Tue May 7 2019 03:29:31