CollisionCheckerComponent.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @package RobotComponents::ArmarXObjects::CollisionCheckerComponent
17  * @author Adrian Knobloch ( adrian dot knobloch at student dot kit dot edu )
18  * @date 2016
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #pragma once
24 
25 
28 
29 #include <MemoryX/interface/components/WorkingMemoryInterface.h>
31 
32 #include <RobotAPI/interface/core/RobotState.h>
33 #include <RobotAPI/interface/visualization/DebugDrawerInterface.h>
35 
36 #include <RobotComponents/interface/components/CollisionCheckerInterface.h>
37 
38 #include <VirtualRobot/Robot.h>
39 #include <VirtualRobot/SceneObject.h>
40 
41 #include <mutex>
42 
43 namespace armarx
44 {
45  /**
46  * @class CollisionCheckerComponentPropertyDefinitions
47  * @brief
48  */
51  {
52  public:
55  {
56  defineRequiredProperty<bool>("UseWorkingMemory", "If true, the WorkingMemory is used to get all SceneObjects. Otherwise a RobotStateComponent is used.");
57  defineOptionalProperty<std::string>("WorkingMemoryName", "WorkingMemory", "The name of the WorkingMemory.");
58  defineOptionalProperty<std::string>("WorkingMemoryListenerTopicName", "WorkingMemoryUpdates", "The name of the topic to listen for WorkingMemory updates.");
59  defineOptionalProperty<std::string>("RobotStateComponentName", "RobotStateComponent", "The name of the RobotStateComponent.");
60  defineOptionalProperty<int>("interval", 100, "The interval of time to check for collisions. (in ms)");
61  defineOptionalProperty<std::string>("CollisionPairs", "[]", "A list of tripels including two SceneObjects or SceneObject lists and a distance from which to warn. Example: [{Armar3:(Ring L J0,Ring L J1),Armar3:(Ring R J0,Ring R J1),2.0},{Armar3:Index L J0,tableb,3.0}]");
62  defineOptionalProperty<std::string>("DistanceListenerTopicName", "DistanceListener", "The topic name to get information about the distances.");
63  defineOptionalProperty<std::string>("CollisionListenerTopicName", "CollisionListener", "The topic name to get information about collisions.");
64  defineOptionalProperty<bool>("UseDebugDrawer", "false", "If true, the distances are printet using the debug drawer.");
65  defineOptionalProperty<std::string>("DebugDrawerTopicName", "DebugDrawerUpdates", "The name of the debug drawer topic.");
66  }
67  };
68 
69  /**
70  * @defgroup Component-CollisionCheckerComponent CollisionCheckerComponent
71  * @ingroup RobotComponents-Components
72  * A description of the component CollisionCheckerComponent.
73  *
74  * @class CollisionCheckerComponent
75  * @ingroup Component-CollisionCheckerComponent
76  * @brief Brief description of class CollisionCheckerComponent.
77  *
78  * Detailed description of class CollisionCheckerComponent.
79  */
81  virtual public armarx::Component,
82  virtual public armarx::CollisionCheckerInterface
83  {
84  private:
85  typedef struct
86  {
87  VirtualRobot::SceneObjectSetPtr objects1;
88  std::string robotName1;
89  std::vector<std::string> nodeNames1;
90  bool usesNodeSet1;
91  std::string nodeSetName1;
92  VirtualRobot::SceneObjectSetPtr objects2;
93  std::string robotName2;
94  std::vector<std::string> nodeNames2;
95  bool usesNodeSet2;
96  std::string nodeSetName2;
97  double warningDistance;
98  } SceneObjectPair;
99  typedef struct
100  {
102  RobotStateComponentInterfacePrx robotStateComponentPrx;
103  } RobotPair;
104 
105  public:
107 
108  /**
109  * @see armarx::ManagedIceObject::getDefaultName()
110  */
111  std::string getDefaultName() const override
112  {
113  return "CollisionCheckerComponent";
114  }
115 
116  void addCollisionPair(const std::string& robotName1, const std::vector<std::string>& nodeNames1, const std::string& robotName2, const std::vector<std::string>& nodeNames2, double warningDistance, const Ice::Current& = Ice::emptyCurrent) override;
117 
118  void removeCollisionPair(const std::string& robotName1, const std::vector<std::string>& nodeNames1, const std::string& robotName2, const std::vector<std::string>& nodeNames2, const Ice::Current& = Ice::emptyCurrent) override;
119 
120  bool hasCollisionPair(const std::string& robotName1, const std::vector<std::string>& nodeNames1, const std::string& robotName2, const std::vector<std::string>& nodeNames2, const Ice::Current& = Ice::emptyCurrent) const override;
121 
122  void setWarningDistance(const std::string& robotName1, const std::vector<std::string>& nodeNames1, const std::string& robotName2, const std::vector<std::string>& nodeNames2, double warningDistance, const Ice::Current& = Ice::emptyCurrent) override;
123  double getWarningDistance(const std::string& robotName1, const std::vector<std::string>& nodeNames1, const std::string& robotName2, const std::vector<std::string>& nodeNames2, const Ice::Current& = Ice::emptyCurrent) const override;
124 
125  CollisionPairList getAllCollisionPairs(const Ice::Current& = Ice::emptyCurrent) const override;
126 
127  int getInterval(const Ice::Current& = Ice::emptyCurrent) const override;
128  void setInterval(int interval, const Ice::Current& = Ice::emptyCurrent) override;
129 
130  protected:
131  /**
132  * @see armarx::ManagedIceObject::onInitComponent()
133  */
134  void onInitComponent() override;
135 
136  /**
137  * @see armarx::ManagedIceObject::onConnectComponent()
138  */
139  void onConnectComponent() override;
140 
141  /**
142  * @see armarx::ManagedIceObject::onDisconnectComponent()
143  */
144  void onDisconnectComponent() override;
145 
146  /**
147  * @see armarx::ManagedIceObject::onExitComponent()
148  */
149  void onExitComponent() override;
150 
151  /**
152  * @see PropertyUser::createPropertyDefinitions()
153  */
155 
156  private:
157  bool resolveCollisionPair(SceneObjectPair& pair);
158  VirtualRobot::SceneObjectPtr getSceneObject(const std::string& robotName, const std::string& nodeName);
159  bool parseNodeSet(const std::string& setAsString, std::string& robotName, std::vector<std::string>& nodeNames, bool& usesNodeSet, std::string& nodeSetName);
160  void reportDistancesAndCollisions();
161  VirtualRobot::SceneObjectPtr getSceneObjectFromWorkingMemory(const std::string& name);
162  void synchronizeObjectsFromWorkingMemory();
163 
164  virtual void addCollisionPair(const std::string& robotName1, const std::vector<std::string>& nodeNames1, const bool usesNodeSet1, const std::string& nodeSetName1, const std::string& robotName2, const std::vector<std::string>& nodeNames2, const bool usesNodeSet2, const std::string& nodeSetName2, double warningDistance);
165 
166  void reportEntityCreated(const std::string& segmentName, const ::memoryx::EntityBasePtr& entity, const ::Ice::Current& = Ice::emptyCurrent) override;
167  void reportEntityUpdated(const std::string& segmentName, const ::memoryx::EntityBasePtr& entityOld, const ::memoryx::EntityBasePtr& entityNew, const ::Ice::Current& = Ice::emptyCurrent) override;
168  void reportEntityRemoved(const std::string& segmentName, const ::memoryx::EntityBasePtr& entity, const ::Ice::Current& = Ice::emptyCurrent) override;
169  void reportSnapshotLoaded(const std::string& segmentName, const ::Ice::Current& = Ice::emptyCurrent) override;
170  void reportSnapshotCompletelyLoaded(const Ice::Current& c = Ice::emptyCurrent) override;
171  void reportMemoryCleared(const std::string& segmentName, const ::Ice::Current& = Ice::emptyCurrent) override;
172 
173  bool useWorkingMemory;
174 
175  std::string workingMemoryName;
176  memoryx::WorkingMemoryInterfacePrx workingMemoryPrx;
177  memoryx::ObjectInstanceMemorySegmentBasePrx objectInstancesPrx;
178  memoryx::AgentInstancesSegmentBasePrx agentInstancesPrx;
179  memoryx::GridFileManagerPtr fileManager;
180  std::vector<VirtualRobot::SceneObjectPtr> workingMemorySceneObjects;
181  std::map<std::string, armarx::PosePtr> currentPositions;
182  std::mutex wmPositionMutex;
183 
184  std::string robotStateComponentName;
185 
186  std::vector<RobotPair> robots;
187 
188  std::vector<SceneObjectPair> sceneObjectPairs;
189 
190  VirtualRobot::CollisionCheckerPtr collisionChecker;
191 
192  CollisionListenerPrx collisionListenerPrx;
193  DistanceListenerPrx distanceListenerPrx;
194 
195  int interval;
197  mutable std::mutex dataMutex;
198 
199  bool connected;
200  std::shared_mutex connectedMutex;
201 
202  DebugDrawerInterfacePrx debugDrawerTopicPrx;
203  bool useDebugDrawer;
204  };
205 }
206 
armarx::CollisionCheckerComponent::setWarningDistance
void setWarningDistance(const std::string &robotName1, const std::vector< std::string > &nodeNames1, const std::string &robotName2, const std::vector< std::string > &nodeNames2, double warningDistance, const Ice::Current &=Ice::emptyCurrent) override
Definition: CollisionCheckerComponent.cpp:619
armarx::CollisionCheckerComponent::onInitComponent
void onInitComponent() override
Definition: CollisionCheckerComponent.cpp:56
armarx::CollisionCheckerComponent::getWarningDistance
double getWarningDistance(const std::string &robotName1, const std::vector< std::string > &nodeNames1, const std::string &robotName2, const std::vector< std::string > &nodeNames2, const Ice::Current &=Ice::emptyCurrent) const override
Definition: CollisionCheckerComponent.cpp:635
Pose.h
armarx::CollisionCheckerComponent::getDefaultName
std::string getDefaultName() const override
Definition: CollisionCheckerComponent.h:111
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
GridFileManager.h
PeriodicTask.h
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::CollisionCheckerComponent::hasCollisionPair
bool hasCollisionPair(const std::string &robotName1, const std::vector< std::string > &nodeNames1, const std::string &robotName2, const std::vector< std::string > &nodeNames2, const Ice::Current &=Ice::emptyCurrent) const override
Definition: CollisionCheckerComponent.cpp:603
armarx::CollisionCheckerComponentPropertyDefinitions::CollisionCheckerComponentPropertyDefinitions
CollisionCheckerComponentPropertyDefinitions(std::string prefix)
Definition: CollisionCheckerComponent.h:53
armarx::CollisionCheckerComponent::onExitComponent
void onExitComponent() override
Definition: CollisionCheckerComponent.cpp:237
armarx::CollisionCheckerComponent::CollisionCheckerComponent
CollisionCheckerComponent()
Definition: CollisionCheckerComponent.cpp:50
armarx::CollisionCheckerComponent::getInterval
int getInterval(const Ice::Current &=Ice::emptyCurrent) const override
Definition: CollisionCheckerComponent.cpp:663
armarx::CollisionCheckerComponent::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: CollisionCheckerComponent.cpp:242
armarx::CollisionCheckerComponent::addCollisionPair
void addCollisionPair(const std::string &robotName1, const std::vector< std::string > &nodeNames1, const std::string &robotName2, const std::vector< std::string > &nodeNames2, double warningDistance, const Ice::Current &=Ice::emptyCurrent) override
Definition: CollisionCheckerComponent.cpp:570
armarx::CollisionCheckerComponent::setInterval
void setInterval(int interval, const Ice::Current &=Ice::emptyCurrent) override
Definition: CollisionCheckerComponent.cpp:668
armarx::CollisionCheckerComponentPropertyDefinitions
Definition: CollisionCheckerComponent.h:49
Component.h
armarx::CollisionCheckerComponent::getAllCollisionPairs
CollisionPairList getAllCollisionPairs(const Ice::Current &=Ice::emptyCurrent) const override
Definition: CollisionCheckerComponent.cpp:651
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:95
armarx::CollisionCheckerComponent
Brief description of class CollisionCheckerComponent.
Definition: CollisionCheckerComponent.h:80
armarx::CollisionCheckerComponent::onDisconnectComponent
void onDisconnectComponent() override
Definition: CollisionCheckerComponent.cpp:213
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
memoryx::GridFileManagerPtr
std::shared_ptr< GridFileManager > GridFileManagerPtr
Definition: AbstractEntityWrapper.h:32
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::CollisionCheckerComponent::removeCollisionPair
void removeCollisionPair(const std::string &robotName1, const std::vector< std::string > &nodeNames1, const std::string &robotName2, const std::vector< std::string > &nodeNames2, const Ice::Current &=Ice::emptyCurrent) override
Definition: CollisionCheckerComponent.cpp:587
IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface >
scene3D::SceneObjectPtr
boost::intrusive_ptr< SceneObject > SceneObjectPtr
Definition: PointerDefinitions.h:40
armarx::CollisionCheckerComponent::onConnectComponent
void onConnectComponent() override
Definition: CollisionCheckerComponent.cpp:137
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18