force_control_collection
Contact.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <unordered_map>
4 
5 #include <mc_rtc/Configuration.h>
6 #include <mc_rtc/gui/StateBuilder.h>
7 #include <SpaceVecAlg/SpaceVecAlg>
8 
9 #include <ForceColl/Constants.h>
10 
11 namespace ForceColl
12 {
15 {
16 public:
17  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
18 
23  FrictionPyramid(double fricCoeff, int ridgeNum = 4);
24 
26  std::vector<Eigen::Vector3d> calcGlobalRidgeList(const Eigen::Matrix3d & rot) const;
27 
29  inline int ridgeNum() const
30  {
31  return static_cast<int>(localRidgeList_.size());
32  }
33 
34 public:
36  std::vector<Eigen::Vector3d> localRidgeList_;
37 };
38 
40 class Contact
41 {
42 public:
45  {
46  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
47 
49  Eigen::Vector3d vertex;
50 
52  std::vector<Eigen::Vector3d> ridgeList;
53 
58  VertexWithRidge(const Eigen::Vector3d & _vertex, const std::vector<Eigen::Vector3d> & _ridgeList)
59  : vertex(_vertex), ridgeList(_ridgeList)
60  {
61  }
62  };
63 
64 public:
68  static std::shared_ptr<Contact> makeSharedFromConfig(const mc_rtc::Configuration & mcRtcConfig);
69 
70 public:
71  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
72 
77  Contact(const std::string & name, std::optional<sva::ForceVecd> maxWrench = std::nullopt);
78 
80  virtual std::string type() const = 0;
81 
83  inline int ridgeNum() const
84  {
85  return static_cast<int>(graspMat_.cols());
86  }
87 
89  virtual void updateGlobalVertices(const sva::PTransformd & pose) = 0;
90 
96  sva::ForceVecd calcWrench(const Eigen::VectorXd & wrenchRatio,
97  const Eigen::Vector3d & momentOrigin = Eigen::Vector3d::Zero()) const;
98 
103  sva::ForceVecd calcLocalWrench(const Eigen::VectorXd & wrenchRatio) const;
104 
112  virtual void addToGUI(mc_rtc::gui::StateBuilder & gui,
113  const std::vector<std::string> & category,
114  double forceScale = constants::defaultForceScale,
115  double fricPyramidScale = constants::defaultFricPyramidScale,
116  const Eigen::VectorXd & wrenchRatio = Eigen::VectorXd::Zero(0));
117 
118 public:
120  std::string name_;
121 
123  Eigen::Matrix<double, 6, Eigen::Dynamic> graspMat_;
124 
126  Eigen::Matrix<double, 6, Eigen::Dynamic> localGraspMat_;
127 
129  std::shared_ptr<FrictionPyramid> fricPyramid_;
130 
132  std::vector<VertexWithRidge> vertexWithRidgeList_;
133 
135  std::optional<sva::ForceVecd> maxWrench_;
136 };
137 
139 class EmptyContact : public Contact
140 {
141 public:
142  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
143 
147  EmptyContact(const std::string & name);
148 
152  EmptyContact(const mc_rtc::Configuration & mcRtcConfig);
153 
155  inline virtual std::string type() const override
156  {
157  return "Empty";
158  }
159 
164  virtual void updateGlobalVertices(const sva::PTransformd & pose) override;
165 };
166 
168 class SurfaceContact : public Contact
169 {
170 public:
174  static void loadVerticesMap(const mc_rtc::Configuration & mcRtcConfig);
175 
177  static inline std::unordered_map<std::string, std::vector<Eigen::Vector3d>> verticesMap;
178 
180  std::vector<Eigen::Vector3d> localVertices_;
181 
182 public:
183  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
184 
192  SurfaceContact(const std::string & name,
193  double fricCoeff,
194  const std::vector<Eigen::Vector3d> & localVertices,
195  const sva::PTransformd & pose,
196  std::optional<sva::ForceVecd> maxWrench = std::nullopt);
197 
201  SurfaceContact(const mc_rtc::Configuration & mcRtcConfig);
202 
204  inline virtual std::string type() const override
205  {
206  return "Surface";
207  }
208 
210  void updateLocalVertices(const std::vector<Eigen::Vector3d> & localVertices);
211 
213  virtual void updateGlobalVertices(const sva::PTransformd & pose) override;
214 
222  virtual void addToGUI(mc_rtc::gui::StateBuilder & gui,
223  const std::vector<std::string> & category,
224  double forceScale = constants::defaultForceScale,
225  double fricPyramidScale = constants::defaultFricPyramidScale,
226  const Eigen::VectorXd & wrenchRatio = Eigen::VectorXd::Zero(0)) override;
227 };
228 
230 class GraspContact : public Contact
231 {
232 public:
236  static void loadVerticesMap(const mc_rtc::Configuration & mcRtcConfig);
237 
239  static inline std::unordered_map<std::string, std::vector<sva::PTransformd>> verticesMap;
240 
242  std::vector<sva::PTransformd> localVertices_;
243 
244 public:
245  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
246 
254  GraspContact(const std::string & name,
255  double fricCoeff,
256  const std::vector<sva::PTransformd> & localVertices,
257  const sva::PTransformd & pose,
258  std::optional<sva::ForceVecd> maxWrench = std::nullopt);
259 
263  GraspContact(const mc_rtc::Configuration & mcRtcConfig);
264 
266  inline virtual std::string type() const override
267  {
268  return "Grasp";
269  }
270 
272  void updateLocalVertices(const std::vector<sva::PTransformd> & localVertices);
273 
275  virtual void updateGlobalVertices(const sva::PTransformd & pose) override;
276 
284  virtual void addToGUI(mc_rtc::gui::StateBuilder & gui,
285  const std::vector<std::string> & category,
286  double forceScale = constants::defaultForceScale,
287  double fricPyramidScale = constants::defaultFricPyramidScale,
288  const Eigen::VectorXd & wrenchRatio = Eigen::VectorXd::Zero(0)) override;
289 };
290 
297 sva::ForceVecd calcTotalWrench(const std::vector<std::shared_ptr<Contact>> & contactList,
298  const Eigen::VectorXd & wrenchRatio,
299  const Eigen::Vector3d & momentOrigin = Eigen::Vector3d::Zero());
300 
307 std::vector<sva::ForceVecd> calcWrenchList(const std::vector<std::shared_ptr<Contact>> & contactList,
308  const Eigen::VectorXd & wrenchRatio,
309  const Eigen::Vector3d & momentOrigin = Eigen::Vector3d::Zero());
310 
316 std::vector<sva::ForceVecd> calcLocalWrenchList(const std::vector<std::shared_ptr<Contact>> & contactList,
317  const Eigen::VectorXd & wrenchRatio);
318 
327 template<template<class...> class MapType, class KeyType, class... RestTypes>
328 MapType<KeyType, sva::ForceVecd> calcWrenchList(
329  const MapType<KeyType, std::shared_ptr<Contact>, RestTypes...> & contactList,
330  const Eigen::VectorXd & wrenchRatio,
331  const Eigen::Vector3d & momentOrigin = Eigen::Vector3d::Zero());
332 
339 template<template<class...> class MapType, class KeyType, class... RestTypes>
340 std::vector<std::shared_ptr<Contact>> getContactVecFromMap(
341  const MapType<KeyType, std::shared_ptr<Contact>, RestTypes...> & contactList);
342 } // namespace ForceColl
343 
344 #include <ForceColl/Contact.hpp>
Contact.hpp
ForceColl::Contact::type
virtual std::string type() const =0
Get type of contact.
ForceColl::constants::defaultForceScale
constexpr double defaultForceScale
Default scale of force markers.
Definition: Constants.h:8
ForceColl::calcTotalWrench
sva::ForceVecd calcTotalWrench(const std::vector< std::shared_ptr< Contact >> &contactList, const Eigen::VectorXd &wrenchRatio, const Eigen::Vector3d &momentOrigin=Eigen::Vector3d::Zero())
Calculate total wrench.
ForceColl::GraspContact::localVertices_
std::vector< sva::PTransformd > localVertices_
List of local verticies.
Definition: Contact.h:242
ForceColl::FrictionPyramid::ridgeNum
int ridgeNum() const
Number of ridges.
Definition: Contact.h:29
ForceColl::SurfaceContact::SurfaceContact
EIGEN_MAKE_ALIGNED_OPERATOR_NEW SurfaceContact(const std::string &name, double fricCoeff, const std::vector< Eigen::Vector3d > &localVertices, const sva::PTransformd &pose, std::optional< sva::ForceVecd > maxWrench=std::nullopt)
Constructor.
ForceColl::Contact::calcLocalWrench
sva::ForceVecd calcLocalWrench(const Eigen::VectorXd &wrenchRatio) const
Calculate the local wrench.
ForceColl::Contact::localGraspMat_
Eigen::Matrix< double, 6, Eigen::Dynamic > localGraspMat_
Local grasp matrix.
Definition: Contact.h:126
ForceColl::SurfaceContact::type
virtual std::string type() const override
Get type of contact.
Definition: Contact.h:204
ForceColl::getContactVecFromMap
std::vector< std::shared_ptr< Contact > > getContactVecFromMap(const MapType< KeyType, std::shared_ptr< Contact >, RestTypes... > &contactList)
Convert vector of contact constraint to map.
Definition: Contact.hpp:22
ForceColl::SurfaceContact
Surface contact.
Definition: Contact.h:168
ForceColl::Contact::graspMat_
Eigen::Matrix< double, 6, Eigen::Dynamic > graspMat_
Grasp matrix.
Definition: Contact.h:123
ForceColl::Contact::vertexWithRidgeList_
std::vector< VertexWithRidge > vertexWithRidgeList_
List of global vertex with ridges.
Definition: Contact.h:132
ForceColl::Contact::updateGlobalVertices
virtual void updateGlobalVertices(const sva::PTransformd &pose)=0
Update graspMat_ and vertexWithRidgeList_ according to the input pose.
ForceColl::calcLocalWrenchList
std::vector< sva::ForceVecd > calcLocalWrenchList(const std::vector< std::shared_ptr< Contact >> &contactList, const Eigen::VectorXd &wrenchRatio)
Calculate local contact wrench list.
Constants.h
ForceColl::Contact::Contact
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Contact(const std::string &name, std::optional< sva::ForceVecd > maxWrench=std::nullopt)
Constructor.
ForceColl::GraspContact::updateLocalVertices
void updateLocalVertices(const std::vector< sva::PTransformd > &localVertices)
Update localVertices_ and localGraspMat_ according to the input pose.
ForceColl::Contact::VertexWithRidge::vertex
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Eigen::Vector3d vertex
Vertex.
Definition: Contact.h:49
ForceColl::Contact::name_
std::string name_
Name of contact.
Definition: Contact.h:120
ForceColl::EmptyContact::updateGlobalVertices
virtual void updateGlobalVertices(const sva::PTransformd &pose) override
Update graspMat_ and vertexWithRidgeList_ according to the input pose.
ForceColl::Contact::fricPyramid_
std::shared_ptr< FrictionPyramid > fricPyramid_
Friction pyramid.
Definition: Contact.h:129
ForceColl::Contact::VertexWithRidge::ridgeList
std::vector< Eigen::Vector3d > ridgeList
Global ridge list.
Definition: Contact.h:52
ForceColl::SurfaceContact::localVertices_
std::vector< Eigen::Vector3d > localVertices_
List of local verticies.
Definition: Contact.h:180
ForceColl::EmptyContact::type
virtual std::string type() const override
Get type of contact.
Definition: Contact.h:155
ForceColl::FrictionPyramid::calcGlobalRidgeList
std::vector< Eigen::Vector3d > calcGlobalRidgeList(const Eigen::Matrix3d &rot) const
Calculate ridge vector list in global coordinates.
ForceColl::EmptyContact
Empty contact.
Definition: Contact.h:139
ForceColl::SurfaceContact::updateLocalVertices
void updateLocalVertices(const std::vector< Eigen::Vector3d > &localVertices)
Update localVertices_ and localGraspMat_ according to the input pose.
ForceColl::Contact::calcWrench
sva::ForceVecd calcWrench(const Eigen::VectorXd &wrenchRatio, const Eigen::Vector3d &momentOrigin=Eigen::Vector3d::Zero()) const
Calculate wrench.
ForceColl::GraspContact::GraspContact
EIGEN_MAKE_ALIGNED_OPERATOR_NEW GraspContact(const std::string &name, double fricCoeff, const std::vector< sva::PTransformd > &localVertices, const sva::PTransformd &pose, std::optional< sva::ForceVecd > maxWrench=std::nullopt)
Constructor.
ForceColl::GraspContact
Grasp contact.
Definition: Contact.h:230
ForceColl::SurfaceContact::loadVerticesMap
static void loadVerticesMap(const mc_rtc::Configuration &mcRtcConfig)
Load map of surface vertices in local coordinates.
ForceColl::calcWrenchList
std::vector< sva::ForceVecd > calcWrenchList(const std::vector< std::shared_ptr< Contact >> &contactList, const Eigen::VectorXd &wrenchRatio, const Eigen::Vector3d &momentOrigin=Eigen::Vector3d::Zero())
Calculate contact wrench list.
ForceColl::GraspContact::addToGUI
virtual void addToGUI(mc_rtc::gui::StateBuilder &gui, const std::vector< std::string > &category, double forceScale=constants::defaultForceScale, double fricPyramidScale=constants::defaultFricPyramidScale, const Eigen::VectorXd &wrenchRatio=Eigen::VectorXd::Zero(0)) override
Add markers to GUI.
ForceColl::EmptyContact::EmptyContact
EIGEN_MAKE_ALIGNED_OPERATOR_NEW EmptyContact(const std::string &name)
Constructor.
ForceColl::Contact
Contact.
Definition: Contact.h:40
ForceColl::Contact::addToGUI
virtual void addToGUI(mc_rtc::gui::StateBuilder &gui, const std::vector< std::string > &category, double forceScale=constants::defaultForceScale, double fricPyramidScale=constants::defaultFricPyramidScale, const Eigen::VectorXd &wrenchRatio=Eigen::VectorXd::Zero(0))
Add markers to GUI.
ForceColl::GraspContact::updateGlobalVertices
virtual void updateGlobalVertices(const sva::PTransformd &pose) override
Update graspMat_ and vertexWithRidgeList_ according to the input pose.
ForceColl::Contact::maxWrench_
std::optional< sva::ForceVecd > maxWrench_
Maximum wrench in local frame that can be accepted by this contact.
Definition: Contact.h:135
ForceColl::SurfaceContact::addToGUI
virtual void addToGUI(mc_rtc::gui::StateBuilder &gui, const std::vector< std::string > &category, double forceScale=constants::defaultForceScale, double fricPyramidScale=constants::defaultFricPyramidScale, const Eigen::VectorXd &wrenchRatio=Eigen::VectorXd::Zero(0)) override
Add markers to GUI.
ForceColl
Definition: Constants.h:3
ForceColl::SurfaceContact::updateGlobalVertices
virtual void updateGlobalVertices(const sva::PTransformd &pose) override
Update graspMat_ and vertexWithRidgeList_ according to the input pose.
ForceColl::Contact::VertexWithRidge
Vertex with ridges.
Definition: Contact.h:44
ForceColl::GraspContact::type
virtual std::string type() const override
Get type of contact.
Definition: Contact.h:266
ForceColl::Contact::makeSharedFromConfig
static std::shared_ptr< Contact > makeSharedFromConfig(const mc_rtc::Configuration &mcRtcConfig)
Make shared pointer from mc_rtc configuration.
ForceColl::SurfaceContact::verticesMap
static std::unordered_map< std::string, std::vector< Eigen::Vector3d > > verticesMap
Map of surface vertices in local coordinates.
Definition: Contact.h:177
ForceColl::Contact::VertexWithRidge::VertexWithRidge
VertexWithRidge(const Eigen::Vector3d &_vertex, const std::vector< Eigen::Vector3d > &_ridgeList)
Constructor.
Definition: Contact.h:58
ForceColl::FrictionPyramid::FrictionPyramid
EIGEN_MAKE_ALIGNED_OPERATOR_NEW FrictionPyramid(double fricCoeff, int ridgeNum=4)
Constructor.
ForceColl::FrictionPyramid
Friction pyramid.
Definition: Contact.h:14
ForceColl::FrictionPyramid::localRidgeList_
std::vector< Eigen::Vector3d > localRidgeList_
Local ridge list.
Definition: Contact.h:36
ForceColl::constants::defaultFricPyramidScale
constexpr double defaultFricPyramidScale
Default scale of friction pyramid markers.
Definition: Constants.h:11
ForceColl::GraspContact::verticesMap
static std::unordered_map< std::string, std::vector< sva::PTransformd > > verticesMap
Map of grasp vertices in local coordinates.
Definition: Contact.h:239
ForceColl::Contact::ridgeNum
int ridgeNum() const
Get the number of ridges.
Definition: Contact.h:83
ForceColl::GraspContact::loadVerticesMap
static void loadVerticesMap(const mc_rtc::Configuration &mcRtcConfig)
Load map of grasp vertices in local coordinates.