crocoddyl  1.8.0
Contact RObot COntrol by Differential DYnamic programming Library (Crocoddyl)
floating-base.hpp
1 // BSD 3-Clause License
3 //
4 // Copyright (C) 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)
30  : Base(state, state->get_nv() - state->get_pinocchio()->joints[1].nv()){};
31  virtual ~ActuationModelFloatingBaseTpl(){};
32 
33  virtual void calc(const boost::shared_ptr<Data>& data, const Eigen::Ref<const VectorXs>& /*x*/,
34  const Eigen::Ref<const VectorXs>& u) {
35  if (static_cast<std::size_t>(u.size()) != nu_) {
36  throw_pretty("Invalid argument: "
37  << "u has wrong dimension (it should be " + std::to_string(nu_) + ")");
38  }
39  data->tau.tail(nu_) = u;
40  };
41 
42 #ifndef NDEBUG
43  virtual void calcDiff(const boost::shared_ptr<Data>& data, const Eigen::Ref<const VectorXs>& /*x*/,
44  const Eigen::Ref<const VectorXs>& /*u*/) {
45 #else
46  virtual void calcDiff(const boost::shared_ptr<Data>&, const Eigen::Ref<const VectorXs>& /*x*/,
47  const Eigen::Ref<const VectorXs>& /*u*/) {
48 #endif
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  virtual boost::shared_ptr<Data> createData() {
54  typedef StateMultibodyTpl<Scalar> StateMultibody;
55  boost::shared_ptr<StateMultibody> state = boost::static_pointer_cast<StateMultibody>(state_);
56  boost::shared_ptr<Data> data = boost::allocate_shared<Data>(Eigen::aligned_allocator<Data>(), this);
57  data->dtau_du.diagonal(-state->get_pinocchio()->joints[1].nv()).fill((Scalar)1.);
58 #ifndef NDEBUG
59  dtau_du_ = data->dtau_du;
60 #endif
61  return data;
62  };
63 
64  protected:
65  using Base::nu_;
66  using Base::state_;
67 
68 #ifndef NDEBUG
69  private:
70  MatrixXs dtau_du_;
71 #endif
72 };
73 
74 } // namespace crocoddyl
75 
76 #endif // CROCODDYL_MULTIBODY_ACTUATIONS_FLOATING_BASE_HPP_
State multibody representation.
Definition: fwd.hpp:300