Contact.h
Go to the documentation of this file.
1 /*
2  * Copyright 2015-2022 CNRS-UM LIRMM, CNRS-AIST JRL
3  */
4 
5 #pragma once
6 
7 #include <mc_control/api.h>
8 
9 #include <mc_rbdyn/Contact.h>
10 
11 #include <mc_rtc/Configuration.h>
12 
13 namespace mc_control
14 {
15 
16 struct MCController;
17 
26 {
27  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
28 
29  Contact(const std::optional<std::string> & r1,
30  const std::optional<std::string> & r2,
31  const std::string & r1Surface,
32  const std::string & r2Surface,
33  double friction = mc_rbdyn::Contact::defaultFriction,
34  const Eigen::Vector6d & dof = Eigen::Vector6d::Ones())
35  : r1(r1), r2(r2), r1Surface(r1Surface), r2Surface(r2Surface), friction(friction), dof(dof)
36  {
37  }
38 
39  std::optional<std::string> r1;
40  std::optional<std::string> r2;
41  std::string r1Surface;
42  std::string r2Surface;
43  mutable double friction;
44  mutable Eigen::Vector6d dof;
45 
46  bool operator==(const Contact & rhs) const
47  {
48  return (r1 == rhs.r1 && r2 == rhs.r2 && r1Surface == rhs.r1Surface && r2Surface == rhs.r2Surface)
49  || (r1 == rhs.r2 && r2 == rhs.r1 && r1Surface == rhs.r2Surface && r2Surface == rhs.r1Surface);
50  }
51 
52  bool operator!=(const Contact & rhs) const { return !(*this == rhs); }
53 
55  Contact() = default;
56 
58  static Contact from_mc_rbdyn(const MCController &, const mc_rbdyn::Contact &);
59 };
60 
61 using ContactSet =
62  std::unordered_set<Contact, std::hash<Contact>, std::equal_to<Contact>, Eigen::aligned_allocator<Contact>>;
63 
64 } // namespace mc_control
65 
66 namespace std
67 {
68 
69 template<>
70 struct hash<mc_control::Contact>
71 {
72  std::size_t operator()(const mc_control::Contact & c) const noexcept
73  {
74  // Same as boost::hash_combine
75  auto hash_combine = [](const std::string & robot, const std::string & surface)
76  {
77  auto h = std::hash<std::string>{}(robot);
78  h ^= std::hash<std::string>{}(surface) + 0x9e3779b9 + (h << 6) + (h >> 2);
79  return h;
80  };
81  return hash_combine(c.r1.value_or(""), c.r1Surface) ^ hash_combine(c.r2.value_or(""), c.r2Surface);
82  }
83 };
84 
85 } // namespace std
86 
87 namespace mc_rtc
88 {
89 
90 template<>
92 {
93  static mc_control::Contact load(const mc_rtc::Configuration & config);
94 };
95 
96 } // namespace mc_rtc
mc_rtc::Configuration
Simplify access to values hold within a JSON file.
Definition: Configuration.h:165
mc_control::Contact::operator==
bool operator==(const Contact &rhs) const
Definition: Contact.h:46
std::hash< mc_control::Contact >::operator()
std::size_t operator()(const mc_control::Contact &c) const noexcept
Definition: Contact.h:72
mc_control::ContactSet
std::unordered_set< Contact, std::hash< Contact >, std::equal_to< Contact >, Eigen::aligned_allocator< Contact > > ContactSet
Definition: Contact.h:62
MC_CONTROL_DLLAPI
#define MC_CONTROL_DLLAPI
Definition: api.h:50
mc_control::Contact::operator!=
bool operator!=(const Contact &rhs) const
Definition: Contact.h:52
mc_control::Contact::r1
std::optional< std::string > r1
Definition: Contact.h:39
Contact.h
mc_control::Contact
Definition: Contact.h:25
mc_rbdyn::Contact::defaultFriction
constexpr static double defaultFriction
Definition: Contact.h:52
api.h
mc_control::Contact::friction
double friction
Definition: Contact.h:43
mc_control::Contact::r2Surface
std::string r2Surface
Definition: Contact.h:42
mc_control::Contact::Contact
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Contact(const std::optional< std::string > &r1, const std::optional< std::string > &r2, const std::string &r1Surface, const std::string &r2Surface, double friction=mc_rbdyn::Contact::defaultFriction, const Eigen::Vector6d &dof=Eigen::Vector6d::Ones())
Definition: Contact.h:29
mc_control::Contact::r1Surface
std::string r1Surface
Definition: Contact.h:41
mc_control::Contact::dof
Eigen::Vector6d dof
Definition: Contact.h:44
mc_control::Contact::r2
std::optional< std::string > r2
Definition: Contact.h:40
Configuration.h
std
Definition: Contact.h:66
mc_rbdyn::Contact
Definition: Contact.h:48
mc_control::fsm::Contact
mc_control::Contact Contact
Definition: Controller.h:22
mc_control
Definition: CompletionCriteria.h:10
mc_rtc::ConfigurationLoader
Definition: Configuration.h:55
mc_control::MCController
MCController is the base class to implement all controllers. It assumes that at least two robots are ...
Definition: MCController.h:98
mc_rtc
Definition: Contact.h:87