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 --user panda3d_viewer
4 
5 import pinocchio as pin
6 import numpy as np
7 import sys
8 
9 from os.path import dirname, join, abspath
10 
11 # add path to the example-robot-data package
12 path = join(dirname(dirname(abspath(__file__))), 'models', 'example-robot-data', 'python')
13 sys.path.append(path)
14 from example_robot_data import loadTalos
15 
16 # import visualizer
17 from panda3d_viewer import ViewerClosedError
18 from pinocchio.visualize.panda3d_visualizer import Panda3dVisualizer
19 
20 talos = loadTalos()
21 talos.setVisualizer(Panda3dVisualizer())
22 talos.initViewer()
23 talos.loadViewerModel(group_name='talos', color=(1, 1, 1, 1))
24 
25 
26 # Play a sample trajectory in a loop
28  update_rate = 60
29  cycle_time = 3
30  traj = np.repeat(talos.q0.reshape((-1, 1)), cycle_time * update_rate, axis=1)
31  beta = np.linspace(0, 1, traj.shape[1])
32  traj[[2, 9, 10, 11, 22, 15, 16, 17, 30]] = (
33  0.39 + 0.685 * np.cos(beta),
34  -beta,
35  2.0 * beta,
36  -beta,
37  0.1 + beta * 1.56,
38  -beta,
39  2.0 * beta,
40  -beta,
41  -0.1 - beta * 1.56,
42  )
43 
44  while True:
45  talos.play(traj, 1. / update_rate)
46  traj = np.flip(traj, 1)
47 
48 
49 try:
51 except ViewerClosedError:
52  # an exception will be thrown when the window is closed
53  pass


pinocchio
Author(s):
autogenerated on Fri Jun 23 2023 02:38:32