SimoxCSpace.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package RobotComponents
19 * @author Raphael Grimm ( raphael dot grimm at kit dot edu )
20 * @date 2015
21 * @copyright http://www.gnu.org/licenses/gpl.txt
22 * GNU General Public License
23 */
24#pragma once
25
26#include <array>
27#include <atomic>
28
29#include <Eigen/Core>
30
31#include <VirtualRobot/CollisionDetection/CDManager.h>
32#include <VirtualRobot/Robot.h>
33#include <VirtualRobot/SceneObjectSet.h>
34#include <VirtualRobot/XML/RobotIO.h>
35
37
38#include <RobotAPI/interface/visualization/DebugDrawerInterface.h>
41
42#include <RobotComponents/interface/components/MotionPlanning/CSpace/SimoxCSpace.h>
43
44#include "CSpace.h"
45#include "GlobalCache.h"
47#include <MemoryX/interface/components/WorkingMemoryInterface.h>
49
50namespace armarx
51{
52 class SimoxCSpace;
53 /**
54 * @brief An ice handle for a SimoxCSpace.
55 */
57
58 /**
59 * @brief The SimoxCSpace contains a set of stationary obstacles and an agent.
60 * The agent can have attached objects.
61 * The objects are loaded from a \ref memoryx::CommonStorageInterfacePrx.
62 * The number of dimensions is determined by the agent's kinematic chains.
63 * @see armarx::SimoxCSpaceBase
64 * @see RobotComponents-Tutorial-SimoxCSpace
65 */
66 class SimoxCSpace : virtual public SimoxCSpaceBase, virtual public CSpace
67 {
68 public:
70
71 /**
72 * @brief ctor
73 * @param commonStoragePrx The common storage containing the objects.
74 * @param loadVisualizationModel Whether to load the visualization model. (true, if you want to display the object. false if you want to plan)
75 */
76 SimoxCSpace(memoryx::CommonStorageInterfacePrx commonStoragePrx,
77 bool loadVisualizationModel = false,
78 float stationaryObjectMargin = 0.0f);
79
80 //from setting the cspace up
81 /**
82 * @brief Adds a stationary object to the cspace.
83 * @param obj The object to add.
84 */
85 void addStationaryObject(const StationaryObject& obj,
86 const Ice::Current& = Ice::emptyCurrent) override;
87 virtual void setStationaryObjects(const StationaryObjectList& objList);
88 /**
89 * @brief Adds a stationary agent to the cspace.
90 * @param obj The object to add.
91 */
92 void setAgent(const AgentPlanningInformation& agentInfo,
93 const Ice::Current& = Ice::emptyCurrent) override;
94
95 /**
96 * @brief Adds all objects except the ones with ids specified in the parameter excludedInstancesIds from the working memory to the cspace.
97 * @param workingMemoryPrx The working memory.
98 * @param excludedInstancesIds the ids of the instances in teh working memory that should not be added
99 */
100 virtual void addObjectsFromWorkingMemory(
101 memoryx::WorkingMemoryInterfacePrx workingMemoryPrx,
102 const std::vector<std::string>& excludedInstancesIds = std::vector<std::string>());
103
104 /**
105 * @brief Load objects from WorkingMemory and puts them into the mesh cache.
106 * @param workingMemoryPrx
107 */
108 static SimoxCSpacePtr
109 PrefetchWorkingMemoryObjects(memoryx::WorkingMemoryInterfacePrx workingMemoryPrx,
110 memoryx::CommonStorageInterfacePrx commonStoragePrx,
112
113 virtual void addPlanarObject(const std::vector<Eigen::Vector3f>& convexHull);
114
115 //using it
116 /**
117 * @brief Initializes the collision test.
118 */
119 void initCollisionTest(const Ice::Current& = Ice::emptyCurrent) override;
120
121 /**
122 * @return A clone of this cspace.
123 */
124 CSpaceBasePtr
125 clone(const Ice::Current& = Ice::emptyCurrent) override
126 {
127 return clone(false);
128 }
129
130 /**
131 * @param loadVisualizationModel Whether the clone should load the visualization model.
132 * @return A clone of this cspace.
133 */
134 virtual CSpaceBasePtr clone(bool loadVisualizationModel);
135
136 virtual Saba::CSpaceSampledPtr createSimoxCSpace() const;
137
138 /**
139 * @param cfg The configuration to check.
140 * @return Whether the given configuration is collision free.
141 */
142 bool isCollisionFree(const ::std::pair<const Ice::Float*, const Ice::Float*>& cfg,
143 const Ice::Current& = Ice::emptyCurrent) override;
144
145 /**
146 * @return The cspace's dimension bounds.
147 */
148 FloatRangeSeq getDimensionsBounds(const Ice::Current& = Ice::emptyCurrent) const override;
149
150 /**
151 * @return The cspace's dimensionality.
152 */
153 Ice::Long
154 getDimensionality(const Ice::Current& = Ice::emptyCurrent) const override
155 {
156 return agentJoints.size();
157 }
158
159 /**
160 * @brief Sets a configuration to check for. (can be used to display a configuration)
161 * @param it A pointer to the configuration.
162 */
163 virtual void
164 setConfig(const std::vector<float> cfg)
165 {
166 assert(cfg.size() == static_cast<std::size_t>(getDimensionality()));
167 setConfig(cfg.data());
168 }
169
170 virtual void setConfig(const float*& it);
171
172 virtual void
173 setConfig(const float*&& it) //deals with vector<float>::data()
174 {
175 setConfig(it); //calls the ref version
176 }
177
178 //getter
179 /**
180 * @return The stationary objects.
181 */
182 const StationaryObjectList&
184 {
185 return stationaryObjects;
186 }
187
188 const AgentPlanningInformation&
189 getAgent() const
190 {
191 return agentInfo;
192 }
193
194 /**
195 * @return The set of stationary objects' scene objects.
196 */
197 const VirtualRobot::SceneObjectSetPtr&
199 {
200 return stationaryObjectSet;
201 }
202
205 {
206 return agentSceneObj;
207 }
208
209 /**
210 * @return The collision checker.
211 */
212 VirtualRobot::CDManager&
214 {
215 return cd;
216 }
217
218 virtual Ice::StringSeq getAgentJointNames() const;
219
220 //utility
221 VectorXf jointMapToVector(const std::map<std::string, float>& jointMap,
222 bool checkForNonexistenJointsInCspace = false) const;
223
224 virtual TrajectoryPtr
225 pathToTrajectory(const Path& p) const
226 {
227 return pathToTrajectory(p.nodes);
228 }
229
230 virtual TrajectoryPtr
231 pathToTrajectory(const PathWithCost& p) const
232 {
233 return pathToTrajectory(p.nodes);
234 }
235
236 virtual TrajectoryPtr pathToTrajectory(const VectorXfSeq& p) const;
237
238 std::vector<armarx::DebugDrawerLineSet>
239 getTraceVisu(const Path& p,
240 const std::vector<std::string>& nodeNames,
241 float traceStepSize = std::numeric_limits<float>::infinity())
242 {
243 return getTraceVisu(p.nodes, nodeNames, traceStepSize);
244 }
245
246 std::vector<armarx::DebugDrawerLineSet>
247 getTraceVisu(const PathWithCost& p,
248 const std::vector<std::string>& nodeNames,
249 float traceStepSize = std::numeric_limits<float>::infinity())
250 {
251 return getTraceVisu(p.nodes, nodeNames, traceStepSize);
252 }
253
254 std::vector<armarx::DebugDrawerLineSet>
255 getTraceVisu(const VectorXfSeq& vecs,
256 const std::vector<std::string>& nodeNames,
257 float traceStepSize = std::numeric_limits<float>::infinity());
258
259 float
261 {
262 return stationaryObjectMargin;
263 }
264
265 void
266 setStationaryObjectMargin(float stationaryObjectMargin)
267 {
268 if (!isInitialized)
269 {
270 this->stationaryObjectMargin = stationaryObjectMargin;
271 }
272 else
273 {
274 ARMARX_ERROR << "Could not set stationary object margin, because the cSpace is "
275 "already initialized.";
276 }
277 }
278
279 //from ice
280 /**
281 * @brief Initializes basic structures after transmission through ice.
282 */
283 void ice_postUnmarshal() override;
284
285 protected:
286 template <class IceBaseClass, class DerivedClass>
288
289 const std::vector<VirtualRobot::RobotNodePtr>&
291 {
292 return agentJoints;
293 }
294
295 /**
296 * @brief Default ctor. Used for ice factories.
297 */
298 SimoxCSpace() = default;
299
300 //data
301 /**
302 * @brief Whether the collision check is initialized
303 */
304 bool isInitialized{false};
305 /**
306 * @brief Whether the visualization model of objects/agents sould be loaded.
307 */
309
310
311 /**
312 * @brief The file manager used to load objects.
313 */
315
316 //cd data
317 /**
318 * @brief The collision checker.
319 */
320 VirtualRobot::CDManager cd;
321
322 /**
323 * @brief The scene objects for stationary objects.
324 */
325 VirtualRobot::SceneObjectSetPtr stationaryObjectSet{
326 new VirtualRobot::SceneObjectSet{"StationaryObjectSet"}};
327
328 std::vector<VirtualRobot::RobotNodePtr> agentJoints;
329
331
332 std::vector<std::vector<Eigen::Vector3f>> stationaryPlanes;
333
337 std::pair<VirtualRobot::RobotIO::RobotDescription, std::string>>
339
340
341 /**
342 * @brief Initializes stationary objects for collision checking.
343 */
345
346 /**
347 * @brief Contains information about an agent.
348 */
350 {
351 /**
352 * @brief The agent's collision model. (contains more data but mainly used for the model)
353 */
355 /**
356 * @brief The agent's joints.
357 */
358 std::vector<VirtualRobot::RobotNodePtr> joints;
359 /**
360 * @brief The collision stes.
361 */
362 std::vector<VirtualRobot::SceneObjectSetPtr> collisionSets;
363 };
364
365 //static functions to load data
366 /**
367 * @brief Initializes an agent.
368 * (Does not need to read from the file system if loadAnyModel is false)
369 * @param agentData Data about the agent.
370 * @param loadAnyModel if unset only the robot structure is loaded.
371 * If set the robot's and objects' collision model are loaded. (depending on
372 * loadVisualizationModel the robot's visualisation model is loaded)
373 */
374 void initAgent(AgentData agentData);
375
376 void
381
382 void
384 {
385 initAgent(getAgentDataFromRobot(std::move(robotPtr)));
386 }
387
388 /**
389 * @param object The object.
390 * @return The given objects manipulation object.
391 */
392 VirtualRobot::ManipulationObjectPtr
393 getSimoxManipulatorObject(const memoryx::ObjectClassBasePtr& object,
395 bool inflate = true,
396 VirtualRobot::CollisionCheckerPtr const& colChecker =
397 VirtualRobot::CollisionCheckerPtr{}) const;
398
399 /**
400 * @param object The object.
401 * @param pose The pose to use.
402 * @return The given objects manipulation object moved to the given pose.
403 */
404 VirtualRobot::ManipulationObjectPtr
405 getMovedSimoxManipulatorObject(const memoryx::ObjectClassBasePtr& object,
406 const armarx::PoseBasePtr& pose,
408
409 AgentData getAgentDataAndLoadRobot() const;
410 AgentData getAgentDataFromRobot(VirtualRobot::RobotPtr robotPtr) const;
411 };
412
413
416
417 /**
418 * @brief Similar to \ref armarx::SimoxCSpace, but prepends dimensions for translation in x and y and a rotation around z. (use this for path planning)
419 */
421 virtual public SimoxCSpace,
422 virtual public SimoxCSpaceWith2DPoseBase
423 {
424 public:
425 SimoxCSpaceWith2DPose(memoryx::CommonStorageInterfacePrx commonStoragePrx,
426 bool loadVisualizationModel = false,
427 float stationaryObjectMargin = 0.0f);
428
429 void
430 setPoseBounds(const Vector3fRange& newBounds)
431 {
432 poseBounds = newBounds;
433 }
434
435 /**
436 * @param loadVisualizationModel Whether the clone should load the visualization model.
437 * @return A clone of this cspace.
438 */
439 CSpaceBasePtr clone(bool loadVisualizationModel) override;
440
441 /**
442 * @return The cspace's dimension bounds.
443 */
444 FloatRangeSeq getDimensionsBounds(const Ice::Current& = Ice::emptyCurrent) const override;
445
446 /**
447 * @return The cspace's dimensionality.
448 */
449 Ice::Long
450 getDimensionality(const Ice::Current& = Ice::emptyCurrent) const override
451 {
452 return agentJoints.size() + 3;
453 }
454
455 Ice::StringSeq getAgentJointNames() const override;
456
457 void setConfig(const float*& it) override;
458
459 protected:
460 template <class IceBaseClass, class DerivedClass>
463
464 Eigen::Matrix4f globalPoseBuffer = Eigen::Matrix4f::Identity();
465 };
466
469
470 /**
471 * @brief Similar to \ref armarx::SimoxCSpace, but prepends dimensions for translation in x, y and z and rotations around x, y and z.
472 * (use this for path planning of flying robots).
473 */
475 virtual public SimoxCSpace,
476 virtual public SimoxCSpaceWith3DPoseBase
477 {
478 public:
479 SimoxCSpaceWith3DPose(memoryx::CommonStorageInterfacePrx commonStoragePrx,
481 float stationaryObjectMargin = 0.0f);
482
483 void
484 setPoseBounds(const Vector6fRange& newBounds)
485 {
486 poseBounds = newBounds;
487 }
488
489 /**
490 * @param loadVisualizationModel Whether the clone should load the visualization model.
491 * @return A clone of this cspace.
492 */
493 CSpaceBasePtr clone(bool loadVisualizationModel) override;
494
495 /**
496 * @return The cspace's dimension bounds.
497 */
498 FloatRangeSeq getDimensionsBounds(const Ice::Current& = Ice::emptyCurrent) const override;
499
500 /**
501 * @return The cspace's dimensionality.
502 */
503 Ice::Long
504 getDimensionality(const Ice::Current& = Ice::emptyCurrent) const override
505 {
506 return agentJoints.size() + 6;
507 }
508
509 void setConfig(const float*& it) override;
510
511 Ice::StringSeq getAgentJointNames() const override;
512
513 protected:
514 template <class IceBaseClass, class DerivedClass>
517
518 Eigen::Matrix4f globalPoseBuffer = Eigen::Matrix4f::Identity();
519 };
520
521} // namespace armarx
Implementation of the slice class CSpaceBase.
Definition CSpace.h:53
bool isCollisionFree(const ::std::pair< const Ice::Float *, const Ice::Float * > &config, const Ice::Current &=Ice::emptyCurrent) override=0
Similar to SimoxCSpace, but prepends dimensions for translation in x and y and a rotation around z.
Ice::StringSeq getAgentJointNames() const override
FloatRangeSeq getDimensionsBounds(const Ice::Current &=Ice::emptyCurrent) const override
Ice::Long getDimensionality(const Ice::Current &=Ice::emptyCurrent) const override
CSpaceBasePtr clone(bool loadVisualizationModel) override
Eigen::Matrix4f globalPoseBuffer
void setConfig(const float *&it) override
void setPoseBounds(const Vector3fRange &newBounds)
SimoxCSpaceWith2DPose(memoryx::CommonStorageInterfacePrx commonStoragePrx, bool loadVisualizationModel=false, float stationaryObjectMargin=0.0f)
Similar to SimoxCSpace, but prepends dimensions for translation in x, y and z and rotations around x,...
Ice::StringSeq getAgentJointNames() const override
SimoxCSpaceWith3DPose(memoryx::CommonStorageInterfacePrx commonStoragePrx, bool loadVisualizationModel, float stationaryObjectMargin=0.0f)
FloatRangeSeq getDimensionsBounds(const Ice::Current &=Ice::emptyCurrent) const override
Ice::Long getDimensionality(const Ice::Current &=Ice::emptyCurrent) const override
CSpaceBasePtr clone(bool loadVisualizationModel) override
Eigen::Matrix4f globalPoseBuffer
void setPoseBounds(const Vector6fRange &newBounds)
void setConfig(const float *&it) override
The SimoxCSpace contains a set of stationary obstacles and an agent.
Definition SimoxCSpace.h:67
AgentData getAgentDataFromRobot(VirtualRobot::RobotPtr robotPtr) const
void ice_postUnmarshal() override
Initializes basic structures after transmission through ice.
CSpaceBasePtr clone(const Ice::Current &=Ice::emptyCurrent) override
VirtualRobot::CDManager cd
The collision checker.
bool isInitialized
Whether the collision check is initialized.
virtual Ice::StringSeq getAgentJointNames() const
void initStationaryObjects()
Initializes stationary objects for collision checking.
std::vector< armarx::DebugDrawerLineSet > getTraceVisu(const Path &p, const std::vector< std::string > &nodeNames, float traceStepSize=std::numeric_limits< float >::infinity())
FloatRangeSeq getDimensionsBounds(const Ice::Current &=Ice::emptyCurrent) const override
void addStationaryObject(const StationaryObject &obj, const Ice::Current &=Ice::emptyCurrent) override
Adds a stationary object to the cspace.
Ice::Long getDimensionality(const Ice::Current &=Ice::emptyCurrent) const override
const AgentPlanningInformation & getAgent() const
virtual Saba::CSpaceSampledPtr createSimoxCSpace() const
virtual void addObjectsFromWorkingMemory(memoryx::WorkingMemoryInterfacePrx workingMemoryPrx, const std::vector< std::string > &excludedInstancesIds=std::vector< std::string >())
Adds all objects except the ones with ids specified in the parameter excludedInstancesIds from the wo...
void initAgent(VirtualRobot::RobotPtr robotPtr)
memoryx::GridFileManagerPtr fileManager
The file manager used to load objects.
VirtualRobot::CDManager & getCD()
virtual TrajectoryPtr pathToTrajectory(const Path &p) const
const VirtualRobot::RobotPtr & getAgentSceneObj() const
GlobalCache< RobotPoolPtr, std::pair< VirtualRobot::RobotIO::RobotDescription, std::string > > robotCache
virtual void addPlanarObject(const std::vector< Eigen::Vector3f > &convexHull)
VectorXf jointMapToVector(const std::map< std::string, float > &jointMap, bool checkForNonexistenJointsInCspace=false) const
VirtualRobot::RobotPtr agentSceneObj
SimoxCSpace()=default
Default ctor.
std::vector< armarx::DebugDrawerLineSet > getTraceVisu(const PathWithCost &p, const std::vector< std::string > &nodeNames, float traceStepSize=std::numeric_limits< float >::infinity())
GlobalCache< VirtualRobot::ManipulationObjectPtr, std::pair< int, std::string > > meshCache
bool loadVisualizationModel
Whether the visualization model of objects/agents sould be loaded.
std::vector< std::vector< Eigen::Vector3f > > stationaryPlanes
virtual void setConfig(const std::vector< float > cfg)
Sets a configuration to check for.
VirtualRobot::ManipulationObjectPtr getSimoxManipulatorObject(const memoryx::ObjectClassBasePtr &object, const memoryx::GridFileManagerPtr &fileManager, bool inflate=true, VirtualRobot::CollisionCheckerPtr const &colChecker=VirtualRobot::CollisionCheckerPtr{}) const
std::vector< armarx::DebugDrawerLineSet > getTraceVisu(const VectorXfSeq &vecs, const std::vector< std::string > &nodeNames, float traceStepSize=std::numeric_limits< float >::infinity())
void setAgent(const AgentPlanningInformation &agentInfo, const Ice::Current &=Ice::emptyCurrent) override
Adds a stationary agent to the cspace.
VirtualRobot::SceneObjectSetPtr stationaryObjectSet
The scene objects for stationary objects.
virtual void setConfig(const float *&&it)
const StationaryObjectList & getStationaryObjects() const
const std::vector< VirtualRobot::RobotNodePtr > & getAgentJoints() const
void initCollisionTest(const Ice::Current &=Ice::emptyCurrent) override
Initializes the collision test.
AgentData getAgentDataAndLoadRobot() const
const VirtualRobot::SceneObjectSetPtr & getStationaryObjectSet() const
SimoxCSpace(memoryx::CommonStorageInterfacePrx commonStoragePrx, bool loadVisualizationModel=false, float stationaryObjectMargin=0.0f)
ctor
VirtualRobot::ManipulationObjectPtr getMovedSimoxManipulatorObject(const memoryx::ObjectClassBasePtr &object, const armarx::PoseBasePtr &pose, memoryx::GridFileManagerPtr &fileManager) const
float getStationaryObjectMargin() const
bool isCollisionFree(const ::std::pair< const Ice::Float *, const Ice::Float * > &cfg, const Ice::Current &=Ice::emptyCurrent) override
void setStationaryObjectMargin(float stationaryObjectMargin)
static SimoxCSpacePtr PrefetchWorkingMemoryObjects(memoryx::WorkingMemoryInterfacePrx workingMemoryPrx, memoryx::CommonStorageInterfacePrx commonStoragePrx, RobotStateComponentInterfacePrx rsc)
Load objects from WorkingMemory and puts them into the mesh cache.
std::vector< VirtualRobot::RobotNodePtr > agentJoints
virtual void setStationaryObjects(const StationaryObjectList &objList)
virtual TrajectoryPtr pathToTrajectory(const PathWithCost &p) const
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:196
std::shared_ptr< class Robot > RobotPtr
Definition Bus.h:19
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< SimoxCSpaceWith2DPose > SimoxCSpaceWith2DPosePtr
IceInternal::Handle< Trajectory > TrajectoryPtr
Definition Trajectory.h:52
IceInternal::Handle< SimoxCSpaceWith3DPose > SimoxCSpaceWith3DPosePtr
::IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface > RobotStateComponentInterfacePrx
IceInternal::Handle< SimoxCSpace > SimoxCSpacePtr
An ice handle for a SimoxCSpace.
Definition SimoxCSpace.h:56
std::shared_ptr< class RobotPool > RobotPoolPtr
std::shared_ptr< GridFileManager > GridFileManagerPtr
Contains information about an agent.
std::vector< VirtualRobot::RobotNodePtr > joints
The agent's joints.
std::vector< VirtualRobot::SceneObjectSetPtr > collisionSets
The collision stes.
VirtualRobot::RobotPtr agent
The agent's collision model.