crocoddyl  1.5.0
Contact RObot COntrol by Differential DYnamic programming Library (Crocoddyl)
com-position.hpp
1 // BSD 3-Clause License
3 //
4 // Copyright (C) 2018-2020, LAAS-CNRS, University of Edinburgh
5 // Copyright note valid unless otherwise stated in individual files.
6 // All rights reserved.
8 
9 #ifndef CROCODDYL_MULTIBODY_COSTS_COM_POSITION_HPP_
10 #define CROCODDYL_MULTIBODY_COSTS_COM_POSITION_HPP_
11 
12 #include "crocoddyl/multibody/fwd.hpp"
13 #include "crocoddyl/multibody/cost-base.hpp"
14 #include "crocoddyl/multibody/data/multibody.hpp"
15 #include "crocoddyl/core/utils/exception.hpp"
16 #include "crocoddyl/core/utils/deprecate.hpp"
17 
18 namespace crocoddyl {
19 
20 template <typename _Scalar>
22  public:
23  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
24 
25  typedef _Scalar Scalar;
34  typedef typename MathBase::Vector3s Vector3s;
35  typedef typename MathBase::VectorXs VectorXs;
36  typedef typename MathBase::MatrixXs MatrixXs;
37 
38  CostModelCoMPositionTpl(boost::shared_ptr<StateMultibody> state,
39  boost::shared_ptr<ActivationModelAbstract> activation, const Vector3s& cref,
40  const std::size_t& nu);
41  CostModelCoMPositionTpl(boost::shared_ptr<StateMultibody> state,
42  boost::shared_ptr<ActivationModelAbstract> activation, const Vector3s& cref);
43  CostModelCoMPositionTpl(boost::shared_ptr<StateMultibody> state, const Vector3s& cref, const std::size_t& nu);
44  CostModelCoMPositionTpl(boost::shared_ptr<StateMultibody> state, const Vector3s& cref);
45  virtual ~CostModelCoMPositionTpl();
46 
47  virtual void calc(const boost::shared_ptr<CostDataAbstract>& data, const Eigen::Ref<const VectorXs>& x,
48  const Eigen::Ref<const VectorXs>& u);
49  virtual void calcDiff(const boost::shared_ptr<CostDataAbstract>& data, const Eigen::Ref<const VectorXs>& x,
50  const Eigen::Ref<const VectorXs>& u);
51  virtual boost::shared_ptr<CostDataAbstract> createData(DataCollectorAbstract* const data);
52 
53  DEPRECATED("Use set_reference<MathBaseTpl<Scalar>::Vector3s>()", void set_cref(const Vector3s& cref_in));
54  DEPRECATED("Use get_reference<MathBaseTpl<Scalar>::Vector3s>()", const Vector3s& get_cref() const);
55 
56  protected:
57  virtual void set_referenceImpl(const std::type_info& ti, const void* pv);
58  virtual void get_referenceImpl(const std::type_info& ti, void* pv) const;
59 
60  using Base::activation_;
61  using Base::nu_;
62  using Base::state_;
63  using Base::unone_;
64 
65  private:
66  Vector3s cref_;
67 };
68 
69 template <typename _Scalar>
70 struct CostDataCoMPositionTpl : public CostDataAbstractTpl<_Scalar> {
71  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
72 
73  typedef _Scalar Scalar;
77  typedef typename MathBase::VectorXs VectorXs;
78  typedef typename MathBase::MatrixXs MatrixXs;
79  typedef typename MathBase::Matrix3xs Matrix3xs;
80  typedef typename MathBase::Matrix6xs Matrix6xs;
81  typedef typename MathBase::Matrix6s Matrix6s;
82  typedef typename MathBase::Vector6s Vector6s;
83 
84  template <template <typename Scalar> class Model>
85  CostDataCoMPositionTpl(Model<Scalar>* const model, DataCollectorAbstract* const data)
86  : Base(model, data), Arr_Jcom(3, model->get_state()->get_nv()) {
87  Arr_Jcom.setZero();
88  // Check that proper shared data has been passed
90  if (d == NULL) {
91  throw_pretty("Invalid argument: the shared data should be derived from DataCollectorMultibody");
92  }
93 
94  // Avoids data casting at runtime
95  pinocchio = d->pinocchio;
96  }
97 
98  pinocchio::DataTpl<Scalar>* pinocchio;
99  Matrix3xs Arr_Jcom;
100 
101  using Base::activation;
102  using Base::cost;
103  using Base::Lu;
104  using Base::Luu;
105  using Base::Lx;
106  using Base::Lxu;
107  using Base::Lxx;
108  using Base::r;
109  using Base::Ru;
110  using Base::Rx;
111  using Base::shared;
112 };
113 
114 } // namespace crocoddyl
115 
116 /* --- Details -------------------------------------------------------------- */
117 /* --- Details -------------------------------------------------------------- */
118 /* --- Details -------------------------------------------------------------- */
119 #include "crocoddyl/multibody/costs/com-position.hxx"
120 
121 #endif // CROCODDYL_MULTIBODY_COSTS_COM_POSITION_HPP_