31 onFreezeCallback(nullptr),
32 onClearFreezeCallback(nullptr),
33 onStateChangeCallback(nullptr) {
36 std::cout <<
"[INIT] Guardian State Machine initialized with freezeCount=" << freezeCount <<
", recoverCount=" << recoverCount << std::endl;
65 if (onFreezeCallback) {
70 logAction(
"FREEZE_NOW - Motion blocked");
75 motionBlocked =
false;
78 if (onClearFreezeCallback) {
79 onClearFreezeCallback();
83 logAction(
"CLEAR_FREEZE - Motion allowed");
116 currentState = newState;
119 executeAction(action);
122 if (onStateChangeCallback && oldState != newState) {
123 onStateChangeCallback(oldState, newState);
127 logTransition(oldState, newState);
143 <<
" | bad_count=" << badCount
144 <<
" good_count=" << goodCount << std::endl;
158void GuardianStateMachine::logAction(
const std::string& action) {
159 std::cout <<
"[ACTION] " << action << std::endl;
187 switch (currentState) {
197 if (badCount >= freezeCount) {
227 if (goodCount >= recoverCount) {
273 std::cout <<
"[OPERATOR] Acknowledgment received" << std::endl;
285 onFreezeCallback = callback;
289 onClearFreezeCallback = callback;
293 onStateChangeCallback = callback;
307 return motionBlocked;
311 return !motionBlocked;
334 default:
return "UNKNOWN";
355 std::cout <<
"\n=== GUARDIAN STATUS ===" << std::endl;
357 std::cout <<
"Motion: " << (motionBlocked ?
"BLOCKED" :
"ALLOWED") << std::endl;
358 std::cout <<
"Bad Count: " << badCount <<
"/" << freezeCount << std::endl;
359 std::cout <<
"Good Count: " << goodCount <<
"/" << recoverCount << std::endl;
360 std::cout <<
"=======================\n" << std::endl;
Finite-state safety supervisor used by ARGUS.
FrameStatus
Per-frame safety classification delivered by vision.
@ FRAME_GOOD
Frame classified as safe.
GuardianEvent
Events consumed by the FSM transition logic.
@ OPERATOR_ACK
Operator/manual acknowledge event.
@ FRAME_BAD
Unsafe-frame event.
@ FRAME_GOOD
Safe-frame 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.
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.
GuardianStateMachine(int fc=30, int rc=3)
Construct the FSM with frame-count hysteresis thresholds.
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.