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;
54 boost::shared_ptr<StateMultibody> state)
57 state->get_pinocchio()
59 state->get_pinocchio()->existJointName(
"root_joint")
60 ? state->get_pinocchio()->getJointId(
"root_joint")
73 virtual void calc(
const boost::shared_ptr<Data>& data,
74 const Eigen::Ref<const VectorXs>& ,
75 const Eigen::Ref<const VectorXs>& u) {
76 if (
static_cast<std::size_t
>(u.size()) !=
nu_) {
77 throw_pretty(
"Invalid argument: "
78 <<
"u has wrong dimension (it should be " +
79 std::to_string(
nu_) +
")");
81 data->tau.tail(
nu_) = u;
92 virtual void calcDiff(
const boost::shared_ptr<Data>& data,
93 const Eigen::Ref<const VectorXs>& ,
94 const Eigen::Ref<const VectorXs>& ) {
96 virtual void calcDiff(
const boost::shared_ptr<Data>&,
97 const Eigen::Ref<const VectorXs>& ,
98 const Eigen::Ref<const VectorXs>& ) {
101 assert_pretty(data->dtau_dx.isZero(),
"dtau_dx has wrong value");
102 assert_pretty(MatrixXs(data->dtau_du).isApprox(dtau_du_),
103 "dtau_du has wrong value");
106 virtual void commands(
const boost::shared_ptr<Data>& data,
107 const Eigen::Ref<const VectorXs>&,
108 const Eigen::Ref<const VectorXs>& tau) {
109 if (
static_cast<std::size_t
>(tau.size()) !=
state_->get_nv()) {
110 throw_pretty(
"Invalid argument: "
111 <<
"tau has wrong dimension (it should be " +
112 std::to_string(
state_->get_nv()) +
")");
114 data->u = tau.tail(
nu_);
119 const Eigen::Ref<const VectorXs>&,
120 const Eigen::Ref<const VectorXs>&) {
123 const Eigen::Ref<const VectorXs>&,
124 const Eigen::Ref<const VectorXs>&) {
127 assert_pretty(MatrixXs(data->Mtau).isApprox(Mtau_),
"Mtau has wrong value");
137 boost::shared_ptr<StateMultibody> state =
138 boost::static_pointer_cast<StateMultibody>(
state_);
139 boost::shared_ptr<Data> data =
140 boost::allocate_shared<Data>(Eigen::aligned_allocator<Data>(),
this);
141 const std::size_t root_joint_id =
142 state->get_pinocchio()->existJointName(
"root_joint")
143 ? state->get_pinocchio()->getJointId(
"root_joint")
145 const std::size_t nfb = state->get_pinocchio()->joints[root_joint_id].nv();
146 data->dtau_du.diagonal(-nfb).setOnes();
147 data->Mtau.diagonal(nfb).setOnes();
148 for (std::size_t i = 0; i < nfb; ++i) {
149 data->tau_set[i] =
false;
152 dtau_du_ = data->dtau_du;
Abstract class for the actuation-mapping model.
boost::shared_ptr< StateAbstract > state_
Model of the state.
std::size_t nu_
Dimension of joint torque inputs.
Floating-base actuation model.
boost::shared_ptr< StateAbstract > state_
Model of the state.
std::size_t nu_
Dimension of joint torque inputs.
ActuationModelFloatingBaseTpl(boost::shared_ptr< StateMultibody > state)
Initialize the floating-base actuation model.
virtual void torqueTransform(const boost::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.
virtual void calc(const boost::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 .
virtual void commands(const boost::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 boost::shared_ptr< Data > &data, const Eigen::Ref< const VectorXs > &, const Eigen::Ref< const VectorXs > &)
Compute the Jacobians of the floating-base actuation function.
virtual boost::shared_ptr< Data > createData()
Create the floating-base actuation data.
State multibody representation.