2026-11-08 19:04:32 +08:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
"""Measure physical MID360 lower-FOV limits. PASS characterizes a limitation, not safe navigation."""
|
|
|
|
|
import argparse,json,os,sys
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
import numpy as np
|
|
|
|
|
import rclpy
|
|
|
|
|
from gazebo_msgs.srv import SpawnEntity,DeleteEntity,GetEntityState
|
2026-11-08 22:44:02 +08:00
|
|
|
from check_omni_robot import Sim,sim_env, shutdown_probe
|
2026-11-08 19:04:32 +08:00
|
|
|
from check_mid360 import SensorProbe,rotate,json_value
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
ap=argparse.ArgumentParser();ap.add_argument('--out',required=True);args=ap.parse_args()
|
|
|
|
|
out=Path(args.out).resolve();out.mkdir(parents=True,exist_ok=True);os.environ.update(sim_env());os.environ['ROS_LOG_DIR']=str(out/'ros')
|
|
|
|
|
report=dict(status='INVALID',scope='stationary ideal sensor visibility only; not navigation acceptance',cases=[]);sim=Sim(str(out/'sim'));p=None
|
|
|
|
|
(out/'collector_snapshot.py').write_bytes(Path(__file__).read_bytes())
|
|
|
|
|
try:
|
|
|
|
|
ok,why=sim.start(lidar=True,drive='contact',sensor_model='mid360',spawn=(-4.5,4.5,.15,0.));report['startup']=why
|
|
|
|
|
if not ok:raise RuntimeError(why)
|
|
|
|
|
rclpy.init();p=SensorProbe()
|
|
|
|
|
if not p.wait_clock():raise RuntimeError('no clock')
|
|
|
|
|
spawn=p.create_client(SpawnEntity,'/spawn_entity');delete=p.create_client(DeleteEntity,'/delete_entity');p.pump(2.)
|
|
|
|
|
for distance,height in [(1.5,.03),(3.,.03),(1.5,.08),(3.,.08),(1.5,.15),(3.,.15),(.6,.3),(1.5,.3),(1.5,.6)]:
|
|
|
|
|
state=p.get_state()
|
|
|
|
|
if state is None:raise RuntimeError('no physical observer pose')
|
|
|
|
|
center=np.array([state['pos'][0]+distance,state['pos'][1],height/2])
|
|
|
|
|
# The far TOP face can be visible even if the front face is below
|
|
|
|
|
# the lower FOV. Include box depth; a point-target approximation
|
2026-11-12 16:42:07 +08:00
|
|
|
# can misclassify a fixture near the lower-FOV boundary.
|
|
|
|
|
q=np.array(state['quaternion']);origin=np.array(state['pos'])+rotate(q,np.array([.015,0.,.33]))
|
2026-11-08 19:04:32 +08:00
|
|
|
inverse=q.copy();inverse[:3]*=-1
|
|
|
|
|
corners=np.array([[center[0]+dx,center[1]+dy,height] for dx in (-.125,.125) for dy in (-.125,.125)])
|
|
|
|
|
local=rotate(inverse,corners-origin)
|
|
|
|
|
maximum_elevation=float(np.arctan2(local[:,2],np.linalg.norm(local[:,:2],axis=1)).max())
|
|
|
|
|
visible=maximum_elevation>=np.deg2rad(-7)
|
|
|
|
|
req=SpawnEntity.Request();req.name='visibility_box_%02d'%len(report['cases']);req.reference_frame='world';req.initial_pose.position.x=float(center[0]);req.initial_pose.position.y=float(center[1]);req.initial_pose.position.z=float(center[2]);req.initial_pose.orientation.w=1.
|
|
|
|
|
req.xml=f'<sdf version="1.6"><model name="visibility_box"><static>true</static><link name="box"><collision name="box"><geometry><box><size>0.25 0.25 {height}</size></box></geometry></collision><visual name="box"><geometry><box><size>0.25 0.25 {height}</size></box></geometry></visual></link></model></sdf>'
|
|
|
|
|
response=p._call(spawn,req,timeout=10)
|
|
|
|
|
if not response or not response.success:raise RuntimeError('box not spawned')
|
|
|
|
|
query=GetEntityState.Request();query.name=req.name;query.reference_frame='world'
|
|
|
|
|
p.pump(.2);exists=p._call(p.cli_get,query,timeout=10)
|
|
|
|
|
if not exists or not exists.success:raise RuntimeError('spawned fixture not independently queryable')
|
|
|
|
|
p.pump(.2);t=p.now();p.pump(1.5)
|
|
|
|
|
frames=[f for f in p.frames if t<f['t'] and f['t']+.1<p.now()]
|
|
|
|
|
if len(frames)<8:raise RuntimeError('insufficient actual scans')
|
2026-11-12 16:42:07 +08:00
|
|
|
q=np.array(state['quaternion']);origin=np.array(state['pos'])+rotate(q,np.array([.015,0.,.33]));all_world=[]
|
2026-11-08 19:04:32 +08:00
|
|
|
for f in frames:all_world.append(rotate(q,f['xyz'])+origin)
|
|
|
|
|
world=np.concatenate(all_world)
|
|
|
|
|
in_box=(abs(world[:,0]-center[0])<.126)&(abs(world[:,1]-center[1])<.126)&(world[:,2]>.005)&(world[:,2]<=height+.002)
|
|
|
|
|
count=int(in_box.sum());ok=count>=5 if visible else count==0
|
|
|
|
|
case=dict(distance_m=distance,height_m=height,expected_visible=visible,observed_returns=count,frames=len(frames),ok=ok,
|
|
|
|
|
navigation_capability='visible points only; motion untested' if count else 'UNSUPPORTED: no returns, cannot promise avoidance')
|
|
|
|
|
report['cases'].append(case);np.savez_compressed(out/('fixture_%02d.npz'%len(report['cases'])),returns=world[in_box],fixture_center=center,observer_position=state['pos'],observer_quaternion=q)
|
|
|
|
|
print(case,flush=True)
|
|
|
|
|
remove=DeleteEntity.Request();remove.name=req.name;response=p._call(delete,remove,timeout=10)
|
|
|
|
|
if response is None:raise RuntimeError('missing delete response')
|
|
|
|
|
case['fixture_name']=req.name;case['delete_response_success']=response.success;case['delete_response']=response.status_message
|
|
|
|
|
# Gazebo deletion is asynchronous. Confirm actual absence, using a
|
|
|
|
|
# unique name so an old deletion cannot affect a subsequent fixture.
|
|
|
|
|
for _ in range(30):
|
|
|
|
|
p.pump(.05);exists=p._call(p.cli_get,query,timeout=10)
|
|
|
|
|
if exists is not None and not exists.success:break
|
|
|
|
|
else:raise RuntimeError('owned fixture still exists after deletion')
|
|
|
|
|
p.pump(.2)
|
|
|
|
|
report['status']='PASS' if all(c['ok'] for c in report['cases']) else 'FAIL'
|
|
|
|
|
except Exception as e:report['error']=repr(e);print(report['error'],flush=True)
|
|
|
|
|
finally:
|
2026-11-08 22:44:02 +08:00
|
|
|
report['ros_cleanup_errors'] = shutdown_probe(p)
|
2026-11-08 19:04:32 +08:00
|
|
|
report['teardown']=sim.stop();(out/'result.json').write_text(json.dumps(report,indent=2,default=json_value)+'\n')
|
|
|
|
|
return dict(PASS=0,FAIL=30,INVALID=40)[report['status']]
|
|
|
|
|
|
|
|
|
|
if __name__=='__main__':sys.exit(main())
|