Crocoddyl
impulse-base.hpp
1 // BSD 3-Clause License
3 //
4 // Copyright (C) 2019-2023, LAAS-CNRS, University of Edinburgh,
5 // Heriot-Watt University
6 // Copyright note valid unless otherwise stated in individual files.
7 // All rights reserved.
9 
10 #ifndef CROCODDYL_MULTIBODY_IMPULSE_BASE_HPP_
11 #define CROCODDYL_MULTIBODY_IMPULSE_BASE_HPP_
12 
13 #include "crocoddyl/core/utils/deprecate.hpp"
14 #include "crocoddyl/multibody/force-base.hpp"
15 #include "crocoddyl/multibody/fwd.hpp"
16 #include "crocoddyl/multibody/states/multibody.hpp"
17 
18 namespace crocoddyl {
19 
20 template <typename _Scalar>
22  public:
23  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
24 
25  typedef _Scalar Scalar;
29  typedef typename MathBase::VectorXs VectorXs;
30  typedef typename MathBase::MatrixXs MatrixXs;
31 
32  ImpulseModelAbstractTpl(boost::shared_ptr<StateMultibody> state,
33  const pinocchio::ReferenceFrame type,
34  const std::size_t nc);
35 
36  DEPRECATED(
37  "Use constructor that passes the type type of contact, this assumes is "
38  "pinocchio::LOCAL",
39  ImpulseModelAbstractTpl(boost::shared_ptr<StateMultibody> state,
40  const std::size_t nc);)
41  virtual ~ImpulseModelAbstractTpl();
42 
43  virtual void calc(const boost::shared_ptr<ImpulseDataAbstract>& data,
44  const Eigen::Ref<const VectorXs>& x) = 0;
45  virtual void calcDiff(const boost::shared_ptr<ImpulseDataAbstract>& data,
46  const Eigen::Ref<const VectorXs>& x) = 0;
47 
48  virtual void updateForce(const boost::shared_ptr<ImpulseDataAbstract>& data,
49  const VectorXs& force) = 0;
50  void updateForceDiff(const boost::shared_ptr<ImpulseDataAbstract>& data,
51  const MatrixXs& df_dx) const;
52  void setZeroForce(const boost::shared_ptr<ImpulseDataAbstract>& data) const;
53  void setZeroForceDiff(
54  const boost::shared_ptr<ImpulseDataAbstract>& data) const;
55 
56  virtual boost::shared_ptr<ImpulseDataAbstract> createData(
57  pinocchio::DataTpl<Scalar>* const data);
58 
59  const boost::shared_ptr<StateMultibody>& get_state() const;
60  std::size_t get_nc() const;
61  DEPRECATED("Use get_nc().", std::size_t get_ni() const;)
62  std::size_t get_nu() const;
63 
67  pinocchio::FrameIndex get_id() const;
68 
72  void set_id(const pinocchio::FrameIndex id);
73 
77  void set_type(const pinocchio::ReferenceFrame type);
78 
82  pinocchio::ReferenceFrame get_type() const;
83 
87  template <class Scalar>
88  friend std::ostream& operator<<(std::ostream& os,
89  const ImpulseModelAbstractTpl<Scalar>& model);
90 
96  virtual void print(std::ostream& os) const;
97 
98  protected:
99  boost::shared_ptr<StateMultibody> state_;
100  std::size_t nc_;
101  pinocchio::FrameIndex id_;
102  pinocchio::ReferenceFrame type_;
103 };
104 
105 template <typename _Scalar>
107  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
108 
109  typedef _Scalar Scalar;
112  typedef typename MathBase::VectorXs VectorXs;
113  typedef typename MathBase::MatrixXs MatrixXs;
114  typedef typename pinocchio::SE3Tpl<Scalar> SE3;
115 
116  template <template <typename Scalar> class Model>
117  ImpulseDataAbstractTpl(Model<Scalar>* const model,
118  pinocchio::DataTpl<Scalar>* const data)
119  : Base(model, data),
120  dv0_dq(model->get_nc(), model->get_state()->get_nv()),
121  dtau_dq(model->get_state()->get_nv(), model->get_state()->get_nv()) {
122  dv0_dq.setZero();
123  dtau_dq.setZero();
124  }
125  virtual ~ImpulseDataAbstractTpl() {}
126 
127  using Base::df_dx;
128  using Base::f;
129  using Base::frame;
130  using Base::Jc;
131  using Base::jMf;
132  using Base::pinocchio;
133 
134  typename SE3::ActionMatrixType fXj;
135  MatrixXs dv0_dq;
136  MatrixXs dtau_dq;
137 };
138 
139 } // namespace crocoddyl
140 
141 /* --- Details -------------------------------------------------------------- */
142 /* --- Details -------------------------------------------------------------- */
143 /* --- Details -------------------------------------------------------------- */
144 #include "crocoddyl/multibody/impulse-base.hxx"
145 
146 #endif // CROCODDYL_MULTIBODY_IMPULSE_BASE_HPP_
virtual void print(std::ostream &os) const
Print relevant information of the impulse model.
void set_id(const pinocchio::FrameIndex id)
Modify the reference frame id.
pinocchio::ReferenceFrame type_
Type of contact.
DEPRECATED("Use get_nc().", std::size_t get_ni() const ;) std pinocchio::FrameIndex get_id() const
Return the reference frame id.
void set_type(const pinocchio::ReferenceFrame type)
Modify the type of contact.
pinocchio::ReferenceFrame get_type() const
Return the type of contact.
pinocchio::FrameIndex id_
Reference frame id of the contact.
friend std::ostream & operator<<(std::ostream &os, const ImpulseModelAbstractTpl< Scalar > &model)
Print information on the impulse model.
State multibody representation.
Definition: multibody.hpp:35
PinocchioData * pinocchio
Pinocchio data.
Definition: force-base.hpp:49
pinocchio::FrameIndex frame
Frame index of the contact frame.
Definition: force-base.hpp:50
SE3 jMf
Local frame placement of the contact frame.
Definition: force-base.hpp:52
MatrixXs Jc
Contact Jacobian.
Definition: force-base.hpp:53
Force f
Contact force expressed in the coordinate defined by type.
Definition: force-base.hpp:54