26 #include "../../util/CollisionCheckUtil.h"
27 #include "../../util/Metrics.h"
29 #include <MotionPlanning/Planner/BiRrt.h>
30 #include <MotionPlanning/CSpace/CSpacePath.h>
33 #include <MotionPlanning/PostProcessing/ShortcutProcessor.h>
35 #include <SimoxUtility/algorithm/string/string_tools.h>
40 Task::Task(
const CSpaceBasePtr& cspace,
const VectorXf& startCfg,
const VectorXf& goalCfg,
const std::string& taskName,
Ice::Long maximalPlanningTimeInSeconds,
float dcdStep)
42 this->cspace = cspace->clone();
43 this->startCfg = startCfg;
44 this->goalCfg = goalCfg;
45 this->dcdStep = dcdStep;
46 this->maximalPlanningTimeInSeconds = maximalPlanningTimeInSeconds;
47 this->taskName = taskName;
49 if (startCfg.size() != goalCfg.size() || startCfg.size() !=
static_cast<std::size_t
>(this->cspace->getDimensionality()))
51 throw std::invalid_argument {
"start and goal have to be the size of the cspace's dimensionality"};
61 std::lock_guard<std::mutex> lock {
mtx};
65 void Task::run(
const RemoteObjectNodePrxList&, const::Ice::Current&)
68 auto failureOutput = [
this]
74 for (
auto set : origCSpace->getCD().getSceneObjectSets())
76 if (origCSpace->getCD().isInCollision(
set))
78 std::string name =
set->getName();
83 for (
auto e :
set->getSceneObjects())
85 names.push_back(e->getName());
90 names.push_back(name);
93 ss <<
"scene object set consisting of " << simox::alg::join(
names,
", ") <<
" is in collision\n";
103 cspace->initCollisionTest();
105 const auto startIsCollisionFree = cspace->isCollisionFree(std::pair<const Ice::Float*, const Ice::Float*> {startCfg.data(), startCfg.data() + startCfg.size()});
106 if (!startIsCollisionFree)
108 ARMARX_WARNING <<
"BiRRT failed trivially: start config is in collision: " << startCfg <<
" Collisions:\n" << failureOutput();
113 const auto goalIscollisionFree = cspace->isCollisionFree(std::pair<const Ice::Float*, const Ice::Float*> { goalCfg.data(), goalCfg.data() + goalCfg.size()});
114 if (!goalIscollisionFree)
116 ARMARX_WARNING <<
"BiRRT failed trivially: goal config is in collision" << goalCfg <<
" Collisions:\n" << failureOutput();
123 ARMARX_INFO <<
"RobotConfig: " << origCSpace->getAgentSceneObj()->getConfig()->getRobotNodeJointValueMap();
129 ARMARX_INFO <<
"BiRRT took : " << (IceUtil::Time::now() - start).toMilliSecondsDouble() <<
" ms";
136 scaledCSpace->unscaleConfig(startCfg);
137 scaledCSpace->unscaleConfig(goalCfg);
138 sampledcSpace->setMetricWeights(Eigen::Map<Eigen::VectorXf>(scaledCSpace->getScalingFactors().data(), scaledCSpace->getScalingFactors().size()));
142 const auto distStartEnd =
euclideanDistance(startCfg.begin(), startCfg.end(), goalCfg.begin());
144 if (distStartEnd <= dcdStep)
147 solution.nodes.emplace_back(startCfg);
148 solution.nodes.emplace_back(goalCfg);
154 Saba::Rrt::RrtMethod mode;
155 mode = Saba::Rrt::eExtend;
157 ARMARX_INFO <<
"CSpace type : " << cspace->ice_id();
163 sampledcSpace->setSamplingSizeDCD(dcdStep);
164 ARMARX_INFO <<
"SamplingSizeDCD: " << sampledcSpace->getSamplingSizeDCD();
165 Saba::BiRrtPtr rrt(
new Saba::BiRrt(sampledcSpace,
169 rrt->setStart(Eigen::Map<Eigen::ArrayXf>(startCfg.data(), startCfg.size()));
170 rrt->setGoal(Eigen::Map<Eigen::ArrayXf>(goalCfg.data(), goalCfg.size()));
172 bool planningSucceeded = rrt->plan();
173 if (planningSucceeded)
176 Saba::CSpacePathPtr tmpSolution = rrt->getSolution();
177 ARMARX_INFO <<
"waypoints: " << tmpSolution->getPoints().size();
182 Saba::ShortcutProcessor shortcutter(tmpSolution, sampledcSpace);
183 tmpSolution = shortcutter.shortenSolutionRandom(100, 200);
184 ARMARX_INFO <<
"Shortcutting resulted into " << tmpSolution->getPoints().size();
186 for (
auto& vec : tmpSolution->getPoints())
188 this->
solution.nodes.push_back(VectorXf {vec.data(), vec.data() + vec.rows()});
231 if (cspace->ice_isA(CSpaceAdaptorBase::ice_staticId()))
233 origCSpace = SimoxCSpacePtr::dynamicCast(CSpaceAdaptorBasePtr::dynamicCast(cspace)->
getOriginalCSpace());
239 origCSpace = SimoxCSpacePtr::dynamicCast(cspace);