Download llm_panda/visualize.py from C2-151/Robot: direct link, hf CLI and curl.
- Browser
- Download file 2.53 kB
-
https://huggingface.co/spaces/C2-151/Robot/resolve/main/llm_panda/visualize.py
- Command line
-
hf download hf://spaces/C2-151/Robot/llm_panda/visualize.py
-
curl -L -o visualize.py https://huggingface.co/spaces/C2-151/Robot/resolve/main/llm_panda/visualize.py
2.53 kB
| """3D scene overlay for the planning stack (toggleable, off by default). | |
| :class:`GuiOverlay` draws directly onto the live PyBullet scene with | |
| ``addUserDebugLine``: each object's true footprint hull (red), the A* route on | |
| the surface (green), and the executed U-shaped trajectory (blue). No extra | |
| dependency, and nothing is drawn unless ``--viz`` / ``:viz`` is enabled. | |
| """ | |
| import logging | |
| import pybullet as pb | |
| from . import config | |
| logger = logging.getLogger(__name__) | |
| _DRAW_Z = config.TABLE_TOP_Z + 0.003 # a sliver above the table top | |
| class GuiOverlay: | |
| """Accumulates PyBullet debug-line items so they can be cleared as a group.""" | |
| def __init__(self): | |
| self._ids = [] | |
| def clear(self): | |
| for item in self._ids: | |
| try: | |
| pb.removeUserDebugItem(item) | |
| except Exception: | |
| pass | |
| self._ids = [] | |
| # -- primitives ----------------------------------------------------- # | |
| def _line(self, a, b, color, width=2.0): | |
| self._ids.append(pb.addUserDebugLine(a, b, color, lineWidth=width)) | |
| def _polygon(self, poly, color, z=None, width=2.0): | |
| z = _DRAW_Z if z is None else z | |
| pts = [[x, y, z] for x, y in poly] | |
| for a, b in zip(pts, pts[1:] + pts[:1]): | |
| self._line(a, b, color, width) | |
| # -- high-level draws ----------------------------------------------- # | |
| def draw_obstacles(self, scene, exclude_ids=None): | |
| """Red outline of each object's true (mesh convex-hull) footprint.""" | |
| exclude = set(exclude_ids or []) | |
| for oid in scene.object_ids: | |
| if oid in exclude: | |
| continue | |
| poly = scene.footprint_polygon(oid) | |
| if len(poly) >= 2: | |
| self._polygon(poly, [1.0, 0.1, 0.1]) | |
| def draw_path(self, xy_path, color=(0.1, 1.0, 0.1), z=None): | |
| """Green polyline of the A* route on the surface.""" | |
| z = _DRAW_Z if z is None else z | |
| pts = [[x, y, z] for x, y in xy_path] | |
| for a, b in zip(pts[:-1], pts[1:]): | |
| self._line(a, b, list(color), width=4.0) | |
| for p in pts: | |
| self._ids.append(pb.addUserDebugPoints([p], [list(color)], pointSize=6)) | |
| def draw_trajectory(self, waypoints, color=(0.2, 0.4, 1.0)): | |
| """Blue polyline of the executed U-shaped TCP trajectory.""" | |
| for a, b in zip(waypoints[:-1], waypoints[1:]): | |
| self._line(list(a), list(b), list(color), width=2.0) | |