33 static const std::string layerName
35 "AStarPathPlannerTestLayer"
40 usingProxy(getProperty<std::string>(
"WorkingMemoryName").getValue());
41 offeringTopic(getProperty<std::string>(
"DebugDrawerName").getValue());
42 usingProxy(getProperty<std::string>(
"AStarPathPlannerName").getValue());
47 workingMemoryPrx = getProxy<memoryx::WorkingMemoryInterfacePrx>(getProperty<std::string>(
"WorkingMemoryName").getValue());
48 debugDrawerPrx = getTopic<armarx::DebugDrawerInterfacePrx>(getProperty<std::string>(
"DebugDrawerName").getValue());
49 aStarPathPlannerPrx = getProxy<armarx::AStarPathPlannerBasePrx>(getProperty<std::string>(
"AStarPathPlannerName").getValue());
52 auto objInstPrx = workingMemoryPrx->getObjectInstancesSegment();
53 const auto objIds = objInstPrx->getAllEntityIds();
55 armarx::ObjectPositionBaseList objects {};
57 for (
const auto&
id : objIds)
59 const memoryx::EntityBasePtr entityBase = objInstPrx->getEntityById(
id);
60 const memoryx::ObjectInstanceBasePtr
object = memoryx::ObjectInstancePtr::dynamicCast(entityBase);
64 const std::string className =
object->getMostProbableClass();
66 memoryx::ObjectClassList classes = workingMemoryPrx->getPriorKnowledge()->getObjectClassesSegment()->getClassWithSubclasses(className);
70 ARMARX_INFO <<
"No classes for most probable class '" << className <<
"' of object '" <<
object->getName() <<
"' with id " << id;
74 armarx::ObjectPositionBase obj;
76 obj.objectClassBase = classes.at(0);
78 obj.objectPose = ::armarx::PoseBasePtr {
new Pose{
object->getPositionBase(),
object->getOrientationBase()}};
80 objects.push_back(obj);
82 ARMARX_VERBOSE <<
"Added class '" << className <<
"' of object '" <<
object->getName() <<
"' with id " << id;
85 ARMARX_INFO <<
"using " << objects.size() <<
"objects";
87 aStarPathPlannerPrx->setCollisionObjects(objects);
89 memoryx::AgentInstancesSegmentBasePrx agSegPrx = workingMemoryPrx->getAgentInstancesSegment();
92 const auto agentIds = agSegPrx->getAllEntityIds();
100 const auto agent0Id = agentIds.at(0);
104 memoryx::AgentInstanceBasePtr agent = agSegPrx->getAgentInstanceById(agent0Id);
106 std::string agentCollisionModelName {
"Platform"};
108 aStarPathPlannerPrx->setAgent(agent, agentCollisionModelName);
109 aStarPathPlannerPrx->setSafetyMargin(0);
113 armarx::Vector3BasePtr from {
new armarx::Vector3{1900.f, 2300.f, 0.f}};
119 Vector3BaseList path;
120 std::size_t iterations = 25;
121 std::chrono::high_resolution_clock::duration duration {0};
123 for (std::size_t i = 1; i <= iterations; ++i)
126 const auto tStart = std::chrono::high_resolution_clock::now();
127 path = aStarPathPlannerPrx->getPath(from, to);
128 const auto tEnd = std::chrono::high_resolution_clock::now();
129 duration += (tEnd - tStart);
131 ARMARX_INFO <<
"Path planning done (avg). T[ms] = " << std::chrono::duration_cast<std::chrono::milliseconds>(duration / iterations).count();
141 std::stringstream lineName {};
142 DrawColor color {1.f, 0.f, 0.f, 1.f};
144 for (std::size_t i = 0; i < path.size() - 1; ++i)
146 lineName.str(layerName);
147 lineName <<
"from_" << i <<
"_to_" << i + 1;
148 debugDrawerPrx->setLineVisu(layerName, lineName.str(), path.at(i), path.at(i + 1), 5.f, color);
158 ARMARX_INFO <<
"Found path whith " << path.size() - 1 <<
" edges";
164 debugDrawerPrx->clearLayer(layerName);
165 debugDrawerPrx->clearDebugLayer();