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


robotican_common
Author(s):
autogenerated on Fri Oct 27 2017 03:02:37