70 lines
3.5 KiB
Python
70 lines
3.5 KiB
Python
#!/usr/bin/python3
|
|||
|
|
"""Check the measured vehicle envelope and sensor reference points before Gazebo.
|
||
|
|
|
||
|
|
Independent acceptance targets are the user's 2026-11-10 measurements. This
|
||
|
|
checks generated geometry/configuration; runtime rays/navigation remain separate.
|
||
|
|
"""
|
||
|
|
import argparse
|
||
|
|
import json
|
||
|
|
from pathlib import Path
|
||
|
|
import xml.etree.ElementTree as ET
|
||
|
|
|
||
|
|
import numpy as np
|
||
|
|
import xacro
|
||
|
|
import yaml
|
||
|
|
from check_omni_robot import check_model_geometry
|
||
|
|
|
||
|
|
ROOT = Path(__file__).resolve().parents[2]
|
||
|
|
ROBOT = ROOT / 'sim_ws/src/r2027_robot_description'
|
||
|
|
BASE_HEIGHT = .15
|
||
|
|
OPTICAL = np.array([.015, 0., .48 - BASE_HEIGHT])
|
||
|
|
IMU = OPTICAL + [.011, .02329, -.04412]
|
||
|
|
|
||
|
|
|
||
|
|
def main():
|
||
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
||
|
|
parser.add_argument('--out', required=True)
|
||
|
|
out = Path(parser.parse_args().out).resolve()
|
||
|
|
out.mkdir(parents=True, exist_ok=True)
|
||
|
|
checks = {}
|
||
|
|
report = {'status': 'INVALID', 'checks': checks,
|
||
|
|
'scope': 'generated SDF and configuration; not runtime acceptance'}
|
||
|
|
try:
|
||
|
|
geometry = check_model_geometry(str(out), 'contact')
|
||
|
|
report['geometry'] = geometry
|
||
|
|
checks['vehicle_envelope'] = geometry['ok'] and np.allclose(
|
||
|
|
geometry['size_xyz'], [.8, .8, .41], atol=1e-9, rtol=0)
|
||
|
|
checks['base_ground_reference'] = abs(geometry['ground_below_base_link'] - BASE_HEIGHT) < 1e-9
|
||
|
|
root = ET.fromstring(xacro.process_file(str(ROBOT / 'sdf/r2027_omni_robot.sdf.xacro'),
|
||
|
|
mappings={'lidar': 'true', 'sensor_model': 'mid360', 'drive': 'contact'}).toxml())
|
||
|
|
(out / 'mid360_expanded.sdf').write_bytes(ET.tostring(root))
|
||
|
|
optical = np.fromstring(root.findtext(".//plugin[@name='mid360_sensor']/lidar_position"), sep=' ')
|
||
|
|
imu = np.fromstring(root.findtext(".//sensor[@name='mid360_imu']/pose"), sep=' ')[:3]
|
||
|
|
checks['physical_optical_mount'] = np.allclose(optical, OPTICAL, atol=1e-9, rtol=0)
|
||
|
|
checks['physical_imu_mount'] = np.allclose(imu, IMU, atol=1e-9, rtol=0)
|
||
|
|
for name in ('lio_navigation', 'lio_terrain'):
|
||
|
|
cfg = yaml.safe_load((ROOT / f'sim_ws/src/br_sim_bringup/config/{name}.yaml').read_text())
|
||
|
|
parameters = cfg['lio_navigation_adapter']['ros__parameters']
|
||
|
|
checks[name + '_optical'] = np.allclose(parameters['lidar_position_base'], OPTICAL, atol=1e-9, rtol=0)
|
||
|
|
checks[name + '_imu'] = np.allclose(parameters['imu_position_base'], IMU, atol=1e-9, rtol=0)
|
||
|
|
inertia = root.find('.//inertial')
|
||
|
|
mass = float(inertia.findtext('mass'))
|
||
|
|
com = np.fromstring(inertia.findtext('pose'), sep=' ')[:3]
|
||
|
|
diagonal = np.array([float(inertia.findtext('inertia/' + key)) for key in ('ixx', 'iyy', 'izz')])
|
||
|
|
checks['inertia_physical'] = bool(mass > 0 and np.all(diagonal > 0) and np.all(2 * diagonal < diagonal.sum()))
|
||
|
|
checks['combined_com'] = np.allclose(com, [0., 0., (5.51*.09 + 4*1.2*(-.05))/10.31], atol=1e-9, rtol=0)
|
||
|
|
report.update(optical_base_m=optical.tolist(), imu_base_m=imu.tolist(),
|
||
|
|
nominal_optical_above_ground_m=float(optical[2] + BASE_HEIGHT),
|
||
|
|
assumed_mass_kg=mass, assumed_com_m=com.tolist(),
|
||
|
|
assumed_inertia_diagonal_kg_m2=diagonal.tolist())
|
||
|
|
report['status'] = 'PASS' if all(checks.values()) else 'FAIL'
|
||
|
|
except Exception as error:
|
||
|
|
report['error'] = repr(error)
|
||
|
|
(out / 'result.json').write_text(json.dumps(report, indent=2) + '\n')
|
||
|
|
print(json.dumps(report, indent=2))
|
||
|
|
return {'PASS': 0, 'FAIL': 30, 'INVALID': 40}[report['status']]
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == '__main__':
|
||
|
|
raise SystemExit(main())
|