File size: 2,272 Bytes
314ecfb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | """Dump traffic-light stop lines per town so recorder logs can be checked for red-light waits offline.
Usage: python traffic_light_stoplines.py --port 2000 --out stoplines.json [--towns Town12 Town13 ...]
Writes {town: [{"loc": [x, y], "stops": [[x, y, yaw_deg, road_id, lane_id], ...]}, ...]}; "loc" is the
traffic-light actor location in metres, which matches the recorder's "Create ...: traffic.traffic_light".
Stop signs go to {town + "/stop_signs": [[x, y, extent_x, extent_y], ...]} (trigger-volume centre and
half extents in metres).
"""
import argparse
import json
import xml.etree.ElementTree as ET
import carla
ROUTES = "leaderboard/data/bench2drive220.xml"
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--port", type=int, default=2000)
ap.add_argument("--out", required=True)
ap.add_argument("--towns", nargs="*")
args = ap.parse_args()
towns = args.towns or sorted({r.get("town") for r in ET.parse(ROUTES).getroot().iter("route")})
client = carla.Client("localhost", args.port, worker_threads=4)
client.set_timeout(600.0)
try:
out = json.load(open(args.out))
except FileNotFoundError:
out = {}
for town in towns:
if town in out and f"{town}/stop_signs" in out:
continue
world = client.load_world(town)
lights = []
for tl in world.get_actors().filter("traffic.traffic_light"):
loc = tl.get_location()
stops = [[w.transform.location.x, w.transform.location.y, w.transform.rotation.yaw, w.road_id, w.lane_id]
for w in tl.get_stop_waypoints()]
lights.append({"loc": [loc.x, loc.y], "stops": stops})
signs = []
for sign in world.get_actors().filter("traffic.stop"):
centre = sign.get_transform().transform(sign.trigger_volume.location)
signs.append([centre.x, centre.y, sign.trigger_volume.extent.x, sign.trigger_volume.extent.y])
out[town] = lights
out[f"{town}/stop_signs"] = signs
json.dump(out, open(args.out, "w"))
print(f"{town}: {len(lights)} traffic lights, {sum(len(l['stops']) for l in lights)} stop lines, "
f"{len(signs)} stop signs", flush=True)
if __name__ == "__main__":
main()
|