5 from collections
import OrderedDict
7 from .. utils
import create_xacro_file
11 s = open(rospy.get_param(
'requested'))
12 yaml_name = rospy.get_param(
'requested')[
13 rospy.get_param(
'requested').rfind(
'/')+1:
14 rospy.get_param(
'requested').rfind(
'.yaml')]
16 master = yaml.safe_load(s)
20 for num, i
in enumerate(coordinates):
22 yaml_name + str(num) +
'.world.xacro',
26 boiler_plate_top=
'<?xml version="1.0" ?>\n' +
27 '<sdf version="1.6" ' +
28 'xmlns:xacro="http://ros.org/wiki/xacro">\n' +
29 '<!-- COORDINATE: ' + str(i) +
' -->\n' +
30 '<world name="robotx_example_course">\n' +
31 ' <xacro:include filename="$(find vrx_gazebo)' +
32 '/worlds/xacros/include_all_xacros.xacro" />\n' +
33 ' <xacro:include_all_xacros />\n',
34 boiler_plate_bot=
'</world>\n</sdf>')
35 os.system(
'rosrun xacro xacro --inorder -o' +
36 rospy.get_param(
'world_target') + yaml_name + str(num) +
38 rospy.get_param(
'world_xacro_target') + yaml_name +
39 str(num) +
'.world.xacro')
40 print 'All ', len(coordinates),
' worlds generated' 45 for axis_name, axis
in master.iteritems():
47 if axis[
'sequence']
is not None and \
48 coordinate[axis_name]
in axis[
'sequence']:
51 if i
in axis[
'sequence'][coordinate[axis_name]]:
52 world[i] += axis[
'sequence'][coordinate[axis_name]]
54 for i
in axis[
'sequence'][coordinate[axis_name]]:
56 if axis[
'sequence'][coordinate[axis_name]][i] == [
None]:
59 world[i] = axis[
'sequence'][coordinate[axis_name]][i]
62 for macro_name, macro_calls
in axis[
'macros'].iteritems():
64 if macro_name
not in world:
65 world[macro_name] = []
66 for params
in macro_calls:
67 if params
is not None:
69 for param, value
in params.iteritems():
71 if value[0] ==
"'" and value[-1] ==
"'":
72 evaluated_params[param] = value[1:-1]
76 evaluated_params[param] =\
77 (
lambda n: eval(f))(coordinate[axis_name])
78 world[macro_name].append(evaluated_params)
80 world[macro_name].append({})
90 for axis, value
in master.iteritems():
92 axies[axis] = value[
'steps']-1
93 iterate(axies_max=axies, coordinates=combinations,
94 current_coordinate=start)
98 def iterate(axies_max={}, coordinates=[], current_coordinate={}):
99 coordinates.append(current_coordinate.copy())
101 if axies_max == current_coordinate:
104 for axis
in current_coordinate:
105 if current_coordinate[axis] < axies_max[axis]:
106 current_coordinate[axis] += 1
109 current_coordinate[axis] = 0
110 iterate(axies_max=axies_max, coordinates=coordinates,
111 current_coordinate=current_coordinate)
def world_gen(coordinate={}, master={})
def linear_combinations(master={})
def iterate(axies_max={}, coordinates=[], current_coordinate={})