-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1727 from 708yamaguchi/sanity-diagnostics
[jsk_tools] Add node to publish diagnostics based on topic and node status
- Loading branch information
Showing
10 changed files
with
254 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
sanity\_diagnostics.py | ||
============== | ||
|
||
## What is this | ||
|
||
This node publishes essential robot topic and node status to `/diagnostics`. | ||
|
||
## Publishing Topics | ||
|
||
* `/diagnostics` (`diagnostic_msgs/DiagnosticStatus`) | ||
|
||
Diagnostics topic | ||
|
||
## Subscribing Topics | ||
|
||
* topics specified in the `~sanity_targets` yaml file | ||
|
||
## Parameter | ||
|
||
* `~sanity_targets` (`String`, default: `/var/lib/robot/sanity_targets.yaml`) | ||
|
||
Yaml file which contains topics and nodes to be monitored. | ||
|
||
Sample yaml format for fetch: | ||
|
||
```yaml | ||
topics: | ||
- /audio | ||
- /base_scan | ||
- /battery_state | ||
- /edgetpu_human_pose_estimator/output/image | ||
- /edgetpu_object_detector/output/image | ||
- /gripper/imu | ||
- /head_camera/depth/image_raw | ||
- /head_camera/rgb/image_raw | ||
- /imu | ||
- /insta360/image_raw | ||
- /joint_states | ||
- /tf | ||
|
||
nodes: | ||
- /amcl | ||
- /auto_dock | ||
- /gripper_driver | ||
- /head_camera/head_camera_nodelet_manager | ||
- /move_base | ||
- /move_group | ||
- /respeaker_node | ||
- /robot_driver | ||
- /roswww | ||
``` | ||
* `~duration` (`Float`, default: `1`) | ||
|
||
Duration in which sanity is checked and `/diagnostics` is published. | ||
|
||
## Usage | ||
|
||
Visualize topic and node diagnostics. | ||
|
||
```bash | ||
roslaunch jsk_tools sample_sanity_diagnostics.launch | ||
``` | ||
|
||
![sanity_diagnostics](https://user-images.githubusercontent.com/19769486/168039418-0171a6dc-9507-436d-a9a6-13a2c7f52327.png) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
analyzers: | ||
topics: | ||
type: diagnostic_aggregator/AnalyzerGroup | ||
path: Topics | ||
analyzers: | ||
head_camera: | ||
type: diagnostic_aggregator/GenericAnalyzer | ||
path: HeadCamera | ||
contains: 'head_camera' | ||
num_items: 1 | ||
nodes: | ||
type: diagnostic_aggregator/AnalyzerGroup | ||
path: Nodes | ||
analyzers: | ||
robot_driver: | ||
type: diagnostic_aggregator/GenericAnalyzer | ||
path: RobotDriver | ||
contains: 'robot_driver' | ||
num_items: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
topics: | ||
- /head_camera/rgb/image_raw | ||
nodes: | ||
- /robot_driver |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<launch> | ||
<arg name="gui" default="true" /> | ||
|
||
<!-- Publish target topic --> | ||
<node name="image_publisher" pkg="rostopic" type="rostopic" | ||
args="pub -s /head_camera/rgb/image_raw sensor_msgs/Image "{ | ||
'header': { | ||
'seq': 0, | ||
'stamp': {'secs': 0, 'nsecs': 0}, | ||
'frame_id': '' | ||
}, | ||
'height': 0, | ||
'width': 0, | ||
'encoding': '', | ||
'is_bigendian': 0, | ||
'step': 0, | ||
'data': ''}"" /> | ||
|
||
<!-- Launch target node --> | ||
<node name="robot_driver" pkg="rostopic" type="rostopic" | ||
args="pub -s /test std_msgs/Empty {}" /> | ||
|
||
<!-- Publish /diagnostics --> | ||
<node name="sanity_diagnostics" pkg="jsk_tools" type="sanity_diagnostics.py"> | ||
<rosparam command="load" file="$(find jsk_tools)/sample/config/sanity_targets.yaml" /> | ||
<rosparam subst_value="true"> | ||
duration: 1 | ||
</rosparam> | ||
</node> | ||
|
||
<!-- Publish /diagnostics_agg --> | ||
<node name="diagnostic_aggregator" | ||
pkg="diagnostic_aggregator" type="aggregator_node" | ||
clear_params="true" > | ||
<rosparam command="load" file="$(find jsk_tools)/sample/config/diagnostics_analyzer.yaml" /> | ||
</node> | ||
|
||
<!-- Visualize diagnostic aggregator --> | ||
<node if="$(arg gui)" | ||
name="rqt_robot_monitor" pkg="rqt_robot_monitor" type="rqt_robot_monitor" /> | ||
|
||
</launch> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#!/usr/bin/env python | ||
|
||
# https://github.com/start-jsk/jsk_apc/blob/master/jsk_arc2017_baxter/node_scripts/sanity_check_for_pick.py # NOQA | ||
|
||
from diagnostic_msgs.msg import DiagnosticStatus | ||
import diagnostic_updater | ||
from jsk_tools.sanity_lib import checkNodeState, checkTopicIsPublished | ||
import rospy | ||
|
||
|
||
class SanityDiagnostics(object): | ||
""" | ||
This node publishes essential robot topic and node status to /diagnostics. | ||
The yaml file is like the following: | ||
topics: | ||
- /kinect_head/rgb/image_raw | ||
- /tf | ||
nodes: | ||
- /kinect_head/kinect_head_nodelet_manager | ||
- /respeaker_node | ||
""" | ||
def __init__(self): | ||
duration = rospy.get_param('~duration', 60) | ||
# Get sanity target topic and node names | ||
topics = rospy.get_param('~topics', []) | ||
nodes = rospy.get_param('~nodes', []) | ||
# Set diagnostic updater for each topic and node | ||
self.updater = diagnostic_updater.Updater() | ||
self.updater.setHardwareID("none") | ||
for topic_name in topics: | ||
self.updater.add( | ||
topic_name, | ||
lambda stat, tn=topic_name: self.check_topic(stat, tn)) | ||
for node_name in nodes: | ||
self.updater.add( | ||
node_name, | ||
lambda stat, nn=node_name: self.check_node(stat, nn)) | ||
# Timer to call updater | ||
self.timer = rospy.Timer( | ||
rospy.Duration(duration), self.check_sanity) | ||
|
||
def check_sanity(self, event): | ||
self.updater.update() | ||
|
||
def check_topic(self, stat, topic_name): | ||
# Assume that topic is published at more than (1.0 / timeout) Hz | ||
topic_state = checkTopicIsPublished(topic_name, timeout=10) | ||
if topic_state: | ||
stat.summary(DiagnosticStatus.OK, 'Topic is published') | ||
else: | ||
stat.summary(DiagnosticStatus.ERROR, 'Topic is not published') | ||
return stat | ||
|
||
def check_node(self, stat, node_name): | ||
node_state = checkNodeState(node_name, needed=True) | ||
if node_state: | ||
stat.summary(DiagnosticStatus.OK, 'Node is alive') | ||
else: | ||
stat.summary(DiagnosticStatus.ERROR, 'Node is dead') | ||
return stat | ||
|
||
|
||
if __name__ == '__main__': | ||
rospy.init_node('sanity_diagnostics') | ||
SanityDiagnostics() | ||
rospy.spin() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<launch> | ||
<include file="$(find jsk_tools)/sample/sample_sanity_diagnostics.launch"> | ||
<arg name="gui" value="false"/> | ||
</include> | ||
|
||
<test test-name="test_sanity_diagnostics" name="test_sanity_diagnostics" | ||
pkg="jsk_tools" type="test_topic_published.py"> | ||
<rosparam> | ||
topic_0: /diagnostics | ||
timeout_0: 30 | ||
topic_1: /diagnostics_agg | ||
timeout_1: 30 | ||
</rosparam> | ||
</test> | ||
|
||
</launch> |