1 |
|
|
/////////////////////////////////////////////////////////////////////////////// |
2 |
|
|
// BSD 3-Clause License |
3 |
|
|
// |
4 |
|
|
// Copyright (C) 2021-2024, LAAS-CNRS, University of Edinburgh, |
5 |
|
|
// Heriot-Watt University |
6 |
|
|
// Copyright note valid unless otherwise stated in individual files. |
7 |
|
|
// All rights reserved. |
8 |
|
|
/////////////////////////////////////////////////////////////////////////////// |
9 |
|
|
|
10 |
|
|
#ifndef CROCODDYL_MULTIBODY_RESIDUALS_COM_POSITION_HPP_ |
11 |
|
|
#define CROCODDYL_MULTIBODY_RESIDUALS_COM_POSITION_HPP_ |
12 |
|
|
|
13 |
|
|
#include "crocoddyl/core/residual-base.hpp" |
14 |
|
|
#include "crocoddyl/multibody/data/multibody.hpp" |
15 |
|
|
#include "crocoddyl/multibody/fwd.hpp" |
16 |
|
|
#include "crocoddyl/multibody/states/multibody.hpp" |
17 |
|
|
|
18 |
|
|
namespace crocoddyl { |
19 |
|
|
|
20 |
|
|
/** |
21 |
|
|
* @brief CoM position residual |
22 |
|
|
* |
23 |
|
|
* This residual function defines the CoM tracking as |
24 |
|
|
* \f$\mathbf{r}=\mathbf{c}-\mathbf{c}^*\f$, where |
25 |
|
|
* \f$\mathbf{c},\mathbf{c}^*\in~\mathbb{R}^3\f$ are the current and reference |
26 |
|
|
* CoM position, respectively. Note that the dimension of the residual vector is |
27 |
|
|
* obtained from 3. Furthermore, the Jacobians of the residual function are |
28 |
|
|
* computed analytically. |
29 |
|
|
* |
30 |
|
|
* As described in `ResidualModelAbstractTpl()`, the residual value and its |
31 |
|
|
* Jacobians are calculated by `calc` and `calcDiff`, respectively. |
32 |
|
|
* |
33 |
|
|
* \sa `ResidualModelAbstractTpl`, `calc()`, `calcDiff()`, `createData()` |
34 |
|
|
*/ |
35 |
|
|
template <typename _Scalar> |
36 |
|
|
class ResidualModelCoMPositionTpl : public ResidualModelAbstractTpl<_Scalar> { |
37 |
|
|
public: |
38 |
|
|
EIGEN_MAKE_ALIGNED_OPERATOR_NEW |
39 |
|
|
|
40 |
|
|
typedef _Scalar Scalar; |
41 |
|
|
typedef MathBaseTpl<Scalar> MathBase; |
42 |
|
|
typedef ResidualModelAbstractTpl<Scalar> Base; |
43 |
|
|
typedef ResidualDataCoMPositionTpl<Scalar> Data; |
44 |
|
|
typedef StateMultibodyTpl<Scalar> StateMultibody; |
45 |
|
|
typedef ResidualDataAbstractTpl<Scalar> ResidualDataAbstract; |
46 |
|
|
typedef DataCollectorAbstractTpl<Scalar> DataCollectorAbstract; |
47 |
|
|
typedef typename MathBase::Vector3s Vector3s; |
48 |
|
|
typedef typename MathBase::VectorXs VectorXs; |
49 |
|
|
|
50 |
|
|
/** |
51 |
|
|
* @brief Initialize the CoM position residual model |
52 |
|
|
* |
53 |
|
|
* @param[in] state State of the multibody system |
54 |
|
|
* @param[in] cref Reference CoM position |
55 |
|
|
* @param[in] nu Dimension of the control vector |
56 |
|
|
*/ |
57 |
|
|
ResidualModelCoMPositionTpl(boost::shared_ptr<StateMultibody> state, |
58 |
|
|
const Vector3s& cref, const std::size_t nu); |
59 |
|
|
|
60 |
|
|
/** |
61 |
|
|
* @brief Initialize the CoM position residual model |
62 |
|
|
* |
63 |
|
|
* The default `nu` value is obtained from `StateAbstractTpl::get_nv()`. |
64 |
|
|
* |
65 |
|
|
* @param[in] state State of the multibody system |
66 |
|
|
* @param[in] cref Reference CoM position |
67 |
|
|
*/ |
68 |
|
|
ResidualModelCoMPositionTpl(boost::shared_ptr<StateMultibody> state, |
69 |
|
|
const Vector3s& cref); |
70 |
|
|
virtual ~ResidualModelCoMPositionTpl(); |
71 |
|
|
|
72 |
|
|
/** |
73 |
|
|
* @brief Compute the CoM position residual |
74 |
|
|
* |
75 |
|
|
* @param[in] data CoM position residual data |
76 |
|
|
* @param[in] x State point \f$\mathbf{x}\in\mathbb{R}^{ndx}\f$ |
77 |
|
|
* @param[in] u Control input \f$\mathbf{u}\in\mathbb{R}^{nu}\f$ |
78 |
|
|
*/ |
79 |
|
|
virtual void calc(const boost::shared_ptr<ResidualDataAbstract>& data, |
80 |
|
|
const Eigen::Ref<const VectorXs>& x, |
81 |
|
|
const Eigen::Ref<const VectorXs>& u); |
82 |
|
|
|
83 |
|
|
/** |
84 |
|
|
* @brief Compute the derivatives of the CoM position residual |
85 |
|
|
* |
86 |
|
|
* @param[in] data CoM position residual data |
87 |
|
|
* @param[in] x State point \f$\mathbf{x}\in\mathbb{R}^{ndx}\f$ |
88 |
|
|
* @param[in] u Control input \f$\mathbf{u}\in\mathbb{R}^{nu}\f$ |
89 |
|
|
*/ |
90 |
|
|
virtual void calcDiff(const boost::shared_ptr<ResidualDataAbstract>& data, |
91 |
|
|
const Eigen::Ref<const VectorXs>& x, |
92 |
|
|
const Eigen::Ref<const VectorXs>& u); |
93 |
|
|
virtual boost::shared_ptr<ResidualDataAbstract> createData( |
94 |
|
|
DataCollectorAbstract* const data); |
95 |
|
|
|
96 |
|
|
/** |
97 |
|
|
* @brief Return the CoM position reference |
98 |
|
|
*/ |
99 |
|
|
const Vector3s& get_reference() const; |
100 |
|
|
|
101 |
|
|
/** |
102 |
|
|
* @brief Modify the CoM position reference |
103 |
|
|
*/ |
104 |
|
|
void set_reference(const Vector3s& cref); |
105 |
|
|
|
106 |
|
|
/** |
107 |
|
|
* @brief Print relevant information of the com-position residual |
108 |
|
|
* |
109 |
|
|
* @param[out] os Output stream object |
110 |
|
|
*/ |
111 |
|
|
virtual void print(std::ostream& os) const; |
112 |
|
|
|
113 |
|
|
protected: |
114 |
|
|
using Base::nu_; |
115 |
|
|
using Base::state_; |
116 |
|
|
using Base::u_dependent_; |
117 |
|
|
using Base::v_dependent_; |
118 |
|
|
|
119 |
|
|
private: |
120 |
|
|
Vector3s cref_; //!< Reference CoM position |
121 |
|
|
}; |
122 |
|
|
|
123 |
|
|
template <typename _Scalar> |
124 |
|
|
struct ResidualDataCoMPositionTpl : public ResidualDataAbstractTpl<_Scalar> { |
125 |
|
|
EIGEN_MAKE_ALIGNED_OPERATOR_NEW |
126 |
|
|
|
127 |
|
|
typedef _Scalar Scalar; |
128 |
|
|
typedef MathBaseTpl<Scalar> MathBase; |
129 |
|
|
typedef ResidualDataAbstractTpl<Scalar> Base; |
130 |
|
|
typedef DataCollectorAbstractTpl<Scalar> DataCollectorAbstract; |
131 |
|
|
typedef typename MathBase::Matrix3xs Matrix3xs; |
132 |
|
|
|
133 |
|
|
template <template <typename Scalar> class Model> |
134 |
|
9554 |
ResidualDataCoMPositionTpl(Model<Scalar>* const model, |
135 |
|
|
DataCollectorAbstract* const data) |
136 |
|
9554 |
: Base(model, data) { |
137 |
|
|
// Check that proper shared data has been passed |
138 |
|
|
DataCollectorMultibodyTpl<Scalar>* d = |
139 |
✓✗ |
9554 |
dynamic_cast<DataCollectorMultibodyTpl<Scalar>*>(shared); |
140 |
✗✓ |
9554 |
if (d == NULL) { |
141 |
|
|
throw_pretty( |
142 |
|
|
"Invalid argument: the shared data should be derived from " |
143 |
|
|
"DataCollectorMultibody"); |
144 |
|
|
} |
145 |
|
|
|
146 |
|
|
// Avoids data casting at runtime |
147 |
|
9554 |
pinocchio = d->pinocchio; |
148 |
|
9554 |
} |
149 |
|
|
|
150 |
|
|
pinocchio::DataTpl<Scalar>* pinocchio; //!< Pinocchio data |
151 |
|
|
using Base::r; |
152 |
|
|
using Base::Ru; |
153 |
|
|
using Base::Rx; |
154 |
|
|
using Base::shared; |
155 |
|
|
}; |
156 |
|
|
|
157 |
|
|
} // namespace crocoddyl |
158 |
|
|
|
159 |
|
|
/* --- Details -------------------------------------------------------------- */ |
160 |
|
|
/* --- Details -------------------------------------------------------------- */ |
161 |
|
|
/* --- Details -------------------------------------------------------------- */ |
162 |
|
|
#include "crocoddyl/multibody/residuals/com-position.hxx" |
163 |
|
|
|
164 |
|
|
#endif // CROCODDYL_MULTIBODY_RESIDUALS_COM_POSITION_HPP_ |