33 static const std::string layerName{
"AStarPathPlannerTestLayer"};
38 usingProxy(getProperty<std::string>(
"WorkingMemoryName").getValue());
39 offeringTopic(getProperty<std::string>(
"DebugDrawerName").getValue());
40 usingProxy(getProperty<std::string>(
"AStarPathPlannerName").getValue());
46 workingMemoryPrx = getProxy<memoryx::WorkingMemoryInterfacePrx>(
47 getProperty<std::string>(
"WorkingMemoryName").getValue());
48 debugDrawerPrx = getTopic<armarx::DebugDrawerInterfacePrx>(
49 getProperty<std::string>(
"DebugDrawerName").getValue());
50 aStarPathPlannerPrx = getProxy<armarx::AStarPathPlannerBasePrx>(
51 getProperty<std::string>(
"AStarPathPlannerName").getValue());
54 auto objInstPrx = workingMemoryPrx->getObjectInstancesSegment();
55 const auto objIds = objInstPrx->getAllEntityIds();
57 armarx::ObjectPositionBaseList objects{};
59 for (
const auto&
id : objIds)
61 const memoryx::EntityBasePtr entityBase = objInstPrx->getEntityById(
id);
62 const memoryx::ObjectInstanceBasePtr
object =
63 memoryx::ObjectInstancePtr::dynamicCast(entityBase);
67 const std::string className =
object->getMostProbableClass();
69 memoryx::ObjectClassList classes = workingMemoryPrx->getPriorKnowledge()
70 ->getObjectClassesSegment()
71 ->getClassWithSubclasses(className);
75 ARMARX_INFO <<
"No classes for most probable class '" << className <<
"' of object '"
76 <<
object->getName() <<
"' with id " << id;
80 armarx::ObjectPositionBase obj;
82 obj.objectClassBase = classes.at(0);
84 obj.objectPose = ::armarx::PoseBasePtr{
85 new Pose{
object->getPositionBase(),
object->getOrientationBase()}};
87 objects.push_back(obj);
89 ARMARX_VERBOSE <<
"Added class '" << className <<
"' of object '" <<
object->getName()
90 <<
"' with id " << id;
93 ARMARX_INFO <<
"using " << objects.size() <<
"objects";
95 aStarPathPlannerPrx->setCollisionObjects(objects);
97 memoryx::AgentInstancesSegmentBasePrx agSegPrx = workingMemoryPrx->getAgentInstancesSegment();
100 const auto agentIds = agSegPrx->getAllEntityIds();
102 if (!agentIds.size())
108 const auto agent0Id = agentIds.at(0);
112 memoryx::AgentInstanceBasePtr agent = agSegPrx->getAgentInstanceById(agent0Id);
114 std::string agentCollisionModelName{
"Platform"};
116 aStarPathPlannerPrx->setAgent(agent, agentCollisionModelName);
117 aStarPathPlannerPrx->setSafetyMargin(0);
127 Vector3BaseList path;
128 std::size_t iterations = 25;
129 std::chrono::high_resolution_clock::duration duration{0};
131 for (std::size_t i = 1; i <= iterations; ++i)
134 const auto tStart = std::chrono::high_resolution_clock::now();
135 path = aStarPathPlannerPrx->getPath(from, to);
136 const auto tEnd = std::chrono::high_resolution_clock::now();
137 duration += (tEnd - tStart);
140 <<
"Path planning done (avg). T[ms] = "
141 << std::chrono::duration_cast<std::chrono::milliseconds>(duration / iterations).count();
151 std::stringstream lineName{};
152 DrawColor color{1.f, 0.f, 0.f, 1.f};
154 for (std::size_t i = 0; i < path.size() - 1; ++i)
156 lineName.str(layerName);
157 lineName <<
"from_" << i <<
"_to_" << i + 1;
158 debugDrawerPrx->setLineVisu(
159 layerName, lineName.str(), path.at(i), path.at(i + 1), 5.f, color);
169 ARMARX_INFO <<
"Found path whith " << path.size() - 1 <<
" edges";
175 debugDrawerPrx->clearLayer(layerName);
176 debugDrawerPrx->clearDebugLayer();