Task.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 <mutex>
27 #include <atomic>
28 #include <condition_variable>
29 
31 
33 
34 #include <RobotComponents/interface/components/MotionPlanning/Tasks/AdaptiveDynamicDomainInformedRRTStar/Task.h>
35 #include <RobotComponents/interface/components/MotionPlanning/Tasks/AdaptiveDynamicDomainInformedRRTStar/ManagerNode.h>
36 #include "../../ResourceRequestStrategies/ComputingPowerRequestStrategy.h"
37 #include "../../util/PlanningUtil.h"
38 
39 #include "util.h"
40 #include "../CPRSAwareMotionPlanningTask.h"
41 
42 namespace armarx::addirrtstar
43 {
44  class Task;
45  /**
46  * @brief An ice handle for an addirrt* \ref Task
47  */
49 
50  /**
51  * @brief An addirrt* task.
52  * The olanning algorithm used is a combination of:
53  * - bulk distributed rrt.
54  * - informed rrt*
55  * - adaptive dynamic domain
56  *
57  * bulks and batches are used as synonyms.
58  */
59  class Task:
60  public virtual cprs::CPRSAwareMotionPlanningTask,
61  public virtual TaskBase,
63  {
64  public:
65  /**
66  * @brief Ctor.
67  * @param cspace The planning cspace.
68  * @param planningComputingPowerRequestStrategy The used cprs.
69  * @param startCfg The start configuration.
70  * @param goalCfg The goal configuration.
71  * @param addParams The parameters for adaptive dynamic domain.
72  * @param targetCost The target cost. (planning stops when a path with a length <= was found)
73  * @param dcdStep The dcd step size.
74  * @param maximalPlanningTimeInSeconds The maximal planning time in seconds. (planning will stop after this time)
75  * @param batchSize The size of a batch.
76  * @param nodeCountDeltaForGoalConnectionTries Number of nodes created (by a worker) before a connect to the goal node is tried (by this worker).
77  * @param initialWorkerCount The in itaial number of worker processes.
78  * @param maximalWorkerCount The maximal number of worker processes.
79  */
80  Task(//problem
81  CSpaceBasePtr cspace,
82  const cprs::ComputingPowerRequestStrategyBasePtr& planningComputingPowerRequestStrategy,
83  VectorXf startCfg,
84  VectorXf goalCfg,
85  const std::string& taskName = "ADDIRRTStarTask",
86  Ice::Long maximalPlanningTimeInSeconds = 300,
87  AdaptiveDynamicDomainParameters addParams = generateADDParamsFromDCDStepsize(0.01f),
88  float targetCost = 0,
89  //general
90  float dcdStep = 0.01f,
91  Ice::Long batchSize = 10,
92  Ice::Long nodeCountDeltaForGoalConnectionTries = 50,
93  //management
94  Ice::Long initialWorkerCount = 1,
95  Ice::Long maximalWorkerCount = std::numeric_limits<Ice::Long>::max()
96  );
97 
98 
99  PathWithCost getPathWithCost(const Ice::Current& = Ice::emptyCurrent) const override
100  {
102  }
103  Path getNthPath(Ice::Long n, const Ice::Current& = Ice::emptyCurrent) const override
104  {
106  }
107 
108  Path getPath(const Ice::Current& = Ice::emptyCurrent) const override
109  {
111  }
112 
113  //TaskControlInterface
114  /**
115  * @return The shortest found path. (with its cost)
116  */
117  PathWithCost getBestPath(const Ice::Current& = Ice::emptyCurrent) const override;
118  /**
119  * @return The number of found paths.
120  */
121  Ice::Long getPathCount(const Ice::Current& = Ice::emptyCurrent) const override;
122  /**
123  * @param index The index.
124  * @return The path at the given index.
125  */
126  PathWithCost getNthPathWithCost(Ice::Long index, const Ice::Current& = Ice::emptyCurrent) const override;
127  /**
128  * @return All found paths.
129  */
130  PathWithCostSeq getAllPathsWithCost(const Ice::Current& = Ice::emptyCurrent) const override;
131 
132  //PlanningControlInterface
133  /**
134  * @brief Aborts the task.
135  */
136  void abortTask(const Ice::Current& = Ice::emptyCurrent) override;
137 
138  //PlanningTaskBase
139  /**
140  * @brief Runs the task.
141  * @param remoteNodes The list of \ref RemoteObjectNodeInterfacePrx used to distribute work to computers.
142  */
143  void run(const RemoteObjectNodePrxList& remoteNodes, const Ice::Current& = Ice::emptyCurrent) override;
144 
145  /**
146  * @brief Used by the manager to store its found paths.
147  * @param newPathList The paths.
148  */
149  void setPaths(const PathWithCostSeq& newPathList, const Ice::Current& = Ice::emptyCurrent) override;
150 
151  /**
152  * @return The current node count.
153  */
154  Ice::Long getNodeCount(const Ice::Current& = Ice::emptyCurrent) const override;
155 
156  // ResourceManagementInterface interface
157  void setMaxCpus(Ice::Int maxCpus, const Ice::Current& = Ice::emptyCurrent) override;
158 
159  Ice::Int getMaxCpus(const Ice::Current& = Ice::emptyCurrent) const override;
160 
161  protected:
162  template<class Base, class Derived> friend class ::armarx::GenericFactory;
163 
164  /**
165  * @brief Checks for illegal parameters
166  */
167  void checkParameters();
168 
169  /**
170  * @brief Ctor used by object factories.
171  */
172  Task():
173  TaskBase(),
174  cachedNodeCount {0}
175  {
176  }
177 
178  /**
179  * @brief Mutex to protect internal structures.
180  */
181  mutable std::recursive_mutex mutex;
182  //we have to ensure that the waiting thread has only locked the recursive mutex once,
183  //since the condition variable only will use the unlock method on the unique_lock once during the wait.
184  //http://stackoverflow.com/questions/14323340/can-you-combine-stdrecursive-mutex-with-stdcondition-variable
185  //
186  //this is given for run
187  /**
188  * @brief CV used by the dispatcher thread to wait until planning is done.
189  */
190  std::condition_variable_any managerDone;
191 
192  /**
193  * @brief The manager node.
194  */
196  /**
197  * @brief All found paths
198  */
199  PathWithCostSeq paths;
200 
201  /**
202  * @brief The cahced node count. The cache is filled when the manager node shuts down.
203  */
205  };
206 }
207 namespace armarx
208 {
212 }
213 
armarx::addirrtstar::Task
An addirrt* task.
Definition: Task.h:59
armarx::addirrtstar::Task::setMaxCpus
void setMaxCpus(Ice::Int maxCpus, const Ice::Current &=Ice::emptyCurrent) override
Definition: Task.cpp:344
armarx::addirrtstar::Task::abortTask
void abortTask(const Ice::Current &=Ice::emptyCurrent) override
Aborts the task.
Definition: Task.cpp:100
armarx::addirrtstar::Task::checkParameters
void checkParameters()
Checks for illegal parameters.
Definition: Task.cpp:231
armarx::addirrtstar::Task::Task
Task()
Ctor used by object factories.
Definition: Task.h:172
armarx::addirrtstar::Task::manager
RemoteHandle< ManagerNodeBasePrx > manager
The manager node.
Definition: Task.h:195
index
uint8_t index
Definition: EtherCATFrame.h:59
util.h
armarx::addirrtstar::Task::getPathCount
Ice::Long getPathCount(const Ice::Current &=Ice::emptyCurrent) const override
Definition: Task.cpp:54
armarx::addirrtstar::Task::managerDone
std::condition_variable_any managerDone
CV used by the dispatcher thread to wait until planning is done.
Definition: Task.h:190
RemoteHandle.h
FactoryCollectionBase.h
armarx::addirrtstar::Task::getNthPathWithCost
PathWithCost getNthPathWithCost(Ice::Long index, const Ice::Current &=Ice::emptyCurrent) const override
Definition: Task.cpp:66
armarx::addirrtstar::Task::getAllPathsWithCost
PathWithCostSeq getAllPathsWithCost(const Ice::Current &=Ice::emptyCurrent) const override
Definition: Task.cpp:87
armarx::cprs::CPRSAwareMotionPlanningTask
Implementation of the slice interface CPRSAwarePlanningTaskBase.
Definition: CPRSAwareMotionPlanningTask.h:41
armarx::addirrtstar::Task::run
void run(const RemoteObjectNodePrxList &remoteNodes, const Ice::Current &=Ice::emptyCurrent) override
Runs the task.
Definition: Task.cpp:128
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::MotionPlanningMultiPathWithCostTaskCI::getPathWithCost
PathWithCost getPathWithCost(const Ice::Current &=Ice::emptyCurrent) const override
Definition: MotionPlanningTaskControlInterface.h:106
armarx::addirrtstar::Task::getPathWithCost
PathWithCost getPathWithCost(const Ice::Current &=Ice::emptyCurrent) const override
Definition: Task.h:99
armarx::addirrtstar::Task::setPaths
void setPaths(const PathWithCostSeq &newPathList, const Ice::Current &=Ice::emptyCurrent) override
Used by the manager to store its found paths.
Definition: Task.cpp:216
armarx::VariantType::Long
const VariantTypeId Long
Definition: Variant.h:917
armarx::MotionPlanningMultiPathWithCostTaskCI::getNthPath
Path getNthPath(Ice::Long n, const Ice::Current &=Ice::emptyCurrent) const override
Definition: MotionPlanningTaskControlInterface.h:110
armarx::MotionPlanningWithCostTaskCI::getPath
Path getPath(const Ice::Current &=Ice::emptyCurrent) const override
Definition: MotionPlanningTaskControlInterface.h:82
armarx::addirrtstar::Task::paths
PathWithCostSeq paths
All found paths.
Definition: Task.h:199
max
T max(T t1, T t2)
Definition: gdiam.h:48
armarx::addirrtstar::Task::cachedNodeCount
Ice::Long cachedNodeCount
The cahced node count.
Definition: Task.h:204
armarx::addirrtstar::Task::getPath
Path getPath(const Ice::Current &=Ice::emptyCurrent) const override
Definition: Task.h:108
armarx::addirrtstar::Task::getNthPath
Path getNthPath(Ice::Long n, const Ice::Current &=Ice::emptyCurrent) const override
Definition: Task.h:103
armarx::addirrtstar::Task::getBestPath
PathWithCost getBestPath(const Ice::Current &=Ice::emptyCurrent) const override
Definition: Task.cpp:36
IceUtil::Handle
Definition: forward_declarations.h:29
armarx::RemoteHandle< ManagerNodeBasePrx >
armarx::VariantType::Int
const VariantTypeId Int
Definition: Variant.h:916
armarx::armem::server::ltm::detail::mixin::Path
std::filesystem::path Path
Definition: DiskStorageMixin.h:17
armarx::addirrtstar::Task::getNodeCount
Ice::Long getNodeCount(const Ice::Current &=Ice::emptyCurrent) const override
Definition: Task.cpp:331
armarx::addirrtstar::Task::mutex
std::recursive_mutex mutex
Mutex to protect internal structures.
Definition: Task.h:181
armarx::addirrtstar::Task::getMaxCpus
Ice::Int getMaxCpus(const Ice::Current &=Ice::emptyCurrent) const override
Definition: Task.cpp:349
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::addirrtstar
Definition: ManagerNode.cpp:35
armarx::MotionPlanningMultiPathWithCostTaskCI
Definition: MotionPlanningTaskControlInterface.h:89