GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: include/pinocchio/algorithm/rnea-second-order-derivatives.hpp Lines: 9 9 100.0 %
Date: 2024-04-26 13:14:21 Branches: 0 0 - %

Line Branch Exec Source
1
//
2
// Copyright (c) 2017-2019 CNRS INRIA
3
4
#ifndef __pinocchio_algorithm_rnea_second_order_derivatives_hpp__
5
#define __pinocchio_algorithm_rnea_second_order_derivatives_hpp__
6
7
#include "pinocchio/container/aligned-vector.hpp"
8
#include "pinocchio/multibody/data.hpp"
9
#include "pinocchio/multibody/model.hpp"
10
11
namespace pinocchio {
12
///
13
/// \brief Computes the Second-Order partial derivatives of the Recursive Newton
14
/// Euler Algorithm w.r.t the joint configuration, the joint velocity and the
15
/// joint acceleration.
16
///
17
/// \tparam JointCollection Collection of Joint types.
18
/// \tparam ConfigVectorType Type of the joint configuration vector.
19
/// \tparam TangentVectorType1 Type of the joint velocity vector.
20
/// \tparam TangentVectorType2 Type of the joint acceleration vector.
21
/// \tparam Tensor1 Type of the 3D-Tensor containing the SO partial
22
/// derivative with respect to the joint configuration vector. The elements of
23
/// Torque vector are along the 1st dim, and joint config along 2nd,3rd
24
/// dimensions.
25
/// \tparam Tensor2 Type of the 3D-Tensor containing the
26
/// Second-Order partial derivative with respect to the joint velocity vector.
27
/// The elements of Torque vector are along the 1st dim, and the velocity
28
/// along 2nd,3rd dimensions.
29
/// \tparam Tensor3 Type of the 3D-Tensor
30
/// containing the cross Second-Order partial derivative with respect to the
31
/// joint configuration and velocty vector. The elements of Torque vector are
32
/// along the 1st dim, and the config. vector along 2nd dimension, and velocity
33
/// along the third dimension.
34
///\tparam Tensor4 Type of the 3D-Tensor containing the cross Second-Order
35
/// partial derivative with respect to the joint configuration and acceleration
36
/// vector. This is also the First-order partial derivative of Mass-Matrix (M)
37
/// with respect to configuration vector. The elements of Torque vector are
38
/// along the 1st dim, and the acceleration vector along 2nd dimension, while
39
/// configuration along the third dimension.
40
///
41
/// \param[in] model The model structure of the rigid body system.
42
/// \param[in] data The data structure of the rigid body system.
43
/// \param[in] q The joint configuration vector (dim model.nq).
44
/// \param[in] v The joint velocity vector (dim model.nv).
45
/// \param[in] a The joint acceleration vector (dim model.nv).
46
/// \param[out] d2tau_dqdq Second-Order Partial derivative of the generalized
47
/// torque vector with respect to the joint configuration.
48
/// \param[out] d2tau_dvdv Second-Order Partial derivative of the generalized
49
/// torque vector with respect to the joint velocity
50
/// \param[out] dtau_dqdv Cross Second-Order Partial derivative of the
51
/// generalized torque vector with respect to the joint configuration and
52
/// velocity.
53
/// \param[out] dtau_dadq Cross Second-Order Partial derivative of
54
/// the generalized torque vector with respect to the joint configuration and
55
/// accleration.
56
/// \remarks d2tau_dqdq,
57
/// d2tau_dvdv, dtau_dqdv and dtau_dadq must be first initialized with zeros
58
/// (d2tau_dqdq.setZero(), etc). The storage order of the 3D-tensor derivatives is
59
/// important. For d2tau_dqdq, the elements of generalized torque varies along
60
/// the rows, while elements of q vary along the columns and pages of the
61
/// tensor. For dtau_dqdv, the elements of generalized torque varies along the
62
/// rows, while elements of v vary along the columns and elements of q along the
63
/// pages of the tensor. Hence, dtau_dqdv is essentially d (d tau/dq)/dv, with
64
/// outer-most derivative representing the third dimension (pages) of the
65
/// tensor.  The tensor dtau_dadq reduces down to dM/dq, and hence the elements
66
/// of q vary along the pages of the tensor. In other words, this tensor
67
/// derivative is d(d tau/da)/dq. All other remaining combinations of
68
/// second-order derivatives of generalized torque are zero.  \sa
69
///
70
template <typename Scalar, int Options,
71
          template <typename, int> class JointCollectionTpl,
72
          typename ConfigVectorType, typename TangentVectorType1,
73
          typename TangentVectorType2, typename Tensor1,
74
          typename Tensor2, typename Tensor3, typename Tensor4>
75
inline void ComputeRNEASecondOrderDerivatives(
76
    const ModelTpl<Scalar, Options, JointCollectionTpl> &model,
77
    DataTpl<Scalar, Options, JointCollectionTpl> &data,
78
    const Eigen::MatrixBase<ConfigVectorType> &q,
79
    const Eigen::MatrixBase<TangentVectorType1> &v,
80
    const Eigen::MatrixBase<TangentVectorType2> &a,
81
    const Tensor1 &d2tau_dqdq, const Tensor2 &d2tau_dvdv,
82
    const Tensor3 &dtau_dqdv, const Tensor4 &dtau_dadq);
83
84
///
85
/// \brief Computes the Second-Order partial derivatives of the Recursive Newton
86
/// Euler Algorithms
87
///        with respect to the joint configuration, the joint velocity and the
88
///        joint acceleration.
89
///
90
/// \tparam JointCollection Collection of Joint types.
91
/// \tparam ConfigVectorType Type of the joint configuration vector.
92
/// \tparam TangentVectorType1 Type of the joint velocity vector.
93
/// \tparam TangentVectorType2 Type of the joint acceleration vector.
94
///
95
/// \param[in] model The model structure of the rigid body system.
96
/// \param[in] data The data structure of the rigid body system.
97
/// \param[in] q The joint configuration vector (dim model.nq).
98
/// \param[in] v The joint velocity vector (dim model.nv).
99
/// \param[in] a The joint acceleration vector (dim model.nv).
100
///
101
/// \returns The results are stored in data.d2tau_dqdq, data.d2tau_dvdv,
102
/// data.d2tau_dqdv, and data.d2tau_dadq which respectively correspond to the
103
/// Second-Order partial derivatives of the joint torque vector with respect to
104
/// the joint configuration, velocity and cross Second-Order partial derivatives
105
/// with respect to configuration/velocity and configuration/acceleration
106
/// respectively.
107
///
108
/// \remarks d2tau_dqdq,
109
/// d2tau_dvdv2, d2tau_dqdv and d2tau_dadq must be first initialized with zeros
110
/// (d2tau_dqdq.setZero(),etc). The storage order of the 3D-tensor derivatives is
111
/// important. For d2tau_dqdq, the elements of generalized torque varies along
112
/// the rows, while elements of q vary along the columns and pages of the
113
/// tensor. For d2tau_dqdv, the elements of generalized torque varies along the
114
/// rows, while elements of v vary along the columns and elements of q along the
115
/// pages of the tensor. Hence, d2tau_dqdv is essentially d (d tau/dq)/dv, with
116
/// outer-most derivative representing the third dimension (pages) of the
117
/// tensor.  The tensor d2tau_dadq reduces down to dM/dq, and hence the elements
118
/// of q vary along the pages of the tensor. In other words, this tensor
119
/// derivative is d(d tau/da)/dq. All other remaining combinations of
120
/// second-order derivatives of generalized torque are zero.  \sa
121
122
template <typename Scalar, int Options,
123
          template <typename, int> class JointCollectionTpl,
124
          typename ConfigVectorType, typename TangentVectorType1,
125
          typename TangentVectorType2>
126
1
inline void ComputeRNEASecondOrderDerivatives(
127
    const ModelTpl<Scalar, Options, JointCollectionTpl> &model,
128
    DataTpl<Scalar, Options, JointCollectionTpl> &data,
129
    const Eigen::MatrixBase<ConfigVectorType> &q,
130
    const Eigen::MatrixBase<TangentVectorType1> &v,
131
    const Eigen::MatrixBase<TangentVectorType2> &a) {
132
1
  (data.d2tau_dqdq).setZero();
133
1
  (data.d2tau_dvdv).setZero();
134
1
  (data.d2tau_dqdv).setZero();
135
1
  (data.d2tau_dadq).setZero();
136
137
1
  ComputeRNEASecondOrderDerivatives(model, data, q.derived(), v.derived(), a.derived(),
138
1
                           data.d2tau_dqdq, data.d2tau_dvdv, data.d2tau_dqdv,
139
1
                           data.d2tau_dadq);
140
1
}
141
142
} // namespace pinocchio
143
144
#include "pinocchio/algorithm/rnea-second-order-derivatives.hxx"
145
146
#endif // ifndef __pinocchio_algorithm_rnea_second_order_derivatives_hpp__