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
167 lines
8.2 KiB
Python
167 lines
8.2 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""Sinh hinh cho doc/MEASURE_AND_CONFIGURE.md. Moi hinh ve tu SO THAT cua tci_trolley + hook_150.
|
||
|
||
Chay: python3 doc/gen_fig.py (ghi ra doc/fig/*.svg)
|
||
"""
|
||
import math
|
||
import os
|
||
|
||
import matplotlib
|
||
matplotlib.use('Agg')
|
||
import matplotlib.pyplot as plt
|
||
from matplotlib.patches import FancyArrowPatch, Rectangle
|
||
|
||
plt.rcParams['font.family'] = 'DejaVu Sans'
|
||
plt.rcParams['font.size'] = 9
|
||
plt.rcParams['svg.fonttype'] = 'path' # nhung chu thanh duong -> khong phu thuoc font may in
|
||
|
||
OUT = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'fig')
|
||
INK, ACC, WARN, MUT = '#1b2733', '#1f6feb', '#c9401a', '#7d8996'
|
||
GRID, TAPE = '#dfe4ea', '#e0b000'
|
||
|
||
# tci_trolley (factory_ss_demo) + hook_150, [m]
|
||
D, O, W = 0.720, 0.517, 0.030 # cart_depth, cart_opening, leg_width
|
||
RW, RL, RTOP = 0.390, 1.031, 0.3595 # robot width, length, top
|
||
LIDAR_X, H_SENSOR = 0.454, 0.184 # lidar ahead of base_link, scan plane height
|
||
H_DECK = 0.380 # example deck underside (sim model trolley_4legs)
|
||
|
||
|
||
def save(fig, name):
|
||
os.makedirs(OUT, exist_ok=True)
|
||
fig.savefig(os.path.join(OUT, name), format='svg', bbox_inches='tight', transparent=True)
|
||
plt.close(fig)
|
||
print(' ', name)
|
||
|
||
|
||
def frame(ax, xlim, ylim, title=None):
|
||
ax.set_xlim(*xlim)
|
||
ax.set_ylim(*ylim)
|
||
ax.set_aspect('equal')
|
||
ax.grid(True, color=GRID, lw=0.5, zorder=0)
|
||
for s in ('top', 'right'):
|
||
ax.spines[s].set_visible(False)
|
||
for s in ('left', 'bottom'):
|
||
ax.spines[s].set_color(MUT)
|
||
ax.tick_params(colors=MUT, labelsize=7)
|
||
if title:
|
||
ax.set_title(title, color=INK, fontsize=10, pad=8)
|
||
|
||
|
||
def arrow(ax, p, q, color=ACC, lw=1.4, style='-|>', ms=9):
|
||
ax.add_patch(FancyArrowPatch(p, q, arrowstyle=style, mutation_scale=ms, color=color, lw=lw,
|
||
zorder=6, shrinkA=0, shrinkB=0))
|
||
|
||
|
||
def dim(ax, p, q, text, offset=(0, 0), color=INK, rot=0):
|
||
arrow(ax, p, q, color=color, lw=0.9, style='<|-|>', ms=7)
|
||
mx, my = (p[0] + q[0]) / 2 + offset[0], (p[1] + q[1]) / 2 + offset[1]
|
||
ax.text(mx, my, text, color=color, fontsize=8, ha='center', va='center', rotation=rot,
|
||
bbox=dict(fc='white', ec='none', alpha=0.85, pad=1.2), zorder=7)
|
||
|
||
|
||
def leg(ax, x, y, taped=False, w=W):
|
||
ax.add_patch(Rectangle((x - w / 2, y - w / 2), w, w, fc=TAPE if taped else INK, ec=INK, lw=0.6,
|
||
zorder=5))
|
||
|
||
|
||
def cart_top():
|
||
"""Nhin tu tren xuong: kich thuoc, canh vao, dich ra va heading."""
|
||
fig, ax = plt.subplots(figsize=(9.4, 4.4))
|
||
frame(ax, (-0.75, 2.40), (-0.62, 0.62), 'Xe hàng 4 chân nhìn từ trên xuống (số của tci_trolley)')
|
||
corners = [(D / 2, O / 2), (D / 2, -O / 2), (-D / 2, O / 2), (-D / 2, -O / 2)]
|
||
for x, y in corners:
|
||
leg(ax, x, y)
|
||
# sàn xe (mờ)
|
||
ax.add_patch(Rectangle((-D / 2 - 0.03, -O / 2 - 0.03), D + 0.06, O + 0.06, fc='none', ec=MUT,
|
||
lw=0.8, ls=':', zorder=2))
|
||
# cạnh vào
|
||
ax.plot([D / 2, D / 2], [-O / 2, O / 2], color=ACC, lw=2.2, alpha=0.35, zorder=3)
|
||
ax.text(D / 2 + 0.03, 0.0, 'CẠNH VÀO', color=ACC, fontsize=8, rotation=90, ha='left',
|
||
va='center')
|
||
# kích thước
|
||
dim(ax, (D / 2 + 0.17, -O / 2), (D / 2 + 0.17, O / 2), 'cart_opening\n0.517', offset=(0.12, 0))
|
||
dim(ax, (-D / 2, -O / 2 - 0.12), (D / 2, -O / 2 - 0.12), 'cart_depth 0.720')
|
||
ax.plot([-D / 2, D / 2], [O / 2, -O / 2], color=MUT, lw=0.8, ls='--', zorder=3)
|
||
ax.text(-0.17, 0.16, 'đường chéo 0.886', color=MUT, fontsize=7.5, rotation=-35)
|
||
# tâm + heading
|
||
ax.plot([0], [0], marker='+', ms=12, mew=2, color=WARN, zorder=7)
|
||
arrow(ax, (0, 0), (-0.30, 0), color=WARN)
|
||
ax.text(-0.30, 0.05, 'forward:\nheading VÀO xe', color=WARN, fontsize=7.5, ha='center',
|
||
va='bottom')
|
||
arrow(ax, (0, 0), (0.25, 0), color=WARN, lw=1.0)
|
||
ax.text(0.20, 0.05, 'backward:\nRA cạnh vào', color=WARN, fontsize=7.5, ha='center',
|
||
va='bottom')
|
||
ax.text(0.0, -0.09, 'dock_target = tâm 4 chân + offset', color=WARN, fontsize=7.5,
|
||
ha='center', va='top', bbox=dict(fc='white', ec='none', alpha=0.85, pad=1.0))
|
||
# robot đứng dò, tiến vào (forward)
|
||
rc = D / 2 + 1.00 + LIDAR_X # cạnh vào cách lidar 1.0 m
|
||
ax.add_patch(Rectangle((rc - RL / 2, -RW / 2), RL, RW, fc='none', ec=INK, lw=1.0, zorder=4))
|
||
ax.plot([rc - LIDAR_X], [0], marker='o', ms=6, color=ACC, zorder=6)
|
||
ax.text(rc - LIDAR_X, 0.06, 'lidar trước', color=ACC, fontsize=7.5, ha='center')
|
||
ax.plot([rc], [0], marker='+', ms=8, color=INK)
|
||
ax.text(rc, -0.07, 'base_link', color=INK, fontsize=7.5, ha='center')
|
||
arrow(ax, (rc + 0.35, 0.30), (rc - 0.25, 0.30), color=INK, lw=1.0)
|
||
ax.text(rc + 0.05, 0.36, 'robot tiến vào', color=INK, fontsize=7.5, ha='center')
|
||
ax.set_xlabel('[m]', color=MUT, fontsize=7)
|
||
save(fig, 'cart_top.svg')
|
||
|
||
|
||
def leg_measure():
|
||
"""Đo tâm–tâm chân bằng hai lần đo mép."""
|
||
fig, ax = plt.subplots(figsize=(6.4, 3.2))
|
||
frame(ax, (-0.42, 0.42), (-0.16, 0.16), 'Đo tâm–tâm hai chân: không chấm được tâm thì đo hai mép')
|
||
big = 0.06 # vẽ chân to gấp đôi cho dễ nhìn; số ghi là số thật
|
||
for y in (-O / 2, O / 2):
|
||
ax.add_patch(Rectangle((y - big / 2, -big / 2), big, big, fc=INK, ec=INK, zorder=5))
|
||
dim(ax, (-O / 2 - big / 2, 0.10), (O / 2 + big / 2, 0.10), 'a = mép NGOÀI – mép ngoài')
|
||
dim(ax, (-O / 2 + big / 2, -0.10), (O / 2 - big / 2, -0.10), 'b = mép TRONG – mép trong')
|
||
dim(ax, (-O / 2, 0.0), (O / 2, 0.0), 'tâm–tâm = (a + b) / 2', color=WARN)
|
||
ax.text(0, -0.145, 'chân vẽ phóng to; cùng công thức cho chân tròn. bề rộng chân = (a − b) / 2',
|
||
color=MUT, fontsize=7.5, ha='center')
|
||
ax.set_yticks([])
|
||
save(fig, 'leg_measure.svg')
|
||
|
||
|
||
def cart_section():
|
||
"""Nhìn dọc hướng chui: khe hai bên, khe gầm, mặt quét lidar, dải phản quang."""
|
||
fig, ax = plt.subplots(figsize=(8.4, 4.8))
|
||
frame(ax, (-0.62, 0.62), (-0.03, 0.52), 'Nhìn dọc hướng chui (cạnh vào) — robot hook_150 dưới gầm')
|
||
ax.plot([-0.62, 0.62], [0, 0], color=INK, lw=1.4)
|
||
ax.text(0.60, 0.008, 'sàn', color=MUT, fontsize=7.5, ha='right', va='bottom')
|
||
for y in (-O / 2, O / 2):
|
||
ax.add_patch(Rectangle((y - W / 2, 0), W, H_DECK, fc=INK, ec=INK, zorder=4))
|
||
ax.add_patch(Rectangle((y - W / 2 - 0.004, H_SENSOR - 0.05), W + 0.008, 0.10, fc=TAPE,
|
||
ec='none', zorder=5))
|
||
ax.add_patch(Rectangle((-O / 2 - 0.03, H_DECK), O + 0.06, 0.02, fc=MUT, ec=INK, lw=0.6,
|
||
zorder=4))
|
||
ax.text(-0.30, H_DECK + 0.035, 'sàn xe — mặt dưới thấp nhất trên lối robot: h_gầm', color=INK,
|
||
fontsize=7.5, ha='left')
|
||
# robot: thân + gồ trên nóc
|
||
ax.add_patch(Rectangle((-RW / 2, 0.02), RW, 0.31, fc='#eef2f6', ec=INK, lw=1.0, zorder=3))
|
||
ax.add_patch(Rectangle((-0.12, 0.33), 0.24, RTOP - 0.33, fc='#eef2f6', ec=INK, lw=1.0,
|
||
zorder=3))
|
||
ax.text(0, 0.10, 'robot\nrộng 0.390', color=INK, fontsize=8, ha='center')
|
||
ax.text(0.13, RTOP - 0.012, 'nóc 0.3595', color=INK, fontsize=7, ha='left', va='top')
|
||
# mặt quét
|
||
ax.plot([-0.62, 0.62], [H_SENSOR, H_SENSOR], color=ACC, lw=1.0, ls='--', zorder=6)
|
||
ax.text(-0.61, H_SENSOR + 0.008, 'mặt quét lidar\nh_sensor = 0.184', color=ACC, fontsize=7.5)
|
||
ax.text(O / 2 + 0.03, H_SENSOR, 'dải phản quang\nh_sensor ± 5 cm', color='#8a6d00',
|
||
fontsize=7, va='center')
|
||
# khe hai bên
|
||
gap = (O - W - RW) / 2
|
||
dim(ax, (RW / 2, 0.26), (O / 2 - W / 2, 0.26), '', color=WARN)
|
||
ax.text(RW / 2 - 0.005, 0.26, 'khe hai bên %.1f mm' % (gap * 1000), color=WARN, fontsize=7.5,
|
||
ha='right', va='center')
|
||
dim(ax, (0.0, RTOP), (0.0, H_DECK), '', color=WARN)
|
||
ax.annotate('khe gầm = h_gầm − nóc robot', xy=(0.005, (RTOP + H_DECK) / 2), xytext=(0.30, 0.47),
|
||
color=WARN, fontsize=7.5, arrowprops=dict(arrowstyle='-', color=WARN, lw=0.7))
|
||
ax.set_xlabel('[m] ngang hướng chui', color=MUT, fontsize=7)
|
||
save(fig, 'cart_section.svg')
|
||
|
||
|
||
if __name__ == '__main__':
|
||
print('fig ->', OUT)
|
||
cart_top()
|
||
leg_measure()
|
||
cart_section()
|