Crocoddyl
 
Loading...
Searching...
No Matches
actuation-squashing.hpp
1
2// BSD 3-Clause License
3//
4// Copyright (C) 2019-2021, University of Edinburgh, IRI: CSIC-UPC
5// Copyright note valid unless otherwise stated in individual files.
6// All rights reserved.
8
9#ifndef CROCODDYL_CORE_ACTUATION_SQUASHING_HPP_
10#define CROCODDYL_CORE_ACTUATION_SQUASHING_HPP_
11
12#include "crocoddyl/core/actuation-base.hpp"
13#include "crocoddyl/core/actuation/squashing-base.hpp"
14#include "crocoddyl/core/fwd.hpp"
15
16namespace crocoddyl {
17
18template <typename _Scalar>
20 public:
21 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
22
23 typedef _Scalar Scalar;
30 typedef typename MathBase::VectorXs VectorXs;
31 typedef typename MathBase::MatrixXs MatrixXs;
32
33 ActuationSquashingModelTpl(std::shared_ptr<ActuationModelAbstract> actuation,
34 std::shared_ptr<SquashingModelAbstract> squashing,
35 const std::size_t nu)
36 : Base(actuation->get_state(), nu),
37 squashing_(squashing),
38 actuation_(actuation) {};
39
40 virtual ~ActuationSquashingModelTpl() {};
41
42 virtual void calc(const std::shared_ptr<ActuationDataAbstract>& data,
43 const Eigen::Ref<const VectorXs>& x,
44 const Eigen::Ref<const VectorXs>& u) {
45 Data* d = static_cast<Data*>(data.get());
46
47 squashing_->calc(d->squashing, u);
48 actuation_->calc(d->actuation, x, d->squashing->u);
49 data->tau = d->actuation->tau;
50 data->tau_set = d->actuation->tau_set;
51 };
52
53 virtual void calcDiff(const std::shared_ptr<ActuationDataAbstract>& data,
54 const Eigen::Ref<const VectorXs>& x,
55 const Eigen::Ref<const VectorXs>& u) {
56 Data* d = static_cast<Data*>(data.get());
57
58 squashing_->calcDiff(d->squashing, u);
59 actuation_->calcDiff(d->actuation, x, d->squashing->u);
60 data->dtau_du.noalias() = d->actuation->dtau_du * d->squashing->du_ds;
61 };
62
63 virtual void commands(const std::shared_ptr<ActuationDataAbstract>& data,
64 const Eigen::Ref<const VectorXs>& x,
65 const Eigen::Ref<const VectorXs>& tau) {
66 if (static_cast<std::size_t>(tau.size()) != this->state_->get_nv()) {
67 throw_pretty("Invalid argument: "
68 << "tau has wrong dimension (it should be " +
69 std::to_string(this->state_->get_nv()) + ")");
70 }
71 this->torqueTransform(data, x, tau);
72 data->u.noalias() = data->Mtau * tau;
73 }
74
75 std::shared_ptr<ActuationDataAbstract> createData() {
76 return std::allocate_shared<Data>(Eigen::aligned_allocator<Data>(), this);
77 };
78
79 const std::shared_ptr<SquashingModelAbstract>& get_squashing() const {
80 return squashing_;
81 };
82 const std::shared_ptr<ActuationModelAbstract>& get_actuation() const {
83 return actuation_;
84 };
85
86 protected:
87 std::shared_ptr<SquashingModelAbstract> squashing_;
88 std::shared_ptr<ActuationModelAbstract> actuation_;
89};
90
91template <typename _Scalar>
93 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
94
95 typedef _Scalar Scalar;
99 typedef typename MathBase::VectorXs VectorXs;
100 typedef typename MathBase::MatrixXs MatrixXs;
101
102 template <template <typename Scalar> class Model>
103 explicit ActuationSquashingDataTpl(Model<Scalar>* const model)
104 : Base(model),
105 squashing(model->get_squashing()->createData()),
106 actuation(model->get_actuation()->createData()) {}
107
109
110 std::shared_ptr<SquashingDataAbstract> squashing;
111 std::shared_ptr<ActuationDataAbstract> actuation;
112
113 using Base::dtau_du;
114 using Base::dtau_dx;
115 using Base::tau;
116 using Base::tau_set;
117};
118
119} // namespace crocoddyl
120
121#endif // CROCODDYL_CORE_ACTIVATION_SQUASH_BASE_HPP_
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.
virtual void commands(const std::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.
virtual void calcDiff(const std::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 std::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 .
std::shared_ptr< ActuationDataAbstract > createData()
Create the actuation data.
std::vector< bool > tau_set
True for joints that are actuacted.
VectorXs tau
Generalized torques.