GazeTargetReachedMonitor.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <mutex>
5
6#include <VirtualRobot/MathTools.h>
7
9
11{
12
13 /**
14 * @brief Thresholds deciding when the gaze counts as fixed on the active target.
15 *
16 * These live on the scheduler rather than in the controller config so they can be retuned
17 * without redeploying the RobotUnit, and so they mean the same thing for every controller
18 * variant (see gaze_controller::computeGazeResidual).
19 */
21 {
22 /// Angular gaze error below which the target counts as fixated [rad].
23 float angularTh = VirtualRobot::MathTools::deg2rad(2.F);
24
25 /// Lateral miss distance below which the target counts as fixated [mm].
26 float lateralTh = 30.F;
27
28 /// Consecutive controller reports required before a decision is taken. At the controller's
29 /// 10 Hz report rate, 5 is half a second of steady gaze.
30 int filterCount = 5;
31 };
32
33 /**
34 * @brief Debounces the low-level controller's residual into a "reached" / "unreachable"
35 * decision for one control target.
36 *
37 * Modelled on navigation's server::GoalReachedMonitor. Reports about any other target are
38 * dropped, so a residual still in flight for a superseded target can never be misattributed.
39 *
40 * Thread-safe: reports arrive on the topic listener thread, the verdict is read by the
41 * scheduler's periodic task.
42 */
44 {
45 public:
46 explicit GazeTargetReachedMonitor(const GazeReachedConfig& config);
47
48 /// Begin monitoring another control target, dropping all state about the previous one.
49 void reset(std::int64_t targetId);
50
51 /// Feed one controller report. Reports about a different target are ignored.
52 void update(std::int64_t targetId,
54 bool targetReachable);
55
56 /// Whether the gaze has been on target for `filterCount` consecutive reports.
57 bool reached() const;
58
59 /// Whether the controller could not reach the target for `filterCount` consecutive reports.
60 bool unreachable() const;
61
62 /// Residual of the most recently accepted report.
64
65 private:
66 const GazeReachedConfig config;
67
68 mutable std::mutex mutex;
69
70 std::int64_t activeTargetId = -1;
71
72 int reachedCount = 0;
73
74 int unreachableCount = 0;
75
76 gaze_controller::GazeResidual latestResidual;
77 };
78
79} // namespace armarx::view_selection::gaze_scheduler
bool unreachable() const
Whether the controller could not reach the target for filterCount consecutive reports.
bool reached() const
Whether the gaze has been on target for filterCount consecutive reports.
void update(std::int64_t targetId, const gaze_controller::GazeResidual &residual, bool targetReachable)
Feed one controller report. Reports about a different target are ignored.
void reset(std::int64_t targetId)
Begin monitoring another control target, dropping all state about the previous one.
gaze_controller::GazeResidual residual() const
Residual of the most recently accepted report.
How far the gaze currently is from a target.
Thresholds deciding when the gaze counts as fixed on the active target.
float lateralTh
Lateral miss distance below which the target counts as fixated [mm].
int filterCount
Consecutive controller reports required before a decision is taken.
float angularTh
Angular gaze error below which the target counts as fixated [rad].