KrisLibrary  1.0.0
Contact.h
1 #ifndef CONTACT_H
2 #define CONTACT_H
3 
5 #include <KrisLibrary/math/matrix.h>
6 #include <KrisLibrary/math/sparsematrix.h>
7 #include <vector>
8 #include <KrisLibrary/errors.h>
9 using namespace Math3D;
10 
16 {
17  inline Real frictionConeHalfAngle() const { return Atan(kFriction); }
18  inline void setfrictionConeHalfAngle(Real phi) { kFriction=Tan(phi); }
20  bool isValidForce(const Vector3& f) const;
24  Real minFriction(const Vector3& f) const;
26  void quadraticForm(Matrix3& A,Vector3& b,Real& c) const;
27 
28  Vector3 x;
29  Vector3 n;
30  Real kFriction;
31 };
32 
38 {
39  inline Real frictionConeHalfAngle() const { return Atan(kFriction); }
40  inline void setfrictionConeHalfAngle(Real phi) { kFriction=Tan(phi); }
42  bool isValidForce(const Vector2& f) const;
46  Real minFriction(const Vector2& f) const;
48  void quadraticForm(Matrix2& A,Vector2& b,Real& c) const;
49 
50  Vector2 x;
51  Vector2 n;
52  Real kFriction;
53 };
54 
62 {
64  void set(int link,const std::vector<ContactPoint>& contacts,int target=-1);
66  void concat(const ContactFormation& formation);
68  void flatten(std::vector<int>& flatLinks,std::vector<ContactPoint>& cps) const;
69  void flatten(std::vector<int>& flatLinks,std::vector<ContactPoint>& cps,std::vector<int>& flattargets) const;
71  int numContactPoints() const;
73  int numForceVariables() const;
74 
75  std::vector<int> links;
76  std::vector<std::vector<ContactPoint> > contacts;
77  std::vector<int> targets;
78 };
79 
88 {
89  void set(int k,const Vector3& n,Real kFriction);
90  bool contains(const Vector3& f) const;
91  bool onBoundary(const Vector3& f) const;
92 
93  std::vector<Vector3> edges;
94  std::vector<Vector3> planes;
95 };
96 
104 void FrictionToFrictionlessContacts(const std::vector<ContactPoint>& c1,int k,std::vector<ContactPoint>& c2);
105 
112 void FrictionToFrictionlessContacts(const std::vector<ContactPoint2D>& c1,std::vector<ContactPoint2D>& c2);
113 
122 void GetFrictionConePlanes(const ContactPoint& contact,int k,Matrix& A);
123 
130 void GetFrictionConePlanes(const ContactPoint2D& contact,Matrix2& A);
131 
139 void GetWrenchMatrix(const std::vector<ContactPoint>& s,const Vector3& cm,Matrix& A);
140 void GetWrenchMatrix(const std::vector<ContactPoint>& s,const Vector3& cm,SparseMatrix& A);
141 void GetWrenchMatrix(const ContactFormation& s,const Vector3& cm,SparseMatrix& A);
142 
152 void GetFrictionConePlanes(const std::vector<ContactPoint>& contacts,int k,Matrix& A);
153 void GetFrictionConePlanes(const std::vector<ContactPoint>& contacts,int k,SparseMatrix& A);
154 void GetFrictionConePlanes(const ContactFormation& s,int k,SparseMatrix& A);
155 
163 void GetFrictionConePlanes(const std::vector<ContactPoint2D>& contacts,Matrix& A);
164 void GetFrictionConePlanes(const std::vector<ContactPoint2D>& contacts,SparseMatrix& A);
165 
166 
167 
168 
169 
177 {
179  CustomContactPoint(const ContactPoint& cp,int numFCEdges=4);
181  void set(const ContactPoint& cp,int numFCEdges=4);
183  void setRobustnessFactor(Real offset);
185  void addNormalForceBounds(Real minimum,Real maximum);
187  void calculateForceMatrix(int numFCEdges=4);
190  void calculateWrenchMatrix(int numFCEdges=4);
193  int numForceVariables() const;
195  int numConstraints() const;
196 
197  Vector3 x;
198  Vector3 n;
199  Real kFriction;
200  Matrix forceMatrix;
201  Vector forceOffset;
202  Matrix wrenchMatrix;
203  Vector wrenchOffset;
204 };
205 
212 {
216  void set(const ContactPoint2D& cp);
218  void setRobustnessFactor(Real offset);
220  void addNormalForceBounds(Real minimum,Real maximum);
222  void calculateForceMatrix();
225  void calculateWrenchMatrix();
228  int numForceVariables() const;
230  int numConstraints() const;
231 
232  Vector2 x;
233  Vector2 n;
234  Real kFriction;
235  Matrix forceMatrix;
236  Vector forceOffset;
237  Matrix wrenchMatrix;
238  Vector wrenchOffset;
239 };
240 
250 {
252  void clear();
254  void set(int link,const std::vector<ContactPoint>& contacts,int numFCEdges);
256  void set(int link,const std::vector<CustomContactPoint>& contacts);
258  void set(const ContactFormation& formation,int numFCEdges);
260  void concat(const CustomContactFormation& formation);
263  void addLinkForceLimit(int link,const Vector3& direction,Real maximum);
266  void addLinkWrenchLimit(int link,const Vector3& fdirection,const Vector3& mdirection,Real maximum);
268  void addForceLimit(const std::vector<int>& contacts,const Vector3& direction,Real maximum);
271  void addWrenchLimit(const std::vector<int>& contacts,const Vector3& fdirection,const Vector3& mdirection,Real maximum);
274  void addLinkForceConstraint(int link,const Matrix& A,const Vector& b,bool equality=false);
277  void addLinkWrenchConstraint(int link,const Matrix& A,const Vector& b,bool equality=false);
281  void addForceConstraint(const std::vector<int>& contacts,const Matrix& A,const Vector& b,bool equality=false);
284  void addForceConstraint(const std::vector<int>& contacts,const std::vector<Matrix>& A,const Vector& b,bool equality=false);
288  void addWrenchConstraint(const std::vector<int>& contacts,const Matrix& A,const Vector& b,bool equality=false);
291  void addWrenchConstraint(const std::vector<int>& contacts,const std::vector<Matrix>& A,const Vector& b,bool equality=false);
293  int numForceVariables() const;
295  int numConstraints() const;
296 
297  std::vector<int> links;
298  std::vector<CustomContactPoint> contacts;
299  std::vector<int> targets;
300  std::vector<std::vector<int> > constraintGroups;
301  std::vector<std::vector<Matrix> > constraintMatrices;
302  std::vector<Vector> constraintOffsets;
303  std::vector<bool> constraintEqualities;
304 };
305 
310 void GetForceMatrix(const std::vector<CustomContactPoint>& contacts,SparseMatrix& A);
311 void GetForceMatrix(const CustomContactFormation& contacts,SparseMatrix& A);
312 
313 
320 void GetWrenchMatrix(const std::vector<CustomContactPoint>& contacts,const Vector3& cm,Matrix& A);
321 void GetWrenchMatrix(const std::vector<CustomContactPoint>& contacts,const Vector3& cm,SparseMatrix& A);
322 void GetWrenchMatrix(const CustomContactFormation& contacts,const Vector3& cm,SparseMatrix& A);
323 
324 
334 void GetFrictionConePlanes(const std::vector<CustomContactPoint>& contacts,Matrix& A,Vector& b);
335 void GetFrictionConePlanes(const std::vector<CustomContactPoint>& contacts,SparseMatrix& A,Vector& b);
336 void GetFrictionConePlanes(const CustomContactFormation& s,SparseMatrix& A,Vector& b);
337 
345 void GetFrictionConePlanes(const std::vector<CustomContactPoint2D>& contacts,Matrix& A,Vector& b);
346 void GetFrictionConePlanes(const std::vector<CustomContactPoint2D>& contacts,SparseMatrix& A,Vector& b);
347 
348 
349 
350 #endif
Polygonal pyramid representation of the friction cone.
Definition: Contact.h:87
A 2x2 matrix class.
Definition: math3d/primitives.h:333
A robot-environment contact formation. The list of contacts contacts[i] is associated with links[i] (...
Definition: Contact.h:61
Definition: Contact.h:211
A single contact point, i.e. a position, normal, and friction coefficient.
Definition: Contact.h:15
A 3D vector class.
Definition: math3d/primitives.h:136
A contact point with custom force / wrench constraints.
Definition: Contact.h:176
Class declarations for useful 3D math types.
Contains all the definitions in the Math3D package.
Definition: AnyGeometry.h:13
A more advanced ContactFormation that accepts custom contact points and custom constraints.
Definition: Contact.h:249
A 3x3 matrix class.
Definition: math3d/primitives.h:469
A 2D vector class.
Definition: math3d/primitives.h:41
A 2D contact point, i.e. a position, normal, and friction coefficient.
Definition: Contact.h:37
void concat(std::vector< T > &a, const std::vector< T > &b)
Concatenates b onto the end of a.
Definition: arrayutils.h:213