Skip to content

feat(opcua): state registers with several healthy values and gates - #781

Closed
mfaferek93 wants to merge 2 commits into
mainfrom
feat/opcua-enum-state-gates
Closed

mfaferek93 wants to merge 2 commits into
mainfrom
feat/opcua-enum-state-gates

Conversation

@mfaferek93

Copy link
Copy Markdown
Collaborator

Summary

  • fault_enum.ok_values: more healthy values beside ok_value. A state machine register (ISA-TR88 state numbers, Machinery item state) has many healthy states; without the list each of them raises the catch-all.
  • inhibit_when / only_when on any detection entry, gated on another polled point of the map:
    • inhibit_when: no fault is raised while the gate point reads one of values (changeover, setup, maintenance mode). A fault raised before keeps its state until its own value clears it.
    • only_when: the rule is evaluated only while the gate matches, otherwise its faults clear (a stop reason that stays latched after the machine runs again).
    • The load fails when the gate names a point that is not in nodes:, names the entry itself, or values is not a non-empty integer list. An unread gate point gates nothing.
  • Fix: a read of an array value terminated the gateway. variant_to_value handles scalars only and getScalarCopy throws BadVariantAccess on an array of a matching type, which no read path caught. auto_browse against any server with array variables (seen on the umati sample server) disabled the plugin in set_context or terminated the process on a later walk. A non-scalar value is now a bad read, so auto_browse skips the node and polling or a subscription drops it.

Tests

  • test_fault_detection: OkValuesAreHealthyStates.
  • test_node_map: parsing of ok_values and both gates, rejection of a gate on a missing point, on itself, and malformed lists.
  • New integration test test_opcua_state_gates (real gateway, fault manager and fixture server): healthy states, aborted in production raises, a raised fault survives an inhibiting mode, aborted during an inhibiting mode is not raised and is raised once the mode ends, catch-all, only_when ignores a latched reason while running and raises it while stopped, planned reason raises nothing. Against the plugin without this change it fails 7 of its expectations.
  • Fixture server gets three Int32 registers and a read-only Int32 array (Recipe.Steps). Without the array fix, test_opcua_read_only and test_opcua_state_gates fail with the plugin disabled (Plugin 'opcua' threw during set_context(): Variant is not a scalar); with it both pass.
  • Local (jazzy, arm64, read-only build): colcon test for ros2_medkit_fault_detection and ros2_medkit_opcua, 568 tests, 0 failures, ctest 28/28 for the plugin.

fault_enum takes ok_values, so a state machine register with many healthy
states does not raise its catch-all. A detection entry can be gated on
another polled point: inhibit_when keeps a fault from being raised while
that point reads one of the listed values, only_when evaluates the rule
only then.
The value conversion only handles scalars, and getScalarCopy throws
BadVariantAccess on an array of a matching type, which no read path
caught. auto_browse on a server with array variables (recipe tables,
alarm lists) took the gateway down. A non-scalar read is now not good,
so auto_browse skips the node and polling or a subscription drops it.
Copilot AI balanced review requested due to automatic review settings November 9, 2026 12:50

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.

🟡 Changes recommended

Unresolved gate lookup and fault-clearing issues can silently disable a valid gate or leave a fault active after its only_when condition stops matching.

2 open issues
What changed in this PR

Adds state-aware fault detection to the OPC UA plugin, building on the shared fault-detection library, and prevents array reads from being treated as scalars.

Changes:

  • Supports multiple healthy enum values and cross-point gates for suppressing or clearing faults.
  • Rejects non-scalar OPC UA values in reads and subscription callbacks.
  • Adds configuration validation, documentation, and unit and integration coverage.
File Description
src/​ros2_medkit_plugins/​ros2_medkit_opcua/​test/​test_node_map.cpp Tests healthy-value lists and gate validation.
src/​ros2_medkit_plugins/​ros2_medkit_opcua/​test/​integration/​test_opcua_state_gates.test.py Exercises fault transitions and array skipping end to end.
src/​ros2_medkit_plugins/​ros2_medkit_opcua/​test/​fixtures/​test_alarm_server/​test_alarm_server.cpp Adds state registers and a read-only array fixture.
src/​ros2_medkit_plugins/​ros2_medkit_opcua/​src/​opcua_poller.cpp Applies gates to evaluated fault signals.
src/​ros2_medkit_plugins/​ros2_medkit_opcua/​src/​opcua_client.cpp Guards scalar conversion against array values.
src/​ros2_medkit_plugins/​ros2_medkit_opcua/​src/​node_map.cpp Parses and validates healthy-value lists and gates.
src/​ros2_medkit_plugins/​ros2_medkit_opcua/​README.md Documents state-register configuration and gate behavior.
src/​ros2_medkit_plugins/​ros2_medkit_opcua/​include/​ros2_medkit_opcua/​node_map.hpp Defines gate configuration on mapped points.
src/​ros2_medkit_plugins/​ros2_medkit_opcua/​CMakeLists.txt Registers and installs the new integration test.
src/​ros2_medkit_fault_detection/​test/​test_fault_detection.cpp Tests multiple healthy enum states.
src/​ros2_medkit_fault_detection/​include/​ros2_medkit_fault_detection/​fault_detection.hpp Extends shared enum evaluation with ok_values.

Review effort: Balanced

if (!gate) {
return std::nullopt;
}
auto g = snapshot_.values.find(gate->node_id_str);
Comment on lines +1495 to +1497
for (auto & s : signals) {
if (only.has_value() && !*only) {
s.active = false;
@mfaferek93

Copy link
Copy Markdown
Collaborator Author

Superseded by #783, which carries this change as its own commit.

@mfaferek93 mfaferek93 closed this Nov 9, 2026
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.

2 participants