feat: add the 4-leg trolley detection action
TrolleyDetectionActionHandler finds a 4-leg trolley in a raw LaserScan with dock_pattern_detector's LegPatternMatcher, filters the detections and writes a static dock_target frame for the docking leg that drives under the trolley. - entry_direction forward/backward sets the goal heading; a lidar that faces the wrong way fails the action instead of writing a reversed goal - an upside-down lidar (roll pi in TF) is detected from TF and its bearings are mirrored; a scan plane tilted more than 5 deg fails the action - profiles validated at boot; optional prior, reflective tape (all/entry) - gtest (11 tests) incl. a recorded Gazebo scan from a roll-pi lidar - sim models trolley_4legs (+ taped variants) the robot can drive under, spawn launch and generator script - doc/MEASURE_AND_CONFIGURE.md: how to measure a trolley and fill the profile
This commit is contained in:
116
sim/gen_trolley_models.py
Normal file
116
sim/gen_trolley_models.py
Normal file
@@ -0,0 +1,116 @@
|
||||
#!/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""" <collision name="{name}">
|
||||
<pose>{x:.4f} {y:.4f} {z0 + h / 2:.4f} 0 0 0</pose>
|
||||
<laser_retro>{retro}</laser_retro>
|
||||
<geometry><box><size>{LEG} {LEG} {h:.4f}</size></box></geometry>
|
||||
</collision>
|
||||
<visual name="{name}_visual">
|
||||
<pose>{x:.4f} {y:.4f} {z0 + h / 2:.4f} 0 0 0</pose>
|
||||
<geometry><box><size>{LEG} {LEG} {h:.4f}</size></box></geometry>
|
||||
<material><ambient>{colour}</ambient><diffuse>{colour}</diffuse></material>
|
||||
</visual>
|
||||
"""
|
||||
|
||||
|
||||
HEADER = """<?xml version="1.0"?>
|
||||
<!--
|
||||
Xe hàng 4 chân ĐƠN GIẢN cho trolley_detection_action trong Gazebo. Sinh bằng
|
||||
sim/gen_trolley_models.py — sửa số ở script rồi sinh lại, đừng sửa tay file này.
|
||||
|
||||
Kích thước chân khớp xe `tci_trolley` của world factory_ss_demo:
|
||||
cart_depth = {depth:.3f} m (trục X của model) cart_opening = {opening:.3f} m (trục Y)
|
||||
chân hộp {leg:.3f} x {leg:.3f} m, cao tới mặt dưới sàn xe {deck:.3f} m
|
||||
|
||||
KHÁC tci_trolley, cố ý:
|
||||
- gốc model ĐÚNG TÂM 4 chân, chân chạm sàn ở z = 0 → spawn z = 0, ground truth = pose model;
|
||||
- KHÔNG có tấm đáy 0.78 x 0.613 x 0.01 m sát sàn mà mesh tci_trolley mang theo (robot đâm vào
|
||||
nó khi chui gầm);
|
||||
- mặt dưới sàn xe ở {deck:.3f} m thay vì 0.352 m: không có khe dẫn hướng cho phần gồ 0.3595 m
|
||||
trên nóc hook_150, nên nâng sàn để chừa 20 mm;
|
||||
- không bánh xe, tay đẩy, thanh mảnh — chỉ chân + mặt sàn. Lidar (0.184 m) chỉ thấy 4 chân.
|
||||
{which}
|
||||
-->
|
||||
<sdf version="1.6">
|
||||
<model name="{name}">
|
||||
<static>true</static>
|
||||
<link name="frame">
|
||||
"""
|
||||
|
||||
FOOTER = f""" <collision name="deck">
|
||||
<pose>0 0 {DECK_Z + DECK_T / 2:.3f} 0 0 0</pose>
|
||||
<geometry><box><size>{DEPTH + LEG + 0.03:.3f} {OPENING + LEG + 0.03:.3f} {DECK_T:.3f}</size></box></geometry>
|
||||
</collision>
|
||||
<visual name="deck_visual">
|
||||
<pose>0 0 {DECK_Z + DECK_T / 2:.3f} 0 0 0</pose>
|
||||
<geometry><box><size>{DEPTH + LEG + 0.03:.3f} {OPENING + LEG + 0.03:.3f} {DECK_T:.3f}</size></box></geometry>
|
||||
</visual>
|
||||
</link>
|
||||
</model>
|
||||
</sdf>
|
||||
"""
|
||||
|
||||
|
||||
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"""<?xml version="1.0"?>
|
||||
<model>
|
||||
<name>{name}</name>
|
||||
<version>1.1</version>
|
||||
<sdf version="1.6">model.sdf</sdf>
|
||||
<author>
|
||||
<name>DuongTD</name>
|
||||
<email>tdd@gmail.com</email>
|
||||
</author>
|
||||
<description>
|
||||
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.
|
||||
</description>
|
||||
</model>
|
||||
""")
|
||||
|
||||
|
||||
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")
|
||||
Reference in New Issue
Block a user