crocoddyl  1.3.0
Contact RObot COntrol by Differential DYnamic programming Library (Crocoddyl)
floating-base.hpp
1 // BSD 3-Clause License
3 //
4 // Copyright (C) 2018-2019, LAAS-CNRS
5 // Copyright note valid unless otherwise stated in individual files.
6 // All rights reserved.
8 
9 #ifndef CROCODDYL_MULTIBODY_ACTUATIONS_FLOATING_BASE_HPP_
10 #define CROCODDYL_MULTIBODY_ACTUATIONS_FLOATING_BASE_HPP_
11 
12 #include "crocoddyl/multibody/fwd.hpp"
13 #include "crocoddyl/core/utils/exception.hpp"
14 #include "crocoddyl/core/actuation-base.hpp"
15 #include "crocoddyl/multibody/states/multibody.hpp"
16 
17 namespace crocoddyl {
18 template <typename _Scalar>
20  public:
21  typedef _Scalar Scalar;
26  typedef typename MathBase::VectorXs VectorXs;
27  typedef typename MathBase::MatrixXs MatrixXs;
28 
29  explicit ActuationModelFloatingBaseTpl(boost::shared_ptr<StateMultibody> state) : Base(state, state->get_nv() - 6) {
30  pinocchio::JointModelFreeFlyerTpl<Scalar> ff_joint;
31  if (state->get_pinocchio()->joints[1].shortname() != ff_joint.shortname()) {
32  throw_pretty("Invalid argument: "
33  << "the first joint has to be free-flyer");
34  }
35  };
36  virtual ~ActuationModelFloatingBaseTpl(){};
37 
38  virtual void calc(const boost::shared_ptr<Data>& data, const Eigen::Ref<const VectorXs>& /*x*/,
39  const Eigen::Ref<const VectorXs>& u) {
40  if (static_cast<std::size_t>(u.size()) != nu_) {
41  throw_pretty("Invalid argument: "
42  << "u has wrong dimension (it should be " + std::to_string(nu_) + ")");
43  }
44  data->tau.tail(nu_) = u;
45  };
46 
47  virtual void calcDiff(const boost::shared_ptr<Data>& data, const Eigen::Ref<const VectorXs>& /*x*/,
48  const Eigen::Ref<const VectorXs>& /*u*/) {
49  // The derivatives has constant values which were set in createData.
50  assert_pretty(data->dtau_dx == MatrixXs::Zero(state_->get_nv(), state_->get_ndx()), "dtau_dx has wrong value");
51  assert_pretty(data->dtau_du == dtau_du_, "dtau_du has wrong value");
52  };
53 
54  virtual boost::shared_ptr<Data> createData() {
55  boost::shared_ptr<Data> data = boost::allocate_shared<Data>(Eigen::aligned_allocator<Data>(), this);
56  data->dtau_du.diagonal(-6).fill((Scalar)1.);
57 #ifndef NDEBUG
58  dtau_du_ = data->dtau_du;
59 #endif
60  return data;
61  };
62 
63  protected:
64  using Base::nu_;
65  using Base::state_;
66 
67 #ifndef NDEBUG
68  private:
69  MatrixXs dtau_du_;
70 #endif
71 };
72 
73 } // namespace crocoddyl
74 
75 #endif // CROCODDYL_MULTIBODY_ACTUATIONS_FLOATING_BASE_HPP_