27 #include "../../util/PlanningUtil.h"
31 Task::Task(
const CSpaceBasePtr& cspace,
const VectorXf& startCfg,
const VectorXf& goalCfg,
const std::string& taskName,
Ice::Long maximalPlanningTimeInSeconds,
float dcdStep,
Ice::Long workerCount)
33 this->cspace = cspace;
34 this->startCfg = startCfg;
35 this->goalCfg = goalCfg;
36 this->dcdStep = dcdStep;
37 this->maximalPlanningTimeInSeconds = maximalPlanningTimeInSeconds;
38 this->workerCount = workerCount;
39 this->taskName = taskName;
44 std::lock_guard<std::mutex> lock {
mtx};
52 std::lock_guard<std::mutex> lock {
mtx};
58 std::lock_guard<std::mutex> lock {
mtx};
63 void Task::run(
const RemoteObjectNodePrxList& remoteNodes,
const Ice::Current&)
66 ARMARX_CHECK_EXPRESSION(std::all_of(remoteNodes.begin(), remoteNodes.end(), [](
const RemoteObjectNodeInterfacePrx & n)
73 const std::string topicName =
"RRTConnectUpdateTopic:" +
getProxy()->ice_getIdentity().name;
76 const auto startIsCollisionFree = cspace->isCollisionFree(std::pair<const Ice::Float*, const Ice::Float*> {startCfg.data(), startCfg.data() + startCfg.size()});
77 if (!startIsCollisionFree)
80 ARMARX_WARNING <<
"MotionPlanningTask " << taskName <<
" trivially failed! start cfg in collision. start:\n" << startCfg;
84 const auto goalIscollisionFree = cspace->isCollisionFree(std::pair<const Ice::Float*, const Ice::Float*> { goalCfg.data(), goalCfg.data() + goalCfg.size()});
85 if (!goalIscollisionFree)
88 ARMARX_WARNING <<
"MotionPlanningTask " << taskName <<
" trivially failed! goal cfg in collision. goal:\n" << goalCfg;
92 if (
euclideanDistance(startCfg.begin(), startCfg.end(), goalCfg.begin()) <= dcdStep)
94 solution.nodes.emplace_back(startCfg);
95 solution.nodes.emplace_back(goalCfg);
96 solution.pathName = taskName +
"_trivialPath_" + ice_staticId();
97 ARMARX_WARNING <<
"MotionPlanningTask " << taskName <<
" trivially succeeded! (start and goal less than dcd step size apart!)";
103 std::unique_lock<std::mutex> lock {
mtx};
104 std::vector<RemoteHandle<WorkerNodeBasePrx>> workers;
105 WorkerNodeBasePrxList workerProxies;
107 workers.reserve(workerCount);
108 auto workerToStart = workerCount;
109 const auto taskName =
getProxy()->ice_getIdentity().name;
110 for (
auto& ron : remoteNodes)
112 auto maxWorkerForNode = ron->getNumberOfCores();
113 for (
Ice::Long i = 0; i < maxWorkerForNode && workerToStart; ++i)
120 TaskBasePrx::uncheckedCast(
getProxy()),
127 workers.emplace_back(ron->registerRemoteHandledObject(workerName, worker));
128 workerProxies.emplace_back(*(workers.back()));
138 for (
auto& w : workers)
140 w->setWorkerNodes(workerProxies);
144 const auto endTime = std::chrono::system_clock::now() + std::chrono::seconds {maximalPlanningTimeInSeconds};
148 doneCV.wait_for(lock, std::chrono::milliseconds {10});
149 if (endTime < std::chrono::system_clock::now())
166 for (
auto& w : workers)
170 doneCV.wait_for(lock, std::chrono::milliseconds {10});
176 std::lock_guard<std::mutex> lock {
mtx};
178 solution.pathName = taskName +
"_path_" + ice_staticId();
186 cspace->initCollisionTest();