94 lines
5.1 KiB
Python
94 lines
5.1 KiB
Python
"""Read-only live signal survey plus explicitly hypothetical route-lane replays.
|
|
|
|
The wider survey does not change the runtime reader's 350 m radius or any game
|
|
state. Replay poses establish the ID/geometry join, not current truck location,
|
|
GPS intent, path validation or permission to operate controls.
|
|
"""
|
|
import json
|
|
import math
|
|
from pathlib import Path
|
|
import sys
|
|
import time
|
|
|
|
import numpy as np
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(ROOT))
|
|
from control.native_route_planner import NativeRoutePlanner
|
|
from control.native_signal_planner import NativeSignalPlanner
|
|
from telemetry.ats_telemetry import ATSTelemetry
|
|
from telemetry.driving_scene import DrivingSceneBuilder
|
|
from telemetry.native_lanes import NativeLaneGraph
|
|
import telemetry.native_signals as native_signals
|
|
|
|
|
|
def main():
|
|
sdk, reader = ATSTelemetry(), native_signals.NativeSignalsReader()
|
|
graph_reader = NativeLaneGraph(radius_m=2500., max_lanes=10000)
|
|
try:
|
|
sdk.get_data(); time.sleep(.08)
|
|
actual = sdk.get_data()
|
|
graph = graph_reader.snapshot(actual)
|
|
if graph_reader.cache is not None and not graph_reader.reason:
|
|
# A wide semaphore survey covers streets at different elevations.
|
|
# Use the source-validated extracted graph rather than the normal
|
|
# ego-height neighborhood filter for these hypothetical replays.
|
|
graph = dict(graph,available=True,lanes=graph_reader.cache['lanes'],
|
|
connections=graph_reader.cache['connections'])
|
|
native_signals.MAX_RANGE_M = 2500. # This short-lived diagnostic process only.
|
|
report = reader.snapshot(actual, graph)
|
|
if report.get('available') is not True or graph.get('available') is not True:
|
|
raise ValueError(str(dict(signals=report.get('reason'),graph=graph.get('reason'))))
|
|
stamp = report['sampled_at']
|
|
# Captured snapshot replay time is explicit. Nothing is handed to the
|
|
# running controller, and graph eligibility remains false throughout.
|
|
graph = dict(graph,sampled_at=stamp,age_s=0.)
|
|
report = dict(report,age_s=0.)
|
|
signal_keys = {(s['prefab_uid'],s['semaphore_id']) for s in report['signals']}
|
|
records = []
|
|
for lane in graph['lanes']:
|
|
if lane.get('kind') != 'prefab' or lane.get('large_vehicle_suitable') is False:
|
|
continue
|
|
if not any((lane['prefab_uid'],c['semaphore_id']) in signal_keys for c in lane['curves']):
|
|
continue
|
|
points = np.asarray(lane['centerline'],float)
|
|
tangent = points[1]-points[0]; length = np.linalg.norm(tangent[[0,2]])
|
|
if length < .01:
|
|
continue
|
|
tangent /= length
|
|
pose = points[0]+tangent*.5
|
|
yaw = math.atan2(-tangent[0],-tangent[2])/(2*math.pi)
|
|
candidate_graph = dict(graph,lanes=[lane],connections=[])
|
|
data = dict(valid=True,paused=False,age=0.,position_valid=True,speed_mps=2.,
|
|
world_position=pose.tolist(),world_rotation=[yaw,0.,0.],native_lane_graph=candidate_graph,
|
|
navigation_route=dict(available=True,sampled_at=stamp,age_s=0.,revision='hypothetical:'+lane['id'],
|
|
nodes=[{'uid':lane['start_node_uid']},{'uid':lane['end_node_uid']}]),
|
|
traffic_signals=report,
|
|
nearby_traffic=dict(available=True,sampled_at=stamp,age_s=0.,
|
|
ego_geometry_available=True,own_front_extent_m=4.))
|
|
scene = DrivingSceneBuilder().snapshot(data,stamp)
|
|
path = NativeRoutePlanner().assess(scene)
|
|
plan = NativeSignalPlanner().assess(scene,path)
|
|
if plan.get('association'):
|
|
records.append(dict(lane_id=lane['id'],hypothetical_pose=pose.tolist(),
|
|
hypothetical_speed_mps=2.,hypothetical_front_extent_m=4.,
|
|
authored_lane_source=lane['provenance'],plan=plan))
|
|
output = dict(read_only=True,controls_issued=False,
|
|
purpose='Exact selected-lane/stop-point/live-phase association proof; hypothetical pose replays only',
|
|
current_truck_route_validated=False,current_truck_route_sampled=False,
|
|
actual_truck_pose=actual['world_position'],actual_truck_speed_mps=actual['speed_mps'],
|
|
actual_truck_park_brake=actual['park_brake'],signal_sampled_at=stamp,
|
|
live_signal_count=len(report['signals']),survey_range_m=2500.,
|
|
graph_provenance=graph['provenance'],rule_provenance=report['traffic_rule_definition'],
|
|
selected_stop_plans=records)
|
|
destination = ROOT/'diagnostics/native-signals/selected-stop-plans.json'
|
|
destination.write_text(json.dumps(output,indent=2,allow_nan=False))
|
|
print(json.dumps(dict(path=str(destination),live_signals=len(report['signals']),
|
|
association_proofs=len(records),states={state:sum(p['plan']['state']==state for p in records)
|
|
for state in ('stop','hold','proceed','unknown')},controls_issued=False)))
|
|
finally:
|
|
reader.close();sdk.close();graph_reader.close()
|
|
|
|
|
|
if __name__ == '__main__':main()
|