9 #ifndef CROCODDYL_MULTIBODY_ACTUATIONS_PROPELLERS_HPP_
10 #define CROCODDYL_MULTIBODY_ACTUATIONS_PROPELLERS_HPP_
12 #include <pinocchio/multibody/fwd.hpp>
13 #include <pinocchio/spatial/se3.hpp>
16 #include "crocoddyl/core/actuation-base.hpp"
17 #include "crocoddyl/core/utils/exception.hpp"
18 #include "crocoddyl/multibody/states/multibody.hpp"
22 enum ThrusterType { CW = 0, CCW };
24 template <
typename _Scalar>
26 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
28 typedef _Scalar Scalar;
29 typedef pinocchio::SE3Tpl<Scalar> SE3;
43 const ThrusterType
type = CW,
45 const Scalar
max_thrust = std::numeric_limits<Scalar>::infinity())
64 const Scalar
max_thrust = std::numeric_limits<Scalar>::infinity())
65 :
pose(SE3::Identity()),
77 ThrusterTpl& operator=(
const ThrusterTpl<Scalar>& other) {
88 template <
typename OtherScalar>
89 bool operator==(
const ThrusterTpl<OtherScalar>& other)
const {
90 return (
pose == other.pose &&
ctorque == other.ctorque &&
95 friend std::ostream& operator<<(std::ostream& os,
96 const ThrusterTpl<Scalar>& X) {
97 os <<
" pose:" << std::endl
98 << X.pose <<
" ctorque: " << X.ctorque << std::endl
99 <<
" type: " << X.type << std::endl
100 <<
"min_thrust: " << X.min_thrust << std::endl
101 <<
"max_thrust: " << X.max_thrust << std::endl;
131 template <
typename _Scalar>
135 typedef _Scalar Scalar;
141 typedef typename MathBase::Vector3s Vector3s;
142 typedef typename MathBase::VectorXs VectorXs;
143 typedef typename MathBase::MatrixXs MatrixXs;
153 boost::shared_ptr<StateMultibody> state,
154 const std::vector<Thruster>& thrusters)
157 state->get_pinocchio()
159 state->get_pinocchio()->existJointName(
"root_joint")
160 ? state->get_pinocchio()->getJointId(
"root_joint")
168 if (!state->get_pinocchio()->existJointName(
"root_joint")) {
171 <<
"the first joint has to be a root one (e.g., free-flyer joint)");
193 virtual void calc(
const boost::shared_ptr<Data>& data,
194 const Eigen::Ref<const VectorXs>&,
195 const Eigen::Ref<const VectorXs>& u) {
196 if (
static_cast<std::size_t
>(u.size()) !=
nu_) {
197 throw_pretty(
"Invalid argument: "
198 <<
"u has wrong dimension (it should be " +
199 std::to_string(
nu_) +
")");
204 data->tau.noalias() = data->dtau_du * u;
216 virtual void calcDiff(
const boost::shared_ptr<Data>& data,
217 const Eigen::Ref<const VectorXs>&,
218 const Eigen::Ref<const VectorXs>&) {
220 virtual void calcDiff(
const boost::shared_ptr<Data>&,
221 const Eigen::Ref<const VectorXs>&,
222 const Eigen::Ref<const VectorXs>&) {
225 assert_pretty(MatrixXs(data->dtau_du).isApprox(
W_thrust_),
226 "dtau_du has wrong value");
229 virtual void commands(
const boost::shared_ptr<Data>& data,
230 const Eigen::Ref<const VectorXs>&,
231 const Eigen::Ref<const VectorXs>& tau) {
232 data->u.noalias() = data->Mtau * tau;
237 const Eigen::Ref<const VectorXs>&,
238 const Eigen::Ref<const VectorXs>&) {
241 const Eigen::Ref<const VectorXs>&,
242 const Eigen::Ref<const VectorXs>&) {
245 assert_pretty(MatrixXs(data->Mtau).isApprox(
Mtau_),
"Mtau has wrong value");
254 boost::shared_ptr<Data> data =
255 boost::allocate_shared<Data>(Eigen::aligned_allocator<Data>(),
this);
279 if (
static_cast<std::size_t
>(thrusters.size()) !=
n_thrusters_) {
280 throw_pretty(
"Invalid argument: "
281 <<
"the number of thrusters is wrong (it should be " +
288 const Vector3s& f_z = p.
pose.rotation() * Vector3s::UnitZ();
289 W_thrust_.template topRows<3>().col(i) += f_z;
290 W_thrust_.template middleRows<3>(3).col(i).noalias() +=
291 p.
pose.translation().cross(Vector3s::UnitZ());
308 const MatrixXs& get_Wthrust()
const {
return W_thrust_; }
310 const MatrixXs& get_S()
const {
return S_; }
312 void print(std::ostream& os)
const {
313 os <<
"ActuationModelFloatingBaseThrusters {nu=" <<
nu_
314 <<
", nthrusters=" <<
n_thrusters_ <<
", thrusters=" << std::endl;
316 os << std::to_string(i) <<
": " <<
thrusters_[i];
334 void updateData(
const boost::shared_ptr<Data>& data) {
337 const std::size_t nv =
state_->get_nv();
338 for (std::size_t k = 0; k < nv; ++k) {
339 if (fabs(
S_(k, k)) < std::numeric_limits<Scalar>::epsilon()) {
340 data->tau_set[k] =
false;
342 data->tau_set[k] =
true;
345 update_data_ =
false;
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.
Actuation models for floating base systems actuated with thrusters.
MatrixXs S_
Selection matrix for under-actuation part.
const std::vector< Thruster > & get_thrusters() const
Return the vector of thrusters.
std::size_t n_thrusters_
Number of thrusters.
std::vector< Thruster > thrusters_
Vector of thrusters.
boost::shared_ptr< StateAbstract > state_
Model of the state.
std::size_t nu_
Dimension of joint torque inputs.
ActuationModelFloatingBaseThrustersTpl(boost::shared_ptr< StateMultibody > state, const std::vector< Thruster > &thrusters)
Initialize the floating base actuation model equipped with thrusters.
std::size_t get_nthrusters() const
Return the number of thrusters.
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 actuation signal and actuation set from its thrust and joint torque inputs .
MatrixXs W_thrust_
Matrix from thrusters thrusts to body wrench.
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 thruster actuation function.
void print(std::ostream &os) const
Print relevant information of the residual model.
void set_thrusters(const std::vector< Thruster > &thrusters)
Modify the vector of thrusters.
virtual boost::shared_ptr< Data > createData()
Create the floating base thruster actuation data.
State multibody representation.
Scalar min_thrust
Minimum thrust.
ThrusterTpl(const SE3 &pose, const Scalar ctorque, const ThrusterType type=CW, const Scalar min_thrust=Scalar(0.), const Scalar max_thrust=std::numeric_limits< Scalar >::infinity())
Initialize the thruster in a give pose from the root joint.
Scalar max_thrust
Minimum thrust.
ThrusterTpl(const Scalar ctorque, const ThrusterType type=CW, const Scalar min_thrust=Scalar(0.), const Scalar max_thrust=std::numeric_limits< Scalar >::infinity())
Initialize the thruster in a pose in the origin of the root joint.
Scalar ctorque
Coefficient of generated torque per thrust.