Crocoddyl
actuation-base.hpp
1 // BSD 3-Clause License
3 //
4 // Copyright (C) 2019-2025, LAAS-CNRS, University of Edinburgh,
5 // Heriot-Watt University
6 // Copyright note valid unless otherwise stated in individual files.
7 // All rights reserved.
9 
10 #ifndef CROCODDYL_CORE_ACTUATION_BASE_HPP_
11 #define CROCODDYL_CORE_ACTUATION_BASE_HPP_
12 
13 #include "crocoddyl/core/fwd.hpp"
14 #include "crocoddyl/core/state-base.hpp"
15 
16 namespace crocoddyl {
17 
19  public:
20  virtual ~ActuationModelBase() = default;
21 
22  CROCODDYL_BASE_CAST(ActuationModelBase, ActuationModelAbstractTpl)
23 };
24 
45 template <typename _Scalar>
47  public:
48  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
49 
50  typedef _Scalar Scalar;
54  typedef typename MathBase::VectorXs VectorXs;
55  typedef typename MathBase::MatrixXs MatrixXs;
56 
63  ActuationModelAbstractTpl(std::shared_ptr<StateAbstract> state,
64  const std::size_t nu);
65  virtual ~ActuationModelAbstractTpl() = default;
66 
76  virtual void calc(const std::shared_ptr<ActuationDataAbstract>& data,
77  const Eigen::Ref<const VectorXs>& x,
78  const Eigen::Ref<const VectorXs>& u) = 0;
79 
89  void calc(const std::shared_ptr<ActuationDataAbstract>& data,
90  const Eigen::Ref<const VectorXs>& x);
91 
99  virtual void calcDiff(const std::shared_ptr<ActuationDataAbstract>& data,
100  const Eigen::Ref<const VectorXs>& x,
101  const Eigen::Ref<const VectorXs>& u) = 0;
102 
112  void calcDiff(const std::shared_ptr<ActuationDataAbstract>& data,
113  const Eigen::Ref<const VectorXs>& x);
114 
124  virtual void commands(const std::shared_ptr<ActuationDataAbstract>& data,
125  const Eigen::Ref<const VectorXs>& x,
126  const Eigen::Ref<const VectorXs>& tau) = 0;
127 
138  virtual void torqueTransform(
139  const std::shared_ptr<ActuationDataAbstract>& data,
140  const Eigen::Ref<const VectorXs>& x, const Eigen::Ref<const VectorXs>& u);
146  virtual std::shared_ptr<ActuationDataAbstract> createData();
147 
151  std::size_t get_nu() const;
152 
156  const std::shared_ptr<StateAbstract>& get_state() const;
157 
161  template <class Scalar>
162  friend std::ostream& operator<<(
163  std::ostream& os, const ActuationModelAbstractTpl<Scalar>& model);
164 
170  virtual void print(std::ostream& os) const;
171 
172  protected:
173  std::size_t nu_;
174  std::shared_ptr<StateAbstract> state_;
175  ActuationModelAbstractTpl() : nu_(0), state_(nullptr) {};
176 };
177 
178 template <typename _Scalar>
180  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
181 
182  typedef _Scalar Scalar;
184  typedef typename MathBase::VectorXs VectorXs;
185  typedef typename MathBase::MatrixXs MatrixXs;
186 
187  template <template <typename Scalar> class Model>
188  explicit ActuationDataAbstractTpl(Model<Scalar>* const model)
189  : tau(model->get_state()->get_nv()),
190  u(model->get_nu()),
191  dtau_dx(model->get_state()->get_nv(), model->get_state()->get_ndx()),
192  dtau_du(model->get_state()->get_nv(), model->get_nu()),
193  Mtau(model->get_nu(), model->get_state()->get_nv()),
194  tau_set(model->get_state()->get_nv(), true) {
195  tau.setZero();
196  u.setZero();
197  dtau_dx.setZero();
198  dtau_du.setZero();
199  Mtau.setZero();
200  }
201  virtual ~ActuationDataAbstractTpl() = default;
202 
203  VectorXs tau;
204  VectorXs u;
205  MatrixXs dtau_dx;
207  MatrixXs dtau_du;
209  MatrixXs Mtau;
211  std::vector<bool> tau_set;
212 };
213 
214 } // namespace crocoddyl
215 
216 /* --- Details -------------------------------------------------------------- */
217 /* --- Details -------------------------------------------------------------- */
218 /* --- Details -------------------------------------------------------------- */
219 #include "crocoddyl/core/actuation-base.hxx"
220 
221 CROCODDYL_DECLARE_EXTERN_TEMPLATE_CLASS(crocoddyl::ActuationModelAbstractTpl)
222 CROCODDYL_DECLARE_EXTERN_TEMPLATE_STRUCT(crocoddyl::ActuationDataAbstractTpl)
223 
224 #endif // CROCODDYL_CORE_ACTUATION_BASE_HPP_
Abstract class for the actuation-mapping model.
std::shared_ptr< StateAbstract > state_
Model of the state.
virtual void print(std::ostream &os) const
Print relevant information of the residual model.
virtual void calc(const std::shared_ptr< ActuationDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)=0
Compute the actuation signal from the state point and joint torque inputs .
void calcDiff(const std::shared_ptr< ActuationDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
Ignore the computation of the Jacobians of the actuation function.
virtual void calcDiff(const std::shared_ptr< ActuationDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)=0
Compute the Jacobians of the actuation function.
virtual void commands(const std::shared_ptr< ActuationDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &tau)=0
Compute the joint torque input from the generalized torques.
virtual void torqueTransform(const std::shared_ptr< ActuationDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)
Compute the torque transform from generalized torques to joint torque inputs.
const std::shared_ptr< StateAbstract > & get_state() const
Return the state.
std::size_t nu_
Dimension of joint torque inputs.
ActuationModelAbstractTpl(std::shared_ptr< StateAbstract > state, const std::size_t nu)
Initialize the actuation model.
friend std::ostream & operator<<(std::ostream &os, const ActuationModelAbstractTpl< Scalar > &model)
Print information on the actuation model.
virtual std::shared_ptr< ActuationDataAbstract > createData()
Create the actuation data.
std::size_t get_nu() const
Return the dimension of the joint-torque input.
void calc(const std::shared_ptr< ActuationDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
Ignore the computation of the actuation signal.
Abstract class for the state representation.
Definition: state-base.hpp:48
std::vector< bool > tau_set
True for joints that are actuacted.
VectorXs tau
Generalized torques.