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