env cleanup

rewards adjustment
pybullet logic contained in SimManager
This commit is contained in:
2026-08-04 21:03:53 +02:00
parent 766f2855da
commit 402c20dfb5
4 changed files with 162 additions and 153 deletions
+11 -14
View File
@@ -172,9 +172,7 @@ class Robot:
# --- RL METHODS ---
def apply_rl_action(self, action: np.ndarray) -> None:
"""
Applies continuous RL action deltas [-1, 1] to current joint angles.
"""
"""Applies continuous RL action deltas [-1, 1] to current joint angles."""
action = np.asarray(action, dtype=np.float32)
scaled_action = np.clip(action, -1.0, 1.0) * self.action_scale
@@ -191,20 +189,19 @@ class Robot:
def get_observation(self, command: Optional[np.ndarray] = None) -> np.ndarray:
"""
Returns observation vector [18 joint angles] + [optional 4 command dimensions].
Queries PyBullet if backend is PyBulletBackend; otherwise falls back to internal state.
Queries SimManager helper if PyBulletBackend is used; falls back to internal state otherwise.
"""
if isinstance(self.backend, PyBulletBackend) and self.backend.sim and hasattr(self.backend.sim, 'physics_client'):
physics_client = self.backend.sim.physics_client
if isinstance(self.backend, PyBulletBackend) and self.backend.sim:
body_id = self.backend.body_id if self.backend.body_id is not None else 0
# Retrieve joint mapping from SimManager/Simulation if available
if hasattr(self.backend.sim, 'robot_joints') and body_id in self.backend.sim.robot_joints:
joint_indices = self.backend.sim.robot_joints[body_id]
if hasattr(self.backend.sim, 'get_robot_joint_angles'):
joint_angles = self.backend.sim.get_robot_joint_angles(body_id)
elif hasattr(self.backend.sim, 'physics_client'):
physics_client = self.backend.sim.physics_client
joint_indices = self.backend.sim.robot_joints.get(body_id, list(range(18))) if hasattr(self.backend.sim, 'robot_joints') else list(range(18))
joint_states = p.getJointStates(body_id, joint_indices, physicsClientId=physics_client)
joint_angles = np.array([state[0] for state in joint_states], dtype=np.float32)
else:
joint_indices = list(range(18))
joint_states = p.getJointStates(body_id, joint_indices, physicsClientId=physics_client)
joint_angles = np.array([state[0] for state in joint_states], dtype=np.float32)
joint_angles = self.current_rad.data.flatten().astype(np.float32)
else:
joint_angles = self.current_rad.data.flatten().astype(np.float32)