38 Generate YAML calibration file from Velodyne db.xml. 40 The input data provided by the manufacturer are in degrees and 41 centimeters. The YAML file uses radians and meters, following ROS 46 from __future__
import print_function
52 from xml.etree
import ElementTree
56 usage =
"""usage: %prog infile.xml [outfile.yaml] 58 Default output file is input file with .yaml suffix.""" 59 parser = optparse.OptionParser(usage=usage)
60 options, args = parser.parse_args()
63 parser.error(
'XML file name missing')
70 yamlFile, ext = os.path.splitext(xmlFile)
73 print(
'converting "' + xmlFile +
'" to "' + yamlFile +
'"')
75 calibrationGood =
True 77 'handle XML calibration error' 78 global calibrationGood
79 calibrationGood =
False 80 print(
'gen_calibration.py: ' + msg)
84 db = ElementTree.parse(xmlFile)
86 xmlError(
'unable to read ' + xmlFile)
87 except ElementTree.ParseError:
88 xmlError(
'XML parse failed for ' + xmlFile)
90 if not calibrationGood:
94 calibration = {
'num_lasers': 0,
'lasers': [],
'distance_resolution': 0.2}
98 'Define key and corresponding value for laser_num' 100 if laser_num < len(calibration[
'lasers']):
101 calibration[
'lasers'][laser_num][key] = val
103 calibration[
'lasers'].append({key: val})
108 enabled = db.find(
'DB/enabled_')
110 print(
'no enabled tags found: assuming all 64 enabled')
112 enabled_lasers = [
True for i
in xrange(num_enabled)]
117 this_enabled = int(el.text) != 0
118 enabled_lasers.append(this_enabled)
123 calibration[
'num_lasers'] = num_enabled
124 print(str(num_enabled) +
' lasers')
127 distLSB = db.find(
'DB/distLSB_')
129 calibration[
'distance_resolution'] = float(distLSB.text) * cm2meters
132 minIntensities = db.find(
'DB/minIntensity_')
133 if minIntensities !=
None:
135 for el
in minIntensities:
137 if enabled_lasers[index]:
144 maxIntensities = db.find(
'DB/maxIntensity_')
145 if maxIntensities !=
None:
147 for el
in maxIntensities:
149 if enabled_lasers[index]:
156 for el
in db.find(
'DB/points_'):
160 if field.tag ==
'id_':
161 index = int(field.text)
162 if not enabled_lasers[index]:
166 if field.tag ==
'rotCorrection_':
168 math.radians(float(field.text)))
169 elif field.tag ==
'vertCorrection_':
171 math.radians(float(field.text)))
172 elif field.tag ==
'distCorrection_':
174 float(field.text) * cm2meters)
175 elif field.tag ==
'distCorrectionX_':
177 float(field.text) * cm2meters)
178 elif field.tag ==
'distCorrectionY_':
180 float(field.text) * cm2meters)
181 elif field.tag ==
'vertOffsetCorrection_':
183 float(field.text) * cm2meters)
184 elif field.tag ==
'horizOffsetCorrection_':
186 float(field.text) * cm2meters)
187 elif field.tag ==
'focalDistance_':
189 float(field.text) * cm2meters)
190 elif field.tag ==
'focalSlope_':
194 if calibration[
'num_lasers'] <= 0:
196 elif calibration[
'num_lasers'] != num_enabled:
197 xmlError(
'inconsistent number of lasers defined')
205 f = open(yamlFile,
'w')
207 yaml.dump(calibration, f)
def addLaserCalibration(laser_num, key, val)