10 num_test=
lambda name, num:
True,
11 param_test=
lambda name, params={}:
True,
14 Purpose: Create a .xacro file to create a custom WAM-V .urdf 17 xacro_target (str): Target file for writing the xacro to 18 NOTE: will overwrite an existing file 19 yaml_file (str): .yaml file with requested macros 20 requested_macros (dict): if dict is passed directly => ignore yaml file 21 boiler_plate_top (str): String to start the xacro file 22 boiler_plate_bot (str): String to end the xacro file 23 num_test (function): test if the number of macro types is allowed 24 param_test (function): test if a macro call parameters are sensible 26 Creates a xacro file at 'xacro_target' 28 Returns test_fail (bool): Indicator if the wamv passed compliance tests 32 xacro_file = open(xacro_target,
'wb')
33 xacro_file.write(boiler_plate_top)
36 if requested_macros
is None:
37 s = open(yaml_file,
'r') 38 requested_macros = yaml.safe_load(s) 41 if requested_macros
is None:
42 xacro_file.write(boiler_plate_bot)
47 for key, objects
in requested_macros.items():
49 test_fail = num_test(key, len(objects))
52 xacro_file.write(
' <!-- === %s === -->\n' % key)
55 test_fail = param_test(key, i)
61 xacro_file.write(
'\n')
63 xacro_file.write(boiler_plate_bot)
70 requested_macros=
None,
75 Purpose: Append gazebo thruster config tags to a .xacro file to 76 create a custom WAM-V .urdf 79 xacro_target (str): Target file for writing the xacro to 80 NOTE: will append an existing file 81 should be used on thruster 84 yaml_file (str): .yaml file with requested macros 85 requested_macros (dict): if dict is passed directly => ignore yaml file 86 boiler_plate_top (str): First string to append to the xacro file 87 boiler_plate_bot (str): Last string to append to the xacro file 89 Appends gazebo thruster config tags to 'xacro_target' 92 xacro_file = open(xacro_target,
'ab')
93 xacro_file.write(boiler_plate_top)
96 if requested_macros
is None:
97 s = open(yaml_file,
'r') 98 requested_macros = yaml.safe_load(s) 101 if requested_macros
is None:
102 xacro_file.write(boiler_plate_bot)
107 for key, objects
in requested_macros.items():
109 xacro_file.write(
' ' +
111 {
'name': obj[
'prefix']}))
113 xacro_file.write(boiler_plate_bot)
118 macro_call =
' <xacro:%s ' % name
126 macro_call +=
'%s="%s" ' % (i, str(params[i]))
127 macro_call += endline
131 macro_call +=
' <%s>\n' % i
132 macro_call += str(params[
'/**' + i])
133 macro_call +=
' </%s>\n' % i
134 macro_call +=
' </xacro:' + name +
'>\n' 143 for i
in xacro_files:
145 macros[name] = params
150 xacro_files = [directory+
'/'+f
for f
in os.listdir(directory)
151 if os.path.isfile(os.path.join(directory, f))
and 152 (f[-6:] ==
'.xacro')]
153 child_directories = [d[0]
for d
in os.walk(directory)]
154 child_directories = child_directories[1:]
155 for i
in child_directories:
157 xacro_files.append(j)
162 xacro_file = open(xacro_file_name,
'r') 163 contents = xacro_file.read() 165 while '<!--' in contents:
166 start = contents.find(
'<!--')
167 end = contents.find(
'-->')
168 contents = contents.replace(contents[start:end+3],
'')
170 start = contents.find(
'<xacro:macro')
171 end = contents.find(
'>', start)
172 declaration = contents[start:end]
174 contents = contents.replace(contents[start:end+1],
'')
176 name_pose = declaration.find(
'name')
177 start = declaration.find(
'"', name_pose)
178 end = declaration.find(
'"', start+1)
179 name = declaration[start+1:end]
181 params_pose = declaration.find(
'params')
182 start = declaration.find(
'"', params_pose)
183 end = declaration.find(
'"', start+1)
184 params_str = declaration[start+1:end].split(
' ')
187 i = i.replace(
'\n',
'')
191 key = i[:i.find(
':')]
193 value = i[i.find(
'=')+1:]
196 value = value.replace(
'\n',
'')
199 if contents.find(
'<xacro:macro') != -1:
200 raise Exception(
'multiple macros defined in %s' % xacro_file_name)
def add_gazebo_thruster_config(xacro_target, yaml_file=None, requested_macros=None, boiler_plate_top='', boiler_plate_bot='')
def parse_xacro_file(xacro_file_name)
def get_macro_files(directory)
def macro_call_gen(name, params={})
def get_macros(directory)