DART 6.10.1
Loading...
Searching...
No Matches
ConstraintSolver.hpp
Go to the documentation of this file.
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_CONSTRAINTSOVER_HPP_
34#define DART_CONSTRAINT_CONSTRAINTSOVER_HPP_
35
36#include <vector>
37
38#include <Eigen/Dense>
39
45
46namespace dart {
47
48namespace dynamics {
49class Skeleton;
50class ShapeNodeCollisionObject;
51} // namespace dynamics
52
53namespace constraint {
54
57{
58public:
65 explicit ConstraintSolver(double timeStep);
66
67 // TODO(JS): Remove timeStep. The timestep can be set by world when a
68 // constraint solver is assigned to a world.
69 // Deprecate
70
73
75 // TODO: implement copy constructor since this class contains a pointer to
76 // allocated memory.
77 ConstraintSolver(const ConstraintSolver& other) = delete;
78
80 virtual ~ConstraintSolver() = default;
81
83 void addSkeleton(const dynamics::SkeletonPtr& skeleton);
84
86 void addSkeletons(const std::vector<dynamics::SkeletonPtr>& skeletons);
87
89 const std::vector<dynamics::SkeletonPtr>& getSkeletons() const;
90
92 void removeSkeleton(const dynamics::SkeletonPtr& skeleton);
93
95 void removeSkeletons(const std::vector<dynamics::SkeletonPtr>& skeletons);
96
98 void removeAllSkeletons();
99
101 void addConstraint(const ConstraintBasePtr& constraint);
102
104 void removeConstraint(const ConstraintBasePtr& constraint);
105
108
111 std::size_t getNumConstraints() const;
112
115
118
120 std::vector<constraint::ConstraintBasePtr> getConstraints();
121
123 std::vector<constraint::ConstConstraintBasePtr> getConstraints() const;
124
127
129 virtual void setTimeStep(double _timeStep);
130
132 double getTimeStep() const;
133
137 DART_DEPRECATED(6.0)
138 void setCollisionDetector(collision::CollisionDetector* collisionDetector);
139
142 const std::shared_ptr<collision::CollisionDetector>& collisionDetector);
143
145 collision::CollisionDetectorPtr getCollisionDetector();
146
148 collision::ConstCollisionDetectorPtr getCollisionDetector() const;
149
152 collision::CollisionGroupPtr getCollisionGroup();
153
156 collision::ConstCollisionGroupPtr getCollisionGroup() const;
157
160 collision::CollisionOption& getCollisionOption();
161
164 const collision::CollisionOption& getCollisionOption() const;
165
167 collision::CollisionResult& getLastCollisionResult();
168
170 const collision::CollisionResult& getLastCollisionResult() const;
171
173 DART_DEPRECATED(6.7)
174 void setLCPSolver(std::unique_ptr<LCPSolver> lcpSolver);
175
177 DART_DEPRECATED(6.7)
178 LCPSolver* getLCPSolver() const;
179
181 void solve();
182
185 virtual void setFromOtherConstraintSolver(const ConstraintSolver& other);
186
187protected:
188 // TODO(JS): Docstring
189 virtual void solveConstrainedGroup(ConstrainedGroup& group) = 0;
190
192 bool containSkeleton(const dynamics::ConstSkeletonPtr& skeleton) const;
193
195 bool checkAndAddSkeleton(const dynamics::SkeletonPtr& skeleton);
196
198 bool containConstraint(const ConstConstraintBasePtr& constraint) const;
199
201 bool checkAndAddConstraint(const ConstraintBasePtr& constraint);
202
204 void updateConstraints();
205
208
211
213 bool isSoftContact(const collision::Contact& contact) const;
214
216
218 collision::CollisionDetectorPtr mCollisionDetector;
219
221 collision::CollisionGroupPtr mCollisionGroup;
222
224 collision::CollisionOption mCollisionOption;
225
227 collision::CollisionResult mCollisionResult;
228
230 double mTimeStep;
231
233 std::vector<dynamics::SkeletonPtr> mSkeletons;
234
237
240
243
246
249
253
256
259
262};
263
264} // namespace constraint
265} // namespace dart
266
267#endif // DART_CONSTRAINT_CONSTRAINTSOVER_HPP_
#define DART_DEPRECATED(version)
Definition Deprecated.hpp:51
std::size_t index
Definition SkelParser.cpp:1672
Definition CollisionDetector.hpp:58
ConstrainedGroup is a group of skeletons that interact each other with constraints.
Definition ConstrainedGroup.hpp:58
ConstraintSolver manages constraints and computes constraint impulses.
Definition ConstraintSolver.hpp:57
std::vector< SoftContactConstraintPtr > mSoftContactConstraints
Soft contact constraints those are automatically created.
Definition ConstraintSolver.hpp:239
void removeSkeletons(const std::vector< dynamics::SkeletonPtr > &skeletons)
Remove multiple skeletons.
Definition ConstraintSolver.cpp:153
std::vector< dynamics::SkeletonPtr > mSkeletons
Skeleton list.
Definition ConstraintSolver.hpp:233
std::vector< constraint::ConstraintBasePtr > getConstraints()
Returns all the constraints added to this ConstraintSolver.
Definition ConstraintSolver.cpp:224
collision::CollisionResult mCollisionResult
Last collision checking result.
Definition ConstraintSolver.hpp:227
void addSkeletons(const std::vector< dynamics::SkeletonPtr > &skeletons)
Add mutiple skeletons.
Definition ConstraintSolver.cpp:120
void clearLastCollisionResult()
Clears the last collision result.
Definition ConstraintSolver.cpp:244
void removeAllConstraints()
Remove all constraints.
Definition ConstraintSolver.cpp:200
bool containConstraint(const ConstConstraintBasePtr &constraint) const
Check if the constraint is contained in this solver.
Definition ConstraintSolver.cpp:429
virtual void solveConstrainedGroup(ConstrainedGroup &group)=0
std::vector< JointCoulombFrictionConstraintPtr > mJointCoulombFrictionConstraints
Joint Coulomb friction constraints those are automatically created.
Definition ConstraintSolver.hpp:252
virtual ~ConstraintSolver()=default
Destructor.
void removeConstraint(const ConstraintBasePtr &constraint)
Remove a constraint.
Definition ConstraintSolver.cpp:183
ConstraintSolver(const ConstraintSolver &other)=delete
Copy constructor.
collision::CollisionGroupPtr getCollisionGroup()
Return collision group of collision objects that are added to this ConstraintSolver.
Definition ConstraintSolver.cpp:307
ConstraintSolver()
Default constructor.
Definition ConstraintSolver.cpp:82
void solveConstrainedGroups()
Solve constrained groups.
Definition ConstraintSolver.cpp:733
std::vector< ContactConstraintPtr > mContactConstraints
Contact constraints those are automatically created.
Definition ConstraintSolver.hpp:236
bool checkAndAddSkeleton(const dynamics::SkeletonPtr &skeleton)
Add skeleton if the constraint is not contained in this solver.
Definition ConstraintSolver.cpp:413
void solve()
Solve constraint impulses and apply them to the skeletons.
Definition ConstraintSolver.cpp:364
virtual void setFromOtherConstraintSolver(const ConstraintSolver &other)
Sets this constraint solver using other constraint solver.
Definition ConstraintSolver.cpp:385
std::size_t getNumConstraints() const
Returns the number of constraints that was manually added to this ConstraintSolver.
Definition ConstraintSolver.cpp:206
void addSkeleton(const dynamics::SkeletonPtr &skeleton)
Add single skeleton.
Definition ConstraintSolver.cpp:99
collision::CollisionDetectorPtr mCollisionDetector
Collision detector.
Definition ConstraintSolver.hpp:218
constraint::ConstraintBasePtr getConstraint(std::size_t index)
Returns a constraint by index.
Definition ConstraintSolver.cpp:212
bool checkAndAddConstraint(const ConstraintBasePtr &constraint)
Add constraint if the constraint is not contained in this solver.
Definition ConstraintSolver.cpp:438
void addConstraint(const ConstraintBasePtr &constraint)
Add a constraint.
Definition ConstraintSolver.cpp:168
collision::CollisionDetectorPtr getCollisionDetector()
Get collision detector.
Definition ConstraintSolver.cpp:294
double getTimeStep() const
Get time step.
Definition ConstraintSolver.cpp:257
virtual void setTimeStep(double _timeStep)
Set time step.
Definition ConstraintSolver.cpp:250
collision::CollisionOption & getCollisionOption()
Returns collision option that is used for collision checkings in this ConstraintSolver to generate co...
Definition ConstraintSolver.cpp:319
std::vector< MimicMotorConstraintPtr > mMimicMotorConstraints
Mimic motor constraints those are automatically created.
Definition ConstraintSolver.hpp:248
std::vector< ServoMotorConstraintPtr > mServoMotorConstraints
Servo motor constraints those are automatically created.
Definition ConstraintSolver.hpp:245
void removeSkeleton(const dynamics::SkeletonPtr &skeleton)
Remove single skeleton.
Definition ConstraintSolver.cpp:133
std::vector< ConstrainedGroup > mConstrainedGroups
Constraint group list.
Definition ConstraintSolver.hpp:261
collision::CollisionResult & getLastCollisionResult()
Return the last collision checking result.
Definition ConstraintSolver.cpp:331
std::vector< ConstraintBasePtr > mManualConstraints
Constraints that manually added.
Definition ConstraintSolver.hpp:255
const std::vector< dynamics::SkeletonPtr > & getSkeletons() const
Returns all the skeletons added to this ConstraintSolver.
Definition ConstraintSolver.cpp:127
collision::CollisionGroupPtr mCollisionGroup
Collision group.
Definition ConstraintSolver.hpp:221
std::vector< ConstraintBasePtr > mActiveConstraints
Active constraints.
Definition ConstraintSolver.hpp:258
bool isSoftContact(const collision::Contact &contact) const
Return true if at least one of colliding body is soft body.
Definition ConstraintSolver.cpp:740
double mTimeStep
Time step.
Definition ConstraintSolver.hpp:230
void setLCPSolver(std::unique_ptr< LCPSolver > lcpSolver)
Set LCP solver.
Definition ConstraintSolver.cpp:344
void removeAllSkeletons()
Remove all skeletons in this constraint solver.
Definition ConstraintSolver.cpp:161
std::vector< JointLimitConstraintPtr > mJointLimitConstraints
Joint limit constraints those are automatically created.
Definition ConstraintSolver.hpp:242
void updateConstraints()
Update constraints.
Definition ConstraintSolver.cpp:454
collision::CollisionOption mCollisionOption
Collision detection option.
Definition ConstraintSolver.hpp:224
bool containSkeleton(const dynamics::ConstSkeletonPtr &skeleton) const
Check if the skeleton is contained in this solver.
Definition ConstraintSolver.cpp:396
LCPSolver * getLCPSolver() const
Get LCP solver.
Definition ConstraintSolver.cpp:353
void setCollisionDetector(collision::CollisionDetector *collisionDetector)
Set collision detector.
Definition ConstraintSolver.cpp:263
void buildConstrainedGroups()
Build constrained groupsContact.
Definition ConstraintSolver.cpp:677
Definition LCPSolver.hpp:45
std::shared_ptr< JointCoulombFrictionConstraint > JointCoulombFrictionConstraintPtr
Definition SmartPointer.hpp:52
std::shared_ptr< const ConstraintBase > ConstConstraintBasePtr
Definition SmartPointer.hpp:45
std::shared_ptr< ContactConstraint > ContactConstraintPtr
Definition SmartPointer.hpp:47
std::shared_ptr< MimicMotorConstraint > MimicMotorConstraintPtr
Definition SmartPointer.hpp:51
std::shared_ptr< ServoMotorConstraint > ServoMotorConstraintPtr
Definition SmartPointer.hpp:50
std::shared_ptr< JointLimitConstraint > JointLimitConstraintPtr
Definition SmartPointer.hpp:49
std::shared_ptr< ConstraintBase > ConstraintBasePtr
Definition SmartPointer.hpp:45
std::shared_ptr< SoftContactConstraint > SoftContactConstraintPtr
Definition SmartPointer.hpp:48
std::shared_ptr< const Skeleton > ConstSkeletonPtr
Definition SmartPointer.hpp:60
std::shared_ptr< Skeleton > SkeletonPtr
Definition SmartPointer.hpp:60
Definition BulletCollisionDetector.cpp:65
Definition SharedLibraryManager.hpp:46