dart
ContactConstraint.hpp
1 /*
2  * Copyright (c) 2011-2021, The DART development contributors
3  * All rights reserved.
4  *
5  * The list of contributors can be found at:
6  * https://github.com/dartsim/dart/blob/master/LICENSE
7  *
8  * This file is provided under the following "BSD-style" License:
9  * Redistribution and use in source and binary forms, with or
10  * without modification, are permitted provided that the following
11  * conditions are met:
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef DART_CONSTRAINT_CONTACTCONSTRAINT_HPP_
34 #define DART_CONSTRAINT_CONTACTCONSTRAINT_HPP_
35 
36 #include "dart/dynamics/CollisionDetector.hpp"
37 #include "dart/dynamics/ConstraintBase.hpp"
38 #include "dart/math/MathTypes.hpp"
39 
40 namespace dart {
41 
42 namespace dynamics {
43 class BodyNode;
44 class Skeleton;
45 } // namespace dynamics
46 
47 namespace dynamics {
48 
51 {
52 public:
54  ContactConstraint(collision::Contact& contact, double timeStep);
55 
57  ~ContactConstraint() override = default;
58 
59  // Documentation inherited
60  const std::string& getType() const override;
61 
63  static const std::string& getStaticType();
64 
65  //----------------------------------------------------------------------------
66  // Property settings
67  //----------------------------------------------------------------------------
68 
70  static void setErrorAllowance(double allowance);
71 
73  static double getErrorAllowance();
74 
76  static void setErrorReductionParameter(double erp);
77 
79  static double getErrorReductionParameter();
80 
82  static void setMaxErrorReductionVelocity(double erv);
83 
85  static double getMaxErrorReductionVelocity();
86 
88  static void setConstraintForceMixing(double cfm);
89 
91  static double getConstraintForceMixing();
92 
94  void setFrictionDirection(const Eigen::Vector3d& dir);
95 
97  const Eigen::Vector3d& getFrictionDirection1() const;
98 
99  //----------------------------------------------------------------------------
100  // Friendship
101  //----------------------------------------------------------------------------
102 
103  friend class ConstraintSolver;
104  friend class ConstrainedGroup;
105 
106 protected:
107  //----------------------------------------------------------------------------
108  // Constraint virtual functions
109  //----------------------------------------------------------------------------
110 
111  // Documentation inherited
112  void update() override;
113 
114  // Documentation inherited
115  void getInformation(ConstraintInfo* info) override;
116 
117  // Documentation inherited
118  void applyUnitImpulse(std::size_t index) override;
119 
120  // Documentation inherited
121  void getVelocityChange(double* vel, bool withCfm) override;
122 
123  // Documentation inherited
124  void excite() override;
125 
126  // Documentation inherited
127  void unexcite() override;
128 
129  // Documentation inherited
130  void applyImpulse(double* lambda) override;
131 
132  // Documentation inherited
133  dynamics::SkeletonPtr getRootSkeleton() const override;
134 
135  // Documentation inherited
136  void uniteSkeletons() override;
137 
138  // Documentation inherited
139  bool isActive() const override;
140 
141  static double computeFrictionCoefficient(
142  const dynamics::ShapeNode* shapeNode);
143  static double computePrimaryFrictionCoefficient(
144  const dynamics::ShapeNode* shapeNode);
145  static double computeSecondaryFrictionCoefficient(
146  const dynamics::ShapeNode* shapeNode);
147  static double computePrimarySlipCompliance(
148  const dynamics::ShapeNode* shapeNode);
149  static double computeSecondarySlipCompliance(
150  const dynamics::ShapeNode* shapeNode);
151  static Eigen::Vector3d computeWorldFirstFrictionDir(
152  const dynamics::ShapeNode* shapenode);
153  static double computeRestitutionCoefficient(
154  const dynamics::ShapeNode* shapeNode);
155 
156 private:
157  using TangentBasisMatrix = Eigen::Matrix<double, 3, 2>;
158 
162  void getRelVelocity(double* relVel);
163 
165  void updateFirstFrictionalDirection();
166 
168  TangentBasisMatrix getTangentBasisMatrixODE(const Eigen::Vector3d& n);
169 
170  // The following functions for getting and setting slip compliance and
171  // accessing the contact object are meant to be used by ConstraintSolver to
172  // update the slip compliances based on the number of contacts between the
173  // collision objects.
174  //
176  double getPrimarySlipCompliance() const;
177 
179  void setPrimarySlipCompliance(double slip);
180 
182  double getSecondarySlipCompliance() const;
183 
185  void setSecondarySlipCompliance(double slip);
186 
188  const collision::Contact& getContact() const;
189 
190 private:
192  double mTimeStep;
193 
195  dynamics::BodyNode* mBodyNodeA;
196 
198  dynamics::BodyNode* mBodyNodeB;
199 
201  collision::Contact& mContact;
202 
204  Eigen::Vector3d mFirstFrictionalDirection;
205 
207  double mPrimaryFrictionCoeff;
208 
210  double mSecondaryFrictionCoeff;
211 
213  double mPrimarySlipCompliance;
214 
216  double mSecondarySlipCompliance;
217 
219  double mRestitutionCoeff;
220 
222  bool mIsSelfCollision;
223 
225  Eigen::Matrix<double, 6, Eigen::Dynamic> mSpatialNormalA;
226 
228  Eigen::Matrix<double, 6, Eigen::Dynamic> mSpatialNormalB;
229 
231  bool mIsFrictionOn;
232 
234  std::size_t mAppliedImpulseIndex;
235 
237  bool mIsBounceOn;
238 
240  bool mActive;
241 
243  static double mErrorAllowance;
244 
247  static double mErrorReductionParameter;
248 
250  static double mMaxErrorReductionVelocity;
251 
255  static double mConstraintForceMixing;
256 };
257 // TODO(JS): Create SelfContactConstraint.
258 
259 } // namespace dynamics
260 } // namespace dart
261 
262 #endif // DART_CONSTRAINT_CONTACTCONSTRAINT_HPP_
ConstrainedGroup is a group of skeletons that interact each other with constraints.
Definition: ConstrainedGroup.hpp:57
Constraint is a base class of concrete constraints classes.
Definition: ConstraintBase.hpp:74
ConstraintInfo.
Definition: ConstraintBase.hpp:49
ConstraintSolver manages constraints and computes constraint impulses.
Definition: ConstraintSolver.hpp:56
Definition: Aspect.cpp:40
Definition: ShapeNode.hpp:48
BodyNode class represents a single node of the skeleton.
Definition: BodyNode.hpp:74
Contact information.
Definition: Contact.hpp:44
ContactConstraint represents a contact constraint between two bodies.
Definition: ContactConstraint.hpp:50