MemoryStatusPublisher.cpp
Go to the documentation of this file.
2
3#include <mutex>
4#include <string>
5#include <utility>
6
9
11
13{
14
21
22 void
23 MemoryStatusPublisher::publish(
24 const armem::MemoryID& gazeTargetID,
25 const std::function<void(gaze_targets::GazeTargetStatus&)>& mutate)
26 {
28
29 {
30 const std::scoped_lock lock(mutex);
31
32 gaze_targets::GazeTargetStatus& lifecycle = lifecycles[gazeTargetID];
33 lifecycle.gazeTargetID = gazeTargetID;
34 mutate(lifecycle);
35
36 published = lifecycle;
37
38 if (lifecycle.isTerminal())
39 {
40 lifecycles.erase(gazeTargetID);
41 }
42 }
43
44 writer->store(published);
45 }
46
47 void
49 const armarx::DateTime& creationTimestamp)
50 {
51 publish(gazeTargetID,
52 [&](gaze_targets::GazeTargetStatus& lifecycle)
53 {
55 lifecycle.creationTimestamp = creationTimestamp;
56 });
57 }
58
59 void
61 {
62 publish(gazeTargetID,
63 [&](gaze_targets::GazeTargetStatus& lifecycle)
64 {
67 });
68 }
69
70 void
72 const gaze_controller::GazeResidual& residual)
73 {
74 publish(gazeTargetID,
75 [&](gaze_targets::GazeTargetStatus& lifecycle)
76 {
79 lifecycle.angularError = residual.angularError;
80 lifecycle.lateralError = residual.lateralError;
81 });
82 }
83
84 void
85 MemoryStatusPublisher::preempted(const armem::MemoryID& gazeTargetID, const std::string& reason)
86 {
87 publish(gazeTargetID,
88 [&](gaze_targets::GazeTargetStatus& lifecycle)
89 {
92 lifecycle.message = reason;
93 });
94 }
95
96 void
97 MemoryStatusPublisher::released(const armem::MemoryID& gazeTargetID, const std::string& reason)
98 {
99 publish(gazeTargetID,
100 [&](gaze_targets::GazeTargetStatus& lifecycle)
101 {
104 lifecycle.message = reason;
105 });
106 }
107
108 void
109 MemoryStatusPublisher::aborted(const armem::MemoryID& gazeTargetID, const std::string& reason)
110 {
111 publish(gazeTargetID,
112 [&](gaze_targets::GazeTargetStatus& lifecycle)
113 {
116 lifecycle.message = reason;
117 });
118 }
119
120 bool
122 {
123 const std::scoped_lock lock(mutex);
124
125 const auto it = lifecycles.find(gazeTargetID);
126
127 return it != lifecycles.end() and it->second.wasReached();
128 }
129
130} // namespace armarx::view_selection::gaze_scheduler
static DateTime Now()
Current time on the virtual clock.
Definition Clock.cpp:93
Represents a point in time.
Definition DateTime.h:25
void aborted(const armem::MemoryID &gazeTargetID, const std::string &reason) override
Left the queue without ever being reached. Terminal, and a failure.
void preempted(const armem::MemoryID &gazeTargetID, const std::string &reason) override
Lost the active slot but stays in the queue. Not terminal.
void requested(const armem::MemoryID &gazeTargetID, const armarx::DateTime &creationTimestamp) override
Admitted to the scheduler's queue.
void scheduled(const armem::MemoryID &gazeTargetID) override
Submitted to the low-level controller.
void released(const armem::MemoryID &gazeTargetID, const std::string &reason) override
Left the queue having been reached. Terminal, and a success for whoever asked.
void reached(const armem::MemoryID &gazeTargetID, const gaze_controller::GazeResidual &residual) override
The gaze settled on the target.
bool wasReached(const armem::MemoryID &gazeTargetID) const override
Whether this target was reached at any point.
MemoryStatusPublisher(std::experimental::observer_ptr< memory::client::status::Writer > writer)
Business Object (BO) class of GazeTargetStatus: the lifecycle of one gaze target request,...
bool isTerminal() const
Whether the target has left the scheduler's queue for good.
std::string message
Reason, for the terminal states. Empty otherwise.
float lateralError
Lateral miss distance at target range at the transition [mm].
armarx::armem::MemoryID gazeTargetID
The gaze target request snapshot this status refers to.
armarx::DateTime preemptedTimestamp
Most recent preemption, if any.
float angularError
Angle between the gaze ray and the direction to the target at the transition [rad].
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
@ Scheduled
submitted to the low-level controller
@ Aborted
left the queue without ever being reached, or the target is out of reach
@ Reached
the gaze residual settled below the threshold
@ Released
left the queue having been reached (duration elapsed, or superseded afterwards)
@ Preempted
lost the active slot but stays in the queue and may be scheduled again
@ Requested
admitted to the scheduler's queue, waiting for scheduling
How far the gaze currently is from a target.
float lateralError
Lateral miss distance at target range [mm].
float angularError
Angle between the gaze ray and the direction to the target [rad].