27 #include "../../util/Metrics.h"
28 #include <RobotComponents/interface/components/MotionPlanning/MotionPlanningServer.h>
29 #include <RobotComponents/interface/components/MotionPlanning/DataStructures.h>
38 std::lock_guard<std::recursive_mutex> lock {
mutex};
50 PathWithCost noPathSentinel;
51 noPathSentinel.cost = std::numeric_limits<Ice::Float>::infinity();
52 return noPathSentinel;
56 std::lock_guard<std::recursive_mutex> lock {
mutex};
68 std::lock_guard<std::recursive_mutex> lock {
mutex};
72 throw IndexOutOfBoundsException {};
89 std::lock_guard<std::recursive_mutex> lock {
mutex};
93 return manager->getAllPathsWithCost();
102 std::lock_guard<std::recursive_mutex> lock {
mutex};
128 void Task::run(
const RemoteObjectNodePrxList& remoteNodes,
const Ice::Current&)
132 const auto dim =
static_cast<std::size_t
>(cspace->getDimensionality());
136 std::unique_lock<std::recursive_mutex> lock {
mutex};
147 cspace->initCollisionTest();
149 if (!(cspace->isCollisionFree(std::make_pair(startCfg.data(), startCfg.data() + startCfg.size()))))
151 ARMARX_VERBOSE_S <<
"trivial task! failed (start is not collision free): \n" << startCfg;
156 if (!(cspace->isCollisionFree(std::make_pair(goalCfg.data(), goalCfg.data() + startCfg.size()))))
158 ARMARX_VERBOSE_S <<
"trivial task! failed (goal is not collision free): \n" << goalCfg;
163 const auto distanceStartGoal =
euclideanDistance(startCfg.begin(), startCfg.end(), goalCfg.begin());
166 if (distanceStartGoal < dcdStep)
168 ARMARX_VERBOSE_S <<
"trivial task! done(the distance from start to goal is smaller than the DCD step size)";
169 paths.emplace_back(VectorXfSeq {startCfg, goalCfg}, distanceStartGoal, taskName +
"_trivialPath_" + ice_staticId());
175 targetCost =
std::max(targetCost, distanceStartGoal);
178 RemoteObjectNodeInterfacePrx rmObjNode = remoteNodes.at(0);
181 TaskBasePrx selfDerivedProxy = TaskBasePrx::uncheckedCast(
getProxy());
185 selfDerivedProxy, remoteNodes,
186 initialWorkerCount, maximalWorkerCount, planningComputingPowerRequestStrategy,
187 dcdStep, maximalPlanningTimeInSeconds, batchSize, nodeCountDeltaForGoalConnectionTries,
188 CSpaceBasePtr::dynamicCast(cspace->clone()),
190 addParams, targetCost
194 std::stringstream remoteObjectName;
195 remoteObjectName << localManagerNode->
getName() <<
"@" <<
getProxy()->ice_getIdentity().name;
198 <<
"\n\t remoteObjectName = " << remoteObjectName.str();
200 manager = rmObjNode->registerRemoteHandledObject(remoteObjectName.str(), localManagerNode);
218 std::lock_guard<std::recursive_mutex> lock {
mutex};
221 std::sort(
paths.begin(),
paths.end(), [](
const PathWithCost & lhs,
const PathWithCost & rhs)
223 return lhs.cost < rhs.cost;
225 for (std::size_t i = 0; i <
paths.size(); ++i)
227 paths.at(i).pathName = taskName +
"_path_" +
to_string(i) + ice_staticId();
234 <<
"\n\t initialWorkerCount " << initialWorkerCount
235 <<
"\n\t maximalWorkerCount " << maximalWorkerCount
236 <<
"\n\t dcdStep " << dcdStep
237 <<
"\n\t batchSize " << batchSize
238 <<
"\n\t cspace " << cspace.get()
239 <<
"\n\t addParams.alpha " << addParams.alpha
240 <<
"\n\t addParams.initialBorderRadius " << addParams.initialBorderRadius
241 <<
"\n\t addParams.minimalRadius " << addParams.minimalRadius
242 <<
"\n\t targetCost " << targetCost
243 <<
"\n\t dim cspace (-1 == null cspace)" << (cspace ? cspace->getDimensionality() : -1)
244 <<
"\n\t dim start " << startCfg.size()
245 <<
"\n\t dim goal " << goalCfg.size()
246 <<
"\n\t start " << startCfg
247 <<
"\n\t goal " << goalCfg;
249 if (!(dcdStep > 0.f))
251 throw std::invalid_argument {
"DCD stepsize <0"};
256 throw std::invalid_argument {
"cspace == nullptr"};
259 const auto dim =
static_cast<std::size_t
>(cspace->getDimensionality());
261 if (!(startCfg.size() == dim))
263 throw std::invalid_argument {
"Dimensions of cspace and start do not match"};
266 if (!(goalCfg.size() == dim))
268 throw std::invalid_argument {
"Dimensions of cspace and goal do not match"};
271 if (!(addParams.alpha >= 0.f))
273 throw std::invalid_argument {
"addParams.alpha < 0.f"};
276 if (!(addParams.minimalRadius > 0.f))
278 throw std::invalid_argument {
"addParams.minimalRadius <= 0.f"};
281 if (!(addParams.initialBorderRadius > addParams.minimalRadius))
283 throw std::invalid_argument {
"addParams.initialBorderRadius <= addParams.minimalRadius"};
286 if (nodeCountDeltaForGoalConnectionTries < 1)
288 throw std::invalid_argument {
"nodeCountDeltaForGoalConnectionTries < 1"};
290 if (!planningComputingPowerRequestStrategy)
292 throw std::invalid_argument {
"planningComputingPowerRequestStrategy == nullptr"};
297 CSpaceBasePtr cspace,
298 const cprs::ComputingPowerRequestStrategyBasePtr& planningComputingPowerRequestStrategy,
301 const std::string& taskName,
303 AdaptiveDynamicDomainParameters addParams,
308 Ice::Long nodeCountDeltaForGoalConnectionTries,
314 this->cspace = cspace;
315 this->planningComputingPowerRequestStrategy = planningComputingPowerRequestStrategy;
316 this->startCfg = std::move(startCfg);
317 this->goalCfg = std::move(goalCfg);
318 this->taskName = taskName;
319 this->addParams = addParams;
320 this->targetCost = targetCost;
321 this->dcdStep = dcdStep;
322 this->maximalPlanningTimeInSeconds = maximalPlanningTimeInSeconds;
323 this->batchSize = batchSize;
324 this->nodeCountDeltaForGoalConnectionTries = nodeCountDeltaForGoalConnectionTries;
325 this->initialWorkerCount = initialWorkerCount;
326 this->maximalWorkerCount = maximalWorkerCount;
333 std::lock_guard<std::recursive_mutex> lock {
mutex};
337 return manager->getNodeCount();