ContactsGenerator.h
Go to the documentation of this file.
00001 
00019 #ifndef URDF2GRASPIT_CONTACTSGENERATOR_H
00020 #define URDF2GRASPIT_CONTACTSGENERATOR_H
00021 // Copyright Jennifer Buehler
00022 
00023 //-----------------------------------------------------
00024 #include <urdf/model.h>
00025 
00026 #include <iostream>
00027 #include <string>
00028 #include <map>
00029 #include <vector>
00030 
00031 #include <Eigen/Core>
00032 #include <Eigen/Geometry>
00033 
00034 #include <urdf2graspit/Urdf2GraspItBase.h>
00035 #include <baselib_binding/SharedPtr.h>
00036 #include <urdf2graspit/DHParam.h>
00037 #include <urdf2graspit/MarkerSelector.h>
00038 #include <urdf2graspit/OutputStructure.h>
00039 
00040 // epsilon value to use when comparing whether two axes are the same
00041 // (difference of angle between axes)
00042 #define U2G_EPSILON 1e-07
00043 
00044 namespace urdf2graspit
00045 {
00046 
00053 class ContactsGenerator: public Urdf2GraspItBase
00054 {
00055 public:
00060     explicit ContactsGenerator(UrdfTraverserPtr& traverser, float _scaleFactor = 1000):
00061         Urdf2GraspItBase(traverser, _scaleFactor),
00062         isContactsScaled(false)
00063     {
00064     }
00065 
00066     ~ContactsGenerator()
00067     {
00068     }
00069 
00080     bool generateContacts(const std::vector<std::string>& rootFingerJoints, const std::string& palmLinkName,
00081                           const float coefficient, const markerselector::MarkerSelector::MarkerMap& markers,
00082                           const std::vector<DHParam>& dh);
00083 
00100     bool generateContactsWithViewer(const std::vector<std::string>& fingerRoots,
00101                                     const std::string& palmLinkName,
00102                                     float standard_coefficient,
00103                                     const std::vector<DHParam>& dh,
00104                                     bool _displayAxes, bool _axesFromDH,
00105                                     float _axesRadius, float _axesLength,
00106                                     const EigenTransform& addVisualTransform,
00107                                     bool facesCCW);
00108 
00112     std::string getContactsFileContent(const std::string& robotName);
00113 
00114 
00115 protected:
00119     class Contact
00120     {
00121     public:
00122         Contact(): numFrictionEdges(-1), fingerNum(-1), linkNum(-1), cof(0) {}
00123         Contact(const Contact& o):
00124             numFrictionEdges(o.numFrictionEdges), frictionEdges(o.frictionEdges),
00125             fingerNum(o.fingerNum), linkNum(o.linkNum),
00126             loc(o.loc), ori(o.ori), norm(o.norm), cof(o.cof) {}
00127 
00128         friend std::ostream& operator<<(std::ostream& o, const Contact& c)
00129         {
00130             o << c.linkNum << ", " << c.fingerNum << ": " << c.loc;
00131             return o;
00132         }
00133 
00134         // Number of friction edges
00135         unsigned int numFrictionEdges;
00136         // Friction edges (6*numFrictionEdges doubles)
00137         // The 6 values specify friction cone boundary wrenches.
00138         // See more documentation in function ContactsGenerator::setUpFrictionEllipsoid().
00139         std::vector<double> frictionEdges;
00140         // Finger number
00141         int fingerNum;
00142         // Link number
00143         int linkNum;
00144         // Contact (frame) location
00145         Eigen::Vector3d loc;
00146         // Contact (frame) orientation
00147         Eigen::Quaterniond ori;
00148         // Contact normal (facing away from link)
00149         Eigen::Vector3d norm;
00150         // Contact friciton coefficient
00151         float cof;
00152     };
00153     typedef baselib_binding::shared_ptr<Contact>::type ContactPtr;
00154 
00155     bool transformToDHReferenceFrames(const std::vector<DHParam>& dh);
00156 
00157     void applyTransformToContacts(LinkPtr& link, const EigenTransform& trans, bool preMult);
00158 
00159 
00160     static bool getDHParam(const std::string jointName, const std::vector<DHParam>& dh, DHParam& jointDH);
00161 
00162     SoNode * getAxesAsInventor(const LinkPtr& from_link,
00163             const std::vector<DHParam>& dh,
00164             float _axesRadius, float _axesLength,
00165             bool linkIsRoot);
00166 private:
00167 
00171     void scaleContacts(double scale_factor);
00172 
00173     // Helper function for generateContacts()
00174     bool generateContactsForallVisuals(const std::string& linkName,
00175                                        const int linkNum, const int fingerNum,
00176                                        const float coefficient,
00177                                        const std::vector<markerselector::MarkerSelector::Marker>& markers);
00178     bool isContactsScaled;
00179 
00180     std::vector<ContactPtr> contacts;
00181     std::map<std::string, std::vector<ContactPtr> > linkContacts;
00182 };
00183 
00184 }  //  namespace urdf2graspit
00185 #endif   // URDF2GRASPIT_CONTACTSGENERATOR_H


urdf2graspit
Author(s): Jennifer Buehler
autogenerated on Wed May 8 2019 02:53:45