A.R.G.U.S 2.1.0
Adaptive Real-Time Guardian for Unsafe Situations
Loading...
Searching...
No Matches
GuardianStateMachine.hpp
Go to the documentation of this file.
1
13#ifndef GUARDIAN_STATE_MACHINE_HPP
14#define GUARDIAN_STATE_MACHINE_HPP
15
16#include <functional>
17#include <string>
18
27
31enum class FrameStatus {
34};
35
39enum class GuardianEvent {
41 FRAME_BAD,
43};
44
48enum class GuardianAction {
49 NONE,
52};
53
64public:
70 GuardianStateMachine(int fc = 30, int rc = 3);
71
75 void processEvent(GuardianEvent event);
76
80 void processFrame(FrameStatus status);
81
86
90 void setOnFreezeCallback(std::function<void()> callback);
91
95 void setOnClearFreezeCallback(std::function<void()> callback);
96
101 std::function<void(GuardianState, GuardianState)> callback);
102
106 GuardianState getState() const;
107
111 bool isMotionBlocked() const;
112
116 bool isMotionAllowed() const;
117
121 int getBadCount() const;
122
126 int getGoodCount() const;
127
131 std::string stateToString(GuardianState state) const;
132
136 std::string getCurrentStateString() const;
137
141 void printStatus() const;
142
143private:
144 // State and counters
145 GuardianState currentState;
146 int badCount;
147 int goodCount;
148 int freezeCount;
149 int recoverCount;
150 bool motionBlocked;
151
152 // Integration callbacks
153 std::function<void()> onFreezeCallback;
154 std::function<void()> onClearFreezeCallback;
155 std::function<void(GuardianState, GuardianState)> onStateChangeCallback;
156
157 // Internal helpers
158 void executeAction(GuardianAction action);
159 void transitionTo(GuardianState newState, GuardianAction action);
160 void logTransition(GuardianState from, GuardianState to);
161 void logAction(const std::string& action);
162};
163
164#endif // GUARDIAN_STATE_MACHINE_HPP
FrameStatus
Per-frame safety classification delivered by vision.
@ FRAME_BAD
Frame classified as unsafe.
@ FRAME_GOOD
Frame classified as safe.
GuardianEvent
Events consumed by the FSM transition logic.
@ OPERATOR_ACK
Operator/manual acknowledge event.
GuardianState
Internal FSM states.
@ SAFE_MONITORING
Normal operation; monitoring incoming frame status.
@ RESET_PENDING
Operator acknowledged; waiting for stable good frames.
@ FROZEN_UNSAFE
Unsafe condition latched; motion remains blocked.
GuardianAction
Side effects emitted by transitions.
@ CLEAR_FREEZE
Clear freeze and allow motion.
@ NONE
No hardware action required.
@ FREEZE_NOW
Immediate freeze/block action.
Event-driven safety state machine with callback hooks.
std::string getCurrentStateString() const
Return readable string for current state.
void operatorAcknowledge()
Inject an operator acknowledge event.
bool isMotionAllowed() const
True when motion is currently allowed.
int getBadCount() const
Get current consecutive bad-frame count.
void setOnStateChangeCallback(std::function< void(GuardianState, GuardianState)> callback)
Register callback fired on state transitions.
void processEvent(GuardianEvent event)
Process an explicit FSM event.
void setOnClearFreezeCallback(std::function< void()> callback)
Register callback fired when freeze is cleared.
GuardianState getState() const
Get current FSM state.
std::string stateToString(GuardianState state) const
Convert a state enum to a readable string.
void setOnFreezeCallback(std::function< void()> callback)
Register callback fired when freeze is commanded.
void processFrame(FrameStatus status)
Convenience wrapper that maps frame status to an FSM event.
void printStatus() const
Print a status snapshot for debugging.
int getGoodCount() const
Get current consecutive good-frame count.
bool isMotionBlocked() const
True when guardian currently blocks motion.