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  element_t
 Internal representation of a node or topic in the error dependency graph. More...
 
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...
 

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_tfind_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_tfind_error_roots ()
 Find all root-cause elements across the entire graph.
 
std::vector< element_info_tfind_roots ()
 Find all root elements (elements with no parents in the dependency graph).
 
std::vector< element_info_tfind_leaves ()
 Find all leaf elements (elements with no children in the dependency graph).
 
std::optional< element_info_tfind_element (const std::string &topic_name)
 Find an element by topic name.
 
std::optional< element_info_tfind_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 to find leaf elements (elements with errors that don't depend on anything else).

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.

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 with no children in the dependency graph).

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 with no parents in the dependency graph).

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: