1 |
|
|
/////////////////////////////////////////////////////////////////////////////// |
2 |
|
|
// BSD 3-Clause License |
3 |
|
|
// |
4 |
|
|
// Copyright (C) 2019-2022, 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_CORE_ACTUATION_BASE_HPP_ |
11 |
|
|
#define CROCODDYL_CORE_ACTUATION_BASE_HPP_ |
12 |
|
|
|
13 |
|
|
#include <boost/make_shared.hpp> |
14 |
|
|
#include <boost/shared_ptr.hpp> |
15 |
|
|
#include <stdexcept> |
16 |
|
|
|
17 |
|
|
#include "crocoddyl/core/fwd.hpp" |
18 |
|
|
#include "crocoddyl/core/mathbase.hpp" |
19 |
|
|
#include "crocoddyl/core/state-base.hpp" |
20 |
|
|
#include "crocoddyl/core/utils/exception.hpp" |
21 |
|
|
|
22 |
|
|
namespace crocoddyl { |
23 |
|
|
|
24 |
|
|
/** |
25 |
|
|
* @brief Abstract class for the actuation-mapping model |
26 |
|
|
* |
27 |
|
|
* The generalized torques \f$\boldsymbol{\tau}\in\mathbb{R}^{nv}\f$ can by any |
28 |
|
|
* nonlinear function of the joint-torque inputs |
29 |
|
|
* \f$\mathbf{u}\in\mathbb{R}^{nu}\f$, and state point |
30 |
|
|
* \f$\mathbf{x}\in\mathbb{R}^{nx}\f$, where `nv`, `nu`, and `ndx` are the |
31 |
|
|
* number of joints, dimension of the joint torque input and state manifold, |
32 |
|
|
* respectively. Additionally, the generalized torques are also named as the |
33 |
|
|
* actuation signals of our system. |
34 |
|
|
* |
35 |
|
|
* The main computations are carried out in `calc()`, and `calcDiff()`, where |
36 |
|
|
* the former computes actuation signal, and the latter computes the Jacobians |
37 |
|
|
* of the actuation-mapping function, i.e., |
38 |
|
|
* \f$\frac{\partial\boldsymbol{\tau}}{\partial\mathbf{x}}\f$ and |
39 |
|
|
* \f$\frac{\partial\boldsymbol{\tau}}{\partial\mathbf{u}}\f$. Note that |
40 |
|
|
* `calcDiff()` requires to run `calc()` first. |
41 |
|
|
* |
42 |
|
|
* \sa `calc()`, `calcDiff()`, `createData()` |
43 |
|
|
*/ |
44 |
|
|
template <typename _Scalar> |
45 |
|
|
class ActuationModelAbstractTpl { |
46 |
|
|
public: |
47 |
|
|
EIGEN_MAKE_ALIGNED_OPERATOR_NEW |
48 |
|
|
|
49 |
|
|
typedef _Scalar Scalar; |
50 |
|
|
typedef MathBaseTpl<Scalar> MathBase; |
51 |
|
|
typedef StateAbstractTpl<Scalar> StateAbstract; |
52 |
|
|
typedef ActuationDataAbstractTpl<Scalar> ActuationDataAbstract; |
53 |
|
|
typedef typename MathBase::VectorXs VectorXs; |
54 |
|
|
typedef typename MathBase::MatrixXs MatrixXs; |
55 |
|
|
|
56 |
|
|
/** |
57 |
|
|
* @brief Initialize the actuation model |
58 |
|
|
* |
59 |
|
|
* @param[in] state State description |
60 |
|
|
* @param[in] nu Dimension of joint-torque input |
61 |
|
|
*/ |
62 |
|
|
ActuationModelAbstractTpl(boost::shared_ptr<StateAbstract> state, |
63 |
|
|
const std::size_t nu); |
64 |
|
|
virtual ~ActuationModelAbstractTpl(); |
65 |
|
|
|
66 |
|
|
/** |
67 |
|
|
* @brief Compute the actuation signal from the state point |
68 |
|
|
* \f$\mathbf{x}\in\mathbb{R}^{ndx}\f$ and joint torque inputs |
69 |
|
|
* \f$\mathbf{u}\in\mathbb{R}^{nu}\f$ |
70 |
|
|
* |
71 |
|
|
* @param[in] data Actuation data |
72 |
|
|
* @param[in] x State point \f$\mathbf{x}\in\mathbb{R}^{ndx}\f$ |
73 |
|
|
* @param[in] u Joint-torque input \f$\mathbf{u}\in\mathbb{R}^{nu}\f$ |
74 |
|
|
*/ |
75 |
|
|
virtual void calc(const boost::shared_ptr<ActuationDataAbstract>& data, |
76 |
|
|
const Eigen::Ref<const VectorXs>& x, |
77 |
|
|
const Eigen::Ref<const VectorXs>& u) = 0; |
78 |
|
|
|
79 |
|
|
/** |
80 |
|
|
* @brief Ignore the computation of the actuation signal |
81 |
|
|
* |
82 |
|
|
* It does not update the actuation signal as this function is used in the |
83 |
|
|
* terminal nodes of an optimal control problem. |
84 |
|
|
* |
85 |
|
|
* @param[in] data Actuation data |
86 |
|
|
* @param[in] x State point \f$\mathbf{x}\in\mathbb{R}^{ndx}\f$ |
87 |
|
|
*/ |
88 |
|
|
void calc(const boost::shared_ptr<ActuationDataAbstract>& data, |
89 |
|
|
const Eigen::Ref<const VectorXs>& x); |
90 |
|
|
|
91 |
|
|
/** |
92 |
|
|
* @brief Compute the Jacobians of the actuation function |
93 |
|
|
* |
94 |
|
|
* @param[in] data Actuation data |
95 |
|
|
* @param[in] x State point \f$\mathbf{x}\in\mathbb{R}^{ndx}\f$ |
96 |
|
|
* @param[in] u Joint-torque input \f$\mathbf{u}\in\mathbb{R}^{nu}\f$ |
97 |
|
|
*/ |
98 |
|
|
virtual void calcDiff(const boost::shared_ptr<ActuationDataAbstract>& data, |
99 |
|
|
const Eigen::Ref<const VectorXs>& x, |
100 |
|
|
const Eigen::Ref<const VectorXs>& u) = 0; |
101 |
|
|
|
102 |
|
|
/** |
103 |
|
|
* @brief Ignore the computation of the Jacobians of the actuation function |
104 |
|
|
* |
105 |
|
|
* It does not update the Jacobians of the actuation function as this function |
106 |
|
|
* is used in the terminal nodes of an optimal control problem. |
107 |
|
|
* |
108 |
|
|
* @param[in] data Actuation data |
109 |
|
|
* @param[in] x State point \f$\mathbf{x}\in\mathbb{R}^{ndx}\f$ |
110 |
|
|
*/ |
111 |
|
|
void calcDiff(const boost::shared_ptr<ActuationDataAbstract>& data, |
112 |
|
|
const Eigen::Ref<const VectorXs>& x); |
113 |
|
|
|
114 |
|
|
/** |
115 |
|
|
* @brief Compute the joint torque input from the generalized torques |
116 |
|
|
* |
117 |
|
|
* It stores the results in `ActuationDataAbstractTpl::u`. |
118 |
|
|
* |
119 |
|
|
* @param[in] data Actuation data |
120 |
|
|
* @param[in] x State point \f$\mathbf{x}\in\mathbb{R}^{ndx}\f$ |
121 |
|
|
* @param[in] tau Generalized torques \f$\mathbf{u}\in\mathbb{R}^{nv}\f$ |
122 |
|
|
*/ |
123 |
|
|
virtual void commands(const boost::shared_ptr<ActuationDataAbstract>& data, |
124 |
|
|
const Eigen::Ref<const VectorXs>& x, |
125 |
|
|
const Eigen::Ref<const VectorXs>& tau) = 0; |
126 |
|
|
|
127 |
|
|
/** |
128 |
|
|
* @brief Compute the torque transform from generalized torques to joint |
129 |
|
|
* torque inputs |
130 |
|
|
* |
131 |
|
|
* It stores the results in `ActuationDataAbstractTpl::Mtau`. |
132 |
|
|
* |
133 |
|
|
* @param[in] data Actuation data |
134 |
|
|
* @param[in] x State point \f$\mathbf{x}\in\mathbb{R}^{ndx}\f$ |
135 |
|
|
* @param[in] tau Joint-torque inputs \f$\mathbf{u}\in\mathbb{R}^{nu}\f$ |
136 |
|
|
*/ |
137 |
|
|
virtual void torqueTransform( |
138 |
|
|
const boost::shared_ptr<ActuationDataAbstract>& data, |
139 |
|
|
const Eigen::Ref<const VectorXs>& x, const Eigen::Ref<const VectorXs>& u); |
140 |
|
|
/** |
141 |
|
|
* @brief Create the actuation data |
142 |
|
|
* |
143 |
|
|
* @return the actuation data |
144 |
|
|
*/ |
145 |
|
|
virtual boost::shared_ptr<ActuationDataAbstract> createData(); |
146 |
|
|
|
147 |
|
|
/** |
148 |
|
|
* @brief Return the dimension of the joint-torque input |
149 |
|
|
*/ |
150 |
|
|
std::size_t get_nu() const; |
151 |
|
|
|
152 |
|
|
/** |
153 |
|
|
* @brief Return the state |
154 |
|
|
*/ |
155 |
|
|
const boost::shared_ptr<StateAbstract>& get_state() const; |
156 |
|
|
|
157 |
|
|
/** |
158 |
|
|
* @brief Print information on the residual model |
159 |
|
|
*/ |
160 |
|
|
template <class Scalar> |
161 |
|
|
friend std::ostream& operator<<( |
162 |
|
|
std::ostream& os, const ResidualModelAbstractTpl<Scalar>& model); |
163 |
|
|
|
164 |
|
|
/** |
165 |
|
|
* @brief Print relevant information of the residual model |
166 |
|
|
* |
167 |
|
|
* @param[out] os Output stream object |
168 |
|
|
*/ |
169 |
|
|
virtual void print(std::ostream& os) const; |
170 |
|
|
|
171 |
|
|
protected: |
172 |
|
|
std::size_t nu_; //!< Dimension of joint torque inputs |
173 |
|
|
boost::shared_ptr<StateAbstract> state_; //!< Model of the state |
174 |
|
|
}; |
175 |
|
|
|
176 |
|
|
template <typename _Scalar> |
177 |
|
|
struct ActuationDataAbstractTpl { |
178 |
|
|
EIGEN_MAKE_ALIGNED_OPERATOR_NEW |
179 |
|
|
|
180 |
|
|
typedef _Scalar Scalar; |
181 |
|
|
typedef MathBaseTpl<Scalar> MathBase; |
182 |
|
|
typedef typename MathBase::VectorXs VectorXs; |
183 |
|
|
typedef typename MathBase::MatrixXs MatrixXs; |
184 |
|
|
|
185 |
|
|
template <template <typename Scalar> class Model> |
186 |
|
209034 |
explicit ActuationDataAbstractTpl(Model<Scalar>* const model) |
187 |
|
209034 |
: tau(model->get_state()->get_nv()), |
188 |
|
|
u(model->get_nu()), |
189 |
|
418068 |
dtau_dx(model->get_state()->get_nv(), model->get_state()->get_ndx()), |
190 |
|
209034 |
dtau_du(model->get_state()->get_nv(), model->get_nu()), |
191 |
|
209034 |
Mtau(model->get_nu(), model->get_state()->get_nv()), |
192 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗
|
209034 |
tau_set(model->get_state()->get_nv(), true) { |
193 |
✓✗ |
209034 |
tau.setZero(); |
194 |
✓✗ |
209034 |
u.setZero(); |
195 |
✓✗ |
209034 |
dtau_dx.setZero(); |
196 |
✓✗ |
209034 |
dtau_du.setZero(); |
197 |
✓✗ |
209034 |
Mtau.setZero(); |
198 |
|
209034 |
} |
199 |
|
105237 |
virtual ~ActuationDataAbstractTpl() {} |
200 |
|
|
|
201 |
|
|
VectorXs tau; //!< Generalized torques |
202 |
|
|
VectorXs u; //!< Joint torques |
203 |
|
|
MatrixXs dtau_dx; //!< Partial derivatives of the actuation model w.r.t. the |
204 |
|
|
//!< state point |
205 |
|
|
MatrixXs dtau_du; //!< Partial derivatives of the actuation model w.r.t. the |
206 |
|
|
//!< joint torque input |
207 |
|
|
MatrixXs Mtau; //!< Torque transform from generalized torques to joint torque |
208 |
|
|
//!< inputs |
209 |
|
|
std::vector<bool> tau_set; //!< True for joints that are actuacted |
210 |
|
|
}; |
211 |
|
|
|
212 |
|
|
} // namespace crocoddyl |
213 |
|
|
|
214 |
|
|
/* --- Details -------------------------------------------------------------- */ |
215 |
|
|
/* --- Details -------------------------------------------------------------- */ |
216 |
|
|
/* --- Details -------------------------------------------------------------- */ |
217 |
|
|
#include "crocoddyl/core/actuation-base.hxx" |
218 |
|
|
|
219 |
|
|
#endif // CROCODDYL_CORE_ACTUATION_BASE_HPP_ |