25#include <armarx/view_selection/gaze_targets/aron/GazeTarget.aron.generated.h>
26#include <armarx/view_selection/gaze_targets/aron/GazeTargetStatus.aron.generated.h>
34 std::string providerSegmentName) :
35 memoryNameSystem(mns),
36 providerSegmentName(providerSegmentName),
37 coreSegmentID(
memory::constants::ViewMemoryName,
38 memory::constants::GazeTargetCoreSegmentName),
39 statusCoreSegmentID(
memory::constants::ViewMemoryName,
40 memory::constants::GazeTargetStatusCoreSegmentName)
50 ARMARX_IMPORTANT <<
"ViewSelection: Waiting for memory '" << coreSegmentID <<
"' ...";
53 memoryWriter = memoryNameSystem.useWriter(coreSegmentID);
54 memoryReader = memoryNameSystem.useReader(coreSegmentID);
55 ARMARX_IMPORTANT <<
"ViewSelection: Connected to memory '" << coreSegmentID <<
"'";
63 statusHandler = [&]() -> std::unique_ptr<MemoryStatusHandlerBase>
65 switch (statusDelivery)
68 return std::make_unique<MemorySubscriber>(providerSegmentName,
71 return std::make_unique<MemoryPolling>(providerSegmentName, memoryNameSystem);
77 waiter.emplace(*statusHandler);
80 std::optional<gaze_targets::GazeTarget>
89 const auto* entityInstance = queryResult.memory.findLatestInstance(entityId);
91 if (entityInstance !=
nullptr)
94 gaze_targets::arondto::GazeTarget::FromAron(entityInstance->data()));
106 if (not memoryWriter)
108 ARMARX_WARNING <<
"Memory writer is null. Did you forget to call "
109 "ViewSelection::connect() in onConnectComponent()?";
112 if (target.name ==
"")
114 ARMARX_WARNING <<
"The target name is empty. Did you forget to initialize it?";
118 gaze_targets::arondto::GazeTarget dto;
123 coreSegmentID.withProviderSegmentName(providerSegmentName).withEntityName(dto.name);
125 update.instancesData = {dto.toAron()};
139 std::optional<gaze_targets::GazeTargetStatus>
148 const auto* entityInstance = queryResult.memory.findLatestInstance(entityId);
150 if (entityInstance ==
nullptr)
152 ARMARX_VERBOSE <<
"No gaze target status found with id:" << entityId;
157 fromAron(gaze_targets::arondto::GazeTargetStatus::FromAron(entityInstance->data()),
status);
165 const std::function<
bool()>& shouldAbort)
167 if (not waiter.has_value())
170 <<
": ViewSelection::connect() was not called.";
176 waiter->expect(target.name);
182 waiter->forget(target.name);
187 waiter->bind(target.name, gazeTargetID);
189 return waiter->wait(target.name, timeout, shouldAbort);
207 for (
const auto& target :
targets)
static DateTime Now()
Current time on the virtual clock.
static Duration Seconds(std::int64_t seconds)
Constructs a duration in seconds.
MemoryID withProviderSegmentName(const std::string &name) const
bool hasEntityName() const
MemoryID withEntityName(const std::string &name) const
The memory name system (MNS) client.
The query::Builder class provides a fluent-style specification of hierarchical queries.
void latestEntitySnapshot(const MemoryID &entityID)
QueryInput buildQueryInput() const
Indicates that a query to the Memory Name System failed.
armarx::armem::MemoryID commitGazeTarget(const gaze_targets::GazeTarget &target)
std::optional< gaze_targets::GazeTargetStatus > readGazeTargetStatus(const std::string &name)
The lifecycle of the named target, as far as the scheduler has published it.
void commitGazeTargets(const std::vector< gaze_targets::GazeTarget > &targets)
void releaseGazeTarget(const gaze_targets::GazeTarget &target)
Give up a target: lowest priority, no duration, not kept in the queue.
std::optional< gaze_targets::GazeTarget > readGazeTarget(const std::string &name)
ViewSelection(armarx::armem::client::MemoryNameSystem &mns, std::string providerSegmentName)
void connect(StatusDelivery statusDelivery=StatusDelivery::Subscription)
GazeTargetWaiter::Result commitGazeTargetAndWait(const gaze_targets::GazeTarget &target, const armarx::Duration &timeout, const std::function< bool()> &shouldAbort={})
Commit a gaze target and block until the robot's gaze is fixed on it.
Business Object (BO) class of GazeTargetStatus: the lifecycle of one gaze target request,...
Business Object (BO) class of GazeTarget.
armarx::core::time::Duration duration
The Priority of a GazeTarget.
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
#define ARMARX_VERBOSE
The logging level for verbose information.
void fromAron(const T &dto, T &bo)
StatusDelivery
How gaze target status updates reach this client.
@ Subscription
Pushed by the memory.
@ Polling
Queried every 100 ms. Works anywhere, at the cost of up to one poll period of latency.
@ TaskDriven
Task-Driven attention has highest priority.
This file is part of ArmarX.
void toAron(arondto::PackagePath &dto, const PackageFileLocation &bo)
void fromAron(const arondto::PackagePath &dto, PackageFileLocation &bo)
Result of an EntityUpdate.
An update of an entity for a specific point in time.