A.R.G.U.S 2.1.0
Adaptive Real-Time Guardian for Unsafe Situations
Loading...
Searching...
No Matches
RobotInterlock.hpp
Go to the documentation of this file.
1
6#pragma once
7
8#include <atomic>
9#include <cstdint>
10
14enum class ControlEvent {
17};
18
22enum class InterlockState {
23 SAFE,
24 FROZEN,
25 FAULT
26};
27
41
46public:
47 virtual ~RobotHardware() = default;
48
53 virtual bool freezeMotion() noexcept = 0;
54
59 virtual bool enableMotion() noexcept = 0;
60};
61
66public:
71 explicit RobotInterlock(RobotHardware& hardware) noexcept;
72
78 void onControlEvent(
79 ControlEvent event,
81
86 void guardianHeartbeat(std::uint32_t tick) noexcept;
87
93 void watchdogCheck(
94 std::uint32_t now,
95 std::uint32_t max_allowed_delay) noexcept;
96
100 void operatorAcknowledge() noexcept;
101
106 bool motionAllowed() const noexcept;
107
112 FreezeReason freezeReason() const noexcept;
113
118 InterlockState state() const noexcept;
119
120private:
121 void freeze(FreezeReason reason) noexcept;
122 void attemptResume() noexcept;
123 void enterFault(FreezeReason reason) noexcept;
124
125 RobotHardware& hardware_;
126 std::atomic<InterlockState> state_;
127 std::atomic<bool> operator_ack_;
128 std::atomic<FreezeReason> freeze_reason_;
129 std::atomic<std::uint32_t> last_guardian_tick_;
130};
131
136public:
141 bool freezeMotion() noexcept override;
142
147 bool enableMotion() noexcept override;
148
149private:
150 static void GPIO_WritePin(int pin, bool value) noexcept;
151
152 static constexpr int ARM_ENABLE_PIN = 1;
153 static constexpr int CUTTER_ENABLE_PIN = 2;
154};
FreezeReason
Latched freeze/fault reason.
@ UNKNOWN_FAULT
Unspecified fault reason.
@ MARKER_LOST
Vision lost expected marker.
@ POSITION_ERROR
Position-related safety violation.
@ VISION_TIMEOUT
Vision heartbeat/timing failure.
@ DEPTH_EXCEEDED
Forbidden depth-layer/colour detected.
@ NONE
No freeze reason currently latched.
@ MARKER_OUT_OF_ROI
Marker/tool moved outside allowed ROI.
@ WATCHDOG_TIMEOUT
Guardian heartbeat timeout.
InterlockState
Interlock state machine output states.
@ FROZEN
Motion blocked due to safety freeze.
@ FAULT
Motion blocked due to hardware/path fault.
@ SAFE
Motion allowed.
ControlEvent
Control commands issued to the interlock.
@ ALLOW_MOTION
Attempt to allow motion when safety conditions permit.
@ FREEZE_NOW
Immediately freeze/deny motion.
Basic physical hardware adapter for interlock freeze/enable actions.
Abstract hardware contract used by RobotInterlock.
virtual ~RobotHardware()=default
virtual bool freezeMotion() noexcept=0
Immediately stop motion output.
virtual bool enableMotion() noexcept=0
Re-enable motion output after safe/ack conditions.
Thread-safe safety gate that owns interlock state transitions.