Crocoddyl
contact-6d.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_CONTACTS_CONTACT_6D_HPP_
11 #define CROCODDYL_MULTIBODY_CONTACTS_CONTACT_6D_HPP_
12 
13 #include <pinocchio/multibody/data.hpp>
14 #include <pinocchio/spatial/motion.hpp>
15 
16 #include "crocoddyl/core/utils/deprecate.hpp"
17 #include "crocoddyl/multibody/contact-base.hpp"
18 #include "crocoddyl/multibody/fwd.hpp"
19 
20 namespace crocoddyl {
21 
22 template <typename _Scalar>
23 class ContactModel6DTpl : public ContactModelAbstractTpl<_Scalar> {
24  public:
25  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
26 
27  typedef _Scalar Scalar;
33  typedef pinocchio::SE3Tpl<Scalar> SE3;
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 
54  ContactModel6DTpl(boost::shared_ptr<StateMultibody> state,
55  const pinocchio::FrameIndex id, const SE3& pref,
56  const pinocchio::ReferenceFrame type, const std::size_t nu,
57  const Vector2s& gains = Vector2s::Zero());
58 
74  ContactModel6DTpl(boost::shared_ptr<StateMultibody> state,
75  const pinocchio::FrameIndex id, const SE3& pref,
76  const pinocchio::ReferenceFrame type,
77  const Vector2s& gains = Vector2s::Zero());
78 
79  DEPRECATED(
80  "Use constructor that passes the type type of contact, this assumes is "
81  "pinocchio::LOCAL",
82  ContactModel6DTpl(boost::shared_ptr<StateMultibody> state,
83  const pinocchio::FrameIndex id, const SE3& pref,
84  const std::size_t nu,
85  const Vector2s& gains = Vector2s::Zero());)
86  DEPRECATED(
87  "Use constructor that passes the type type of contact, this assumes is "
88  "pinocchio::LOCAL",
89  ContactModel6DTpl(boost::shared_ptr<StateMultibody> state,
90  const pinocchio::FrameIndex id, const SE3& pref,
91  const Vector2s& gains = Vector2s::Zero());)
92  virtual ~ContactModel6DTpl();
93 
101  virtual void calc(const boost::shared_ptr<ContactDataAbstract>& data,
102  const Eigen::Ref<const VectorXs>& x);
103 
111  virtual void calcDiff(const boost::shared_ptr<ContactDataAbstract>& data,
112  const Eigen::Ref<const VectorXs>& x);
113 
120  virtual void updateForce(const boost::shared_ptr<ContactDataAbstract>& data,
121  const VectorXs& force);
122 
126  virtual boost::shared_ptr<ContactDataAbstract> createData(
127  pinocchio::DataTpl<Scalar>* const data);
128 
132  const SE3& get_reference() const;
133 
137  const Vector2s& get_gains() const;
138 
142  void set_reference(const SE3& reference);
143 
149  virtual void print(std::ostream& os) const;
150 
151  protected:
152  using Base::id_;
153  using Base::nc_;
154  using Base::nu_;
155  using Base::state_;
156  using Base::type_;
157 
158  private:
159  SE3 pref_;
160  Vector2s gains_;
161 };
162 
163 template <typename _Scalar>
164 struct ContactData6DTpl : public ContactDataAbstractTpl<_Scalar> {
165  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
166 
167  typedef _Scalar Scalar;
170  typedef typename MathBase::Matrix3s Matrix3s;
171  typedef typename MathBase::Matrix6xs Matrix6xs;
172  typedef typename MathBase::Matrix6s Matrix6s;
173  typedef typename MathBase::MatrixXs MatrixXs;
174  typedef typename pinocchio::SE3Tpl<Scalar> SE3;
175  typedef typename pinocchio::MotionTpl<Scalar> Motion;
176  typedef typename pinocchio::ForceTpl<Scalar> Force;
177 
178  template <template <typename Scalar> class Model>
179  ContactData6DTpl(Model<Scalar>* const model,
180  pinocchio::DataTpl<Scalar>* const data)
181  : Base(model, data),
182  rMf(SE3::Identity()),
183  lwaMl(SE3::Identity()),
184  v(Motion::Zero()),
185  a0_local(Motion::Zero()),
186  f_local(Force::Zero()),
187  da0_local_dx(6, model->get_state()->get_ndx()),
188  fJf(6, model->get_state()->get_nv()),
189  v_partial_dq(6, model->get_state()->get_nv()),
190  a_partial_dq(6, model->get_state()->get_nv()),
191  a_partial_dv(6, model->get_state()->get_nv()),
192  a_partial_da(6, model->get_state()->get_nv()),
193  fJf_df(6, model->get_state()->get_nv()) {
194  frame = model->get_id();
195  jMf = model->get_state()->get_pinocchio()->frames[frame].placement;
196  fXj = jMf.inverse().toActionMatrix();
197  da0_local_dx.setZero();
198  fJf.setZero();
199  v_partial_dq.setZero();
200  a_partial_dq.setZero();
201  a_partial_dv.setZero();
202  a_partial_da.setZero();
203  av_world_skew.setZero();
204  aw_world_skew.setZero();
205  av_skew.setZero();
206  aw_skew.setZero();
207  fv_skew.setZero();
208  fw_skew.setZero();
209  rMf_Jlog6.setZero();
210  fJf_df.setZero();
211  }
212 
213  using Base::a0;
214  using Base::da0_dx;
215  using Base::df_du;
216  using Base::df_dx;
217  using Base::f;
218  using Base::frame;
219  using Base::fXj;
220  using Base::Jc;
221  using Base::jMf;
222  using Base::pinocchio;
223 
224  SE3 rMf;
225  SE3 lwaMl;
226  Motion v;
227  Motion a0_local;
228  Force f_local;
229  Matrix6xs da0_local_dx;
230  MatrixXs fJf;
231  Matrix6xs v_partial_dq;
232  Matrix6xs a_partial_dq;
233  Matrix6xs a_partial_dv;
234  Matrix6xs a_partial_da;
235  Matrix3s av_world_skew;
236  Matrix3s aw_world_skew;
237  Matrix3s av_skew;
238  Matrix3s aw_skew;
239  Matrix3s fv_skew;
240  Matrix3s fw_skew;
241  Matrix6s rMf_Jlog6;
242  MatrixXs fJf_df;
243 };
244 
245 } // namespace crocoddyl
246 /* --- Details -------------------------------------------------------------- */
247 /* --- Details -------------------------------------------------------------- */
248 /* --- Details -------------------------------------------------------------- */
249 #include "crocoddyl/multibody/contacts/contact-6d.hxx"
250 
251 #endif // CROCODDYL_MULTIBODY_CONTACTS_CONTACT_6D_HPP_
const SE3 & get_reference() const
Return the reference frame placement.
virtual void print(std::ostream &os) const
Print relevant information of the 6d 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 6d contact data.
virtual void calc(const boost::shared_ptr< ContactDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
Compute the 3d contact Jacobian and drift.
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 6d contact holonomic constraint.
void set_reference(const SE3 &reference)
Modify the reference frame placement.
ContactModel6DTpl(boost::shared_ptr< StateMultibody > state, const pinocchio::FrameIndex id, const SE3 &pref, const pinocchio::ReferenceFrame type, const Vector2s &gains=Vector2s::Zero())
Initialize the 6d contact model.
ContactModel6DTpl(boost::shared_ptr< StateMultibody > state, const pinocchio::FrameIndex id, const SE3 &pref, const pinocchio::ReferenceFrame type, const std::size_t nu, const Vector2s &gains=Vector2s::Zero())
Initialize the 6d contact model.
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