panda3d-viewer-play.py
Go to the documentation of this file.
1 # This examples shows how to load and move a robot in panda3d_viewer.
2 # Note: this feature requires panda3d_viewer to be installed, this can be done using
3 # pip install panda3d_viewer
4 # ruff: noqa: E402
5 
6 
7 import sys
8 from pathlib import Path
9 
10 import numpy as np
11 
12 # Add path to the example-robot-data package from git submodule.
13 # If you have a proper install version, there is no need for this sys.path thing
14 path = Path(__file__).parent.parent / "models" / "example-robot-data" / "python"
15 sys.path.append(str(path))
16 from example_robot_data.robots_loader import TalosLoader
17 from panda3d_viewer import ViewerClosedError
18 from pinocchio.visualize.panda3d_visualizer import Panda3dVisualizer
19 
20 # talos is a RobotWrapper object
21 talos = TalosLoader().robot
22 # Attach talos to the viewer scene
23 talos.setVisualizer(Panda3dVisualizer())
24 talos.initViewer()
25 talos.loadViewerModel(group_name="talos", color=(1, 1, 1, 1))
26 record_video = False
27 
28 
29 # Play a sample trajectory in a loop
31  update_rate = 60
32  cycle_time = 3
33  traj = np.repeat(talos.q0.reshape((-1, 1)), cycle_time * update_rate, axis=1)
34  beta = np.linspace(0, 1, traj.shape[1])
35  traj[[2, 9, 10, 11, 22, 15, 16, 17, 30]] = (
36  0.39 + 0.685 * np.cos(beta),
37  -beta,
38  2.0 * beta,
39  -beta,
40  0.1 + beta * 1.56,
41  -beta,
42  2.0 * beta,
43  -beta,
44  -0.1 - beta * 1.56,
45  )
46 
47  if record_video:
48  dt = 1 / 60
49  fps = 1.0 / dt
50  filename = "talos.mp4"
51  ctx = talos.viz.create_video_ctx(filename, fps=fps)
52  print(f"[video will be recorded @ {filename}]")
53  else:
54  from contextlib import nullcontext
55 
56  ctx = nullcontext()
57  print("[no recording]")
58 
59  while True:
60  with ctx:
61  talos.play(traj.T, 1.0 / update_rate)
62  traj = np.flip(traj, 1)
63  if record_video:
64  break
65 
66 
67 try:
69 except ViewerClosedError:
70  # an exception will be thrown when the window is closed
71  pass
example_robot_data.robots_loader
Definition: robots_loader.py:1
panda3d-viewer-play.play_sample_trajectory
def play_sample_trajectory()
Definition: panda3d-viewer-play.py:30
example_robot_data.robots_loader.TalosLoader
Definition: robots_loader.py:265
pinocchio.visualize.panda3d_visualizer
Definition: panda3d_visualizer.py:1
pinocchio.visualize.panda3d_visualizer.Panda3dVisualizer
Definition: panda3d_visualizer.py:17


pinocchio
Author(s):
autogenerated on Wed May 28 2025 02:41:21