CollisionsConstraint.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 
8 
9 #include <mc_rbdyn/Collision.h>
10 
12 #include <mc_rtc/void_ptr.h>
13 
14 namespace mc_solver
15 {
16 
17 struct QPSolver;
18 
26 {
27 public:
29  constexpr static double defaultDampingOffset = 0.1;
30 
31 public:
39  CollisionsConstraint(const mc_rbdyn::Robots & robots, unsigned int r1Index, unsigned int r2Index, double timeStep);
40 
47  bool removeCollision(QPSolver & solver, const std::string & b1Name, const std::string & b2Name);
48 
55  void removeCollisions(QPSolver & solver, const std::vector<mc_rbdyn::Collision> & cols);
56 
63  bool removeCollisionByBody(QPSolver & solver, const std::string & byName, const std::string & b2Name);
64 
75  void addCollision(QPSolver & solver, const mc_rbdyn::Collision & col);
76 
84  void addCollisions(QPSolver & solver, const std::vector<mc_rbdyn::Collision> & cols);
85 
87  bool hasCollision(const std::string & c1, const std::string & c2) const noexcept;
88 
90  void reset();
91 
93  inline bool automaticMonitor() const noexcept { return autoMonitor_; }
94 
101  inline void automaticMonitor(bool a) noexcept { autoMonitor_ = a; }
102 
103  void addToSolverImpl(QPSolver & solver) override;
104 
105  void update(QPSolver & solver) override;
106 
107  void removeFromSolverImpl(QPSolver & solver) override;
108 
109 public:
120  unsigned int r1Index;
122  unsigned int r2Index;
124  std::vector<mc_rbdyn::Collision> cols;
125 
126 private:
127  /* Internal sauce to manage collisions */
128  int collId;
129  std::map<std::string, std::pair<int, mc_rbdyn::Collision>> collIdDict;
130  std::string __keyByNames(const std::string & name1, const std::string & name2);
131  int __createCollId(const mc_rbdyn::Collision & col);
132  std::pair<int, mc_rbdyn::Collision> __popCollId(const std::string & name1, const std::string & name2);
134  void __addCollision(mc_solver::QPSolver & solver, const mc_rbdyn::Collision & col);
135 
136  /* Internal management for collision display */
137  bool autoMonitor_ = true;
138  std::unordered_set<int> monitored_;
139  std::shared_ptr<mc_rtc::gui::StateBuilder> gui_;
140  std::vector<std::string> category_;
141  void addMonitorButton(int collId, const mc_rbdyn::Collision & col);
142  void toggleCollisionMonitor(int collId, const mc_rbdyn::Collision * col = nullptr);
143 };
144 
145 } // namespace mc_solver
mc_rbdyn::Robots
Definition: Robots.h:15
void_ptr.h
ConstraintSet.h
mc_solver::CollisionsConstraint::automaticMonitor
bool automaticMonitor() const noexcept
Definition: CollisionsConstraint.h:93
mc_solver::QPSolver
Definition: QPSolver.h:85
mc_solver::CollisionsConstraint::r2Index
unsigned int r2Index
Definition: CollisionsConstraint.h:122
mc_solver::ConstraintSet
This class is a basis to wrap Constraint functions from Tasks. The aim of such wrappers should be two...
Definition: ConstraintSet.h:20
Collision.h
StateBuilder.h
mc_rtc::void_ptr
std::unique_ptr< void, void(*)(void *)> void_ptr
Definition: void_ptr.h:14
mc_solver::CollisionsConstraint::constraint_
mc_rtc::void_ptr constraint_
Definition: CollisionsConstraint.h:118
mc_solver::CollisionsConstraint
Definition: CollisionsConstraint.h:25
mc_solver
Definition: Contact.h:17
mc_solver::CollisionsConstraint::cols
std::vector< mc_rbdyn::Collision > cols
Definition: CollisionsConstraint.h:124
mc_solver::CollisionsConstraint::automaticMonitor
void automaticMonitor(bool a) noexcept
Definition: CollisionsConstraint.h:101
mc_solver::CollisionsConstraint::r1Index
unsigned int r1Index
Definition: CollisionsConstraint.h:120
MC_SOLVER_DLLAPI
#define MC_SOLVER_DLLAPI
Definition: api.h:50
mc_rbdyn::Collision
Definition: Collision.h:20