Crocoddyl
actuation-base.hpp
1 // 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.
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 
44 template <typename _Scalar>
46  public:
47  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
48 
49  typedef _Scalar Scalar;
53  typedef typename MathBase::VectorXs VectorXs;
54  typedef typename MathBase::MatrixXs MatrixXs;
55 
62  ActuationModelAbstractTpl(boost::shared_ptr<StateAbstract> state,
63  const std::size_t nu);
64  virtual ~ActuationModelAbstractTpl();
65 
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 
88  void calc(const boost::shared_ptr<ActuationDataAbstract>& data,
89  const Eigen::Ref<const VectorXs>& x);
90 
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 
111  void calcDiff(const boost::shared_ptr<ActuationDataAbstract>& data,
112  const Eigen::Ref<const VectorXs>& x);
113 
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 
137  virtual void torqueTransform(
138  const boost::shared_ptr<ActuationDataAbstract>& data,
139  const Eigen::Ref<const VectorXs>& x, const Eigen::Ref<const VectorXs>& u);
145  virtual boost::shared_ptr<ActuationDataAbstract> createData();
146 
150  std::size_t get_nu() const;
151 
155  const boost::shared_ptr<StateAbstract>& get_state() const;
156 
160  template <class Scalar>
161  friend std::ostream& operator<<(
162  std::ostream& os, const ResidualModelAbstractTpl<Scalar>& model);
163 
169  virtual void print(std::ostream& os) const;
170 
171  protected:
172  std::size_t nu_;
173  boost::shared_ptr<StateAbstract> state_;
174 };
175 
176 template <typename _Scalar>
178  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
179 
180  typedef _Scalar Scalar;
182  typedef typename MathBase::VectorXs VectorXs;
183  typedef typename MathBase::MatrixXs MatrixXs;
184 
185  template <template <typename Scalar> class Model>
186  explicit ActuationDataAbstractTpl(Model<Scalar>* const model)
187  : tau(model->get_state()->get_nv()),
188  u(model->get_nu()),
189  dtau_dx(model->get_state()->get_nv(), model->get_state()->get_ndx()),
190  dtau_du(model->get_state()->get_nv(), model->get_nu()),
191  Mtau(model->get_nu(), model->get_state()->get_nv()),
192  tau_set(model->get_state()->get_nv(), true) {
193  tau.setZero();
194  u.setZero();
195  dtau_dx.setZero();
196  dtau_du.setZero();
197  Mtau.setZero();
198  }
199  virtual ~ActuationDataAbstractTpl() {}
200 
201  VectorXs tau;
202  VectorXs u;
203  MatrixXs dtau_dx;
205  MatrixXs dtau_du;
207  MatrixXs Mtau;
209  std::vector<bool> tau_set;
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_
Abstract class for the actuation-mapping model.
virtual void commands(const boost::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 calc(const boost::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 .
const boost::shared_ptr< StateAbstract > & get_state() const
Return the state.
void calc(const boost::shared_ptr< ActuationDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
Ignore the computation of the actuation signal.
virtual void print(std::ostream &os) const
Print relevant information of the residual model.
void calcDiff(const boost::shared_ptr< ActuationDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
Ignore the computation of the Jacobians of the actuation function.
friend std::ostream & operator<<(std::ostream &os, const ResidualModelAbstractTpl< Scalar > &model)
Print information on the residual model.
boost::shared_ptr< StateAbstract > state_
Model of the state.
virtual void calcDiff(const boost::shared_ptr< ActuationDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)=0
Compute the Jacobians of the actuation function.
std::size_t nu_
Dimension of joint torque inputs.
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.
virtual boost::shared_ptr< ActuationDataAbstract > createData()
Create the actuation data.
std::size_t get_nu() const
Return the dimension of the joint-torque input.
ActuationModelAbstractTpl(boost::shared_ptr< StateAbstract > state, const std::size_t nu)
Initialize the actuation model.
Abstract class for residual models.
Abstract class for the state representation.
Definition: state-base.hpp:46
std::vector< bool > tau_set
True for joints that are actuacted.
VectorXs tau
Generalized torques.