Crocoddyl
Loading...
Searching...
No Matches
full.hpp
1
2// BSD 3-Clause License
3//
4// Copyright (C) 2019-2025, 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_MULTIBODY_ACTUATIONS_FULL_HPP_
11#define CROCODDYL_MULTIBODY_ACTUATIONS_FULL_HPP_
12
13#include "crocoddyl/core/actuation-base.hpp"
14#include "crocoddyl/core/state-base.hpp"
15#include "crocoddyl/multibody/fwd.hpp"
16#include "crocoddyl/multibody/states/multibody.hpp"
17
18namespace crocoddyl {
19
31template <typename _Scalar>
33 public:
34 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
35 CROCODDYL_DERIVED_CAST(ActuationModelBase, ActuationModelFullTpl)
36
37 typedef _Scalar Scalar;
38 typedef MathBaseTpl<Scalar> MathBase;
41 typedef StateAbstractTpl<Scalar> StateAbstract;
42 typedef typename MathBase::VectorXs VectorXs;
43 typedef typename MathBase::MatrixXs MatrixXs;
44
50 explicit ActuationModelFullTpl(std::shared_ptr<StateAbstract> state)
51 : Base(state, state->get_nv()) {
53 dynamic_cast<StateMultibodyTpl<Scalar>*>(state.get());
54 if (s != NULL) {
55 Base::u_lb_ = Scalar(-1.) * s->get_pinocchio()->effortLimit;
56 Base::u_ub_ = s->get_pinocchio()->effortLimit;
57 }
58 };
59 virtual ~ActuationModelFullTpl() = default;
60
68 virtual void calc(const std::shared_ptr<Data>& data,
69 const Eigen::Ref<const VectorXs>& /*x*/,
70 const Eigen::Ref<const VectorXs>& u) override {
71 if (static_cast<std::size_t>(u.size()) != nu_) {
72 throw_pretty(
73 "Invalid argument: " << "u has wrong dimension (it should be " +
74 std::to_string(nu_) + ")");
75 }
76 data->tau = u;
77 };
78
86#ifndef NDEBUG
87 virtual void calcDiff(const std::shared_ptr<Data>& data,
88 const Eigen::Ref<const VectorXs>& /*x*/,
89 const Eigen::Ref<const VectorXs>&) override {
90#else
91 virtual void calcDiff(const std::shared_ptr<Data>&,
92 const Eigen::Ref<const VectorXs>& /*x*/,
93 const Eigen::Ref<const VectorXs>&) override {
94#endif
95 // The derivatives has constant values which were set in createData.
96 assert_pretty(data->dtau_dx.isZero(), "dtau_dx has wrong value");
97 assert_pretty(MatrixXs(data->dtau_du)
98 .isApprox(MatrixXs::Identity(state_->get_nv(), nu_)),
99 "dtau_du has wrong value");
100 };
101
102 virtual void commands(const std::shared_ptr<Data>& data,
103 const Eigen::Ref<const VectorXs>&,
104 const Eigen::Ref<const VectorXs>& tau) override {
105 if (static_cast<std::size_t>(tau.size()) != nu_) {
106 throw_pretty(
107 "Invalid argument: " << "tau has wrong dimension (it should be " +
108 std::to_string(nu_) + ")");
109 }
110 data->u = tau;
111 }
112
113#ifndef NDEBUG
114 virtual void torqueTransform(const std::shared_ptr<Data>& data,
115 const Eigen::Ref<const VectorXs>&,
116 const Eigen::Ref<const VectorXs>&) override {
117#else
118 virtual void torqueTransform(const std::shared_ptr<Data>&,
119 const Eigen::Ref<const VectorXs>&,
120 const Eigen::Ref<const VectorXs>&) override {
121#endif
122 // The torque transform has constant values which were set in createData.
123 assert_pretty(MatrixXs(data->Mtau).isApprox(MatrixXs::Identity(nu_, nu_)),
124 "Mtau has wrong value");
125 }
126
133 virtual std::shared_ptr<Data> createData() override {
134 std::shared_ptr<Data> data =
135 std::allocate_shared<Data>(Eigen::aligned_allocator<Data>(), this);
136 data->dtau_du.diagonal().setOnes();
137 data->Mtau.setIdentity();
138 return data;
139 };
140
141 template <typename NewScalar>
143 typedef ActuationModelFullTpl<NewScalar> ReturnType;
144 ReturnType ret(state_->template cast<NewScalar>());
145 return ret;
146 }
147
153 virtual void print(std::ostream& os) const override {
154 os << "ActuationModelFull {nu=" << nu_ << ", nv=" << state_->get_nv()
155 << "}";
156 }
157
158 protected:
159 using Base::nu_;
160 using Base::state_;
161};
162
163} // namespace crocoddyl
164
165CROCODDYL_DECLARE_EXTERN_TEMPLATE_CLASS(crocoddyl::ActuationModelFullTpl)
166
167#endif // CROCODDYL_MULTIBODY_ACTUATIONS_FULL_HPP_
ActuationModelAbstractTpl(std::shared_ptr< StateAbstract > state, const std::size_t nu)
Initialize the actuation model.
Full actuation model.
Definition full.hpp:32
std::shared_ptr< StateAbstract > state_
virtual void calc(const std::shared_ptr< Data > &data, const Eigen::Ref< const VectorXs > &, const Eigen::Ref< const VectorXs > &u) override
Compute the full actuation.
Definition full.hpp:68
virtual std::shared_ptr< Data > createData() override
Create the full actuation data.
Definition full.hpp:133
virtual void commands(const std::shared_ptr< Data > &data, const Eigen::Ref< const VectorXs > &, const Eigen::Ref< const VectorXs > &tau) override
Compute the joint torque input from the generalized torques.
Definition full.hpp:102
virtual void torqueTransform(const std::shared_ptr< Data > &data, const Eigen::Ref< const VectorXs > &, const Eigen::Ref< const VectorXs > &) override
Compute the torque transform from generalized torques to joint torque inputs.
Definition full.hpp:114
ActuationModelFullTpl(std::shared_ptr< StateAbstract > state)
Initialize the full actuation model.
Definition full.hpp:50
virtual void calcDiff(const std::shared_ptr< Data > &data, const Eigen::Ref< const VectorXs > &, const Eigen::Ref< const VectorXs > &) override
Compute the Jacobians of the full actuation model.
Definition full.hpp:87
virtual void print(std::ostream &os) const override
Print relevant information of the joint-effort residual.
Definition full.hpp:153
Abstract class for the state representation.
State multibody representation.
Definition multibody.hpp:34
const std::shared_ptr< PinocchioModel > & get_pinocchio() const
Return the Pinocchio model (i.e., model of the rigid body system).