#!/usr/bin/env python3 """Generate the simple 4-leg trolley SDF models in sim/models. Run from anywhere: python3 sim/gen_trolley_models.py sim/models Edit the numbers here and regenerate; do not hand-edit the .sdf files. """ import os import sys OUT = sys.argv[1] DEPTH, OPENING, LEG = 0.720, 0.517, 0.030 # [m] leg centres and leg section, same as tci_trolley # [m] Underside of the deck. The real tci_trolley sits at 0.352 m and relies on a guide slot for the # 0.3595 m hump of hook_150; these models have no slot, so the deck is raised to leave 20 mm. DECK_Z = 0.380 DECK_T = 0.020 # [m] deck thickness BAND = (0.14, 0.24) # [m] reflective band around the lidar plane (0.184) CORNERS = [("entry_left", DEPTH / 2, OPENING / 2), ("entry_right", DEPTH / 2, -OPENING / 2), ("far_left", -DEPTH / 2, OPENING / 2), ("far_right", -DEPTH / 2, -OPENING / 2)] def box(name, x, y, z0, z1, retro): h = z1 - z0 colour = '0.9 0.9 0.2 1' if retro else '0.3 0.3 0.3 1' return f""" {x:.4f} {y:.4f} {z0 + h / 2:.4f} 0 0 0 {retro} {LEG} {LEG} {h:.4f} {x:.4f} {y:.4f} {z0 + h / 2:.4f} 0 0 0 {LEG} {LEG} {h:.4f} {colour}{colour} """ HEADER = """ true """ FOOTER = f""" 0 0 {DECK_Z + DECK_T / 2:.3f} 0 0 0 {DEPTH + LEG + 0.03:.3f} {OPENING + LEG + 0.03:.3f} {DECK_T:.3f} 0 0 {DECK_Z + DECK_T / 2:.3f} 0 0 0 {DEPTH + LEG + 0.03:.3f} {OPENING + LEG + 0.03:.3f} {DECK_T:.3f} """ def model(name, taped, which, summary): text = HEADER.format(depth=DEPTH, opening=OPENING, leg=LEG, deck=DECK_Z, which=which, name=name) for leg, x, y in CORNERS: if leg in taped: text += box(f"{leg}_low", x, y, 0.0, BAND[0], 0) text += box(f"{leg}_band", x, y, BAND[0], BAND[1], 2000) text += box(f"{leg}_high", x, y, BAND[1], DECK_Z, 0) else: text += box(leg, x, y, 0.0, DECK_Z, 0) text += FOOTER d = os.path.join(OUT, name) os.makedirs(d, exist_ok=True) with open(os.path.join(d, "model.sdf"), "w") as f: f.write(text) with open(os.path.join(d, "model.config"), "w") as f: f.write(f""" {name} 1.1 model.sdf DuongTD tdd@gmail.com Xe hàng 4 chân 0.720 x 0.517 m, chân hộp 30 mm, sàn xe cao {DECK_Z:.3f} m, {summary}. Gốc model ở tâm 4 chân. Dùng chạy thử trolley_detection_action + chui gầm trong Gazebo. """) model("trolley_4legs", set(), "Bản này: KHÔNG dải phản quang — dò bằng hình học (`tape_enabled: false`).", "không dải phản quang") model("trolley_4legs_tape_all", {"entry_left", "entry_right", "far_left", "far_right"}, "Bản này: dải trên CẢ 4 chân (`tape_legs: all`), collision 0.14–0.24 m khai laser_retro 2000.", "dải phản quang cả 4 chân") model("trolley_4legs_tape_entry", {"entry_left", "entry_right"}, "Bản này: dải chỉ trên 2 chân ở đầu +X (`tape_legs: entry`) — đầu +X là cạnh vào.", "dải phản quang 2 chân đầu +X") print("ok")