Crocoddyl
actuation.hpp
1 // BSD 3-Clause License
3 //
4 // Copyright (C) 2019-2024, University of Edinburgh, LAAS-CNRS
5 // Heriot-Watt University
6 // Copyright note valid unless otherwise stated in individual files.
7 // All rights reserved.
9 
10 #ifndef CROCODDYL_CORE_NUMDIFF_ACTUATION_HPP_
11 #define CROCODDYL_CORE_NUMDIFF_ACTUATION_HPP_
12 
13 #include <iostream>
14 #include <vector>
15 
16 #include "crocoddyl/core/actuation-base.hpp"
17 #include "crocoddyl/core/fwd.hpp"
18 
19 namespace crocoddyl {
20 
33 template <typename _Scalar>
35  public:
36  typedef _Scalar Scalar;
41  typedef typename MathBase::VectorXs VectorXs;
42  typedef typename MathBase::MatrixXs MatrixXs;
43 
50  explicit ActuationModelNumDiffTpl(boost::shared_ptr<Base> model);
51 
56 
60  virtual void calc(const boost::shared_ptr<ActuationDataAbstract>& data,
61  const Eigen::Ref<const VectorXs>& x,
62  const Eigen::Ref<const VectorXs>& u);
63 
68  virtual void calc(const boost::shared_ptr<ActuationDataAbstract>& data,
69  const Eigen::Ref<const VectorXs>& x);
70 
74  virtual void calcDiff(const boost::shared_ptr<ActuationDataAbstract>& data,
75  const Eigen::Ref<const VectorXs>& x,
76  const Eigen::Ref<const VectorXs>& u);
77 
83  virtual void calcDiff(const boost::shared_ptr<ActuationDataAbstract>& data,
84  const Eigen::Ref<const VectorXs>& x);
85 
89  virtual void commands(const boost::shared_ptr<ActuationDataAbstract>& data,
90  const Eigen::Ref<const VectorXs>& x,
91  const Eigen::Ref<const VectorXs>& tau);
92 
96  virtual void torqueTransform(
97  const boost::shared_ptr<ActuationDataAbstract>& data,
98  const Eigen::Ref<const VectorXs>& x, const Eigen::Ref<const VectorXs>& u);
99 
103  virtual boost::shared_ptr<ActuationDataAbstract> createData();
104 
108  const boost::shared_ptr<Base>& get_model() const;
109 
114  const Scalar get_disturbance() const;
115 
120  void set_disturbance(const Scalar disturbance);
121 
122  private:
123  boost::shared_ptr<Base> model_;
125  Scalar e_jac_;
127 
128  protected:
129  using Base::nu_;
130 };
131 
132 template <typename _Scalar>
134  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
135 
136  typedef _Scalar Scalar;
138  typedef typename MathBase::VectorXs VectorXs;
140 
147  template <template <typename Scalar> class Model>
148  explicit ActuationDataNumDiffTpl(Model<Scalar>* const model)
149  : Base(model),
150  dx(model->get_model()->get_state()->get_ndx()),
151  du(model->get_model()->get_nu()),
152  xp(model->get_model()->get_state()->get_nx()) {
153  dx.setZero();
154  du.setZero();
155  xp.setZero();
156  const std::size_t ndx = model->get_model()->get_state()->get_ndx();
157  const std::size_t nu = model->get_model()->get_nu();
158  data_0 = model->get_model()->createData();
159  for (std::size_t i = 0; i < ndx; ++i) {
160  data_x.push_back(model->get_model()->createData());
161  }
162  for (std::size_t i = 0; i < nu; ++i) {
163  data_u.push_back(model->get_model()->createData());
164  }
165  }
166 
167  Scalar x_norm;
168  Scalar
170  Scalar
172  VectorXs dx;
173  VectorXs du;
174  VectorXs xp;
176  boost::shared_ptr<Base> data_0;
177  std::vector<boost::shared_ptr<Base> >
179  std::vector<boost::shared_ptr<Base> >
181 
182  using Base::dtau_du;
183  using Base::dtau_dx;
184  using Base::tau;
185 };
186 
187 } // namespace crocoddyl
188 
189 /* --- Details -------------------------------------------------------------- */
190 /* --- Details -------------------------------------------------------------- */
191 /* --- Details -------------------------------------------------------------- */
192 #include "crocoddyl/core/numdiff/actuation.hxx"
193 
194 #endif // CROCODDYL_CORE_NUMDIFF_ACTUATION_HPP_
Abstract class for the actuation-mapping model.
std::size_t nu_
Dimension of joint torque inputs.
This class computes the numerical differentiation of an actuation model.
Definition: actuation.hpp:34
virtual void calcDiff(const boost::shared_ptr< ActuationDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
virtual void calcDiff(const boost::shared_ptr< ActuationDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)
Compute the Jacobians of the actuation function.
virtual void calc(const boost::shared_ptr< ActuationDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)
Compute the actuation signal from the state point and joint torque inputs .
const Scalar get_disturbance() const
Return the disturbance constant used by the numerical differentiation routine.
virtual void commands(const boost::shared_ptr< ActuationDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &tau)
Compute the joint torque input from the generalized torques.
void set_disturbance(const Scalar disturbance)
Modify the disturbance constant used by the numerical differentiation routine.
virtual void calc(const boost::shared_ptr< ActuationDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
virtual void torqueTransform(const boost::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.
ActuationModelNumDiffTpl(boost::shared_ptr< Base > model)
Initialize the numdiff residual model.
const boost::shared_ptr< Base > & get_model() const
Return the original actuation model.
virtual boost::shared_ptr< ActuationDataAbstract > createData()
Create the actuation data.
virtual ~ActuationModelNumDiffTpl()
Destroy the numdiff actuation model.
VectorXs tau
Generalized torques.
std::vector< boost::shared_ptr< Base > > data_u
The temporary data associated with the control variation.
Definition: actuation.hpp:180
Scalar x_norm
Norm of the state vector.
Definition: actuation.hpp:167
boost::shared_ptr< Base > data_0
The data that contains the final results.
Definition: actuation.hpp:176
Scalar uh_jac
Disturbance value used for computing .
Definition: actuation.hpp:171
Scalar xh_jac
Disturbance value used for computing .
Definition: actuation.hpp:169
VectorXs du
Control disturbance.
Definition: actuation.hpp:173
std::vector< boost::shared_ptr< Base > > data_x
The temporary data associated with the state variation.
Definition: actuation.hpp:178
ActuationDataNumDiffTpl(Model< Scalar > *const model)
Initialize the numdiff actuation data.
Definition: actuation.hpp:148
VectorXs dx
State disturbance.
Definition: actuation.hpp:172