status_reporting.cpp
Go to the documentation of this file.
1#include "status_reporting.h"
2
3#include <mutex>
4#include <string>
5
8
10
12{
13
14 void
15 StatusReporter::update(const std::int64_t targetId,
16 const GazeResidual& residual,
17 const bool targetReachable)
18 {
19 this->angularError.store(residual.angularError);
20 this->lateralError.store(residual.lateralError);
21 this->targetReachable.store(targetReachable);
22
23 // Written last: the scheduler drops reports whose id it does not recognize, so an id must
24 // never be paired with a residual older than itself.
25 this->targetId.store(targetId);
26 }
27
28 void
29 StatusReporter::setTarget(const std::int64_t targetId, const std::string& targetName)
30 {
31 const std::scoped_lock lock(targetNameMutex);
32
33 this->targetNameId = targetId;
34 this->targetName = targetName;
35 }
36
37 void
38 StatusReporter::report(const GazeControllerStatusListenerPrx& topic)
39 {
40 // Ice proxy handles do not compare against nullptr; they convert to bool.
41 if (not topic)
42 {
43 return;
44 }
45
47
48 // onPublish runs at the RobotUnit's publish rate, far above what the scheduler needs to
49 // debounce a decision.
50 if (lastReported.isValid() and
52 {
53 return;
54 }
55
56 lastReported = now;
57
59 status.targetId = targetId.load();
60 status.angularError = angularError.load();
61 status.lateralError = lateralError.load();
62 status.targetReachable = targetReachable.load();
63 armarx::core::time::toIce(status.timestamp, now);
64
65 {
66 const std::scoped_lock lock(targetNameMutex);
67
68 // Only if the name belongs to the target the residual was measured against.
69 status.targetName = targetNameId == status.targetId ? targetName : std::string();
70 }
71
72 topic->reportGazeControllerStatus(status);
73 }
74
75} // namespace armarx::view_selection::gaze_controller
static DateTime Now()
Current time on the virtual clock.
Definition Clock.cpp:93
Represents a point in time.
Definition DateTime.h:25
void report(const GazeControllerStatusListenerPrx &topic)
Publishes the current residual, rate limited.
void update(std::int64_t targetId, const GazeResidual &residual, bool targetReachable)
Called from the control side, at whatever rate it computes the residual.
void setTarget(std::int64_t targetId, const std::string &targetName)
Called from updateConfig(), so a report can name the target it is about.
void toIce(dto::ClockType::ClockTypeEnum &dto, const ClockType &bo)
const armarx::Duration GazeControllerStatusPublishInterval
Rate limit for those reports.
Definition constants.h:14
Periodic report of the low-level gaze controller's residual.
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].