Skip to content

Commit

Permalink
track with camera
Browse files Browse the repository at this point in the history
  • Loading branch information
schmidma committed Feb 1, 2025
1 parent d3b919d commit 3ee4b9e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,12 @@ def _handle_perturbation(self, mods: int) -> None:
)
self.perturbation.active = perturbation_kind

def track_with_camera(self, body: int | str) -> None:
bodyid = self.model.body(body).id
self.camera.type = mujoco.mjtCamera.mjCAMERA_TRACKING.value
self.camera.trackbodyid = bodyid
self.camera.fixedcamid = -1

def _handle_selection(self, mods: int) -> None:
class Mode(Enum):
Select = 1
Expand All @@ -603,7 +609,10 @@ class Mode(Enum):
mode = None
if self._interaction_state.left_double_click_pressed:
mode = Mode.Select
elif self._interaction_state.right_double_click_pressed:
elif (
self._interaction_state.right_double_click_pressed
and mods != glfw.MOD_CONTROL
):
mode = Mode.LookAt
elif (
self._interaction_state.right_double_click_pressed
Expand Down
2 changes: 1 addition & 1 deletion tools/machine-learning/mujoco/scripts/mujoco-walking.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def main(*, throw_tomatoes: bool, load_policy: str | None) -> None:

while viewer.is_alive:
start_time = time.time()
# viewer.camera.lookat[:] = env.data.site("Robot").xpos
viewer.track_with_camera("Nao")
observation, reward, _terminated, _truncated, infos = env.step(action)
if model:
action, _ = model.predict(observation, deterministic=True)
Expand Down

0 comments on commit 3ee4b9e

Please sign in to comment.