35 Top-level library routines we expose to the end-user 38 from __future__
import with_statement
42 import roslib.packages
49 Find ROS resource inside of a package. 51 @param pkg: ROS package name 53 @param resource: resource filename 56 val = roslib.packages.find_resource(pkg, resource)
60 raise rospy.ROSException(
"cannot find resource")
64 def __init__(self, filename):
65 self.filename = filename
66 self._fp = open(filename,
'w')
68 def append(self, msg):
72 if self._fp
is not None:
78 if isinstance(obj, roslib.message.Message):
87 Load single message from YAML dictionary representation. 89 @param type_: Message class 90 @type type_: class (Message subclass) 91 @param filename: Name of YAML file 95 if yaml_str.strip() ==
'':
98 msg_dict = yaml.safe_load(yaml_str)
99 if not isinstance(msg_dict, dict):
101 raise ValueError(
"yaml file [%s] does not contain a dictionary" % filename)
103 raise ValueError(
"yaml string does not contain a dictionary")
105 roslib.message.fill_message_args(m, [msg_dict])
111 Load single message from YAML dictionary representation. 113 @param type_: Message class 114 @type type_: class (Message subclass) 115 @param filename: Name of YAML file 118 with open(filename,
'r') as f: 124 Load messages from YAML list-of-dictionaries representation. 126 @param type_: Message class 127 @type type_: class (Message subclass) 128 @param filename: Name of YAML file 132 yaml_doc = yaml.safe_load(yaml_str)
134 for msg_dict
in yaml_doc:
135 if not isinstance(msg_dict, dict):
137 raise ValueError(
"yaml file [%s] does not contain a list of dictionaries" % filename)
139 raise ValueError(
"yaml string does not contain a list of dictionaries")
141 roslib.message.fill_message_args(m, msg_dict)
148 Load messages from YAML list-of-dictionaries representation. 150 @param type_: Message class 151 @type type_: class (Message subclass) 152 @param filename: Name of YAML file 155 with open(filename,
'r') as f: 161 convert value to YAML representation 162 @param val: to convert to string representation. Most likely a Message. 164 @param indent: indentation 166 @param time_offset: if not None, time fields will be displayed 167 as deltas from time_offset 168 @type time_offset: Time 170 if type(msg)
in [int, long, float, str, bool]:
173 elif isinstance(msg, rospy.Time)
or isinstance(msg, rospy.Duration):
174 if time_offset
is not None and isinstance(msg, rospy.Time):
175 msg = msg-time_offset
177 return '\n%ssecs: %s\n%snsecs: %s' % (indent, msg.secs, indent, msg.nsecs)
179 elif type(msg)
in [list, tuple]:
182 return str(list(msg))
184 if type(msg0)
in [int, float, str, bool]
or \
185 isinstance(msg0, rospy.Time)
or isinstance(msg0, rospy.Duration)
or \
186 isinstance(msg0, list)
or isinstance(msg0, tuple):
188 return str(list(msg))
190 indent = indent +
' ' 191 return "["+
','.join([roslib.message.strify_message(v, indent, time_offset)
for v
in msg])+
"]" 192 elif isinstance(msg, rospy.Message):
195 '\n'.join([
'%s%s: %s' % (
196 indent, f, roslib.message.strify_message(getattr(msg, f),
' ' + indent, time_offset))
for f
in msg.__slots__])
197 return '\n'.join([
'%s%s: %s' % (indent, f, roslib.message.strify_message(getattr(msg, f),
' ' + indent, time_offset))
for f
in msg.__slots__])
def findros(pkg, resource)
def yaml_msgs(type_, filename)
def _message_to_yaml(msg, indent='', time_offset=None)
def yaml_msgs_str(type_, yaml_str, filename=None)
def yaml_msg_str(type_, yaml_str, filename=None)
def yaml_msg(type_, filename)