Skip to content

Commit

Permalink
feat(diagnostic_graph_utils): componentize node (autowarefoundation#7189
Browse files Browse the repository at this point in the history
)

Signed-off-by: Takagi, Isamu <[email protected]>
  • Loading branch information
isamu-takagi authored and karishma1911 committed Jun 3, 2024
1 parent 116e460 commit 65c6a36
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 33 deletions.
13 changes: 10 additions & 3 deletions system/diagnostic_graph_utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@ ament_auto_add_library(${PROJECT_NAME} SHARED
src/lib/subscription.cpp
)

ament_auto_add_executable(dump
ament_auto_add_library(${PROJECT_NAME}_tools SHARED
src/node/dump.cpp
src/node/converter.cpp
)

ament_auto_add_executable(converter
src/node/converter.cpp
rclcpp_components_register_node(${PROJECT_NAME}_tools
PLUGIN "diagnostic_graph_utils::DumpNode"
EXECUTABLE dump_node
)

rclcpp_components_register_node(${PROJECT_NAME}_tools
PLUGIN "diagnostic_graph_utils::ConverterNode"
EXECUTABLE converter_node
)

ament_auto_package()
4 changes: 2 additions & 2 deletions system/diagnostic_graph_utils/doc/node/converter.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This tool converts `/diagnostics_graph` to `/diagnostics_array` so it can be rea
## Usage

```bash
ros2 run diagnostic_graph_utils converter
ros2 run diagnostic_graph_utils converter_node
```

## Examples
Expand All @@ -19,7 +19,7 @@ ros2 launch diagnostic_graph_aggregator example-main.launch.xml
Terminal 2:

```bash
ros2 run diagnostic_graph_utils converter
ros2 run diagnostic_graph_utils converter_node
```

Terminal 3:
Expand Down
4 changes: 2 additions & 2 deletions system/diagnostic_graph_utils/doc/node/dump.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This tool displays `/diagnostics_graph` in table format.
## Usage

```bash
ros2 run diagnostic_graph_utils dump
ros2 run diagnostic_graph_utils dump_node
```

## Examples
Expand All @@ -19,7 +19,7 @@ ros2 launch diagnostic_graph_aggregator example-main.launch.xml
Terminal 2:

```bash
ros2 run diagnostic_graph_utils dump
ros2 run diagnostic_graph_utils dump_node
```

Output:
Expand Down
1 change: 1 addition & 0 deletions system/diagnostic_graph_utils/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

<depend>diagnostic_msgs</depend>
<depend>rclcpp</depend>
<depend>rclcpp_components</depend>
<depend>tier4_system_msgs</depend>

<test_depend>ament_lint_auto</test_depend>
Expand Down
15 changes: 3 additions & 12 deletions system/diagnostic_graph_utils/src/node/converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
namespace diagnostic_graph_utils
{

ConverterNode::ConverterNode() : Node("converter")
ConverterNode::ConverterNode(const rclcpp::NodeOptions & options) : Node("converter", options)
{
using std::placeholders::_1;
pub_array_ = create_publisher<DiagnosticArray>("/diagnostics_array", rclcpp::QoS(1));
Expand All @@ -40,14 +40,5 @@ void ConverterNode::on_update(DiagGraph::ConstSharedPtr graph)

} // namespace diagnostic_graph_utils

int main(int argc, char ** argv)
{
using diagnostic_graph_utils::ConverterNode;
rclcpp::init(argc, argv);
rclcpp::executors::SingleThreadedExecutor executor;
auto node = std::make_shared<ConverterNode>();
executor.add_node(node);
executor.spin();
executor.remove_node(node);
rclcpp::shutdown();
}
#include <rclcpp_components/register_node_macro.hpp>
RCLCPP_COMPONENTS_REGISTER_NODE(diagnostic_graph_utils::ConverterNode)
2 changes: 1 addition & 1 deletion system/diagnostic_graph_utils/src/node/converter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace diagnostic_graph_utils
class ConverterNode : public rclcpp::Node
{
public:
ConverterNode();
explicit ConverterNode(const rclcpp::NodeOptions & options);

private:
using DiagnosticArray = diagnostic_msgs::msg::DiagnosticArray;
Expand Down
15 changes: 3 additions & 12 deletions system/diagnostic_graph_utils/src/node/dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
namespace diagnostic_graph_utils
{

DumpNode::DumpNode() : Node("dump")
DumpNode::DumpNode(const rclcpp::NodeOptions & options) : Node("dump", options)
{
using std::placeholders::_1;
sub_graph_.register_create_callback(std::bind(&DumpNode::on_create, this, _1));
Expand Down Expand Up @@ -132,14 +132,5 @@ void DumpNode::on_update(DiagGraph::ConstSharedPtr graph)

} // namespace diagnostic_graph_utils

int main(int argc, char ** argv)
{
using diagnostic_graph_utils::DumpNode;
rclcpp::init(argc, argv);
rclcpp::executors::SingleThreadedExecutor executor;
auto node = std::make_shared<DumpNode>();
executor.add_node(node);
executor.spin();
executor.remove_node(node);
rclcpp::shutdown();
}
#include <rclcpp_components/register_node_macro.hpp>
RCLCPP_COMPONENTS_REGISTER_NODE(diagnostic_graph_utils::DumpNode)
2 changes: 1 addition & 1 deletion system/diagnostic_graph_utils/src/node/dump.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace diagnostic_graph_utils
class DumpNode : public rclcpp::Node
{
public:
DumpNode();
explicit DumpNode(const rclcpp::NodeOptions & options);

private:
void on_create(DiagGraph::ConstSharedPtr graph);
Expand Down

0 comments on commit 65c6a36

Please sign in to comment.