dart
JacobianNode.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_DYNAMICS_JACOBIANNODE_HPP_
34 #define DART_DYNAMICS_JACOBIANNODE_HPP_
35 
36 #include <memory>
37 #include <unordered_set>
38 
39 #include "dart/dynamics/Frame.hpp"
40 #include "dart/dynamics/Node.hpp"
41 #include "dart/dynamics/SmartPointer.hpp"
42 
43 namespace dart {
44 namespace dynamics {
45 
46 class Skeleton;
47 class DegreeOfFreedom;
48 class InverseKinematics;
49 
53 DART_DECLARE_CLASS_WITH_VIRTUAL_BASE_BEGIN
54 class JacobianNode : public virtual Frame, public Node
55 {
56 public:
58  virtual ~JacobianNode();
59 
60  using Node::getName;
61  using Node::setName;
62 
65  const std::shared_ptr<InverseKinematics>& getIK(bool _createIfNull = false);
66 
70  const std::shared_ptr<InverseKinematics>& getOrCreateIK();
71 
75  std::shared_ptr<const InverseKinematics> getIK() const;
76 
80  const std::shared_ptr<InverseKinematics>& createIK();
81 
83  void clearIK();
84 
85  //----------------------------------------------------------------------------
87  //----------------------------------------------------------------------------
88 
90  virtual bool dependsOn(std::size_t _genCoordIndex) const = 0;
91 
93  virtual std::size_t getNumDependentGenCoords() const = 0;
94 
97  virtual std::size_t getDependentGenCoordIndex(
98  std::size_t _arrayIndex) const = 0;
99 
101  virtual const std::vector<std::size_t>& getDependentGenCoordIndices()
102  const = 0;
103 
105  virtual std::size_t getNumDependentDofs() const = 0;
106 
108  virtual DegreeOfFreedom* getDependentDof(std::size_t _index) = 0;
109 
111  virtual const DegreeOfFreedom* getDependentDof(std::size_t _index) const = 0;
112 
114  virtual const std::vector<DegreeOfFreedom*>& getDependentDofs() = 0;
115 
117  virtual const std::vector<const DegreeOfFreedom*>& getDependentDofs()
118  const = 0;
119 
122  virtual const std::vector<const DegreeOfFreedom*> getChainDofs() const = 0;
123 
125 
126  //----------------------------------------------------------------------------
128  //----------------------------------------------------------------------------
129 
132  virtual const math::Jacobian& getJacobian() const = 0;
133 
136  virtual math::Jacobian getJacobian(const Frame* _inCoordinatesOf) const = 0;
137 
140  virtual math::Jacobian getJacobian(const Eigen::Vector3d& _offset) const = 0;
141 
144  virtual math::Jacobian getJacobian(
145  const Eigen::Vector3d& _offset, const Frame* _inCoordinatesOf) const = 0;
146 
149  virtual const math::Jacobian& getWorldJacobian() const = 0;
150 
154  virtual math::Jacobian getWorldJacobian(
155  const Eigen::Vector3d& _offset) const = 0;
156 
159  virtual math::LinearJacobian getLinearJacobian(
160  const Frame* _inCoordinatesOf = Frame::World()) const = 0;
161 
164  virtual math::LinearJacobian getLinearJacobian(
165  const Eigen::Vector3d& _offset,
166  const Frame* _inCoordinatesOf = Frame::World()) const = 0;
167 
170  virtual math::AngularJacobian getAngularJacobian(
171  const Frame* _inCoordinatesOf = Frame::World()) const = 0;
172 
181  virtual const math::Jacobian& getJacobianSpatialDeriv() const = 0;
182 
190  virtual math::Jacobian getJacobianSpatialDeriv(
191  const Frame* _inCoordinatesOf) const = 0;
192 
203  virtual math::Jacobian getJacobianSpatialDeriv(
204  const Eigen::Vector3d& _offset) const = 0;
205 
208  virtual math::Jacobian getJacobianSpatialDeriv(
209  const Eigen::Vector3d& _offset, const Frame* _inCoordinatesOf) const = 0;
210 
218  virtual const math::Jacobian& getJacobianClassicDeriv() const = 0;
219 
226  virtual math::Jacobian getJacobianClassicDeriv(
227  const Frame* _inCoordinatesOf) const = 0;
228 
236  virtual math::Jacobian getJacobianClassicDeriv(
237  const Eigen::Vector3d& _offset,
238  const Frame* _inCoordinatesOf = Frame::World()) const = 0;
239 
246  virtual math::LinearJacobian getLinearJacobianDeriv(
247  const Frame* _inCoordinatesOf = Frame::World()) const = 0;
248 
256  virtual math::LinearJacobian getLinearJacobianDeriv(
257  const Eigen::Vector3d& _offset,
258  const Frame* _inCoordinatesOf = Frame::World()) const = 0;
259 
262  virtual math::AngularJacobian getAngularJacobianDeriv(
263  const Frame* _inCoordinatesOf = Frame::World()) const = 0;
264 
266 
269  DART_DEPRECATED(6.2)
270  void notifyJacobianUpdate();
271 
274  void dirtyJacobian();
275 
278  DART_DEPRECATED(6.2)
280 
283  void dirtyJacobianDeriv();
284 
285 protected:
287  JacobianNode(BodyNode* bn);
288 
290  mutable bool mIsBodyJacobianDirty;
291 
293  mutable bool mIsWorldJacobianDirty;
294 
297 
300 
302  std::shared_ptr<InverseKinematics> mIK;
303 
305  std::unordered_set<JacobianNode*> mChildJacobianNodes;
306 };
307 DART_DECLARE_CLASS_WITH_VIRTUAL_BASE_END
308 
309 } // namespace dynamics
310 } // namespace dart
311 
312 #endif // DART_DYNAMICS_JACOBIANNODE_HPP_
bool mIsBodyJacobianSpatialDerivDirty
Dirty flag for spatial time derivative of body Jacobian.
Definition: JacobianNode.hpp:296
std::shared_ptr< InverseKinematics > mIK
Inverse kinematics module which gets lazily created upon request.
Definition: JacobianNode.hpp:302
virtual const std::string & setName(const std::string &newName)=0
Set the name of this Node.
virtual bool dependsOn(std::size_t _genCoordIndex) const =0
Return true if _genCoordIndex-th generalized coordinate.
virtual const std::vector< std::size_t > & getDependentGenCoordIndices() const =0
Indices of the generalized coordinates which affect this JacobianNode.
The Node class is a base class for BodyNode and any object that attaches to a BodyNode.
Definition: Node.hpp:79
virtual math::AngularJacobian getAngularJacobian(const Frame *_inCoordinatesOf=Frame::World()) const =0
Return the angular Jacobian targeting the origin of this BodyNode.
The Frame class serves as the backbone of DART&#39;s kinematic tree structure.
Definition: Frame.hpp:57
void notifyJacobianUpdate()
Notify this BodyNode and all its descendents that their Jacobians need to be updated.
Definition: JacobianNode.cpp:99
bool mIsWorldJacobianClassicDerivDirty
Dirty flag for the classic time derivative of the Jacobian.
Definition: JacobianNode.hpp:299
const std::shared_ptr< InverseKinematics > & createIK()
Create a new IK module for this JacobianNode.
Definition: JacobianNode.cpp:72
virtual const math::Jacobian & getJacobian() const =0
Return the generalized Jacobian targeting the origin of this JacobianNode.
std::shared_ptr< const InverseKinematics > getIK() const
Get a pointer to an IK module for this JacobianNode.
Definition: JacobianNode.cpp:66
void dirtyJacobianDeriv()
Notify this BodyNode and all its descendents that their Jacobian derivatives need to be updated...
Definition: JacobianNode.cpp:126
virtual math::AngularJacobian getAngularJacobianDeriv(const Frame *_inCoordinatesOf=Frame::World()) const =0
Return the angular Jacobian time derivative, in terms of any coordinate Frame.
bool mIsWorldJacobianDirty
Dirty flag for world Jacobian.
Definition: JacobianNode.hpp:293
virtual std::size_t getNumDependentGenCoords() const =0
The number of the generalized coordinates which affect this JacobianNode.
Definition: Aspect.cpp:40
The JacobianNode class serves as a common interface for BodyNodes and EndEffectors to both be used as...
Definition: JacobianNode.hpp:54
void clearIK()
Wipe away the IK module for this JacobianNode, leaving it as a nullptr.
Definition: JacobianNode.cpp:79
virtual DegreeOfFreedom * getDependentDof(std::size_t _index)=0
Get a pointer to the _indexth dependent DegreeOfFreedom for this BodyNode.
JacobianNode(BodyNode *bn)
Constructor.
Definition: JacobianNode.cpp:85
void notifyJacobianDerivUpdate()
Notify this BodyNode and all its descendents that their Jacobian derivatives need to be updated...
Definition: JacobianNode.cpp:120
virtual const std::vector< DegreeOfFreedom * > & getDependentDofs()=0
Return a std::vector of DegreeOfFreedom pointers that this Node depends on.
virtual const math::Jacobian & getJacobianClassicDeriv() const =0
Return the classical time derivative of the generalized Jacobian targeting the origin of this BodyNod...
bool mIsBodyJacobianDirty
Dirty flag for body Jacobian.
Definition: JacobianNode.hpp:290
virtual std::size_t getDependentGenCoordIndex(std::size_t _arrayIndex) const =0
Return a generalized coordinate index from the array index (< getNumDependentDofs) ...
const std::shared_ptr< InverseKinematics > & getOrCreateIK()
Get a pointer to an IK module for this JacobianNode.
Definition: JacobianNode.cpp:60
virtual ~JacobianNode()
Virtual destructor.
Definition: JacobianNode.cpp:44
void dirtyJacobian()
Notify this BodyNode and all its descendents that their Jacobians need to be updated.
Definition: JacobianNode.cpp:105
virtual std::size_t getNumDependentDofs() const =0
Same as getNumDependentGenCoords()
BodyNode class represents a single node of the skeleton.
Definition: BodyNode.hpp:74
DegreeOfFreedom class is a proxy class for accessing single degrees of freedom (aka generalized coord...
Definition: DegreeOfFreedom.hpp:54
virtual const math::Jacobian & getJacobianSpatialDeriv() const =0
Return the spatial time derivative of the generalized Jacobian targeting the origin of this BodyNode...
virtual const math::Jacobian & getWorldJacobian() const =0
Return the generalized Jacobian targeting the origin of this JacobianNode.
virtual math::LinearJacobian getLinearJacobianDeriv(const Frame *_inCoordinatesOf=Frame::World()) const =0
Return the linear Jacobian (classical) time derivative, in terms of any coordinate Frame...
virtual math::LinearJacobian getLinearJacobian(const Frame *_inCoordinatesOf=Frame::World()) const =0
Return the linear Jacobian targeting the origin of this BodyNode.
std::unordered_set< JacobianNode * > mChildJacobianNodes
JacobianNode children that descend from this JacobianNode.
Definition: JacobianNode.hpp:305
virtual const std::string & getName() const =0
Get the name of this Node.
virtual const std::vector< const DegreeOfFreedom * > getChainDofs() const =0
Returns a DegreeOfFreedom vector containing the dofs that form a Chain leading up to this JacobianNod...