Skip to content

Shared fault-detection: threshold + status-bit + fault-code enum#486

Draft
mfaferek93 wants to merge 6 commits into
mainfrom
feat/shared-fault-detection
Draft

Shared fault-detection: threshold + status-bit + fault-code enum#486
mfaferek93 wants to merge 6 commits into
mainfrom
feat/shared-fault-detection

Conversation

@mfaferek93

Copy link
Copy Markdown
Collaborator

Closes #481

New header-only ros2_medkit_fault_detection evaluator with three composable modes (numeric threshold, status-word bit decode, fault-code enum) and an edge-detecting transition tracker. The OPC UA plugin is migrated onto it and gains status_bits / fault_enum node-map blocks (no threshold regression). Load-time global fault-code uniqueness prevents cross-entry flapping and extends the event_alarms collision check.

Tested: 56 unit tests incl. poller-level integration.

Introduce ros2_medkit_fault_detection, a header-only evaluator that maps a
raw value to faults via three composable modes: numeric threshold, status-word
bit decode, and fault-code enum. Migrate the OPC UA plugin's threshold path
onto it so it gains bit-decode and enum via new status_bits/fault_enum
node-map blocks, with raise/clear edge detection in the shared tracker.

Refs #481
The shared FaultTransitionTracker is keyed by fault_code alone, so two
detection entries emitting the same code flapped raise/clear every poll
cycle. Reject duplicate detection codes at load and extend the
event_alarms collision check to status_bits/fault_enum. Decode uint64_t
status registers and warn on bit >= 64; README notes unsigned status words.

Refs #481
Copilot AI review requested due to automatic review settings June 30, 2026 17:24
@mfaferek93 mfaferek93 marked this pull request as draft June 30, 2026 17:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a shared, protocol-agnostic fault-detection evaluator (ros2_medkit_fault_detection) supporting threshold, status-word bit decode, and fault-code enum mapping, and migrates the OPC UA plugin to use it via new node-map blocks (status_bits, fault_enum) while preserving existing threshold behavior.

Changes:

  • Added a new header-only ros2_medkit_fault_detection package with an evaluator + transition tracker and unit tests.
  • Updated OPC UA node-map loading and poller evaluation to emit shared fault-detection signals across threshold/status-bit/enum modes, including load-time fault-code collision validation.
  • Expanded OPC UA node-map tests and documentation to cover the new detection modes and collision rules.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/ros2_medkit_plugins/ros2_medkit_opcua/test/test_node_map.cpp Adds tests for parsing and poller-level behavior for threshold/status_bits/fault_enum detection modes and collision cases.
src/ros2_medkit_plugins/ros2_medkit_opcua/src/opcua_poller.cpp Replaces threshold-only alarm evaluation with shared fault-detection evaluation + edge tracking.
src/ros2_medkit_plugins/ros2_medkit_opcua/src/opcua_plugin.cpp Updates alarm callback plumbing to forward shared FaultSignal transitions with entity context.
src/ros2_medkit_plugins/ros2_medkit_opcua/src/opcua_client.cpp Adds uint64_t Variant handling for status-word/enum scenarios.
src/ros2_medkit_plugins/ros2_medkit_opcua/src/node_map.cpp Lowers node-map detection blocks into shared DetectionRule and enforces fault-code uniqueness / event collision checks.
src/ros2_medkit_plugins/ros2_medkit_opcua/README.md Documents new node-map blocks and configuration constraints for shared fault detection.
src/ros2_medkit_plugins/ros2_medkit_opcua/package.xml Adds dependency on ros2_medkit_fault_detection.
src/ros2_medkit_plugins/ros2_medkit_opcua/include/ros2_medkit_opcua/opcua_poller.hpp Updates alarm callback contract and replaces prior per-code state map with shared transition tracker.
src/ros2_medkit_plugins/ros2_medkit_opcua/include/ros2_medkit_opcua/opcua_plugin.hpp Updates fault bridge callback signature to accept shared FaultSignal.
src/ros2_medkit_plugins/ros2_medkit_opcua/include/ros2_medkit_opcua/node_map.hpp Adds shared DetectionRule storage and a detection_entries() accessor.
src/ros2_medkit_plugins/ros2_medkit_opcua/CMakeLists.txt Adds ros2_medkit_fault_detection as a build/test dependency.
src/ros2_medkit_fault_detection/test/test_fault_detection.cpp Adds unit tests covering threshold/status-bit/enum evaluation and transition tracking.
src/ros2_medkit_fault_detection/README.md Documents the shared evaluator API and intended usage by protocol plugins.
src/ros2_medkit_fault_detection/package.xml Declares the new package and its build/test dependencies.
src/ros2_medkit_fault_detection/include/ros2_medkit_fault_detection/fault_detection.hpp Implements the header-only evaluator, rule types, and FaultTransitionTracker.
src/ros2_medkit_fault_detection/CMakeLists.txt Defines the header-only INTERFACE target and test/lint wiring.

Comment thread src/ros2_medkit_plugins/ros2_medkit_opcua/src/opcua_client.cpp Outdated
Comment thread src/ros2_medkit_plugins/ros2_medkit_opcua/README.md
@mfaferek93 mfaferek93 self-assigned this Jun 30, 2026
Exclude ament_cmake_clang_format from ament_lint_auto so the explicit
ament_clang_format() hook is the only clang_format test (was registered
twice, failing configure), and fix its CONFIG_FILE path to the repo root.
Add <type_traits> include, make the uint64->int64 reinterpret well-defined
via memcpy under C++17, and correct the out-of-range bit README wording.

Refs #481
Extend test_alarm_server with writable StatusWord/FaultCode Int32
registers and a set command, and add poll-path bit-decode plus
enum-transition scenarios to run_alarm_tests.sh asserting raise/clear
via SOVD /api/v1/faults.

Refs #481
NaN/inf/uncoercible values now emit no signal, so a transition tracker
holds a standing fault instead of a bad read clearing it. Enum decode
adds a catch-all for unmapped non-ok codes, status-word decode an
optional width mask, and node-map malformed scalars warn not default.

Refs #481
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shared fault-detection: threshold + status-bit + fault-code enum

2 participants