gepetto-viewer.py
Go to the documentation of this file.
1 # NOTE: this example needs gepetto-gui to be installed
2 # usage: launch gepetto-gui and then run this test
3 
4 import pinocchio as pin
5 import numpy as np
6 import sys
7 import os
8 from os.path import dirname, join, abspath
9 
10 from pinocchio.visualize import GepettoVisualizer
11 
12 # Load the URDF model.
13 # Conversion with str seems to be necessary when executing this file with ipython
14 pinocchio_model_dir = join(dirname(dirname(str(abspath(__file__)))),"models")
15 
16 model_path = join(pinocchio_model_dir,"example-robot-data/robots")
17 mesh_dir = pinocchio_model_dir
18 urdf_filename = "talos_reduced.urdf"
19 urdf_model_path = join(join(model_path,"talos_data/robots"),urdf_filename)
20 
21 model, collision_model, visual_model = pin.buildModelsFromUrdf(urdf_model_path, mesh_dir, pin.JointModelFreeFlyer())
22 viz = GepettoVisualizer(model, collision_model, visual_model)
23 
24 # Initialize the viewer.
25 try:
26  viz.initViewer()
27 except ImportError as err:
28  print("Error while initializing the viewer. It seems you should install gepetto-viewer")
29  print(err)
30  sys.exit(0)
31 
32 try:
33  viz.loadViewerModel("pinocchio")
34 except AttributeError as err:
35  print("Error while loading the viewer model. It seems you should start gepetto-viewer")
36  print(err)
37  sys.exit(0)
38 
39 # Display a robot configuration.
40 q0 = pin.neutral(model)
41 viz.display(q0)
42 
43 # Display another robot.
44 viz2 = GepettoVisualizer(model, collision_model, visual_model)
45 viz2.initViewer(viz.viewer)
46 viz2.loadViewerModel(rootNodeName = "pinocchio2")
47 q = q0.copy()
48 q[1] = 1.0
49 viz2.display(q)
50 


pinocchio
Author(s):
autogenerated on Tue Jun 1 2021 02:45:03