Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5651715

Browse files
committedMar 14, 2024
update tools
Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp>
1 parent d313a58 commit 5651715

19 files changed

+403
-148
lines changed
 

‎system/diagnostic_graph_aggregator/CMakeLists.txt

+10-3
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,17 @@ ament_auto_add_executable(converter
2222
)
2323
target_include_directories(converter PRIVATE src/common)
2424

25-
ament_auto_add_executable(tool
26-
src/tool/tool.cpp
25+
ament_auto_add_executable(tree
26+
src/tool/tree.cpp
27+
src/tool/utils/loader.cpp
2728
)
28-
target_include_directories(tool PRIVATE src/common)
29+
target_include_directories(tree PRIVATE src/common)
30+
31+
ament_auto_add_executable(plantuml
32+
src/tool/plantuml.cpp
33+
src/tool/utils/loader.cpp
34+
)
35+
target_include_directories(plantuml PRIVATE src/common)
2936

3037
if(BUILD_TESTING)
3138
get_filename_component(RESOURCE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/test/files ABSOLUTE)

‎system/diagnostic_graph_aggregator/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ You can reuse the graph by making partial edits. For example, disable hardware c
7171
ros2 launch diagnostic_graph_aggregator example-edit.launch.xml
7272
```
7373

74+
## Debug tools
75+
76+
- [dump](./doc/tool/dump.md)
77+
- [converter](./doc/tool/converter.md)
78+
- [tree](./doc/tool/tree.md)
79+
7480
## Graph file format
7581

7682
- [graph](./doc/format/graph.md)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Converter tool
2+
3+
This tool converts `/diagnostics_graph` to `/diagnostics_agg` so it can be read by tools such as `rqt_runtime_monitor` and `rqt_robot_monitor`.
4+
5+
## Usage
6+
7+
```bash
8+
ros2 launch diagnostic_graph_aggregator converter.launch.xml complement:=false
9+
```
10+
11+
The `complement` argument specifies whether to add an intermediate path that does not exist.
12+
This means that if the graph contains paths `/A/B` and `/A/B/C/D/E`, the intermediate paths `/A`, `/A/B/C` and `/A/B/C/D` will be added.
13+
This is useful for tree view in `rqt_robot_monitor`. The completed node has an error level of `SATLE`.
14+
15+
## Examples
16+
17+
```bash
18+
ros2 launch diagnostic_graph_aggregator example-main.launch.xml complement:=false
19+
ros2 run rqt_runtime_monitor rqt_runtime_monitor --ros-args -r diagnostics:=diagnostics_agg
20+
```
21+
22+
![rqt_runtime_monitor](./images/rqt_runtime_monitor.png)
23+
24+
```bash
25+
ros2 launch diagnostic_graph_aggregator example-main.launch.xml complement:=true
26+
ros2 run rqt_robot_monitor rqt_robot_monitor
27+
```
28+
29+
![rqt_robot_monitor](./images/rqt_robot_monitor.png)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Dump tool
2+
3+
This tool displays `/diagnostics_graph` in table format.
4+
5+
## Usage
6+
7+
```bash
8+
ros2 run diagnostic_graph_aggregator dump
9+
```
10+
11+
## Examples
12+
13+
```bash
14+
ros2 launch diagnostic_graph_aggregator example-main.launch.xml
15+
ros2 run diagnostic_graph_aggregator dump
16+
```
17+
18+
```txt
19+
| ----- | ----- | -------------------------------- | ----- |
20+
| index | level | name | links |
21+
| ----- | ----- | -------------------------------- | ----- |
22+
| 0 | OK | /sensing/radars/front | |
23+
| 1 | OK | /sensing/lidars/front | |
24+
| 2 | ERROR | /sensing/lidars/top | |
25+
| 3 | OK | /functions/obstacle_detection | 1 0 |
26+
| 4 | ERROR | /functions/pose_estimation | 2 |
27+
| 5 | OK | /external/remote_command | |
28+
| 6 | OK | /external/joystick_command | |
29+
| 7 | ERROR | /autoware/modes/pull_over | 4 3 |
30+
| 8 | OK | /autoware/modes/comfortable_stop | 3 |
31+
| 9 | OK | /autoware/modes/emergency_stop | |
32+
| 10 | OK | /autoware/modes/remote | 5 |
33+
| 11 | OK | /autoware/modes/local | 6 |
34+
| 12 | ERROR | /autoware/modes/autonomous | 4 3 |
35+
| 13 | OK | /autoware/modes/stop | |
36+
```
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Tree tool
2+
3+
This tool displays the graph structure of the configuration file in tree format.
4+
5+
## Usage
6+
7+
```bash
8+
ros2 run diagnostic_graph_aggregator tree <graph-config-path>
9+
```
10+
11+
## Examples
12+
13+
```bash
14+
ros2 run diagnostic_graph_aggregator tree system/diagnostic_graph_aggregator/example/graph/main.yaml
15+
```
16+
17+
```txt
18+
===== root nodes =================================
19+
- /autoware/modes/local (and)
20+
- /external/joystick_command (diag)
21+
- /autoware/modes/comfortable_stop (and)
22+
- /functions/obstacle_detection (or)
23+
- /autoware/modes/pull_over (and)
24+
- /functions/pose_estimation (and)
25+
- /functions/obstacle_detection (or)
26+
- /autoware/modes/autonomous (and)
27+
- /functions/pose_estimation (and)
28+
- /functions/obstacle_detection (or)
29+
- /autoware/modes/remote (and)
30+
- /external/remote_command (diag)
31+
===== intermediate nodes =========================
32+
- /functions/obstacle_detection (or)
33+
- /sensing/lidars/front (diag)
34+
- /sensing/radars/front (diag)
35+
- /functions/pose_estimation (and)
36+
- /sensing/lidars/top (diag)
37+
===== isolated nodes =============================
38+
- /autoware/modes/stop (const)
39+
- /autoware/modes/emergency_stop (const)
40+
```
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
<launch>
2+
<arg name="complement" default="false"/>
23
<include file="$(find-pkg-share diagnostic_graph_aggregator)/launch/diagnostic_graph_aggregator.launch.xml">
34
<arg name="graph_file" value="$(find-pkg-share diagnostic_graph_aggregator)/example/graph/edit.yaml"/>
45
</include>
5-
<node pkg="diagnostic_graph_aggregator" exec="converter" name="converter"/>
6+
<include file="$(find-pkg-share diagnostic_graph_aggregator)/launch/converter.launch.xml">
7+
<arg name="complement" value="$(var complement)"/>
8+
</include>
69
<executable cmd="python3 $(find-pkg-share diagnostic_graph_aggregator)/example/dummy-diags.py"/>
710
</launch>
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
<launch>
2-
<include file="$(find-pkg-share diagnostic_graph_aggregator)/launch/diagnostic_graph_aggregator.launch.xml">
2+
<arg name="complement" default="false"/>
3+
<include file="$(find-pkg-share diagnostic_graph_aggregator)/launch/aggregator.launch.xml">
34
<arg name="graph_file" value="$(find-pkg-share diagnostic_graph_aggregator)/example/graph/main.yaml"/>
45
</include>
5-
<node pkg="diagnostic_graph_aggregator" exec="converter" name="converter"/>
6+
<include file="$(find-pkg-share diagnostic_graph_aggregator)/launch/converter.launch.xml">
7+
<arg name="complement" value="$(var complement)"/>
8+
</include>
69
<executable cmd="python3 $(find-pkg-share diagnostic_graph_aggregator)/example/dummy-diags.py"/>
710
</launch>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<launch>
2+
<arg name="complement"/>
3+
<node pkg="diagnostic_graph_aggregator" exec="converter" name="converter">
4+
<param name="complement_inner_nodes" value="$(var complement)"/>
5+
</node>
6+
</launch>

‎system/diagnostic_graph_aggregator/script/dump.py

-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ def callback(self, msg):
8484
if __name__ == "__main__":
8585
parser = argparse.ArgumentParser()
8686
parser.add_argument("--topic", default="/diagnostics_graph")
87-
parser.add_argument("--order", default="index")
8887
args, unparsed = parser.parse_known_args()
8988

9089
try:

‎system/diagnostic_graph_aggregator/src/node/converter.cpp

+39-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#include <memory>
1818
#include <string>
19+
#include <unordered_map>
20+
#include <vector>
1921

2022
namespace diagnostic_graph_aggregator
2123
{
@@ -35,6 +37,29 @@ std::string level_to_string(DiagnosticLevel level)
3537
return "UNKNOWN";
3638
}
3739

40+
std::string parent_path(const std::string & path)
41+
{
42+
return path.substr(0, path.rfind('/'));
43+
}
44+
45+
std::vector<std::string> complement_paths(const DiagnosticGraph & graph)
46+
{
47+
std::unordered_map<std::string, bool> paths;
48+
for (const auto & node : graph.nodes) {
49+
std::string path = node.status.name;
50+
paths[path] = false;
51+
while (path = parent_path(path), !path.empty()) {
52+
if (paths.count(path)) break;
53+
paths[path] = true;
54+
}
55+
}
56+
std::vector<std::string> result;
57+
for (const auto & [path, flag] : paths) {
58+
if (flag) result.push_back(path);
59+
}
60+
return result;
61+
}
62+
3863
ToolNode::ToolNode() : Node("diagnostic_graph_aggregator_converter")
3964
{
4065
using std::placeholders::_1;
@@ -43,7 +68,8 @@ ToolNode::ToolNode() : Node("diagnostic_graph_aggregator_converter")
4368

4469
const auto callback = std::bind(&ToolNode::on_graph, this, _1);
4570
sub_graph_ = create_subscription<DiagnosticGraph>("/diagnostics_graph", qos_graph, callback);
46-
pub_array_ = create_publisher<DiagnosticArray>("/diagnostics_array", qos_array);
71+
pub_array_ = create_publisher<DiagnosticArray>("/diagnostics_agg", qos_array);
72+
complement_inner_nodes_ = declare_parameter<bool>("complement_inner_nodes");
4773
}
4874

4975
void ToolNode::on_graph(const DiagnosticGraph::ConstSharedPtr msg)
@@ -63,6 +89,18 @@ void ToolNode::on_graph(const DiagnosticGraph::ConstSharedPtr msg)
6389
}
6490
}
6591
}
92+
93+
if (complement_inner_nodes_) {
94+
if (!inner_node_names_) {
95+
inner_node_names_ = complement_paths(*msg);
96+
}
97+
for (const auto & name : inner_node_names_.value()) {
98+
message.status.emplace_back();
99+
message.status.back().name = name;
100+
message.status.back().level = DiagnosticStatus::STALE;
101+
}
102+
}
103+
66104
pub_array_->publish(message);
67105
}
68106

‎system/diagnostic_graph_aggregator/src/node/converter.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020
#include <rclcpp/rclcpp.hpp>
2121

22+
#include <string>
23+
#include <vector>
24+
2225
namespace diagnostic_graph_aggregator
2326
{
2427

@@ -28,6 +31,8 @@ class ToolNode : public rclcpp::Node
2831
ToolNode();
2932

3033
private:
34+
bool complement_inner_nodes_;
35+
std::optional<std::vector<std::string>> inner_node_names_;
3136
rclcpp::Subscription<DiagnosticGraph>::SharedPtr sub_graph_;
3237
rclcpp::Publisher<DiagnosticArray>::SharedPtr pub_array_;
3338
void on_graph(const DiagnosticGraph::ConstSharedPtr msg);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2023 The Autoware Contributors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "utils/loader.hpp"
16+
17+
#include <iostream>
18+
19+
namespace diagnostic_graph_aggregator
20+
{
21+
22+
void dump_root(const std::string & path)
23+
{
24+
const auto graph = load_graph_nodes(path);
25+
const auto color = "#FFFFFF";
26+
27+
for (const auto & node : graph.nodes) {
28+
std::cout << "card " << node << " " << color << " [" << std::endl;
29+
std::cout << node->path << std::endl;
30+
std::cout << "]" << std::endl;
31+
}
32+
33+
for (const auto & node : graph.nodes) {
34+
for (const auto & child : node->children) {
35+
std::cout << node << " --> " << child << std::endl;
36+
}
37+
}
38+
}
39+
40+
} // namespace diagnostic_graph_aggregator
41+
42+
int main(int argc, char ** argv)
43+
{
44+
if (argc != 2) {
45+
std::cerr << "usage: plantuml <path>" << std::endl;
46+
return 1;
47+
}
48+
diagnostic_graph_aggregator::dump_root(argv[1]);
49+
}

‎system/diagnostic_graph_aggregator/src/tool/tool.cpp

-140
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright 2023 The Autoware Contributors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "utils/loader.hpp"
16+
17+
#include <iostream>
18+
19+
namespace diagnostic_graph_aggregator
20+
{
21+
22+
void dump_node(const GraphNode * node, const std::string & indent = "", bool root = true)
23+
{
24+
const auto path = node->path.empty() ? "" : node->path + " ";
25+
const auto type = "(" + node->type + ")";
26+
std::cout << indent << "- " << path << type << std::endl;
27+
28+
if (root || node->parents.size() == 1) {
29+
for (const auto child : node->children) {
30+
dump_node(child, indent + " ", false);
31+
}
32+
}
33+
}
34+
35+
void dump_root(const std::string & path)
36+
{
37+
const auto graph = load_graph_nodes(path);
38+
39+
std::cout << "===== root nodes =================================" << std::endl;
40+
for (const auto & node : graph.nodes) {
41+
if (node->parents.size() == 0 && node->children.size() != 0) {
42+
dump_node(node);
43+
}
44+
}
45+
std::cout << "===== intermediate nodes =========================" << std::endl;
46+
for (const auto & node : graph.nodes) {
47+
if (node->parents.size() >= 2) {
48+
dump_node(node);
49+
}
50+
}
51+
52+
std::cout << "===== isolated nodes =============================" << std::endl;
53+
for (const auto & node : graph.nodes) {
54+
if (node->parents.size() == 0 && node->children.size() == 0) {
55+
dump_node(node);
56+
}
57+
}
58+
}
59+
60+
} // namespace diagnostic_graph_aggregator
61+
62+
int main(int argc, char ** argv)
63+
{
64+
if (argc != 2) {
65+
std::cerr << "usage: tree <path>" << std::endl;
66+
return 1;
67+
}
68+
diagnostic_graph_aggregator::dump_root(argv[1]);
69+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright 2023 The Autoware Contributors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "loader.hpp"
16+
17+
#include <unordered_map>
18+
#include <utility>
19+
20+
namespace diagnostic_graph_aggregator
21+
{
22+
23+
GraphRoot load_graph_nodes(const std::string & path)
24+
{
25+
GraphRoot result;
26+
{
27+
std::unordered_map<BaseUnit *, GraphNode::UniquePtr> mapping;
28+
Graph graph;
29+
graph.init(path);
30+
31+
for (const auto & node : graph.nodes()) {
32+
auto data = std::make_unique<GraphNode>();
33+
data->path = node->path();
34+
data->type = node->type();
35+
mapping[node] = std::move(data);
36+
}
37+
38+
for (const auto & [node, data] : mapping) {
39+
for (const auto & link : node->children()) {
40+
const auto parent = data.get();
41+
const auto child = mapping.at(link).get();
42+
child->parents.push_back(parent);
43+
parent->children.push_back(child);
44+
}
45+
}
46+
47+
for (auto & [node, data] : mapping) {
48+
result.owner.push_back(std::move(data));
49+
}
50+
for (const auto & node : result.owner) {
51+
result.nodes.push_back(node.get());
52+
}
53+
}
54+
return result;
55+
}
56+
57+
} // namespace diagnostic_graph_aggregator
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright 2023 The Autoware Contributors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef TOOL__UTILS__LOADER_HPP_
16+
#define TOOL__UTILS__LOADER_HPP_
17+
18+
#include "graph/graph.hpp"
19+
#include "graph/types.hpp"
20+
#include "graph/units.hpp"
21+
22+
#include <memory>
23+
#include <string>
24+
#include <vector>
25+
26+
namespace diagnostic_graph_aggregator
27+
{
28+
29+
struct GraphNode
30+
{
31+
using UniquePtr = std::unique_ptr<GraphNode>;
32+
std::string type;
33+
std::string path;
34+
std::vector<GraphNode *> children;
35+
std::vector<GraphNode *> parents;
36+
};
37+
38+
struct GraphRoot
39+
{
40+
std::vector<GraphNode::UniquePtr> owner;
41+
std::vector<GraphNode *> nodes;
42+
};
43+
44+
GraphRoot load_graph_nodes(const std::string & path);
45+
46+
} // namespace diagnostic_graph_aggregator
47+
48+
#endif // TOOL__UTILS__LOADER_HPP_

0 commit comments

Comments
 (0)
Please sign in to comment.