relay_screenshot.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 """
3 Call snapshot service of rviz (provided by ScreenshotListener tool)
4 when a topic is published.
5 
6 This script is useful to automatically record result of ros processing.
7 
8 NOTE:
9  rviz should be in fron of other windows because
10 """
11 
12 import rospy
13 from jsk_rviz_plugins.srv import Screenshot
14 
15 def callback(msg):
16  global counter
17  rospy.loginfo('received a message, save a screenshot to {0}'.format(file_format.format(counter)))
18  try:
19  screenshot_srv(file_format.format(counter))
20  counter = counter + 1
21  except rospy.ServiceException as e:
22  rospy.logerr('Failed to call screenshot service call. Have you add ScreenshotListener to rviz and file_format is correct? file_format is "{0}"'.format(file_format))
23 
24 
25 if __name__ == '__main__':
26  counter = 0
27  rospy.init_node('relay_screenshot')
28  screenshot_srv = rospy.ServiceProxy('/rviz/screenshot', Screenshot)
29  file_format = rospy.get_param('~file_format', 'rviz_screenshot_{0:0>5}.png')
30  sub = rospy.Subscriber('~input', rospy.msg.AnyMsg, callback)
31  rospy.spin()
relay_screenshot.screenshot_srv
screenshot_srv
Definition: relay_screenshot.py:28
relay_screenshot.callback
def callback(msg)
Definition: relay_screenshot.py:15


jsk_rviz_plugins
Author(s): Kei Okada , Yohei Kakiuchi , Shohei Fujii , Ryohei Ueda
autogenerated on Fri Dec 13 2024 03:49:57