Crocoddyl
contact-3d.hpp
1 // BSD 3-Clause License
3 //
4 // Copyright (C) 2019-2023, LAAS-CNRS, University f_world Edinburgh,
5 // Heriot-Watt University
6 // Copyright note valid unless otherwise stated in individual files.
7 // All rights reserved.
9 
10 #ifndef CROCODDYL_MULTIBODY_CONTACTS_CONTACT_3D_HPP_
11 #define CROCODDYL_MULTIBODY_CONTACTS_CONTACT_3D_HPP_
12 
13 #include <pinocchio/algorithm/frames.hpp>
14 #include <pinocchio/algorithm/kinematics-derivatives.hpp>
15 #include <pinocchio/multibody/data.hpp>
16 #include <pinocchio/spatial/motion.hpp>
17 
18 #include "crocoddyl/core/utils/deprecate.hpp"
19 #include "crocoddyl/core/utils/exception.hpp"
20 #include "crocoddyl/multibody/contact-base.hpp"
21 #include "crocoddyl/multibody/fwd.hpp"
22 
23 namespace crocoddyl {
24 
25 template <typename _Scalar>
26 class ContactModel3DTpl : public ContactModelAbstractTpl<_Scalar> {
27  public:
28  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
29 
30  typedef _Scalar Scalar;
36  typedef typename MathBase::Matrix3s Matrix3s;
37  typedef typename MathBase::Vector2s Vector2s;
38  typedef typename MathBase::Vector3s Vector3s;
39  typedef typename MathBase::VectorXs VectorXs;
40 
56  ContactModel3DTpl(boost::shared_ptr<StateMultibody> state,
57  const pinocchio::FrameIndex id, const Vector3s& xref,
58  const pinocchio::ReferenceFrame type, const std::size_t nu,
59  const Vector2s& gains = Vector2s::Zero());
60 
76  ContactModel3DTpl(boost::shared_ptr<StateMultibody> state,
77  const pinocchio::FrameIndex id, const Vector3s& xref,
78  const pinocchio::ReferenceFrame type,
79  const Vector2s& gains = Vector2s::Zero());
80 
81  DEPRECATED(
82  "Use constructor that passes the type type of contact, this assumes is "
83  "pinocchio::LOCAL",
84  ContactModel3DTpl(boost::shared_ptr<StateMultibody> state,
85  const pinocchio::FrameIndex id, const Vector3s& xref,
86  const std::size_t nu,
87  const Vector2s& gains = Vector2s::Zero());)
88  DEPRECATED(
89  "Use constructor that passes the type type of contact, this assumes is "
90  "pinocchio::LOCAL",
91  ContactModel3DTpl(boost::shared_ptr<StateMultibody> state,
92  const pinocchio::FrameIndex id, const Vector3s& xref,
93  const Vector2s& gains = Vector2s::Zero());)
94  virtual ~ContactModel3DTpl();
95 
103  virtual void calc(const boost::shared_ptr<ContactDataAbstract>& data,
104  const Eigen::Ref<const VectorXs>& x);
105 
113  virtual void calcDiff(const boost::shared_ptr<ContactDataAbstract>& data,
114  const Eigen::Ref<const VectorXs>& x);
115 
122  virtual void updateForce(const boost::shared_ptr<ContactDataAbstract>& data,
123  const VectorXs& force);
124 
128  virtual boost::shared_ptr<ContactDataAbstract> createData(
129  pinocchio::DataTpl<Scalar>* const data);
130 
134  const Vector3s& get_reference() const;
135 
139  const Vector2s& get_gains() const;
140 
144  void set_reference(const Vector3s& reference);
145 
151  virtual void print(std::ostream& os) const;
152 
153  protected:
154  using Base::id_;
155  using Base::nc_;
156  using Base::nu_;
157  using Base::state_;
158  using Base::type_;
159 
160  private:
161  Vector3s xref_;
162  Vector2s gains_;
163 };
164 
165 template <typename _Scalar>
166 struct ContactData3DTpl : public ContactDataAbstractTpl<_Scalar> {
167  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
168 
169  typedef _Scalar Scalar;
172  typedef typename MathBase::Vector3s Vector3s;
173  typedef typename MathBase::Matrix3s Matrix3s;
174  typedef typename MathBase::Matrix3xs Matrix3xs;
175  typedef typename MathBase::Matrix6xs Matrix6xs;
176  typedef typename pinocchio::MotionTpl<Scalar> Motion;
177  typedef typename pinocchio::ForceTpl<Scalar> Force;
178 
179  template <template <typename Scalar> class Model>
180  ContactData3DTpl(Model<Scalar>* const model,
181  pinocchio::DataTpl<Scalar>* const data)
182  : Base(model, data),
183  v(Motion::Zero()),
184  f_local(Force::Zero()),
185  da0_local_dx(3, model->get_state()->get_ndx()),
186  fJf(6, model->get_state()->get_nv()),
187  v_partial_dq(6, model->get_state()->get_nv()),
188  a_partial_dq(6, model->get_state()->get_nv()),
189  a_partial_dv(6, model->get_state()->get_nv()),
190  a_partial_da(6, model->get_state()->get_nv()),
191  fXjdv_dq(6, model->get_state()->get_nv()),
192  fXjda_dq(6, model->get_state()->get_nv()),
193  fXjda_dv(6, model->get_state()->get_nv()),
194  fJf_df(3, model->get_state()->get_nv()) {
195  frame = model->get_id();
196  jMf = model->get_state()->get_pinocchio()->frames[frame].placement;
197  fXj = jMf.inverse().toActionMatrix();
198  a0_local.setZero();
199  dp.setZero();
200  dp_local.setZero();
201  da0_local_dx.setZero();
202  fJf.setZero();
203  v_partial_dq.setZero();
204  a_partial_dq.setZero();
205  a_partial_dv.setZero();
206  a_partial_da.setZero();
207  vv_skew.setZero();
208  vw_skew.setZero();
209  a0_skew.setZero();
210  a0_world_skew.setZero();
211  dp_skew.setZero();
212  f_skew.setZero();
213  fXjdv_dq.setZero();
214  fXjda_dq.setZero();
215  fXjda_dv.setZero();
216  fJf_df.setZero();
217  }
218 
219  using Base::a0;
220  using Base::da0_dx;
221  using Base::df_du;
222  using Base::df_dx;
223  using Base::f;
224  using Base::frame;
225  using Base::fXj;
226  using Base::Jc;
227  using Base::jMf;
228  using Base::pinocchio;
229 
230  Motion v;
231  Vector3s a0_local;
232  Vector3s dp;
233  Vector3s dp_local;
234  Force f_local;
235  Matrix3xs da0_local_dx;
236  Matrix6xs fJf;
237  Matrix6xs v_partial_dq;
238  Matrix6xs a_partial_dq;
239  Matrix6xs a_partial_dv;
240  Matrix6xs a_partial_da;
241  Matrix3s vv_skew;
242  Matrix3s vw_skew;
243  Matrix3s a0_skew;
244  Matrix3s a0_world_skew;
245  Matrix3s dp_skew;
246  Matrix3s f_skew;
247  Matrix6xs fXjdv_dq;
248  Matrix6xs fXjda_dq;
249  Matrix6xs fXjda_dv;
250  Matrix3xs fJf_df;
251 };
252 
253 } // namespace crocoddyl
254 
255 /* --- Details -------------------------------------------------------------- */
256 /* --- Details -------------------------------------------------------------- */
257 /* --- Details -------------------------------------------------------------- */
258 #include "crocoddyl/multibody/contacts/contact-3d.hxx"
259 
260 #endif // CROCODDYL_MULTIBODY_CONTACTS_CONTACT_3D_HPP_
void set_reference(const Vector3s &reference)
Modify the reference frame translation.
const Vector3s & get_reference() const
Return the reference frame translation.
ContactModel3DTpl(boost::shared_ptr< StateMultibody > state, const pinocchio::FrameIndex id, const Vector3s &xref, const pinocchio::ReferenceFrame type, const Vector2s &gains=Vector2s::Zero())
Initialize the 3d contact model.
virtual void print(std::ostream &os) const
Print relevant information of the 3d 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 3d contact data.
virtual void calc(const boost::shared_ptr< ContactDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
Compute the 3d contact Jacobian and drift.
ContactModel3DTpl(boost::shared_ptr< StateMultibody > state, const pinocchio::FrameIndex id, const Vector3s &xref, const pinocchio::ReferenceFrame type, const std::size_t nu, const Vector2s &gains=Vector2s::Zero())
Initialize the 3d contact model.
const Vector2s & get_gains() const
Return the Baumgarte stabilization gains.
virtual void calcDiff(const boost::shared_ptr< ContactDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
Compute the derivatives of the 3d contact holonomic constraint.
pinocchio::ReferenceFrame type_
Type of contact.
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