Crocoddyl
contact-2d.hpp
1 // BSD 3-Clause License
3 //
4 // Copyright (C) 2020-2021, LAAS-CNRS, University of Edinburgh
5 // Copyright note valid unless otherwise stated in individual files.
6 // All rights reserved.
8 
9 #ifndef CROCODDYL_MULTIBODY_CONTACTS_CONTACT_2D_HPP_
10 #define CROCODDYL_MULTIBODY_CONTACTS_CONTACT_2D_HPP_
11 
12 #include <pinocchio/algorithm/frames.hpp>
13 #include <pinocchio/algorithm/kinematics-derivatives.hpp>
14 #include <pinocchio/multibody/data.hpp>
15 #include <pinocchio/spatial/motion.hpp>
16 
17 #include "crocoddyl/core/utils/exception.hpp"
18 #include "crocoddyl/multibody/contact-base.hpp"
19 #include "crocoddyl/multibody/fwd.hpp"
20 
21 namespace crocoddyl {
22 
23 template <typename _Scalar>
24 class ContactModel2DTpl : public ContactModelAbstractTpl<_Scalar> {
25  public:
26  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
27 
28  typedef _Scalar Scalar;
34  typedef typename MathBase::Vector2s Vector2s;
35  typedef typename MathBase::Vector3s Vector3s;
36  typedef typename MathBase::VectorXs VectorXs;
37  typedef typename MathBase::Matrix3s Matrix3s;
38 
48  ContactModel2DTpl(boost::shared_ptr<StateMultibody> state,
49  const pinocchio::FrameIndex id, const Vector2s& xref,
50  const std::size_t nu,
51  const Vector2s& gains = Vector2s::Zero());
52 
63  ContactModel2DTpl(boost::shared_ptr<StateMultibody> state,
64  const pinocchio::FrameIndex id, const Vector2s& xref,
65  const Vector2s& gains = Vector2s::Zero());
66  virtual ~ContactModel2DTpl();
67 
75  virtual void calc(const boost::shared_ptr<ContactDataAbstract>& data,
76  const Eigen::Ref<const VectorXs>& x);
77 
85  virtual void calcDiff(const boost::shared_ptr<ContactDataAbstract>& data,
86  const Eigen::Ref<const VectorXs>& x);
87 
94  virtual void updateForce(const boost::shared_ptr<ContactDataAbstract>& data,
95  const VectorXs& force);
96 
100  virtual boost::shared_ptr<ContactDataAbstract> createData(
101  pinocchio::DataTpl<Scalar>* const data);
102 
106  const Vector2s& get_reference() const;
107 
111  const Vector2s& get_gains() const;
112 
116  void set_reference(const Vector2s& reference);
117 
123  virtual void print(std::ostream& os) const;
124 
125  protected:
126  using Base::id_;
127  using Base::nc_;
128  using Base::nu_;
129  using Base::state_;
130 
131  private:
132  Vector2s xref_;
133  Vector2s gains_;
134 };
135 
136 template <typename _Scalar>
137 struct ContactData2DTpl : public ContactDataAbstractTpl<_Scalar> {
138  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
139 
140  typedef _Scalar Scalar;
143  typedef typename MathBase::Matrix2s Matrix2s;
144  typedef typename MathBase::Matrix3s Matrix3s;
145  typedef typename MathBase::Matrix6xs Matrix6xs;
146  typedef typename MathBase::Vector3s Vector3s;
147 
148  template <template <typename Scalar> class Model>
149  ContactData2DTpl(Model<Scalar>* const model,
150  pinocchio::DataTpl<Scalar>* const data)
151  : Base(model, data),
152  fJf(6, model->get_state()->get_nv()),
153  v_partial_dq(6, model->get_state()->get_nv()),
154  a_partial_dq(6, model->get_state()->get_nv()),
155  a_partial_dv(6, model->get_state()->get_nv()),
156  a_partial_da(6, model->get_state()->get_nv()),
157  fXjdv_dq(6, model->get_state()->get_nv()),
158  fXjda_dq(6, model->get_state()->get_nv()),
159  fXjda_dv(6, model->get_state()->get_nv()) {
160  frame = model->get_id();
161  jMf = model->get_state()->get_pinocchio()->frames[frame].placement;
162  fXj = jMf.inverse().toActionMatrix();
163  fJf.setZero();
164  v_partial_dq.setZero();
165  a_partial_dq.setZero();
166  a_partial_dv.setZero();
167  a_partial_da.setZero();
168  fXjdv_dq.setZero();
169  fXjda_dq.setZero();
170  fXjda_dv.setZero();
171  vv.setZero();
172  vw.setZero();
173  vv_skew.setZero();
174  vw_skew.setZero();
175  oRf.setZero();
176  }
177 
178  using Base::a0;
179  using Base::da0_dx;
180  using Base::df_du;
181  using Base::df_dx;
182  using Base::f;
183  using Base::frame;
184  using Base::fXj;
185  using Base::Jc;
186  using Base::jMf;
187  using Base::pinocchio;
188 
189  pinocchio::MotionTpl<Scalar> v;
190  pinocchio::MotionTpl<Scalar> a;
191  Matrix6xs fJf;
192  Matrix6xs v_partial_dq;
193  Matrix6xs a_partial_dq;
194  Matrix6xs a_partial_dv;
195  Matrix6xs a_partial_da;
196  Matrix6xs fXjdv_dq;
197  Matrix6xs fXjda_dq;
198  Matrix6xs fXjda_dv;
199  Vector3s vv;
200  Vector3s vw;
201  Matrix3s vv_skew;
202  Matrix3s vw_skew;
203  Matrix2s oRf;
204 };
205 
206 } // namespace crocoddyl
207 
208 /* --- Details -------------------------------------------------------------- */
209 /* --- Details -------------------------------------------------------------- */
210 /* --- Details -------------------------------------------------------------- */
211 #include "crocoddyl/multibody/contacts/contact-2d.hxx"
212 
213 #endif // CROCODDYL_MULTIBODY_CONTACTS_CONTACT_2D_HPP_
const Vector2s & get_reference() const
Return the reference frame translation.
virtual void print(std::ostream &os) const
Print relevant information of the 2d contact model.
virtual void updateForce(const boost::shared_ptr< ContactDataAbstract > &data, const VectorXs &force)
Convert the force into a stack of spatial forces.
virtual boost::shared_ptr< ContactDataAbstract > createData(pinocchio::DataTpl< Scalar > *const data)
Create the 2d contact data.
virtual void calc(const boost::shared_ptr< ContactDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
Compute the 2d contact Jacobian and drift.
const Vector2s & get_gains() const
Create the 2d contact data.
virtual void calcDiff(const boost::shared_ptr< ContactDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
Compute the derivatives of the 2d contact holonomic constraint.
ContactModel2DTpl(boost::shared_ptr< StateMultibody > state, const pinocchio::FrameIndex id, const Vector2s &xref, const Vector2s &gains=Vector2s::Zero())
Initialize the 2d contact model.
ContactModel2DTpl(boost::shared_ptr< StateMultibody > state, const pinocchio::FrameIndex id, const Vector2s &xref, const std::size_t nu, const Vector2s &gains=Vector2s::Zero())
Initialize the 2d contact model.
void set_reference(const Vector2s &reference)
Modify the reference frame translation.
pinocchio::FrameIndex id_
Reference frame id of the contact.
State multibody representation.
Definition: multibody.hpp:35
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
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
Force f
Contact force expressed in the coordinate defined by type.
Definition: force-base.hpp:54