DART  6.10.1
DegreeOfFreedom.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_DYNAMICS_DEGREEOFFREEDOM_HPP_
34 #define DART_DYNAMICS_DEGREEOFFREEDOM_HPP_
35 
36 #include <memory>
37 #include <string>
38 #include <Eigen/Core>
39 
41 #include "dart/common/Subject.hpp"
43 
44 namespace dart {
45 namespace dynamics {
46 
47 class Skeleton;
48 class Joint;
49 class BodyNode;
50 
54 class DegreeOfFreedom : public virtual common::Subject
55 {
56 public:
57  friend class Joint;
58  template <class>
59  friend class GenericJoint;
60  friend class Skeleton;
61 
62  DegreeOfFreedom(const DegreeOfFreedom&) = delete;
63 
70  const std::string& setName(
71  const std::string& _name, bool _preserveName = true);
72 
88  const std::string& getName() const;
89 
94  void preserveName(bool _preserve);
95 
97  bool isNamePreserved() const;
98 
100  std::size_t getIndexInSkeleton() const;
101 
103  std::size_t getIndexInTree() const;
104 
106  std::size_t getIndexInJoint() const;
107 
109  std::size_t getTreeIndex() const;
110 
111  //----------------------------------------------------------------------------
113  //----------------------------------------------------------------------------
114 
116  void setCommand(double _command);
117 
119  double getCommand() const;
120 
122  void resetCommand();
123 
125 
126  //----------------------------------------------------------------------------
128  //----------------------------------------------------------------------------
129 
131  void setPosition(double _position);
132 
134  double getPosition() const;
135 
137  void setPositionLimits(double _lowerLimit, double _upperLimit);
138 
140  void setPositionLimits(const std::pair<double, double>& _limits);
141 
143  std::pair<double, double> getPositionLimits() const;
144 
146  void setPositionLowerLimit(double _limit);
147 
149  double getPositionLowerLimit() const;
150 
152  void setPositionUpperLimit(double _limit);
153 
155  double getPositionUpperLimit() const;
156 
161  bool isCyclic() const;
162 
164  bool hasPositionLimit() const;
165 
167  void resetPosition();
168 
170  void setInitialPosition(double _initial);
171 
173  double getInitialPosition() const;
174 
176 
177  //----------------------------------------------------------------------------
179  //----------------------------------------------------------------------------
180 
182  void setVelocity(double _velocity);
183 
185  double getVelocity() const;
186 
188  void setVelocityLimits(double _lowerLimit, double _upperLimit);
189 
191  void setVelocityLimits(const std::pair<double, double>& _limits);
192 
194  std::pair<double, double> getVelocityLimits() const;
195 
197  void setVelocityLowerLimit(double _limit);
198 
200  double getVelocityLowerLimit() const;
201 
203  void setVelocityUpperLimit(double _limit);
204 
206  double getVelocityUpperLimit() const;
207 
209  void resetVelocity();
210 
212  void setInitialVelocity(double _initial);
213 
215  double getInitialVelocity() const;
216 
218 
219  //----------------------------------------------------------------------------
221  //----------------------------------------------------------------------------
222 
224  void setAcceleration(double _acceleration);
225 
227  double getAcceleration() const;
228 
230  void resetAcceleration();
231 
233  void setAccelerationLimits(double _lowerLimit, double _upperLimit);
234 
236  void setAccelerationLimits(const std::pair<double, double>& _limits);
237 
239  std::pair<double, double> getAccelerationLimits() const;
240 
242  void setAccelerationLowerLimit(double _limit);
243 
245  double getAccelerationLowerLimit() const;
246 
248  void setAccelerationUpperLimit(double _limit);
249 
251  double getAccelerationUpperLimit() const;
252 
254 
255  //----------------------------------------------------------------------------
257  //----------------------------------------------------------------------------
258 
260  void setForce(double _force);
261 
263  double getForce() const;
264 
266  void resetForce();
267 
269  void setForceLimits(double _lowerLimit, double _upperLimit);
270 
272  void setForceLimits(const std::pair<double, double>& _limits);
273 
275  std::pair<double, double> getForceLimits() const;
276 
278  void setForceLowerLimit(double _limit);
279 
281  double getForceLowerLimit() const;
282 
284  void setForceUpperLimit(double _limit);
285 
287  double getForceUpperLimit() const;
288 
290 
291  //----------------------------------------------------------------------------
293  //----------------------------------------------------------------------------
294 
296  void setVelocityChange(double _velocityChange);
297 
299  double getVelocityChange() const;
300 
302  void resetVelocityChange();
303 
305 
306  //----------------------------------------------------------------------------
308  //----------------------------------------------------------------------------
309 
311  void setConstraintImpulse(double _impulse);
312 
314  double getConstraintImpulse() const;
315 
317  void resetConstraintImpulse();
318 
320 
321  //----------------------------------------------------------------------------
323  //----------------------------------------------------------------------------
324 
326  void setSpringStiffness(double _k);
327 
329  double getSpringStiffness() const;
330 
332  void setRestPosition(double _q0);
333 
335  double getRestPosition() const;
336 
339  void setDampingCoefficient(double _coeff);
340 
343  double getDampingCoefficient() const;
344 
346  void setCoulombFriction(double _friction);
347 
349  double getCoulombFriction() const;
350 
352 
353  //----------------------------------------------------------------------------
355  //----------------------------------------------------------------------------
356 
358  Joint* getJoint();
359 
361  const Joint* getJoint() const;
362 
365 
368 
371 
373  const BodyNode* getChildBodyNode() const;
374 
377 
379  const BodyNode* getParentBodyNode() const;
380 
382 
383 protected:
386  DegreeOfFreedom(Joint* _joint, std::size_t _indexInJoint);
387 
392  std::size_t mIndexInJoint;
393 
395  std::size_t mIndexInSkeleton;
396 
398  std::size_t mIndexInTree;
399 
402  // Note that we do not need to store BodyNode or Skeleton, because we can
403  // access them through this joint pointer. Moreover, we never need to check
404  // whether mJoint is nullptr, because only Joints are allowed to create a
405  // DegreeOfFreedom and every DegreeOfFreedom is deleted when its Joint is
406  // destructed.
407 };
409 
410 } // namespace dynamics
411 } // namespace dart
412 
413 #endif // DART_DYNAMICS_DEGREEOFFREEDOM_HPP_
#define DART_DECLARE_CLASS_WITH_VIRTUAL_BASE_END
Definition: ClassWithVirtualBase.hpp:44
#define DART_DECLARE_CLASS_WITH_VIRTUAL_BASE_BEGIN
Definition: ClassWithVirtualBase.hpp:43
The Subject class is a base class for any object that wants to report when it gets destroyed.
Definition: Subject.hpp:58
BodyNode class represents a single node of the skeleton.
Definition: BodyNode.hpp:79
DegreeOfFreedom class is a proxy class for accessing single degrees of freedom (aka generalized coord...
Definition: DegreeOfFreedom.hpp:55
double getDampingCoefficient() const
Get coefficient of damping (viscous friction) force for this generalized coordinate.
Definition: DegreeOfFreedom.cpp:462
void resetForce()
Set the generalized force of this DegreeOfFreedom to zero.
Definition: DegreeOfFreedom.cpp:347
void setAccelerationLimits(double _lowerLimit, double _upperLimit)
Set the acceleration limits of this DegreeOfFreedom.
Definition: DegreeOfFreedom.cpp:289
void setVelocity(double _velocity)
Set the velocity of this DegreeOfFreedom.
Definition: DegreeOfFreedom.cpp:196
void setAccelerationUpperLimit(double _limit)
Set the upper acceleration limit of this DegreeOfFreedom.
Definition: DegreeOfFreedom.cpp:323
bool isCyclic() const
Get whether this DOF is cyclic.
Definition: DegreeOfFreedom.cpp:172
void resetPosition()
Set the position of this DegreeOfFreedom to zero.
Definition: DegreeOfFreedom.cpp:178
double getForceUpperLimit() const
Get the upper generalized force limit of this DegreeOfFreedom.
Definition: DegreeOfFreedom.cpp:390
double getPosition() const
Get the position of this DegreeOfFreedom.
Definition: DegreeOfFreedom.cpp:114
void resetConstraintImpulse()
Set the constraint impulse of this generalized coordinate to zero.
Definition: DegreeOfFreedom.cpp:426
void setAcceleration(double _acceleration)
Set the acceleration of this DegreeOfFreedom.
Definition: DegreeOfFreedom.cpp:271
BodyNode * getChildBodyNode()
Get the BodyNode downstream of this DegreeOfFreedom.
Definition: DegreeOfFreedom.cpp:504
void setForce(double _force)
Set the generalized force of this DegreeOfFreedom.
Definition: DegreeOfFreedom.cpp:335
double getCoulombFriction() const
Get Coulomb friction force for this generalized coordinate.
Definition: DegreeOfFreedom.cpp:474
DegreeOfFreedom(const DegreeOfFreedom &)=delete
void setCoulombFriction(double _friction)
Set Coulomb friction force for this generalized coordinate.
Definition: DegreeOfFreedom.cpp:468
std::size_t getIndexInTree() const
Get this DegreeOfFreedom's index within its tree.
Definition: DegreeOfFreedom.cpp:72
std::size_t getIndexInSkeleton() const
Get this DegreeOfFreedom's index within its Skeleton.
Definition: DegreeOfFreedom.cpp:66
double getForce() const
Get the generalized force of this DegreeOfFreedom.
Definition: DegreeOfFreedom.cpp:341
Joint * getJoint()
Get the Joint that this DegreeOfFreedom belongs to.
Definition: DegreeOfFreedom.cpp:480
std::size_t getTreeIndex() const
Get the index of the tree that this DegreeOfFreedom belongs to.
Definition: DegreeOfFreedom.cpp:84
std::pair< double, double > getVelocityLimits() const
Get the velocity limits of this DegreeOfFreedom.
Definition: DegreeOfFreedom.cpp:228
const std::string & getName() const
Get the name of this DegreeOfFreedom.
Definition: DegreeOfFreedom.cpp:48
void resetCommand()
Set the command of this DegreeOfFreedom to zero.
Definition: DegreeOfFreedom.cpp:102
bool hasPositionLimit() const
Get whether the position of this DegreeOfFreedom has limits.
Definition: DegreeOfFreedom.cpp:166
std::pair< double, double > getForceLimits() const
Get the generalized force limits of this DegreeOfFreedom.
Definition: DegreeOfFreedom.cpp:366
std::size_t mIndexInTree
Index of this DegreeOfFreedom within its tree.
Definition: DegreeOfFreedom.hpp:398
void setDampingCoefficient(double _coeff)
Set coefficient of damping (viscous friction) force for this generalized coordinate.
Definition: DegreeOfFreedom.cpp:456
double getAcceleration() const
Get the acceleration of this DegreeOfFreedom.
Definition: DegreeOfFreedom.cpp:277
void setRestPosition(double _q0)
Set rest position for the spring force of this generalized coordinate.
Definition: DegreeOfFreedom.cpp:444
double getRestPosition() const
Get rest position for the spring force of this generalized coordinate.
Definition: DegreeOfFreedom.cpp:450
std::size_t getIndexInJoint() const
Get this DegreeOfFreedom's index within its Joint.
Definition: DegreeOfFreedom.cpp:78
void setVelocityLowerLimit(double _limit)
Set the lower velocity limit of this DegreeOfFreedom.
Definition: DegreeOfFreedom.cpp:235
void setAccelerationLowerLimit(double _limit)
Set the lower acceleration limit of this DegreeOfFreedom.
Definition: DegreeOfFreedom.cpp:311
void setSpringStiffness(double _k)
Set stiffness of the spring force for this generalized coordinate.
Definition: DegreeOfFreedom.cpp:432
void setCommand(double _command)
Set the command of this DegreeOfFreedom.
Definition: DegreeOfFreedom.cpp:90
double getAccelerationLowerLimit() const
Get the lower acceleration limit of this DegreeOfFreedom.
Definition: DegreeOfFreedom.cpp:317
double getVelocityUpperLimit() const
Get the upper Velocity limit of this DegreeOfFreedom.
Definition: DegreeOfFreedom.cpp:253
std::pair< double, double > getAccelerationLimits() const
Get the acceleration limits of this DegreeOfFreedom.
Definition: DegreeOfFreedom.cpp:304
double getVelocityChange() const
Get the velocity change of this DegreeOfFreedom.
Definition: DegreeOfFreedom.cpp:402
double getSpringStiffness() const
Get stiffness of the spring force for this generalized coordinate.
Definition: DegreeOfFreedom.cpp:438
void setPositionLimits(double _lowerLimit, double _upperLimit)
Set the position limits of this DegreeOfFreedom.
Definition: DegreeOfFreedom.cpp:120
void setVelocityUpperLimit(double _limit)
Set the upper velocity limit of this DegreeOfFreedom.
Definition: DegreeOfFreedom.cpp:247
void setInitialPosition(double _initial)
Change the position that resetPosition() will give to this DegreeOfFreedom.
Definition: DegreeOfFreedom.cpp:184
BodyNode * getParentBodyNode()
Get the BodyNode upstream of this DegreeOfFreedom.
Definition: DegreeOfFreedom.cpp:516
double getInitialVelocity() const
Get the velocity that resetVelocity() will give to this DegreeOfFreedom.
Definition: DegreeOfFreedom.cpp:265
void setForceLimits(double _lowerLimit, double _upperLimit)
Set the generalized force limits of this DegreeOfFreedom.
Definition: DegreeOfFreedom.cpp:353
double getCommand() const
Get the command of this DegreeOfFreedom.
Definition: DegreeOfFreedom.cpp:96
double getVelocityLowerLimit() const
Get the lower velocity limit of this DegreeOfFreedom.
Definition: DegreeOfFreedom.cpp:241
double getPositionLowerLimit() const
Get the lower position limit of this DegreeOfFreedom.
Definition: DegreeOfFreedom.cpp:148
std::pair< double, double > getPositionLimits() const
Get the position limits of this DegreeOfFreedom.
Definition: DegreeOfFreedom.cpp:134
double getAccelerationUpperLimit() const
Get the upper acceleration limit of this DegreeOfFreedom.
Definition: DegreeOfFreedom.cpp:329
double getConstraintImpulse() const
Get the constraint impulse of this generalized coordinate.
Definition: DegreeOfFreedom.cpp:420
void setVelocityChange(double _velocityChange)
Set the velocity change of this DegreeOfFreedom.
Definition: DegreeOfFreedom.cpp:396
double getVelocity() const
Get the velocity of this DegreeOfFreedom.
Definition: DegreeOfFreedom.cpp:202
SkeletonPtr getSkeleton()
Get the Skeleton that this DegreeOfFreedom is inside of.
Definition: DegreeOfFreedom.cpp:492
double getInitialPosition() const
Get the position that resetPosition() will give to this DegreeOfFreedom.
Definition: DegreeOfFreedom.cpp:190
Joint * mJoint
The joint that this DegreeOfFreedom belongs to.
Definition: DegreeOfFreedom.hpp:401
void preserveName(bool _preserve)
Prevent Joint::updateDegreeOfFreedomNames() from changing the name of this degree of freedom.
Definition: DegreeOfFreedom.cpp:54
void setPositionUpperLimit(double _limit)
Set the upper position limit of this DegreeOfFreedom.
Definition: DegreeOfFreedom.cpp:154
std::size_t mIndexInJoint
Index of this DegreeOfFreedom within its Joint.
Definition: DegreeOfFreedom.hpp:392
void setConstraintImpulse(double _impulse)
Set the constraint impulse of this generalized coordinate.
Definition: DegreeOfFreedom.cpp:414
double getForceLowerLimit() const
Get the lower generalized force limit of this DegreeOfFreedom.
Definition: DegreeOfFreedom.cpp:378
bool isNamePreserved() const
Check whether DegreeOfFreedom::lockName(bool) is activate.
Definition: DegreeOfFreedom.cpp:60
void setForceLowerLimit(double _limit)
Set the lower generalized force limit of this DegreeOfFreedom.
Definition: DegreeOfFreedom.cpp:372
void setVelocityLimits(double _lowerLimit, double _upperLimit)
Set the velocity limits of this DegreeOfFreedom.
Definition: DegreeOfFreedom.cpp:214
double getPositionUpperLimit() const
Get the upper position limit of this DegreeOfFreedom.
Definition: DegreeOfFreedom.cpp:160
void setInitialVelocity(double _initial)
Change the velocity that resetVelocity() will give to this DegreeOfFreedom.
Definition: DegreeOfFreedom.cpp:259
void resetAcceleration()
Set the acceleration of this DegreeOfFreedom to zero.
Definition: DegreeOfFreedom.cpp:283
std::size_t mIndexInSkeleton
Index of this DegreeOfFreedom within its Skeleton.
Definition: DegreeOfFreedom.hpp:395
const std::string & setName(const std::string &_name, bool _preserveName=true)
Change the name of this DegreeOfFreedom.
Definition: DegreeOfFreedom.cpp:41
void setPosition(double _position)
Set the position of this DegreeOfFreedom.
Definition: DegreeOfFreedom.cpp:108
void resetVelocityChange()
Set the velocity change of this DegreeOfFreedom to zero.
Definition: DegreeOfFreedom.cpp:408
void setForceUpperLimit(double _limit)
Set the upper generalized force limit of this DegreeOfFreedom.
Definition: DegreeOfFreedom.cpp:384
void setPositionLowerLimit(double _limit)
Set the lower position limit of this DegreeOfFreedom.
Definition: DegreeOfFreedom.cpp:142
void resetVelocity()
Set the velocity of this DegreeOfFreedom to zero.
Definition: DegreeOfFreedom.cpp:208
Definition: GenericJoint.hpp:48
class Joint
Definition: Joint.hpp:60
class Skeleton
Definition: Skeleton.hpp:59
std::shared_ptr< const Skeleton > ConstSkeletonPtr
Definition: SmartPointer.hpp:60
std::shared_ptr< Skeleton > SkeletonPtr
Definition: SmartPointer.hpp:60
Definition: BulletCollisionDetector.cpp:65