live: real-time browser viewer (AICC-client based), sensor-built top-down map shared module, run_live.sh one-command mode
This commit is contained in:
+2
-50
@@ -135,57 +135,9 @@ class FrameRecorder:
|
||||
return Image.open(io.BytesIO(base64.b64decode(out["png_b64"]))).convert("RGB")
|
||||
|
||||
def _map_frame(self, pos: tuple[float, float], yaw: float) -> Image.Image:
|
||||
from PIL import Image, ImageDraw
|
||||
from testbed.room.mapview import draw_sensor_map
|
||||
|
||||
size = self.MAP_SIZE
|
||||
scale = size / self.ROOM
|
||||
|
||||
def xy(x: float, z: float) -> tuple[float, float]:
|
||||
return (x * scale, size - z * scale)
|
||||
|
||||
img = Image.new("RGB", (size, size), (52, 52, 58))
|
||||
d = ImageDraw.Draw(img)
|
||||
for i in range(int(self.ROOM) + 1):
|
||||
c = 60 if i % 2 == 0 else 54
|
||||
d.line([xy(i, 0), xy(i, self.ROOM)], fill=(c, c, c + 6), width=1)
|
||||
d.line([xy(0, i), xy(self.ROOM, i)], fill=(c, c, c + 6), width=1)
|
||||
if self.layout:
|
||||
for ob in self.layout.get("obstacles", []):
|
||||
x0, z0 = xy(ob["x"] - ob["width"] / 2, ob["z"] - ob["depth"] / 2)
|
||||
x1, z1 = xy(ob["x"] + ob["width"] / 2, ob["z"] + ob["depth"] / 2)
|
||||
d.rectangle(
|
||||
[min(x0, x1), min(z0, z1), max(x0, x1), max(z0, z1)],
|
||||
fill=(150, 90, 60),
|
||||
outline=(20, 20, 26),
|
||||
width=2,
|
||||
)
|
||||
b = self.layout.get("beacon", {})
|
||||
bx, bz = xy(b.get("x", 12.5), b.get("z", 12.5))
|
||||
d.ellipse(
|
||||
[bx - 8, bz - 8, bx + 8, bz + 8],
|
||||
fill=(120, 210, 235),
|
||||
outline=(20, 20, 26),
|
||||
width=2,
|
||||
)
|
||||
if len(self.path) > 1:
|
||||
pts = [xy(x, z) for x, z in self.path]
|
||||
d.line(pts, fill=(255, 170, 60), width=3)
|
||||
cx, cz = xy(*pos)
|
||||
d.ellipse(
|
||||
[cx - 7, cz - 7, cx + 7, cz + 7],
|
||||
fill=(240, 240, 250),
|
||||
outline=(20, 20, 26),
|
||||
width=2,
|
||||
)
|
||||
rad = math.radians(yaw)
|
||||
tip = xy(pos[0] + math.sin(rad) * 0.7, pos[1] + math.cos(rad) * 0.7)
|
||||
d.line([(cx, cz), tip], fill=(30, 30, 40), width=3)
|
||||
d.text(
|
||||
(8, 8),
|
||||
f"step {self.step} pos ({pos[0]:.1f}, {pos[1]:.1f}) yaw {yaw:.0f}",
|
||||
fill=(230, 230, 230),
|
||||
)
|
||||
return img
|
||||
return draw_sensor_map(self.layout, pos, yaw, self.path, step=self.step)
|
||||
|
||||
def finish(self, interacted: bool) -> Image.Image:
|
||||
"""Write demo.gif + demo_summary.png; returns the summary image."""
|
||||
|
||||
Reference in New Issue
Block a user