29#include <RobotComponents/interface/components/MotionPlanning/DataStructures.h>
30#include <RobotComponents/interface/components/MotionPlanning/MotionPlanningServer.h>
40 std::lock_guard<std::recursive_mutex> lock{
mutex};
52 PathWithCost noPathSentinel;
53 noPathSentinel.cost = std::numeric_limits<Ice::Float>::infinity();
54 return noPathSentinel;
60 std::lock_guard<std::recursive_mutex> lock{
mutex};
73 std::lock_guard<std::recursive_mutex> lock{
mutex};
77 throw IndexOutOfBoundsException{};
95 std::lock_guard<std::recursive_mutex> lock{
mutex};
99 return manager->getAllPathsWithCost();
109 std::lock_guard<std::recursive_mutex> lock{
mutex};
136 Task::run(
const RemoteObjectNodePrxList& remoteNodes,
const Ice::Current&)
140 const auto dim =
static_cast<std::size_t
>(cspace->getDimensionality());
144 std::unique_lock<std::recursive_mutex> lock{
mutex};
155 cspace->initCollisionTest();
157 if (!(cspace->isCollisionFree(
158 std::make_pair(startCfg.data(), startCfg.data() + startCfg.size()))))
160 ARMARX_VERBOSE_S <<
"trivial task! failed (start is not collision free): \n"
166 if (!(cspace->isCollisionFree(
167 std::make_pair(goalCfg.data(), goalCfg.data() + startCfg.size()))))
169 ARMARX_VERBOSE_S <<
"trivial task! failed (goal is not collision free): \n" << goalCfg;
174 const auto distanceStartGoal =
178 if (distanceStartGoal < dcdStep)
180 ARMARX_VERBOSE_S <<
"trivial task! done(the distance from start to goal is smaller "
181 "than the DCD step size)";
182 paths.emplace_back(VectorXfSeq{startCfg, goalCfg},
184 taskName +
"_trivialPath_" + ice_staticId());
190 targetCost = std::max(targetCost, distanceStartGoal);
193 RemoteObjectNodeInterfacePrx rmObjNode =
197 TaskBasePrx selfDerivedProxy = TaskBasePrx::uncheckedCast(
getProxy());
202 planningComputingPowerRequestStrategy,
204 maximalPlanningTimeInSeconds,
206 nodeCountDeltaForGoalConnectionTries,
207 CSpaceBasePtr::dynamicCast(cspace->clone()),
213 std::stringstream remoteObjectName;
214 remoteObjectName << localManagerNode->getName() <<
"@"
215 <<
getProxy()->ice_getIdentity().name;
218 <<
"\n\t remoteObjectName = " << remoteObjectName.str();
220 manager = rmObjNode->registerRemoteHandledObject(remoteObjectName.str(), localManagerNode);
239 std::lock_guard<std::recursive_mutex> lock{
mutex};
242 std::sort(
paths.begin(),
244 [](
const PathWithCost& lhs,
const PathWithCost& rhs)
245 { return lhs.cost < rhs.cost; });
246 for (std::size_t i = 0; i <
paths.size(); ++i)
248 paths.at(i).pathName = taskName +
"_path_" +
to_string(i) + ice_staticId();
256 <<
"\n\t initialWorkerCount " << initialWorkerCount
257 <<
"\n\t maximalWorkerCount " << maximalWorkerCount <<
"\n\t dcdStep "
258 << dcdStep <<
"\n\t batchSize " << batchSize <<
"\n\t cspace "
259 << cspace.get() <<
"\n\t addParams.alpha " << addParams.alpha
260 <<
"\n\t addParams.initialBorderRadius " << addParams.initialBorderRadius
261 <<
"\n\t addParams.minimalRadius " << addParams.minimalRadius
262 <<
"\n\t targetCost " << targetCost <<
"\n\t dim cspace (-1 == null cspace)"
263 << (cspace ? cspace->getDimensionality() : -1) <<
"\n\t dim start "
264 << startCfg.size() <<
"\n\t dim goal " << goalCfg.size() <<
"\n\t start "
265 << startCfg <<
"\n\t goal " << goalCfg;
267 if (!(dcdStep > 0.f))
269 throw std::invalid_argument{
"DCD stepsize <0"};
274 throw std::invalid_argument{
"cspace == nullptr"};
277 const auto dim =
static_cast<std::size_t
>(cspace->getDimensionality());
279 if (!(startCfg.size() == dim))
281 throw std::invalid_argument{
"Dimensions of cspace and start do not match"};
284 if (!(goalCfg.size() == dim))
286 throw std::invalid_argument{
"Dimensions of cspace and goal do not match"};
289 if (!(addParams.alpha >= 0.f))
291 throw std::invalid_argument{
"addParams.alpha < 0.f"};
294 if (!(addParams.minimalRadius > 0.f))
296 throw std::invalid_argument{
"addParams.minimalRadius <= 0.f"};
299 if (!(addParams.initialBorderRadius > addParams.minimalRadius))
301 throw std::invalid_argument{
"addParams.initialBorderRadius <= addParams.minimalRadius"};
304 if (nodeCountDeltaForGoalConnectionTries < 1)
306 throw std::invalid_argument{
"nodeCountDeltaForGoalConnectionTries < 1"};
308 if (!planningComputingPowerRequestStrategy)
310 throw std::invalid_argument{
"planningComputingPowerRequestStrategy == nullptr"};
315 CSpaceBasePtr cspace,
316 const cprs::ComputingPowerRequestStrategyBasePtr& planningComputingPowerRequestStrategy,
319 const std::string& taskName,
320 Ice::Long maximalPlanningTimeInSeconds,
321 AdaptiveDynamicDomainParameters addParams,
326 Ice::Long nodeCountDeltaForGoalConnectionTries,
328 Ice::Long initialWorkerCount,
329 Ice::Long maximalWorkerCount)
331 this->cspace = cspace;
332 this->planningComputingPowerRequestStrategy = planningComputingPowerRequestStrategy;
333 this->startCfg = std::move(startCfg);
334 this->goalCfg = std::move(goalCfg);
335 this->taskName = taskName;
336 this->addParams = addParams;
337 this->targetCost = targetCost;
338 this->dcdStep = dcdStep;
339 this->maximalPlanningTimeInSeconds = maximalPlanningTimeInSeconds;
340 this->batchSize = batchSize;
341 this->nodeCountDeltaForGoalConnectionTries = nodeCountDeltaForGoalConnectionTries;
342 this->initialWorkerCount = initialWorkerCount;
343 this->maximalWorkerCount = maximalWorkerCount;
351 std::lock_guard<std::recursive_mutex> lock{
mutex};
355 return manager->getNodeCount();
bool isRunning(const Ice::Current &=Ice::emptyCurrent) const override
Returns whether the task is currently planning.
bool finishedRunning(const Ice::Current &=Ice::emptyCurrent) const override
Returns whether the task has finished planning.
bool setTaskStatus(TaskStatus::Status newTaskStatus, const Ice::Current &=Ice::emptyCurrent) override
MotionPlanningTaskBasePrx & getProxy()
TaskStatus::Status getTaskStatus(const Ice::Current &=Ice::emptyCurrent) const override
Manages the planning of the addirrt* algorithm.
void setPaths(const PathWithCostSeq &newPathList, const Ice::Current &=Ice::emptyCurrent) override
Used by the manager to store its found paths.
PathWithCostSeq getAllPathsWithCost(const Ice::Current &=Ice::emptyCurrent) const override
Ice::Long getPathCount(const Ice::Current &=Ice::emptyCurrent) const override
PathWithCost getNthPathWithCost(Ice::Long index, const Ice::Current &=Ice::emptyCurrent) const override
RemoteHandle< ManagerNodeBasePrx > manager
The manager node.
PathWithCostSeq paths
All found paths.
std::condition_variable_any managerDone
CV used by the dispatcher thread to wait until planning is done.
std::recursive_mutex mutex
Mutex to protect internal structures.
void abortTask(const Ice::Current &=Ice::emptyCurrent) override
Aborts the task.
PathWithCost getBestPath(const Ice::Current &=Ice::emptyCurrent) const override
void setMaxCpus(Ice::Int maxCpus, const Ice::Current &=Ice::emptyCurrent) override
void checkParameters()
Checks for illegal parameters.
Task()
Ctor used by object factories.
Ice::Long cachedNodeCount
The cahced node count.
Ice::Long getNodeCount(const Ice::Current &=Ice::emptyCurrent) const override
Ice::Int getMaxCpus(const Ice::Current &=Ice::emptyCurrent) const override
void run(const RemoteObjectNodePrxList &remoteNodes, const Ice::Current &=Ice::emptyCurrent) override
Runs the task.
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
#define ARMARX_DEBUG_S
The logging level for output that is only interesting while debugging.
#define ARMARX_WARNING_S
The logging level for unexpected behaviour, but not a serious problem.
IceInternal::Handle< ManagerNode > ManagerNodePtr
An ice handle for a ManagerNode.
float euclideanDistance(IteratorType1 first1, IteratorType1 last1, IteratorType2 first2)
Returns the euclidean distance.
const std::string & to_string(const std::string &s)