Contact.h
Go to the documentation of this file.
1 /*
2  * Copyright 2015-2019 CNRS-UM LIRMM, CNRS-AIST JRL
3  */
4 
5 #ifndef _H_MCRBDYN_CONTACT_H_
6 #define _H_MCRBDYN_CONTACT_H_
7 
8 #include <mc_rbdyn/api.h>
9 #include <mc_rtc/Configuration.h>
10 
11 #include <Tasks/QPContacts.h>
12 
13 #include <SpaceVecAlg/SpaceVecAlg>
14 
15 #include <memory>
16 
17 namespace mc_solver
18 {
19 
21 {
22  QPContactPtr() : unilateralContact(nullptr), bilateralContact(nullptr) {}
23  tasks::qp::UnilateralContact * unilateralContact;
24  tasks::qp::BilateralContact * bilateralContact;
25 };
26 
28 {
30  std::vector<sva::PTransformd> points;
31 };
32 
33 } // namespace mc_solver
34 
35 namespace mc_rbdyn
36 {
37 
38 struct Robot;
39 struct Robots;
40 struct Surface;
41 
42 MC_RBDYN_DLLAPI std::vector<sva::PTransformd> computePoints(const mc_rbdyn::Surface & robotSurface,
43  const mc_rbdyn::Surface & envSurface,
44  const sva::PTransformd & X_es_rs);
45 
46 struct ContactImpl;
47 
49 {
50 public:
51  constexpr static int nrConeGen = 4;
52  constexpr static double defaultFriction = 0.7;
53  constexpr static unsigned int nrBilatPoints = 4;
54 
55 public:
56  Contact(const mc_rbdyn::Robots & robots,
57  const std::string & robotSurface,
58  const std::string & envSurface,
59  double friction = defaultFriction);
60  Contact(const mc_rbdyn::Robots & robots,
61  const std::string & robotSurface,
62  const std::string & envSurface,
63  const sva::PTransformd & X_es_rs,
64  double friction = defaultFriction);
65  Contact(const mc_rbdyn::Robots & robots,
66  unsigned int r1Index,
67  unsigned int r2Index,
68  const std::string & r1Surface,
69  const std::string & r2Surface,
70  double friction = defaultFriction,
71  int ambiguityId = -1);
72  Contact(const mc_rbdyn::Robots & robots,
73  unsigned int r1Index,
74  unsigned int r2Index,
75  const std::string & r1Surface,
76  const std::string & r2Surface,
77  const sva::PTransformd & X_r2s_r1s,
78  double friction = defaultFriction,
79  int ambiguityId = -1);
80  Contact(const mc_rbdyn::Robots & robots,
81  unsigned int r1Index,
82  unsigned int r2Index,
83  const std::string & r1Surface,
84  const std::string & r2Surface,
85  const sva::PTransformd & X_r2s_r1s,
86  const sva::PTransformd & X_b_s,
87  double friction = defaultFriction,
88  int ambiguityId = -1);
89 
90 private:
91  Contact(const mc_rbdyn::Robots & robots,
92  const std::string & robotSurface,
93  const std::string & envSurface,
94  const sva::PTransformd & X_es_rs,
95  double friction,
96  bool is_fixed);
97 
98 public:
99  Contact(const Contact & contact);
100  Contact & operator=(const Contact &);
101  ~Contact();
102 
103  unsigned int r1Index() const;
104 
105  unsigned int r2Index() const;
106 
107  const std::shared_ptr<mc_rbdyn::Surface> & r1Surface() const;
108 
109  const std::shared_ptr<mc_rbdyn::Surface> & r2Surface() const;
110 
111  const sva::PTransformd & X_r2s_r1s() const;
112 
113  void X_r2s_r1s(const sva::PTransformd & in);
114 
115  const sva::PTransformd & X_b_s() const;
116 
117  const int & ambiguityId() const;
118 
119  bool isFixed() const;
120 
122  double friction() const;
123 
125  void friction(double friction);
126 
127  std::pair<std::string, std::string> surfaces() const;
128 
129  sva::PTransformd X_0_r1s(const mc_rbdyn::Robot & robot) const;
130  sva::PTransformd X_0_r1s(const mc_rbdyn::Robots & robots) const;
131 
132  sva::PTransformd X_0_r2s(const mc_rbdyn::Robot & robot) const;
133  sva::PTransformd X_0_r2s(const mc_rbdyn::Robots & robots) const;
134 
135  std::vector<sva::PTransformd> r1Points();
136 
137  std::vector<sva::PTransformd> r2Points();
138 
139  sva::PTransformd compute_X_r2s_r1s(const mc_rbdyn::Robots & robots) const;
140 
141  tasks::qp::ContactId contactId(const mc_rbdyn::Robots & robots) const;
142 
143  mc_solver::QPContactPtr taskContact(const mc_rbdyn::Robots & robots) const;
144 
145  mc_solver::QPContactPtrWPoints taskContactWPoints(const mc_rbdyn::Robots & robots,
146  const sva::PTransformd * X_es_rs = nullptr) const;
147 
148  std::string toStr() const;
149 
151  Contact swap(const mc_rbdyn::Robots & robots) const;
152 
153  inline const Eigen::Vector6d & dof() const noexcept { return dof_; }
154 
155  inline void dof(const Eigen::Vector6d & dof) noexcept { dof_ = dof; }
156 
157  bool operator==(const Contact & rhs) const;
158  bool operator!=(const Contact & rhs) const;
159 
160 private:
161  std::unique_ptr<ContactImpl> impl;
162  Eigen::Vector6d dof_ = Eigen::Vector6d::Ones();
163  mc_solver::QPContactPtr taskContact(const mc_rbdyn::Robots & robots,
164  const sva::PTransformd & X_b1_b2,
165  const std::vector<sva::PTransformd> & points) const;
166 
167 public:
168  static mc_rbdyn::Contact load(const mc_rbdyn::Robots & robots, const mc_rtc::Configuration & config);
169 
170  static std::vector<mc_rbdyn::Contact> loadVector(const mc_rbdyn::Robots & robots,
171  const mc_rtc::Configuration & config);
172 };
173 
174 } // namespace mc_rbdyn
175 
176 #endif
mc_rtc::Configuration
Simplify access to values hold within a JSON file.
Definition: Configuration.h:165
mc_rbdyn::Robots
Definition: Robots.h:15
mc_solver::QPContactPtr::QPContactPtr
QPContactPtr()
Definition: Contact.h:22
mc_solver::QPContactPtrWPoints::points
std::vector< sva::PTransformd > points
Definition: Contact.h:30
mc_solver::QPContactPtr::unilateralContact
tasks::qp::UnilateralContact * unilateralContact
Definition: Contact.h:23
mc_solver::QPContactPtr
Definition: Contact.h:20
mc_rbdyn::Robot
Definition: Robot.h:62
mc_solver::QPContactPtrWPoints::qpcontact_ptr
QPContactPtr qpcontact_ptr
Definition: Contact.h:29
mc_rbdyn::computePoints
MC_RBDYN_DLLAPI std::vector< sva::PTransformd > computePoints(const mc_rbdyn::Surface &robotSurface, const mc_rbdyn::Surface &envSurface, const sva::PTransformd &X_es_rs)
api.h
mc_rbdyn::Contact::dof
const Eigen::Vector6d & dof() const noexcept
Definition: Contact.h:153
mc_rbdyn::Contact::dof
void dof(const Eigen::Vector6d &dof) noexcept
Definition: Contact.h:155
mc_rbdyn::Surface
Definition: Surface.h:24
MC_RBDYN_DLLAPI
#define MC_RBDYN_DLLAPI
Definition: api.h:50
mc_rbdyn::operator==
bool operator==(const mc_rbdyn::BodySensor &lhs, const mc_rbdyn::BodySensor &rhs)
Definition: BodySensor.h:147
Configuration.h
mc_rbdyn::Contact
Definition: Contact.h:48
mc_solver
Definition: Contact.h:17
mc_control::fsm::Contact
mc_control::Contact Contact
Definition: Controller.h:22
mc_solver::QPContactPtrWPoints
Definition: Contact.h:27
mc_rbdyn
Definition: generic_gripper.h:14
mc_rtc::gui::Robot
auto Robot(const std::string &name, GetT get_fn)
Definition: Robot.h:56
mc_solver::QPContactPtr::bilateralContact
tasks::qp::BilateralContact * bilateralContact
Definition: Contact.h:24