Skip to content

feat(opcua): address node map entries by browse path - #780

Closed
mfaferek93 wants to merge 1 commit into
mainfrom
feat/opcua-node-by-browse-path
Closed

mfaferek93 wants to merge 1 commit into
mainfrom
feat/opcua-node-by-browse-path

Conversation

@mfaferek93

Copy link
Copy Markdown
Collaborator

What

A node map entry can give a browse_path instead of a node_id:

namespaces:
  di: "http://opcfoundation.org/UA/DI/"
  rob: "http://opcfoundation.org/UA/Robotics/"
nodes:
  - browse_path: "di:DeviceSet/*/rob:SafetyStates/*/di:ParameterSet/rob:EmergencyStop"
    entity_id: robot_safety
    data_name: emergency_stop
    data_type: bool
    alarm: {fault_code: ROBOT_EMERGENCY_STOP, severity: ERROR, threshold: 0.5, above_threshold: true}

Why

Companion specifications (OPC 40010 Robotics, Machinery, PackML, ...) fix the
BrowseNames and the namespace URI of their nodes. They do not fix NodeIds, and
the namespace index is the server's choice, which can change when it restarts.
A map written against one server's NodeIds only fits that server. A browse path
written against the specification fits every server that implements it.

How

  • Steps from the Objects folder: <alias>:<BrowseName> with aliases from a new
    top-level namespaces: map, <index>:<BrowseName>, or * for any child (an
    instance the vendor names). The last step must be a Variable.
  • An entry with a browse path waits outside entries() until a session
    resolves it, so the poller never subscribes a null NodeId. It is resolved
    after connect, before auto_browse and before the subscribe, and again from
    on_connected on every new session: a path that was missing is retried, and
    a node that moved (namespaces renumbered) is re-keyed, publisher included.
  • Under *, children are tried in browse order with backtracking, first full
    match wins, capped at 2000 children per path.
  • Explicit wins: a resolved entry replaces an auto_browse entry for the same
    node. Fault-code uniqueness covers both kinds of entry at load.
  • Read-only: Browse and a NamespaceArray read only.

Tests

  • New test_browse_path (13 cases): parsing and its refusals, wildcard walk
    with backtracking, namespace matched by URI and not by index, last step must
    be a Variable, node budget, waiting entries, replacing an auto-browsed entry,
    following a node that moved on the next session, fault-code uniqueness, one
    address per entry.
  • Full ros2_medkit_opcua ctest, read-only build: 28/28.
  • End to end against an asyncua server built on the DI 1.04 + Robotics 1.01.2
    nodesets: entries resolve after a failed first connect, the server restarting
    with two more namespaces in front is followed to the new NodeIds, and a link
    lost and restored keeps the faults. A gateway without this change skips the
    same entries.

Not in this PR

  • auto_alarms folds the SourceNode NodeId string, index included, into the
    derived fault code, so the same condition gets another code after the
    namespaces are renumbered.
  • auto_browse entries from the previous session stay after a renumbering until
    the gateway restarts.

A companion specification fixes BrowseNames and namespace URIs, not NodeIds or
namespace indices. A node map entry may now give a browse_path from the Objects
folder (namespace aliases, * for a vendor-named instance) instead of a node_id.
It is resolved on every new session, so a server that renumbers its namespaces
after a restart is followed to the new NodeIds.
Copilot AI balanced review requested due to automatic review settings November 9, 2026 12:08

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

Critical reconnect and namespace-remapping defects can direct reads and writes to unrelated OPC UA variables, producing incorrect telemetry and fault detection.

5 open issues
What changed in this PR

Adds browse-path addressing to the OPC-UA plugin, allowing node maps to use specification-defined names and namespace URIs instead of server-specific NodeIds.

Changes:

  • Parses namespace aliases and browse paths, including wildcard traversal.
  • Resolves mappings before subscriptions and revisits them on reconnect, with publisher re-keying for moved nodes.
  • Adds focused unit tests and documents the configuration format.
File Description
src/​ros2_medkit_plugins/​ros2_medkit_opcua/​test/​test_browse_path.cpp Tests parsing, traversal, pending entries, and remapping.
src/​ros2_medkit_plugins/​ros2_medkit_opcua/​src/​opcua_plugin.cpp Integrates session resolution and publisher updates.
src/​ros2_medkit_plugins/​ros2_medkit_opcua/​src/​opcua_client.cpp Implements namespace URI lookup.
src/​ros2_medkit_plugins/​ros2_medkit_opcua/​src/​node_map.cpp Parses and reconciles browse-addressed entries.
src/​ros2_medkit_plugins/​ros2_medkit_opcua/​src/​address_space_browser.cpp Implements bounded traversal with backtracking.
src/​ros2_medkit_plugins/​ros2_medkit_opcua/​README.md Documents browse-path configuration and behavior.
src/​ros2_medkit_plugins/​ros2_medkit_opcua/​include/​ros2_medkit_opcua/​opcua_plugin.hpp Declares the session-resolution helper.
src/​ros2_medkit_plugins/​ros2_medkit_opcua/​include/​ros2_medkit_opcua/​opcua_client.hpp Exposes namespace lookup.
src/​ros2_medkit_plugins/​ros2_medkit_opcua/​include/​ros2_medkit_opcua/​node_map.hpp Defines browse-path data and resolution interfaces.
src/​ros2_medkit_plugins/​ros2_medkit_opcua/​include/​ros2_medkit_opcua/​address_space_browser.hpp Exposes path resolution and namespace-aware browsing.
src/​ros2_medkit_plugins/​ros2_medkit_opcua/​CMakeLists.txt Registers the browse-path test target.

Review effort: Balanced

Comment on lines +1456 to +1458
auto node_id = resolve(entry);
if (!node_id || node_id->toString() == entry.node_id_str) {
continue;
Comment on lines +1461 to +1465
if (node_id_index_.count(moved_to) > 0) {
RCLCPP_WARN(rclcpp::get_logger("opcua.node_map"),
"browse_path '%s' now resolves to %s, which another entry maps - keeping %s",
entry.browse_path_str.c_str(), moved_to.c_str(), entry.node_id_str.c_str());
continue;
Comment on lines +1933 to +1934
for (const auto & entry : node_map_.entries()) {
walk(entry);
Comment on lines +1415 to +1416
const auto index = std::stoul(prefix);
if (prefix.size() > 5 || index > 65535) {
Comment on lines +1973 to +1974
if (resolution.joined > 0) {
create_value_publishers();
@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