57 agentInstances =
wm->getAgentInstancesSegment();
58 graphSegment = prior->getGraphSegment();
60 graphNodes = graphSegment->getNodesByScene(sceneName);
66 return "AgentAtPredicateProvider";
78 PredicateInstanceList result;
79 const std::string predicateName = agentAt.name;
81 for (
const auto& agentEntity : agentInstances->getAllEntities())
83 AgentInstanceBasePtr agent = AgentInstanceBasePtr::dynamicCast(agentEntity);
84 EntityRefBasePtr agentRef =
85 wm->getAgentInstancesSegment()->getEntityRefById(agentEntity->getId());
87 GraphNodeBasePtr closestNode =
88 psr->getNearestNodeToPose(sceneName,
"robotlocation", agent->getPoseBase());
90 const auto agentPoseEigen =
91 armarx::FramedPosePtr::dynamicCast(agent->getPoseBase())->toEigen();
92 auto closestPoseEigen =
93 armarx::FramedPosePtr::dynamicCast(closestNode->getPose())->toEigen();
94 auto dist = (closestPoseEigen.block<2, 1>(0, 3) - agentPoseEigen.block<2, 1>(0, 3)).
norm();
96 ARMARX_INFO <<
"for agent '" << agent->getName() <<
"', closest node: '"
97 << closestNode->getName() <<
"', dist: " << dist;
98 float selectedDistanceThreshold =
armarx::Contains(agent->getName(),
"human",
true)
99 ? humanDistanceThreshold
101 if (dist <= selectedDistanceThreshold)
103 const CachedNodeInfo& cacheEntry = getCacheEntry(closestNode->getId());
105 for (
const auto& nodeRef : cacheEntry.agentAtNodeRefs)
107 ARMARX_DEBUG <<
"agentAt(" << agent->getName() <<
", " << nodeRef->entityName
109 result.push_back(PredicateInstance{predicateName, {agentRef, nodeRef},
true});
117AgentAtPredicateProvider::CachedNodeInfo
118AgentAtPredicateProvider::getCacheEntry(
const std::string& nodeId)
120 auto it = nodeInfoCache.find(nodeId);
121 if (it != nodeInfoCache.end())
126 CachedNodeInfo newEntry{nodeId, {}};
127 std::vector<std::pair<EntityRefBasePtr, bool>> agentAtCandidates;
129 bool allRobotLocations =
true;
130 for (
const GraphNodeBasePtr& nodeBase : graphNodes)
132 GraphNodePtr node = GraphNodePtr::dynamicCast(nodeBase);
133 if (node->isMetaEntity())
138 auto it = nodeParentsCache.find(node->getName());
139 if (it == nodeParentsCache.end())
142 nodeParentsCache.insert({node->getName(), node->getAllParentsAsStringList()}).first;
145 auto parents = it->second;
147 auto n = psr->getNearestRobotLocationNode(node);
148 ARMARX_DEBUG <<
"to '" << node->getName() <<
"', closest robot location is '"
149 <<
n->getName() <<
"'";
150 if (
n->getId() == nodeId)
153 bool isRobotLocation =
154 std::find(parents.cbegin(), parents.cend(),
"robotlocation") != parents.cend();
155 allRobotLocations &= isRobotLocation;
156 ARMARX_DEBUG <<
"for query node '" << graphSegment->getEntityRefById(nodeId)->entityName
157 <<
"', considering node '" << node->getName() <<
"'";
158 agentAtCandidates.push_back(
159 {graphSegment->getEntityRefById(node->getId()), isRobotLocation});
163 if (!agentAtCandidates.empty())
165 if (allRobotLocations)
167 ARMARX_DEBUG <<
"for query '" << nodeId <<
"', result is '"
168 << agentAtCandidates.front().first->entityName <<
"'";
169 newEntry.agentAtNodeRefs.push_back(agentAtCandidates.front().first);
173 for (
const auto& entry : agentAtCandidates)
177 ARMARX_DEBUG <<
"for query '" << nodeId <<
"', result is '"
178 << entry.first->entityName <<
"'";
179 newEntry.agentAtNodeRefs.push_back(entry.first);
186 nodeInfoCache.insert({nodeId, newEntry});
Property< PropertyType > getProperty(const std::string &name)
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
void onConnectWorldStateUpdater() override
void onInitWorldStateUpdater() override
AgentAtPredicateProvider()
PredicateInstanceList calcPredicates(const Ice::Current &) override
PredicateInfoList getPredicateInfos(const Ice::Current &c=Ice::emptyCurrent) override
std::string getDefaultName() const override
Retrieve default name of component.
#define ARMARX_INFO
The normal logging level.
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
bool Contains(const ContainerType &container, const ElementType &searchElement)
constexpr auto n() noexcept
IceInternal::Handle< GraphNode > GraphNodePtr
double norm(const Point &a)