Guest User

Untitled

a guest
Nov 22nd, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. from collections import OrderedDict
  2. import os
  3. import json
  4.  
  5. import genmsg
  6. import rosmsg
  7. import rospkg
  8.  
  9.  
  10. def load_specs(context, search_path, msg):
  11. spec = genmsg.load_msg_by_type(context, msg, search_path)
  12. genmsg.load_depends(context, spec, search_path)
  13.  
  14.  
  15. def _get_info(context, msg):
  16. base_type = genmsg.msgs.bare_msg_type(msg)
  17. if base_type in genmsg.msgs.BUILTIN_TYPES:
  18. return base_type
  19. else:
  20. spec = context.get_registered(base_type)
  21. return OrderedDict((k, _get_info(context, t)) for k, t in
  22. zip(spec.names, spec.types))
  23.  
  24.  
  25. def get_info(context, search_path, msg):
  26. load_specs(context, search_path, msg)
  27. return _get_info(context, msg)
  28.  
  29.  
  30. rospack = rospkg.RosPack()
  31.  
  32. search_path = {}
  33. for p in rospack.list():
  34. package_paths = rosmsg._get_package_paths(p, rospack)
  35. search_path[p] = [os.path.join(d, 'msg') for d in package_paths]
  36.  
  37. context = genmsg.MsgContext.create_default()
  38.  
  39. info = get_info(
  40. context, search_path, 'geometry_msgs/PoseWithCovarianceStamped')
  41. print(json.dumps(info, indent=4))
Add Comment
Please, Sign In to add comment