Files
vslam_cpp/tools/gen_two_ramp_world.py

171 lines
8.2 KiB
Python

#!/usr/bin/env python3
"""Sinh world mo phong HAI DOC: resources/worlds/slope_two_ramps.world + hai model.
Gon hon slope_test (5 lan doc): mot sanh phang o giua, moi ben mot doc len mot
tang. Quet het mot vong (len doc trai, vong tang trai, xuong, qua sanh, len doc
phai, vong tang phai, xuong) ~85 m, ~5 phut o 0.3 m/s, va moi doc deu da di CA
LEN LAN XUONG -- camera dinh vi lai nhan ra ca hai huong.
Bo cuc (nhin tu tren xuong, x sang phai, y len tren; met):
y=8 +---------+--#------#---+-------------------+-----------+---------+
| | | | | |
| TANG | doc 10 do | | doc 15 | TANG |
| TRAI | rong 8 m | SANH GIUA | do, rong | PHAI |
| z=1.5 | | z = 0 | 8 m | z=1.5 |
| | | | | |
y=0 +---------+-------------+-------------------+-----------+---------+
x=0 6.0 14.5 24.5 30.1 36.1
Hai doc RONG HET NHA (8 m, giua hai tuong bao) -- doc ngoai troi giua cac toa
nha thuong rong. Goc, do dac va cot KHAC NHAU de world KHONG doi xung -- doi
xung thi dinh vi lai nhap nhang (lat 180 do), nhu sanh tren cua slope_test.
Doc trai co hai cot nho o tuong y = 8 (#, LiDAR co cho bam doc theo doc); doc
phai tuong tron (LiDAR mu doc truc -- truong hop can camera).
Doc rong thi tuong gia o chan doc (tia LiDAR cham mat doc) cung rong het nha,
ma camera chi thay ~3 m be ngang o 4 m: muon xoa het thi di doc theo vai lan
(giua va sat hai tuong), khong chi mot duong giua.
Cung quy uoc voi tools/gen_slope_world.py (dung lai Obj, SDF, CONFIG,
include, write cua no): model `vslam_terrain_*` la DIA HINH, mesh co toa do
texture theo met, do dac lay tu ~/gazebo_models/aws_hospital_fuel.
Chay tu goc repo:
python3 tools/gen_two_ramp_world.py
export GAZEBO_MODEL_PATH=$PWD/resources/models
./build/app/vslam_node --sim --sim-gl --world resources/worlds/slope_two_ramps.world \\
--x 19.5 --y 4.0 --yaw 3.1416 --max-speed 0.3 --token t
"""
import argparse
import math
import os
import gen_slope_world as base
H = 1.5 # do cao hai tang, m
DEG_L, DEG_R = 10.0, 15.0 # goc doc trai / phai
WALL_T = 0.2
WALL_H = H + 2.5
DEPTH = 8.0 # be rong toan nha theo y
FLOOR_L = 6.0 # chieu dai tang trai / phai theo x
HALL_L = 10.0
Y_RL0, Y_RL1 = 0.0, DEPTH # hai doc rong het nha
Y_RR0, Y_RR1 = 0.0, DEPTH
LEN_L = H / math.tan(math.radians(DEG_L))
LEN_R = H / math.tan(math.radians(DEG_R))
X_L1 = FLOOR_L # het tang trai = dinh doc trai
X_H0 = X_L1 + LEN_L # chan doc trai = dau sanh
X_H1 = X_H0 + HALL_L # cuoi sanh = chan doc phai
X_R0 = X_H1 + LEN_R # dinh doc phai = dau tang phai
X_END = X_R0 + FLOOR_L
TERRAIN = 'vslam_terrain_two_ramps'
WALLS = 'vslam_two_ramps_walls'
# Do dac: (model, x, y, z, yaw). Sat tuong bao, de trong long doc va giua hai
# chan / dinh doc -- chan duong len doc la lop an toan dung xe truoc doc.
FURNITURE = [
('MetalCabinet', X_H0 + 0.6, 7.4, 0.0, 0.0),
('IVStand', X_H0 + 2.5, 0.8, 0.0, 0.0),
('VendingMachine', X_H0 + 5.0, 7.5, 0.0, -math.pi / 2),
('StorageRack', X_H0 + 6.5, 0.6, 0.0, 0.0),
('PatientWheelChair', X_H1 - 0.7, 1.0, 0.0, 0.0),
('MetalCabinet', 0.6, 7.0, H, 0.0),
('BedTable', 2.5, 0.8, H, 0.0),
('IVStand', 4.5, 7.2, H, 0.0),
('StorageRack', X_R0 + 2.9, 0.6, H, 0.0),
('BedTable', X_R0 + 4.4, 7.4, H, 0.0),
('VendingMachine', X_END - 0.6, 2.0, H, math.pi),
]
def terrain_mesh():
m = base.Obj('Dia hinh world hai doc: sanh z=0, hai tang z=%.2f, doc %g / %g do.\n'
'Z-UP, met. Sinh boi tools/gen_two_ramp_world.py -- dung sua tay.'
% (H, DEG_L, DEG_R))
m.quad([(0, 0, H), (X_L1, 0, H), (X_L1, DEPTH, H), (0, DEPTH, H)]) # tang trai
m.quad([(X_L1, Y_RL0, H), (X_H0, Y_RL0, 0), (X_H0, Y_RL1, 0), (X_L1, Y_RL1, H)]) # doc trai
m.quad([(X_H0, 0, 0), (X_H1, 0, 0), (X_H1, DEPTH, 0), (X_H0, DEPTH, 0)]) # sanh
m.quad([(X_H1, Y_RR0, 0), (X_R0, Y_RR0, H), (X_R0, Y_RR1, H), (X_H1, Y_RR1, 0)]) # doc phai
m.quad([(X_R0, 0, H), (X_END, 0, H), (X_END, DEPTH, H), (X_R0, DEPTH, H)]) # tang phai
return m.text()
def walls_mesh():
m = base.Obj('Tuong bao va cot cua world hai doc. Z-UP, met.\n'
'Sinh boi tools/gen_two_ramp_world.py -- dung sua tay.')
t = WALL_T
# Vong ngoai. Hai doc rong het nha nen khong co tuong rieng cho doc.
m.box(-t, -t, 0, 0, DEPTH + t, WALL_H)
m.box(X_END, -t, 0, X_END + t, DEPTH + t, WALL_H)
m.box(-t, -t, 0, X_END + t, 0, WALL_H)
m.box(-t, DEPTH, 0, X_END + t, DEPTH + t, WALL_H)
# Doc trai: hai cot nho nho ra 0.15 m o tuong y lon -- LiDAR co moc doc theo doc.
for xc in (X_L1 + 0.35 * LEN_L, X_L1 + 0.7 * LEN_L):
m.box(xc - 0.2, Y_RL1 - 0.15, 0, xc + 0.2, Y_RL1, WALL_H)
# Cot trong sanh va hai tang (lech nhau, khong doi xung), tranh duong vao doc.
m.box(X_H0 + 3.3, 5.8, 0, X_H0 + 3.7, 6.2, WALL_H)
m.box(X_H0 + 6.8, 2.3, 0, X_H0 + 7.2, 2.7, WALL_H)
m.box(2.8, 4.8, H, 3.2, 5.2, WALL_H)
m.box(X_R0 + 3.2, 3.3, H, X_R0 + 3.6, 3.7, WALL_H)
return m.text()
def world_text():
parts = ['<?xml version="1.0" ?>\n',
'<!-- World HAI DOC. Sinh boi tools/gen_two_ramp_world.py -- dung sua tay.\n'
' Sanh giua z = 0 (x %.1f-%.1f); doc trai %g do (y %.1f-%.1f) len tang trai,\n'
' doc phai %g do (y %.1f-%.1f) len tang phai, hai tang z = %.1f.\n'
' Xuat phat goi y: --x %.1f --y 4.0 --yaw 3.1416 (giua sanh, nhin ve doc trai). -->\n'
% (X_H0, X_H1, DEG_L, Y_RL0, Y_RL1, DEG_R, Y_RR0, Y_RR1, H, (X_H0 + X_H1) / 2),
'<sdf version="1.6">\n <world name="slope_two_ramps">\n',
' <include><uri>model://ground_plane</uri></include>\n',
' <include><uri>model://sun</uri></include>\n',
base.include(TERRAIN + '_1', TERRAIN, 0, 0, 0, 0),
base.include(WALLS + '_1', WALLS, 0, 0, 0, 0)]
count = {}
for name, x, y, z, yaw in FURNITURE:
count[name] = count.get(name, 0) + 1
parts.append(base.include('%s_%d' % (name, count[name]), name, x, y, z, yaw))
parts.append(' </world>\n</sdf>\n')
return ''.join(parts)
def main():
here = os.path.dirname(os.path.abspath(__file__))
ap = argparse.ArgumentParser(description=__doc__.splitlines()[0])
ap.add_argument('--root', default=os.path.dirname(here),
help='goc repo (mac dinh: thu muc cha cua tools/)')
a = ap.parse_args()
models = os.path.join(a.root, 'resources', 'models')
base.write(os.path.join(models, TERRAIN, 'meshes', 'terrain.obj'), terrain_mesh())
base.write(os.path.join(models, TERRAIN, 'model.sdf'),
base.SDF.format(name=TERRAIN, mesh='terrain.obj'))
base.write(os.path.join(models, TERRAIN, 'model.config'),
base.CONFIG.format(name=TERRAIN, desc='Sanh, hai doc va hai tang (dia hinh).')
.replace('gen_slope_world.py', 'gen_two_ramp_world.py'))
base.write(os.path.join(models, WALLS, 'meshes', 'walls.obj'), walls_mesh())
base.write(os.path.join(models, WALLS, 'model.sdf'),
base.SDF.format(name=WALLS, mesh='walls.obj'))
base.write(os.path.join(models, WALLS, 'model.config'),
base.CONFIG.format(name=WALLS, desc='Tuong bao va cot.')
.replace('gen_slope_world.py', 'gen_two_ramp_world.py'))
base.write(os.path.join(a.root, 'resources', 'worlds', 'slope_two_ramps.world'), world_text())
print('sanh giua x %.2f-%.2f (z 0); tang trai x 0-%.2f, tang phai x %.2f-%.2f (z %.1f)'
% (X_H0, X_H1, X_L1, X_R0, X_END, H))
for name, deg, x0, x1, y0, y1 in (('trai', DEG_L, X_L1, X_H0, Y_RL0, Y_RL1),
('phai', DEG_R, X_H1, X_R0, Y_RR0, Y_RR1)):
print('doc %s %g do: x %.2f-%.2f, y %.1f-%.1f, dai %.2f m, tam (%.2f, %.2f), '
'tuong gia o chan doc cach %.2f m'
% (name, deg, x0, x1, y0, y1, x1 - x0, (x0 + x1) / 2, (y0 + y1) / 2,
0.2165 / math.tan(math.radians(deg))))
if __name__ == '__main__':
main()