GazeboGraspFix.h
Go to the documentation of this file.
1 //
2 // Created by tom on 19/09/16.
3 //
4 
5 #ifndef ROBOTICAN_COMMON_GAZEBOGRASPFIX_H
6 #define ROBOTICAN_COMMON_GAZEBOGRASPFIX_H
7 
8 #include <boost/bind.hpp>
9 #include <gazebo/gazebo.hh>
10 #include <gazebo/physics/physics.hh>
11 #include <gazebo/common/common.hh>
12 #include <gazebo/transport/TransportTypes.hh>
13 #include <stdio.h>
15 // #include <gazebo_grasp_plugin/CollidingPoint.h>
16 
17 namespace gazebo {
18 
96  class GazeboGraspFix : public ModelPlugin {
97  public:
99  GazeboGraspFix(physics::ModelPtr _model);
100  virtual ~GazeboGraspFix();
101 
105  virtual void OnAttach(const std::string& objectName, const std::string& armName){}
109  virtual void OnDetach(const std::string& objectName, const std::string& armName){}
110 
111  private:
112  virtual void Init();
113  virtual void Load(physics::ModelPtr _parent, sdf::ElementPtr _sdf);
136  void OnUpdate();
137 
138  void InitValues();
139 
140 
153  void OnContact(const ConstContactsPtr& ptr);
154 
160  bool checkGrip(const std::vector<math::Vector3>& forces, float minAngleDiff, float lengthRatio);
161 
162  bool isGripperLink(const std::string& linkName, std::string& gripperName) const;
163 
167  std::map<std::string, std::string> getAttachedObjects() const;
168 
173  class ObjectContactInfo;
174 
178  bool objectAttachedToGripper(const ObjectContactInfo& objContInfo, std::string& attachedToGripper) const;
179 
183  bool objectAttachedToGripper(const std::string& gripperName, std::string& attachedToGripper) const;
184 
185 
186  // physics::ModelPtr model;
187  // physics::PhysicsEnginePtr physics;
188  physics::WorldPtr world;
189 
190  // sorted by their name, all grippers of the robot
191  std::map<std::string, GazeboGraspGripper> grippers;
192 
193  event::ConnectionPtr update_connection;
194  transport::NodePtr node;
195  transport::SubscriberPtr contactSub; //subscriber to contact updates
196 
197  // tolerance (in degrees) between force vectors to
198  // beconsidered "opposing"
200 
201  // when an object is attached, collisions with it may be disabled, in case the
202  // robot still keeps wobbling.
204 
205  // all collisions per gazebo collision link (each entry
206  // belongs to a physics::CollisionPtr element). The key
207  // is the collision link name, the value is the gripper name
208  // this collision link belongs to.
209  std::map<std::string, std::string> collisions;
210 
211 
216 
217  // Contact forces sorted by object name the gripper collides with (first key)
218  // and the link colliding (second key).
219  std::map<std::string, std::map<std::string, CollidingPoint> > contacts;
220  boost::mutex mutexContacts; //mutex protects contacts
221 
222  // when an object was first attached, it had these colliding points.
223  // First key is object name, second is the link colliding, as in \e contacts.
224  // Only the links of *one* gripper are stored here. This indirectly imposes the
225  // limitation that no two grippers can grasp the object (while it would be
226  // possible, the release condition is tied to only one link, so the object may
227  // not be released properly).
228  std::map<std::string, std::map<std::string, CollidingPoint> > attachGripContacts;
229 
230 
231  // Records how many subsequent update calls the grip on that object has been recorded
232  // as "holding". Every loop, if a grip is not recorded, this number decreases.
233  // When it reaches \e grip_count_threshold, it will be attached.
234  // The number won't increase above max_grip_count once it has reached that number.
235  std::map<std::string, int> gripCounts;
236 
237  // *maximum* number in \e gripCounts to be recorded.
239 
240  // number of recorded "grips" in the past (in gripCount) which, when it is exceeded, counts
241  // as the object grasped, and when it is lower, as released.
243 
244  // once an object is gripped, the relative position of the collision link surface to the
245  // object is remembered. As soon as this distance changes more than release_tolerance,
246  // the object is released.
248 
249  //nano seconds between two updates
250  common::Time updateRate;
251 
252  //last time OnUpdate() was called
253  common::Time prevUpdateTime;
254  };
255 
256 }
257 
258 
259 #endif //ROBOTICAN_COMMON_GAZEBOGRASPFIX_H
bool isGripperLink(const std::string &linkName, std::string &gripperName) const
std::map< std::string, std::string > collisions
std::map< std::string, std::map< std::string, CollidingPoint > > attachGripContacts
common::Time prevUpdateTime
transport::NodePtr node
bool checkGrip(const std::vector< math::Vector3 > &forces, float minAngleDiff, float lengthRatio)
virtual void OnDetach(const std::string &objectName, const std::string &armName)
physics::WorldPtr world
virtual void OnAttach(const std::string &objectName, const std::string &armName)
std::map< std::string, int > gripCounts
void OnContact(const ConstContactsPtr &ptr)
std::map< std::string, GazeboGraspGripper > grippers
std::map< std::string, std::map< std::string, CollidingPoint > > contacts
bool objectAttachedToGripper(const ObjectContactInfo &objContInfo, std::string &attachedToGripper) const
boost::mutex mutexContacts
event::ConnectionPtr update_connection
transport::SubscriberPtr contactSub
std::map< std::string, std::string > getAttachedObjects() const
virtual void Load(physics::ModelPtr _parent, sdf::ElementPtr _sdf)


robotican_common
Author(s):
autogenerated on Wed Jan 3 2018 03:48:33