DART  6.7.3
ContactConstraint.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2019, 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 
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 constraint {
48 
51 {
52 public:
54  ContactConstraint(collision::Contact& contact, double timeStep);
55 
57  ~ContactConstraint() override = default;
58 
59  //----------------------------------------------------------------------------
60  // Property settings
61  //----------------------------------------------------------------------------
62 
64  static void setErrorAllowance(double allowance);
65 
67  static double getErrorAllowance();
68 
70  static void setErrorReductionParameter(double erp);
71 
73  static double getErrorReductionParameter();
74 
76  static void setMaxErrorReductionVelocity(double erv);
77 
79  static double getMaxErrorReductionVelocity();
80 
82  static void setConstraintForceMixing(double cfm);
83 
85  static double getConstraintForceMixing();
86 
88  void setFrictionDirection(const Eigen::Vector3d& dir);
89 
91  const Eigen::Vector3d& getFrictionDirection1() const;
92 
93  //----------------------------------------------------------------------------
94  // Friendship
95  //----------------------------------------------------------------------------
96 
97  friend class ConstraintSolver;
98  friend class ConstrainedGroup;
99 
100 protected:
101  //----------------------------------------------------------------------------
102  // Constraint virtual functions
103  //----------------------------------------------------------------------------
104 
105  // Documentation inherited
106  void update() override;
107 
108  // Documentation inherited
109  void getInformation(ConstraintInfo* info) override;
110 
111  // Documentation inherited
112  void applyUnitImpulse(std::size_t index) override;
113 
114  // Documentation inherited
115  void getVelocityChange(double* vel, bool withCfm) override;
116 
117  // Documentation inherited
118  void excite() override;
119 
120  // Documentation inherited
121  void unexcite() override;
122 
123  // Documentation inherited
124  void applyImpulse(double* lambda) override;
125 
126  // Documentation inherited
127  dynamics::SkeletonPtr getRootSkeleton() const override;
128 
129  // Documentation inherited
130  void uniteSkeletons() override;
131 
132  // Documentation inherited
133  bool isActive() const override;
134 
135 private:
136  using TangentBasisMatrix = Eigen::Matrix<double, 3, 2>;
137 
141  void getRelVelocity(double* relVel);
142 
145 
147  TangentBasisMatrix getTangentBasisMatrixODE(const Eigen::Vector3d& n);
148 
149 private:
151  double mTimeStep;
152 
155 
158 
161 
163  Eigen::Vector3d mFirstFrictionalDirection;
164 
167 
170 
173 
175  Eigen::Matrix<double, 6, Eigen::Dynamic> mSpatialNormalA;
176 
178  Eigen::Matrix<double, 6, Eigen::Dynamic> mSpatialNormalB;
179 
182 
184  std::size_t mAppliedImpulseIndex;
185 
188 
190  bool mActive;
191 
193  static double mErrorAllowance;
194 
198 
201 
205  static double mConstraintForceMixing;
206 };
207 // TODO(JS): Create SelfContactConstraint.
208 
209 } // namespace constraint
210 } // namespace dart
211 
212 #endif // DART_CONSTRAINT_CONTACTCONSTRAINT_HPP_
std::size_t index
Definition: SkelParser.cpp:1617
ConstrainedGroup is a group of skeletons that interact each other with constraints.
Definition: ConstrainedGroup.hpp:58
Constraint is a base class of concrete constraints classes.
Definition: ConstraintBase.hpp:75
ConstraintSolver manages constraints and computes constraint impulses.
Definition: ConstraintSolver.hpp:56
ContactConstraint represents a contact constraint between two bodies.
Definition: ContactConstraint.hpp:51
double mTimeStep
Time step.
Definition: ContactConstraint.hpp:151
const Eigen::Vector3d & getFrictionDirection1() const
Get first frictional direction.
Definition: ContactConstraint.cpp:335
void setFrictionDirection(const Eigen::Vector3d &dir)
Set first frictional direction.
Definition: ContactConstraint.cpp:329
bool mIsFrictionOn
Definition: ContactConstraint.hpp:181
void update() override
Update constraint using updated Skeleton's states.
Definition: ContactConstraint.cpp:341
static void setErrorAllowance(double allowance)
Set global error reduction parameter.
Definition: ContactConstraint.cpp:233
void excite() override
Excite the constraint.
Definition: ContactConstraint.cpp:573
static double mMaxErrorReductionVelocity
Maximum error reduction velocity.
Definition: ContactConstraint.hpp:200
bool mActive
Definition: ContactConstraint.hpp:190
bool isActive() const override
Return true if this constraint is active.
Definition: ContactConstraint.cpp:661
static void setErrorReductionParameter(double erp)
Set global error reduction parameter.
Definition: ContactConstraint.cpp:254
void applyImpulse(double *lambda) override
Apply computed constraint impulse to constrained skeletons.
Definition: ContactConstraint.cpp:593
static void setMaxErrorReductionVelocity(double erv)
Set global error reduction parameter.
Definition: ContactConstraint.cpp:280
static double getConstraintForceMixing()
Get global constraint force mixing parameter.
Definition: ContactConstraint.cpp:323
Eigen::Matrix< double, 6, Eigen::Dynamic > mSpatialNormalB
Local body jacobians for mBodyNode2.
Definition: ContactConstraint.hpp:178
double mFrictionCoeff
Coefficient of Friction.
Definition: ContactConstraint.hpp:166
void updateFirstFrictionalDirection()
Definition: ContactConstraint.cpp:678
void getInformation(ConstraintInfo *info) override
Fill LCP variables.
Definition: ContactConstraint.cpp:350
static double mErrorReductionParameter
Global constraint error redection parameter in the range of [0, 1].
Definition: ContactConstraint.hpp:197
static double getErrorAllowance()
Get global error reduction parameter.
Definition: ContactConstraint.cpp:248
collision::Contact & mContact
Contact between mBodyNode1 and mBodyNode2.
Definition: ContactConstraint.hpp:160
void getRelVelocity(double *relVel)
Get change in relative velocity at contact point due to external impulse.
Definition: ContactConstraint.cpp:650
TangentBasisMatrix getTangentBasisMatrixODE(const Eigen::Vector3d &n)
Definition: ContactConstraint.cpp:692
static double getMaxErrorReductionVelocity()
Get global error reduction parameter.
Definition: ContactConstraint.cpp:295
std::size_t mAppliedImpulseIndex
Index of applied impulse.
Definition: ContactConstraint.hpp:184
dynamics::BodyNode * mBodyNodeA
Fircst body node.
Definition: ContactConstraint.hpp:154
void applyUnitImpulse(std::size_t index) override
Apply unit impulse to constraint space.
Definition: ContactConstraint.cpp:480
void unexcite() override
Unexcite the constraint.
Definition: ContactConstraint.cpp:583
~ContactConstraint() override=default
Destructor.
void getVelocityChange(double *vel, bool withCfm) override
Get velocity change due to the uint impulse.
Definition: ContactConstraint.cpp:550
static double getErrorReductionParameter()
Get global error reduction parameter.
Definition: ContactConstraint.cpp:274
static double mErrorAllowance
Global constraint error allowance.
Definition: ContactConstraint.hpp:193
bool mIsBounceOn
Definition: ContactConstraint.hpp:187
Eigen::Matrix< double, 6, Eigen::Dynamic > mSpatialNormalA
Local body jacobians for mBodyNode1.
Definition: ContactConstraint.hpp:175
double mRestitutionCoeff
Coefficient of restitution.
Definition: ContactConstraint.hpp:169
void uniteSkeletons() override
Definition: ContactConstraint.cpp:748
Eigen::Matrix< double, 3, 2 > TangentBasisMatrix
Definition: ContactConstraint.hpp:136
static double mConstraintForceMixing
Global constraint force mixing parameter in the range of [1e-9, 1].
Definition: ContactConstraint.hpp:205
dynamics::BodyNode * mBodyNodeB
Second body node.
Definition: ContactConstraint.hpp:157
dynamics::SkeletonPtr getRootSkeleton() const override
Definition: ContactConstraint.cpp:667
bool mIsSelfCollision
Whether this contact is self-collision.
Definition: ContactConstraint.hpp:172
ContactConstraint(collision::Contact &contact, double timeStep)
Constructor.
Definition: ContactConstraint.cpp:67
Eigen::Vector3d mFirstFrictionalDirection
First frictional direction.
Definition: ContactConstraint.hpp:163
static void setConstraintForceMixing(double cfm)
Set global constraint force mixing parameter.
Definition: ContactConstraint.cpp:301
BodyNode class represents a single node of the skeleton.
Definition: BodyNode.hpp:78
std::shared_ptr< Skeleton > SkeletonPtr
Definition: SmartPointer.hpp:60
Definition: BulletCollisionDetector.cpp:63
Contact information.
Definition: Contact.hpp:45
ConstraintInfo.
Definition: ConstraintBase.hpp:50