mrs_lib
Various reusable classes, functions and utilities for use in MRS projects
Loading...
Searching...
No Matches
mrs_lib::errorgraph::Errorgraph Class Reference

A directed graph representing error dependencies between ROS nodes and topics. More...

#include <errorgraph.h>

Classes

struct  error_t
 Represents a single error reported by a node. More...
struct  node_info_t
 Public view of a node element, returned by query methods. More...
struct  topic_info_t
 Public view of a topic element, returned by query methods. More...
struct  element_t
 Internal representation of a node or topic in the error dependency graph. More...

Public Types

using element_info_t = std::variant<node_info_t, topic_info_t>
 Type-safe variant representing either a node or topic element info.

Public Member Functions

 Errorgraph (rclcpp::Clock::SharedPtr clock)
 Construct an empty Errorgraph.
void write_dot (std::ostream &os)
 Write the graph in Graphviz DOT format.
std::vector< element_info_t > find_dependency_roots (const node_id_t &node_id, bool *loop_detected_out=nullptr)
 Find the root-cause elements blocking the given node.
std::vector< element_info_t > find_error_roots ()
 Find all root-cause elements across the entire graph.
std::vector< element_info_t > find_roots ()
 Find all root elements (elements that are not exclusively waiting for something else).
std::vector< element_info_t > find_leaves ()
 Find all leaf elements (elements that nothing else in the graph depends on).
std::optional< element_info_t > find_element (const std::string &topic_name)
 Find an element by topic name.
std::optional< element_info_t > find_element (const node_id_t &node_id)
 Find an element by node ID.
element_info_t add_element_from_msg (const errorgraph_element_msg_t &msg)
 Add or update an element from a received ROS message.

Detailed Description

A directed graph representing error dependencies between ROS nodes and topics.

The Errorgraph aggregates error reports from nodes in the system (published as errorgraph_element_msg_t messages) and builds a dependency graph. Nodes report which other nodes or topics they are waiting for, allowing the graph to trace error propagation and identify root causes.

Typical usage:

  1. Subscribe to error messages from all nodes in the system.
  2. Feed each received message to add_element_from_msg().
  3. Query the graph using find_error_roots(), find_dependency_roots(), etc.
  4. Optionally export the graph in DOT format using write_dot() for visualization.
Note
Return types: Query methods return element_info_t (a std::variant<node_info_t, topic_info_t>) which contains a copy of the element's data. Use std::get<node_info_t>(element_info) or std::get<topic_info_t>(element_info) to access the specific type.
See also
ErrorPublisher for the publishing side that nodes use to report errors.
ErroGraphViewer at https://github.com/ctu-mrs/mrs_errorgraph_viewer/blob/ros2/src/errorgraph_viewer.cpp for an example of using the Errorgraph and visualizing it.

Constructor & Destructor Documentation

◆ Errorgraph()

mrs_lib::errorgraph::Errorgraph::Errorgraph ( rclcpp::Clock::SharedPtr clock)
inlineexplicit

Construct an empty Errorgraph.

Parameters
clockClock used for timestamping and staleness detection.

Member Function Documentation

◆ add_element_from_msg()

Errorgraph::element_info_t mrs_lib::errorgraph::Errorgraph::add_element_from_msg ( const errorgraph_element_msg_t & msg)

Add or update an element from a received ROS message.

If an element with the same source node already exists, its errors and timestamp are updated. Otherwise, a new element is created and any dependency edges implied by the errors are added to the graph.

Parameters
msgThe received ErrorgraphElement message.
Returns
A copy of the added or updated element info.

◆ find_dependency_roots()

std::vector< Errorgraph::element_info_t > mrs_lib::errorgraph::Errorgraph::find_dependency_roots ( const node_id_t & node_id,
bool * loop_detected_out = nullptr )

Find the root-cause elements blocking the given node.

Traverses the dependency graph from the specified node, following "waiting for" edges. An element is returned as a root cause if it doesn't depend on anything else, or if it carries a genuine error of its own – even while it also depends on something else, in which case traversal continues past it to find further root causes down the chain too. If a genuine dependency loop is encountered (see DFS()), every element that is a member of that loop is returned as well, not just one representative – so a 3-element cycle with no genuine error anywhere in it yields 3 root-cause entries, one per member.

Parameters
node_idThe node to trace dependencies for.
loop_detected_outIf non-null, set to true when a cycle is detected.
Returns
Copies of root-cause element info as type-safe variants.

◆ find_element() [1/2]

std::optional< Errorgraph::element_info_t > mrs_lib::errorgraph::Errorgraph::find_element ( const node_id_t & node_id)

Find an element by node ID.

Parameters
node_idThe node ID to search for.
Returns
A copy of the element info, or std::nullopt if not found.

◆ find_element() [2/2]

std::optional< Errorgraph::element_info_t > mrs_lib::errorgraph::Errorgraph::find_element ( const std::string & topic_name)

Find an element by topic name.

Parameters
topic_nameThe topic name to search for.
Returns
A copy of the element info, or std::nullopt if not found.

◆ find_error_roots()

std::vector< Errorgraph::element_info_t > mrs_lib::errorgraph::Errorgraph::find_error_roots ( )

Find all root-cause elements across the entire graph.

An element is excluded only if every one of its non-"no error" entries is a "waiting for" dependency (see element_t::is_only_waiting_for()); an element with at least one genuine error, or with no dependency at all, is always included. Unlike find_roots(), a healthy (no-error, actively-reporting) element with no other element waiting on it is also excluded, to avoid reporting uninteresting leaves as "root causes". As with find_roots(), every element that is a member of a genuine dependency loop (no genuine error anywhere in the loop) is included too, consistent with find_dependency_roots() – see DFS().

Returns
Copies of elements that have errors and are not blocked by other elements.

◆ find_leaves()

std::vector< Errorgraph::element_info_t > mrs_lib::errorgraph::Errorgraph::find_leaves ( )

Find all leaf elements (elements that nothing else in the graph depends on).

An element is a leaf if no other element is waiting for it, i.e. its parents list is empty.

Returns
Copies of leaf element info as type-safe variants.

◆ find_roots()

std::vector< Errorgraph::element_info_t > mrs_lib::errorgraph::Errorgraph::find_roots ( )

Find all root elements (elements that are not exclusively waiting for something else).

An element is excluded only if every one of its non-"no error" entries is a "waiting for" dependency (see element_t::is_only_waiting_for()); an element with at least one genuine error, or with no dependency at all, is always included. Every element that is a member of a genuine dependency loop (no genuine error anywhere in the loop) is included too, consistent with find_dependency_roots() – otherwise such a loop would vanish from the result entirely; see DFS() for how a genuine loop is distinguished from mere reconvergence.

Returns
Copies of root element info as type-safe variants.

◆ write_dot()

void mrs_lib::errorgraph::Errorgraph::write_dot ( std::ostream & os)

Write the graph in Graphviz DOT format.

Parameters
osOutput stream to write the DOT representation to.

The documentation for this class was generated from the following files:
  • /home/runner/work/mrs_lib/mrs_lib/include/mrs_lib/errorgraph/errorgraph.h
  • /home/runner/work/mrs_lib/mrs_lib/src/errorgraph/errorgraph.cpp