multiple-contacts.hxx
Go to the documentation of this file.
1 // BSD 3-Clause License
3 //
4 // Copyright (C) 2019-2022, LAAS-CNRS, University of Edinburgh
5 // Copyright note valid unless otherwise stated in individual files.
6 // All rights reserved.
8 
9 namespace sobec {
10 namespace newcontacts {
11 
12 template <typename Scalar>
14  boost::shared_ptr<StateMultibody> state, const std::size_t nu)
15  : Base(state, nu) {}
16 
17 template <typename Scalar>
19  boost::shared_ptr<StateMultibody> state)
20  : Base(state) {}
21 
22 template <typename Scalar>
24 
25 template <typename Scalar>
27  const boost::shared_ptr<ContactDataMultiple>& data,
28  const boost::shared_ptr<MatrixXs> df_dx,
29  const boost::shared_ptr<MatrixXs> df_du) const {
30  const std::size_t ndx = this->get_state()->get_ndx();
31  if (static_cast<std::size_t>(df_dx->rows()) != this->get_nc() ||
32  static_cast<std::size_t>(df_dx->cols()) != ndx) {
33  throw_pretty("Invalid argument: "
34  << "df_dx has wrong dimension (it should be " +
35  std::to_string(this->get_nc()) + "," +
36  std::to_string(ndx) + ")");
37  }
38  if (static_cast<std::size_t>(df_du->rows()) != this->get_nc() ||
39  static_cast<std::size_t>(df_du->cols()) != this->get_nu()) {
40  throw_pretty("Invalid argument: "
41  << "df_du has wrong dimension (it should be " +
42  std::to_string(this->get_nc()) + "," +
43  std::to_string(this->get_nu()) + ")");
44  }
45  if (static_cast<std::size_t>(data->contacts.size()) !=
46  this->get_contacts().size()) {
47  throw_pretty("Invalid argument: "
48  << "it doesn't match the number of contact datas and models");
49  }
50 
51  std::size_t nc = 0;
52  typename ContactModelContainer::const_iterator it_m, end_m;
53  typename ContactDataContainer::const_iterator it_d, end_d;
54  for (it_m = this->get_contacts().begin(), end_m = this->get_contacts().end(),
55  it_d = data->contacts.begin(), end_d = data->contacts.end();
56  it_m != end_m || it_d != end_d; ++it_m, ++it_d) {
57  const boost::shared_ptr<ContactItem>& m_i = it_m->second;
58  const boost::shared_ptr<ContactDataAbstract>& d_i = it_d->second;
59  assert_pretty(it_m->first == it_d->first,
60  "it doesn't match the contact name between data and model");
61  if (m_i->active) {
62  const std::size_t nc_i = m_i->contact->get_nc();
63  m_i->contact->updateForceDiff(d_i, df_dx->block(nc, 0, nc_i, ndx),
64  df_du->block(nc, 0, nc_i, this->get_nu()));
65  nc += nc_i;
66  } else {
67  m_i->contact->setZeroForceDiff(d_i);
68  }
69  }
70 }
71 
72 template <typename Scalar>
74  const boost::shared_ptr<ContactDataMultiple>& data,
75  pinocchio::DataTpl<Scalar>& pinocchio) const {
76  const std::size_t nv = this->get_state()->get_nv();
77  if (static_cast<std::size_t>(data->contacts.size()) !=
78  this->get_contacts().size()) {
79  throw_pretty("Invalid argument: "
80  << "it doesn't match the number of contact datas and models");
81  }
82  typename ContactModelContainer::const_iterator it_m, end_m;
83  typename ContactDataContainer::const_iterator it_d, end_d;
84  for (it_m = this->get_contacts().begin(), end_m = this->get_contacts().end(),
85  it_d = data->contacts.begin(), end_d = data->contacts.end();
86  it_m != end_m || it_d != end_d; ++it_m, ++it_d) {
87  const boost::shared_ptr<ContactItem>& m_i = it_m->second;
88  const boost::shared_ptr<ContactDataAbstract>& d_i = it_d->second;
89  assert_pretty(it_m->first == it_d->first,
90  "it doesn't match the contact name between data and model");
91  if (m_i->active) {
92  const std::size_t nc_i = m_i->contact->get_nc();
93  if (nc_i == 6) {
95  static_cast<ContactModel6DTpl<Scalar>*>(m_i->contact.get());
97  static_cast<ContactData6DTpl<Scalar>*>(d_i.get());
98  if (cm_i->get_type() == pinocchio::WORLD ||
99  cm_i->get_type() == pinocchio::LOCAL_WORLD_ALIGNED) {
100  pinocchio.dtau_dq.block(0, 0, nv, nv) += cd_i->drnea_skew_term_;
101  }
102  }
103  if (nc_i == 3) {
105  static_cast<ContactModel3DTpl<Scalar>*>(m_i->contact.get());
107  static_cast<ContactData3DTpl<Scalar>*>(d_i.get());
108  if (cm_i->get_type() == pinocchio::WORLD ||
109  cm_i->get_type() == pinocchio::LOCAL_WORLD_ALIGNED) {
110  pinocchio.dtau_dq.block(0, 0, nv, nv) += cd_i->drnea_skew_term_;
111  }
112  }
113  if (nc_i == 1) {
115  static_cast<ContactModel1DTpl<Scalar>*>(m_i->contact.get());
117  static_cast<ContactData1DTpl<Scalar>*>(d_i.get());
118  if (cm_i->get_type() == pinocchio::WORLD ||
119  cm_i->get_type() == pinocchio::LOCAL_WORLD_ALIGNED) {
120  pinocchio.dtau_dq.block(0, 0, nv, nv) += cd_i->drnea_skew_term_;
121  }
122  }
123  }
124  }
125 }
126 
127 // template <typename Scalar>
128 // MathBase::MatrixXs ContactModelMultipleTpl<Scalar>::rotateJacobians(const
129 // boost::shared_ptr<MathBase::MatrixXs>& Jin) {
130 // MathBase::MatrixXs Jout = MatrixXs(Jin);
131 // std::size_t nc = 0;
132 // const std::size_t nv = this->get_state()->get_nv();
133 // typename ContactModelContainer::const_iterator it_m, end_m;
134 // typename ContactDataContainer::const_iterator it_d, end_d;
135 // for (it_m = this->get_contacts().begin(), end_m =
136 // this->get_contacts().end(), it_d = data->contacts.begin(), end_d =
137 // data->contacts.end();
138 // it_m != end_m || it_d != end_d; ++it_m, ++it_d) {
139 // const boost::shared_ptr<ContactItem>& m_i = it_m->second;
140 // const boost::shared_ptr<ContactDataAbstract>& d_i = it_d->second;
141 // assert_pretty(it_m->first == it_d->first, "it doesn't match the contact
142 // name between data and model"); if (m_i->active) {
143 // const std::size_t nc_i = m_i->contact->get_nc();
144 // // if (nc_i == 3) {
145 // // ContactModel3DTpl<Scalar>* cm_i =
146 // static_cast<ContactModel3DTpl<Scalar>*>(m_i->contact.get());
147 // // ContactData3DTpl<Scalar>* cd_i =
148 // static_cast<ContactData3DTpl<Scalar>*>(d_i.get());
149 // // Jout.block(nc, 0, nc_i, nv) = m_i->contact->Jc;
150 // // }
151 // if (nc_i == 1) {
152 // ContactModel1DTpl<Scalar>* cm_i =
153 // static_cast<ContactModel1DTpl<Scalar>*>(m_i->contact.get());
154 // ContactData1DTpl<Scalar>* cd_i =
155 // static_cast<ContactData1DTpl<Scalar>*>(d_i.get()); Jout.block(nc, 0,
156 // nc_i, nv) = (d_i->oRf * d_i->fJf.topRows(3)).row(cm_i->get_mask());
157 // // d->oRf * d->fJf
158 // }
159 // nc += nc_i;
160 // }
161 // }
162 // return Jout
163 // }
164 
165 } // namespace newcontacts
166 } // namespace sobec
sobec::newcontacts::ContactModelMultipleTpl::updateForceDiff
void updateForceDiff(const boost::shared_ptr< ContactDataMultiple > &data, const boost::shared_ptr< MatrixXs > df_dx, const boost::shared_ptr< MatrixXs > df_du) const
Update the Jacobian of the spatial force defined in frame coordinate.
Definition: multiple-contacts.hxx:26
sobec::newcontacts::ContactData6DTpl
Definition: contact6d.hpp:157
sobec::newcontacts::ContactModel3DTpl
Definition: contact3d.hpp:28
sobec::newcontacts::ContactModel3DTpl::get_type
const pinocchio::ReferenceFrame & get_type() const
Get pinocchio::ReferenceFrame.
Definition: contact3d.hxx:202
sobec::newcontacts::ContactModelMultipleTpl::~ContactModelMultipleTpl
~ContactModelMultipleTpl()
Definition: multiple-contacts.hxx:23
sobec::newcontacts::ContactModel6DTpl::get_type
const pinocchio::ReferenceFrame & get_type() const
Get pinocchio::ReferenceFrame.
Definition: contact6d.hxx:190
sobec::newcontacts::ContactModelMultipleTpl::Base
crocoddyl::ContactModelMultipleTpl< Scalar > Base
Definition: multiple-contacts.hpp:44
sobec::newcontacts::ContactData1DTpl
Definition: contact1d.hpp:173
sobec
Definition: activation-quad-ref.hpp:19
sobec::newcontacts::ContactData3DTpl
Definition: contact3d.hpp:155
sobec::newcontacts::ContactModel1DTpl::get_type
const pinocchio::ReferenceFrame & get_type() const
Get pinocchio::ReferenceFrame.
Definition: contact1d.hxx:208
sobec::newcontacts::ContactModelMultipleTpl::ContactModelMultipleTpl
ContactModelMultipleTpl(boost::shared_ptr< StateMultibody > state, const std::size_t nu)
Initialize the multi-contact model.
Definition: multiple-contacts.hxx:13
sobec::newcontacts::ContactModel6DTpl
Definition: contact6d.hpp:28
sobec::newcontacts::ContactModel1DTpl
Definition: contact1d.hpp:29
sobec::newcontacts::ContactModelMultipleTpl::updateRneaDerivatives
void updateRneaDerivatives(const boost::shared_ptr< ContactDataMultiple > &data, pinocchio::DataTpl< Scalar > &pinocchio) const
Update the RNEA derivatives dtau_dq by adding the skew term (necessary for contacts expressed in LOCA...
Definition: multiple-contacts.hxx:73