configure_wamv.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 import rospy
3 import os
4 
5 from compliance import Sensor_Compliance
6 from compliance import Thruster_Compliance
7 
8 from .. utils import create_xacro_file
9 from .. utils import add_gazebo_thruster_config
10 
11 
12 def main():
13 
14  rospy.init_node("wamv_generator", anonymous=True)
15  # Check if yaml files were given
16  received_thruster_yaml = len(rospy.get_param('thruster_yaml')) > 0
17  received_sensor_yaml = len(rospy.get_param('sensor_yaml')) > 0
18 
19  # Setup thruster xacro
20  if received_thruster_yaml:
21  thruster_compliant = create_thruster_xacro()
22 
23  # Setup sensor xacro
24  if received_sensor_yaml:
25  sensor_compliant = create_sensor_xacro()
26 
27  # Setup command to generate WAM-V urdf file
28  wamv_target = rospy.get_param('wamv_target')
29  wamv_gazebo = rospy.get_param('wamv_gazebo')
30 
31  create_urdf_command = ("rosrun xacro xacro --inorder -o " + wamv_target +
32  " '" + wamv_gazebo + "'")
33 
34  # Add xacro files if created
35  if received_thruster_yaml:
36  yaml = 'thruster_yaml'
37  thruster_xacro_target = yaml_to_xacro_extension(rospy.get_param(yaml))
38  create_urdf_command += (" yaml_thruster_generation:=true "
39  "thruster_xacro_file:=" +
40  thruster_xacro_target)
41  if received_sensor_yaml:
42  yaml = 'sensor_yaml'
43  sensor_xacro_target = yaml_to_xacro_extension(rospy.get_param(yaml))
44  create_urdf_command += (" yaml_sensor_generation:=true "
45  "sensor_xacro_file:=" + sensor_xacro_target)
46 
47  # Create urdf and print to console
48  os.system(create_urdf_command)
49  if not (thruster_compliant and sensor_compliant):
50  rospy.logerr('\nThis sensor/thruster configuration is NOT compliant ' +
51  'with the (current) VRX constraints. A urdf file will ' +
52  'be created, but please note that the above errors ' +
53  'must be fixed for this to be a valid configuration ' +
54  'for the VRX competition.\n')
55 
56  print('WAM-V urdf file sucessfully generated. File location: ' +
57  wamv_target)
58 
60  """
61  Purpose: Create a thruster xacro file using the given
62  rosparameters
63  """
64  # Get yaml files for thruster number and pose
65  thruster_yaml = rospy.get_param('thruster_yaml')
66  rospy.loginfo('\nUsing %s as the thruster configuration yaml file\n' %
67  thruster_yaml)
68 
69  # Set thruster xacro target
70  thruster_xacro_target = yaml_to_xacro_extension(thruster_yaml)
71 
72  # Things to start/open the macro
73  thruster_boiler_plate_top = ('<?xml version="1.0"?>\n'
74  '<robot '
75  'xmlns:xacro="http://ros.org/wiki/xacro" '
76  'name="wam-v-thrusters">\n'
77  ' <xacro:include filename='
78  '"$(find wamv_description)/urdf/thrusters/'
79  'engine.xacro" />\n')
80 
81  # Things to close the macro
82  thruster_boiler_plate_bot = ''
83 
84  # Check if valid number of thrusters and valid thruster parameters
85  comp = Thruster_Compliance()
86  thruster_num_test = comp.number_compliance
87  thruster_param_test = comp.param_compliance
88 
89  # Create thruster xacro with thruster macros
90  compliant = create_xacro_file(yaml_file=thruster_yaml,
91  xacro_target=thruster_xacro_target,
92  boiler_plate_top=thruster_boiler_plate_top,
93  boiler_plate_bot=thruster_boiler_plate_bot,
94  num_test=thruster_num_test,
95  param_test=thruster_param_test)
96 
97  gz_boiler_plate_top = (' <gazebo>\n'
98  ' <plugin name="wamv_gazebo_thrust" '
99  'filename="libusv_gazebo_thrust_plugin.so">\n'
100  ' <cmdTimeout>1.0</cmdTimeout>\n'
101  ' <robotNamespace>${namespace}</robotNamespace>\n'
102  ' <xacro:include filename="$(find wamv_gazebo)'
103  '/urdf/thruster_layouts/'
104  'wamv_gazebo_thruster_config.xacro" />\n')
105  gz_boiler_plate_bot = (' </plugin>\n'
106  ' </gazebo>\n'
107  '</robot>')
108 
109  # Append gazebo thruster config to thruster xacro
110  add_gazebo_thruster_config(yaml_file=thruster_yaml,
111  xacro_target=thruster_xacro_target,
112  boiler_plate_top=gz_boiler_plate_top,
113  boiler_plate_bot=gz_boiler_plate_bot,
114  )
115  return compliant
116 
117 
119  """
120  Purpose: Create a sensor xacro file using the given
121  rosparameters
122  """
123  # Get yaml files for sensor number and pose
124  sensor_yaml = rospy.get_param('sensor_yaml')
125  rospy.loginfo('\nUsing %s as the sensor configuration yaml file\n' %
126  sensor_yaml)
127 
128  # Set sensor xacro target
129  sensor_xacro_target = yaml_to_xacro_extension(sensor_yaml)
130 
131  # Things to start/open the macro
132  sensor_boiler_plate_top = ('<?xml version="1.0"?>\n'
133  '<robot '
134  'xmlns:xacro="http://ros.org/wiki/xacro" '
135  'name="wam-v-sensors">\n' +
136  ' <xacro:macro name="yaml_sensors">\n')
137 
138  # Things to close the macro
139  sensor_boiler_plate_bot = ' </xacro:macro>\n</robot>'
140 
141  # Check if valid number of sensors and valid sensor parameters
142  comp = Sensor_Compliance()
143  sensor_num_test = comp.number_compliance
144  sensor_param_test = comp.param_compliance
145 
146  # Create sensor xacro with sensor macros
147  return create_xacro_file(yaml_file=sensor_yaml,
148  xacro_target=sensor_xacro_target,
149  boiler_plate_top=sensor_boiler_plate_top,
150  boiler_plate_bot=sensor_boiler_plate_bot,
151  num_test=sensor_num_test,
152  param_test=sensor_param_test)
153 
154 
156  return string[0:string.index('.')] + '.xacro'
def add_gazebo_thruster_config(xacro_target, yaml_file=None, requested_macros=None, boiler_plate_top='', boiler_plate_bot='')
Definition: utils.py:73


vrx_gazebo
Author(s): Brian Bingham , Carlos Aguero
autogenerated on Thu May 7 2020 03:54:56