10 #ifndef CROCODDYL_MULTIBODY_ACTUATIONS_FLOATING_BASE_HPP_
11 #define CROCODDYL_MULTIBODY_ACTUATIONS_FLOATING_BASE_HPP_
13 #include "crocoddyl/core/actuation-base.hpp"
14 #include "crocoddyl/core/utils/exception.hpp"
15 #include "crocoddyl/multibody/fwd.hpp"
16 #include "crocoddyl/multibody/states/multibody.hpp"
35 template <
typename _Scalar>
39 typedef _Scalar Scalar;
44 typedef typename MathBase::VectorXs VectorXs;
45 typedef typename MathBase::MatrixXs MatrixXs;
56 state->get_pinocchio()
58 state->get_pinocchio()->existJointName(
"root_joint")
59 ? state->get_pinocchio()->getJointId(
"root_joint")
72 virtual void calc(
const std::shared_ptr<Data>& data,
73 const Eigen::Ref<const VectorXs>& ,
74 const Eigen::Ref<const VectorXs>& u) {
75 if (
static_cast<std::size_t
>(u.size()) !=
nu_) {
77 "Invalid argument: " <<
"u has wrong dimension (it should be " +
78 std::to_string(
nu_) +
")");
80 data->tau.tail(
nu_) = u;
91 virtual void calcDiff(
const std::shared_ptr<Data>& data,
92 const Eigen::Ref<const VectorXs>& ,
93 const Eigen::Ref<const VectorXs>& ) {
95 virtual void calcDiff(
const std::shared_ptr<Data>&,
96 const Eigen::Ref<const VectorXs>& ,
97 const Eigen::Ref<const VectorXs>& ) {
100 assert_pretty(data->dtau_dx.isZero(),
"dtau_dx has wrong value");
101 assert_pretty(MatrixXs(data->dtau_du).isApprox(dtau_du_),
102 "dtau_du has wrong value");
105 virtual void commands(
const std::shared_ptr<Data>& data,
106 const Eigen::Ref<const VectorXs>&,
107 const Eigen::Ref<const VectorXs>& tau) {
108 if (
static_cast<std::size_t
>(tau.size()) !=
state_->get_nv()) {
110 "Invalid argument: " <<
"tau has wrong dimension (it should be " +
111 std::to_string(
state_->get_nv()) +
")");
113 data->u = tau.tail(
nu_);
118 const Eigen::Ref<const VectorXs>&,
119 const Eigen::Ref<const VectorXs>&) {
122 const Eigen::Ref<const VectorXs>&,
123 const Eigen::Ref<const VectorXs>&) {
126 assert_pretty(MatrixXs(data->Mtau).isApprox(Mtau_),
"Mtau has wrong value");
136 std::shared_ptr<StateMultibody> state =
137 std::static_pointer_cast<StateMultibody>(
state_);
138 std::shared_ptr<Data> data =
139 std::allocate_shared<Data>(Eigen::aligned_allocator<Data>(),
this);
140 const std::size_t root_joint_id =
141 state->get_pinocchio()->existJointName(
"root_joint")
142 ? state->get_pinocchio()->getJointId(
"root_joint")
144 const std::size_t nfb = state->get_pinocchio()->joints[root_joint_id].nv();
145 data->dtau_du.diagonal(-nfb).setOnes();
146 data->Mtau.diagonal(nfb).setOnes();
147 for (std::size_t i = 0; i < nfb; ++i) {
148 data->tau_set[i] =
false;
151 dtau_du_ = data->dtau_du;
Abstract class for the actuation-mapping model.
std::shared_ptr< StateAbstract > state_
Model of the state.
std::size_t nu_
Dimension of joint torque inputs.
Floating-base actuation model.
virtual std::shared_ptr< Data > createData()
Create the floating-base actuation data.
std::shared_ptr< StateAbstract > state_
Model of the state.
virtual void commands(const std::shared_ptr< Data > &data, const Eigen::Ref< const VectorXs > &, const Eigen::Ref< const VectorXs > &tau)
Compute the joint torque input from the generalized torques.
virtual void calcDiff(const std::shared_ptr< Data > &data, const Eigen::Ref< const VectorXs > &, const Eigen::Ref< const VectorXs > &)
Compute the Jacobians of the floating-base actuation function.
virtual void calc(const std::shared_ptr< Data > &data, const Eigen::Ref< const VectorXs > &, const Eigen::Ref< const VectorXs > &u)
Compute the floating-base actuation signal from the joint-torque input .
ActuationModelFloatingBaseTpl(std::shared_ptr< StateMultibody > state)
Initialize the floating-base actuation model.
std::size_t nu_
Dimension of joint torque inputs.
virtual void torqueTransform(const std::shared_ptr< Data > &data, const Eigen::Ref< const VectorXs > &, const Eigen::Ref< const VectorXs > &)
Compute the torque transform from generalized torques to joint torque inputs.
State multibody representation.