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. |
7 |
|
|
/////////////////////////////////////////////////////////////////////////////// |
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 |
|
|
|
16 |
|
|
namespace crocoddyl { |
17 |
|
|
|
18 |
|
|
template <typename _Scalar> |
19 |
|
|
class ActuationSquashingModelTpl : public ActuationModelAbstractTpl<_Scalar> { |
20 |
|
|
public: |
21 |
|
|
EIGEN_MAKE_ALIGNED_OPERATOR_NEW |
22 |
|
|
|
23 |
|
|
typedef _Scalar Scalar; |
24 |
|
|
typedef MathBaseTpl<Scalar> MathBase; |
25 |
|
|
typedef ActuationModelAbstractTpl<Scalar> Base; |
26 |
|
|
typedef ActuationSquashingDataTpl<Scalar> Data; |
27 |
|
|
typedef ActuationModelAbstractTpl<Scalar> ActuationModelAbstract; |
28 |
|
|
typedef ActuationDataAbstractTpl<Scalar> ActuationDataAbstract; |
29 |
|
|
typedef SquashingModelAbstractTpl<Scalar> SquashingModelAbstract; |
30 |
|
|
typedef typename MathBase::VectorXs VectorXs; |
31 |
|
|
typedef typename MathBase::MatrixXs MatrixXs; |
32 |
|
|
|
33 |
|
280 |
ActuationSquashingModelTpl( |
34 |
|
|
boost::shared_ptr<ActuationModelAbstract> actuation, |
35 |
|
|
boost::shared_ptr<SquashingModelAbstract> squashing, const std::size_t nu) |
36 |
|
|
: Base(actuation->get_state(), nu), |
37 |
|
|
squashing_(squashing), |
38 |
✓✗ |
280 |
actuation_(actuation){}; |
39 |
|
|
|
40 |
|
564 |
virtual ~ActuationSquashingModelTpl(){}; |
41 |
|
|
|
42 |
|
14098 |
virtual void calc(const boost::shared_ptr<ActuationDataAbstract>& data, |
43 |
|
|
const Eigen::Ref<const VectorXs>& x, |
44 |
|
|
const Eigen::Ref<const VectorXs>& u) { |
45 |
|
14098 |
Data* d = static_cast<Data*>(data.get()); |
46 |
|
|
|
47 |
|
14098 |
squashing_->calc(d->squashing, u); |
48 |
✓✗ |
14098 |
actuation_->calc(d->actuation, x, d->squashing->u); |
49 |
|
14098 |
data->tau = d->actuation->tau; |
50 |
|
14098 |
data->tau_set = d->actuation->tau_set; |
51 |
|
14098 |
}; |
52 |
|
|
|
53 |
|
4691 |
virtual void calcDiff(const boost::shared_ptr<ActuationDataAbstract>& data, |
54 |
|
|
const Eigen::Ref<const VectorXs>& x, |
55 |
|
|
const Eigen::Ref<const VectorXs>& u) { |
56 |
|
4691 |
Data* d = static_cast<Data*>(data.get()); |
57 |
|
|
|
58 |
|
4691 |
squashing_->calcDiff(d->squashing, u); |
59 |
✓✗ |
4691 |
actuation_->calcDiff(d->actuation, x, d->squashing->u); |
60 |
✓✗✓✗
|
4691 |
data->dtau_du.noalias() = d->actuation->dtau_du * d->squashing->du_ds; |
61 |
|
4691 |
}; |
62 |
|
|
|
63 |
|
2425 |
virtual void commands(const boost::shared_ptr<ActuationDataAbstract>& data, |
64 |
|
|
const Eigen::Ref<const VectorXs>& x, |
65 |
|
|
const Eigen::Ref<const VectorXs>& tau) { |
66 |
✗✓ |
2425 |
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 |
|
2425 |
this->torqueTransform(data, x, tau); |
72 |
✓✗✓✗
|
2425 |
data->u.noalias() = data->Mtau * tau; |
73 |
|
2425 |
} |
74 |
|
|
|
75 |
|
8089 |
boost::shared_ptr<ActuationDataAbstract> createData() { |
76 |
✓✗ |
8089 |
return boost::allocate_shared<Data>(Eigen::aligned_allocator<Data>(), this); |
77 |
|
|
}; |
78 |
|
|
|
79 |
|
8089 |
const boost::shared_ptr<SquashingModelAbstract>& get_squashing() const { |
80 |
|
8089 |
return squashing_; |
81 |
|
|
}; |
82 |
|
8089 |
const boost::shared_ptr<ActuationModelAbstract>& get_actuation() const { |
83 |
|
8089 |
return actuation_; |
84 |
|
|
}; |
85 |
|
|
|
86 |
|
|
protected: |
87 |
|
|
boost::shared_ptr<SquashingModelAbstract> squashing_; |
88 |
|
|
boost::shared_ptr<ActuationModelAbstract> actuation_; |
89 |
|
|
}; |
90 |
|
|
|
91 |
|
|
template <typename _Scalar> |
92 |
|
|
struct ActuationSquashingDataTpl : public ActuationDataAbstractTpl<_Scalar> { |
93 |
|
|
EIGEN_MAKE_ALIGNED_OPERATOR_NEW |
94 |
|
|
|
95 |
|
|
typedef _Scalar Scalar; |
96 |
|
|
typedef ActuationDataAbstractTpl<Scalar> Base; |
97 |
|
|
typedef SquashingDataAbstractTpl<Scalar> SquashingDataAbstract; |
98 |
|
|
typedef MathBaseTpl<Scalar> MathBase; |
99 |
|
|
typedef typename MathBase::VectorXs VectorXs; |
100 |
|
|
typedef typename MathBase::MatrixXs MatrixXs; |
101 |
|
|
|
102 |
|
|
template <template <typename Scalar> class Model> |
103 |
|
8089 |
explicit ActuationSquashingDataTpl(Model<Scalar>* const model) |
104 |
|
|
: Base(model), |
105 |
|
8089 |
squashing(model->get_squashing()->createData()), |
106 |
✓✗✓✗
|
16178 |
actuation(model->get_actuation()->createData()) {} |
107 |
|
|
|
108 |
|
16182 |
~ActuationSquashingDataTpl() {} |
109 |
|
|
|
110 |
|
|
boost::shared_ptr<SquashingDataAbstract> squashing; |
111 |
|
|
boost::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_ |