code reduction for training and eval

reward and everything else changed
again
wont be the last time
This commit is contained in:
2026-08-05 22:44:05 +02:00
parent 15e0206739
commit c93c524a10
10 changed files with 606 additions and 814 deletions
+18 -62
View File
@@ -44,7 +44,7 @@ class MetricsHUD:
robot_rewards: List[float],
cmd_vel: np.ndarray,
fps: float = 0.0,
avg_height: float = 0.0,
height: float = 0.0,
roll_pitch: Tuple[float, float] = (0.0, 0.0)
) -> None:
"""Updates floating black text block in 3D space with billboarding."""
@@ -65,7 +65,7 @@ class MetricsHUD:
f"----------------------\n"
f"Top Rewards: [{top1}, {top2}, {top3}]\n"
f"Cmd (X,Y,W): [{vx:+.2f}, {vy:+.2f}, {omega:+.2f}]\n"
f"Height: {avg_height:.3f} m\n"
f"Height: {height:.3f} m\n"
f"Roll/Pitch: {roll_pitch[0]:+.1f}° / {roll_pitch[1]:+.1f}°"
)
@@ -76,69 +76,25 @@ class MetricsHUD:
# Calculate dynamic orientation to align text flat against camera plane
text_orientation = self._get_camera_facing_orientation()
if self._text_id is None:
self._text_id = p.addUserDebugText(
text=hud_text,
textPosition=text_position,
textColorRGB=text_color,
textSize=0.1,
textOrientation=text_orientation,
physicsClientId=self.client_id
)
else:
self._text_id = p.addUserDebugText(
text=hud_text,
textPosition=text_position,
textColorRGB=text_color,
textSize=0.1,
textOrientation=text_orientation,
replaceItemUniqueId=self._text_id,
physicsClientId=self.client_id
)
# Safely remove the old text to prevent PyBullet ghosting/overlapping
if self._text_id is not None:
try:
p.removeUserDebugItem(self._text_id, physicsClientId=self.client_id)
except Exception:
pass
# Draw fresh text
self._text_id = p.addUserDebugText(
text=hud_text,
textPosition=text_position,
textColorRGB=text_color,
textSize=0.1,
textOrientation=text_orientation,
physicsClientId=self.client_id
)
def reset(self) -> None:
"""Removes the active debug text item so a new episode starts with a clean overlay."""
if self._text_id is not None:
try:
p.removeUserDebugItem(self._text_id, physicsClientId=self.client_id)
except Exception:
pass
self._text_id = None
class LeaderCrown:
"""Renders a floating crown or star emoji above the leading robot in PyBullet."""
def __init__(self, physics_client_id: int = 0):
self.client_id = physics_client_id
self._text_id = None
def update(self, leader_pos: list[float]):
"""Positions a floating crown ~0.35m directly above the lead robot's base."""
crown_pos = [leader_pos[0], leader_pos[1], leader_pos[2] + 0.35]
# You can use "👑 CROWN", "⭐ LEADER", or "★ TOP1"
crown_text = "👑"
if self._text_id is None:
self._text_id = p.addUserDebugText(
text=crown_text,
textPosition=crown_pos,
textColorRGB=[1.0, 0.84, 0.0],
textSize=2.0,
physicsClientId=self.client_id
)
else:
self._text_id = p.addUserDebugText(
text=crown_text,
textPosition=crown_pos,
textColorRGB=[1.0, 0.84, 0.0],
textSize=2.0,
replaceItemUniqueId=self._text_id,
physicsClientId=self.client_id
)
def reset(self):
if self._text_id is not None:
try:
p.removeUserDebugItem(self._text_id, physicsClientId=self.client_id)