view_frames.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # Copyright (c) 2008, Willow Garage, Inc.
3 # All rights reserved.
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are met:
7 #
8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution.
13 # * Neither the name of the Willow Garage, Inc. nor the names of its
14 # contributors may be used to endorse or promote products derived from
15 # this software without specific prior written permission.
16 #
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 # POSSIBILITY OF SUCH DAMAGE.
28 
29 # author: Wim Meeussen
30 
31 import rospy
32 import tf2_py as tf2
33 import yaml
34 import subprocess
35 from tf2_msgs.srv import FrameGraph
36 import tf2_ros
37 
38 def main():
39  rospy.init_node('view_frames')
40 
41  # listen to tf for 5 seconds
42  rospy.loginfo('Listening to tf data during 5 seconds...')
43  rospy.sleep(0.00001)
44  buffer = tf2_ros.Buffer()
45  listener = tf2_ros.TransformListener(buffer)
46  rospy.sleep(5.0)
47 
48  rospy.loginfo('Generating graph in frames.pdf file...')
49  rospy.wait_for_service('~tf2_frames')
50  srv = rospy.ServiceProxy('~tf2_frames', FrameGraph)
51  data = yaml.load(srv().frame_yaml)
52  with open('frames.gv', 'w') as f:
53  f.write(generate_dot(data))
54  subprocess.Popen('dot -Tpdf frames.gv -o frames.pdf'.split(' ')).communicate()
55 
56 def generate_dot(data):
57  if len(data) == 0:
58  return 'digraph G { "No tf data received" }'
59 
60  dot = 'digraph G {\n'
61  for el in data:
62  map = data[el]
63  dot += '"'+map['parent']+'" -> "'+str(el)+'"'
64  dot += '[label=" '
65  dot += 'Broadcaster: '+map['broadcaster']+'\\n'
66  dot += 'Average rate: '+str(map['rate'])+'\\n'
67  dot += 'Buffer length: '+str(map['buffer_length'])+'\\n'
68  dot += 'Most recent transform: '+str(map['most_recent_transform'])+'\\n'
69  dot += 'Oldest transform: '+str(map['oldest_transform'])+'\\n'
70  dot += '"];\n'
71  if not map['parent'] in data:
72  root = map['parent']
73  dot += 'edge [style=invis];\n'
74  dot += ' subgraph cluster_legend { style=bold; color=black; label ="view_frames Result";\n'
75  dot += '"Recorded at time: '+str(rospy.Time.now().to_sec())+'"[ shape=plaintext ] ;\n'
76  dot += '}->"'+root+'";\n}'
77  return dot
78 
79 
80 if __name__ == '__main__':
81  main()
def main()
Definition: view_frames.py:38
def generate_dot(data)
Definition: view_frames.py:56


tf2_tools
Author(s): Wim Meeussen
autogenerated on Fri Jun 7 2019 21:46:01