10 #ifndef CROCODDYL_CORE_ACTUATION_SQUASHING_HPP_
11 #define CROCODDYL_CORE_ACTUATION_SQUASHING_HPP_
13 #include "crocoddyl/core/actuation-base.hpp"
14 #include "crocoddyl/core/actuation/squashing-base.hpp"
15 #include "crocoddyl/core/fwd.hpp"
19 template <
typename _Scalar>
22 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
25 typedef _Scalar Scalar;
31 typedef typename MathBase::VectorXs VectorXs;
32 typedef typename MathBase::MatrixXs MatrixXs;
35 std::shared_ptr<SquashingModelAbstract> squashing,
37 :
Base(actuation->get_state(), nu),
38 squashing_(squashing),
39 actuation_(actuation) {};
43 virtual void calc(
const std::shared_ptr<ActuationDataAbstract>& data,
44 const Eigen::Ref<const VectorXs>& x,
45 const Eigen::Ref<const VectorXs>& u)
override {
46 Data* d =
static_cast<Data*
>(data.get());
48 squashing_->calc(d->squashing, u);
49 actuation_->calc(d->actuation, x, d->squashing->u);
50 data->tau = d->actuation->tau;
51 data->tau_set = d->actuation->tau_set;
54 virtual void calcDiff(
const std::shared_ptr<ActuationDataAbstract>& data,
55 const Eigen::Ref<const VectorXs>& x,
56 const Eigen::Ref<const VectorXs>& u)
override {
57 Data* d =
static_cast<Data*
>(data.get());
59 squashing_->calcDiff(d->squashing, u);
60 actuation_->calcDiff(d->actuation, x, d->squashing->u);
61 data->dtau_du.noalias() = d->actuation->dtau_du * d->squashing->du_ds;
64 virtual void commands(
const std::shared_ptr<ActuationDataAbstract>& data,
65 const Eigen::Ref<const VectorXs>& x,
66 const Eigen::Ref<const VectorXs>& tau)
override {
67 if (
static_cast<std::size_t
>(tau.size()) != this->state_->get_nv()) {
68 throw_pretty(
"Invalid argument: "
69 <<
"tau has wrong dimension (it should be " +
70 std::to_string(this->
state_->get_nv()) +
")");
73 data->u.noalias() = data->Mtau * tau;
76 std::shared_ptr<ActuationDataAbstract>
createData()
override {
77 return std::allocate_shared<Data>(Eigen::aligned_allocator<Data>(),
this);
80 template <
typename NewScalar>
83 ReturnType ret(actuation_->template cast<NewScalar>(),
84 squashing_->template cast<NewScalar>(),
nu_);
88 const std::shared_ptr<SquashingModelAbstract>& get_squashing()
const {
91 const std::shared_ptr<Base>& get_actuation()
const {
return actuation_; };
94 std::shared_ptr<SquashingModelAbstract> squashing_;
95 std::shared_ptr<Base> actuation_;
100 template <
typename _Scalar>
102 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
104 typedef _Scalar Scalar;
108 typedef typename MathBase::VectorXs VectorXs;
109 typedef typename MathBase::MatrixXs MatrixXs;
111 template <
template <
typename Scalar>
class Model>
114 squashing(model->get_squashing()->createData()),
115 actuation(model->get_actuation()->createData()) {}
119 std::shared_ptr<SquashingDataAbstract> squashing;
120 std::shared_ptr<Base> actuation;
Abstract class for the actuation-mapping model.
std::shared_ptr< StateAbstract > state_
Model of the state.
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.
std::size_t nu_
Dimension of joint torque inputs.
virtual void calc(const std::shared_ptr< ActuationDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u) override
Compute the actuation signal from the state point and joint torque inputs .
std::shared_ptr< ActuationDataAbstract > createData() override
Create the actuation data.
virtual void commands(const std::shared_ptr< ActuationDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &tau) override
Compute the joint torque input from the generalized torques.
virtual void calcDiff(const std::shared_ptr< ActuationDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u) override
Compute the Jacobians of the actuation function.
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.
std::size_t nu_
Dimension of joint torque inputs.
std::vector< bool > tau_set
True for joints that are actuacted.
VectorXs tau
Generalized torques.