pinocchio  2.4.0-dirty
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
Display a model using GepettoViewer
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 pin.switchToNumpyMatrix()
6 import numpy as np
7 import sys
8 import os
9 from os.path import dirname, join, abspath
10 
11 from pinocchio.visualize import GepettoVisualizer
12 
13 # Load the URDF model.
14 # Conversion with str seems to be necessary when executing this file with ipython
15 pinocchio_model_dir = join(dirname(dirname(str(abspath(__file__)))),"models")
16 
17 model_path = join(pinocchio_model_dir,"others/robots")
18 mesh_dir = model_path
19 urdf_filename = "talos_reduced.urdf"
20 urdf_model_path = join(join(model_path,"talos_data/urdf"),urdf_filename)
21 
22 model, collision_model, visual_model = pin.buildModelsFromUrdf(urdf_model_path, mesh_dir, pin.JointModelFreeFlyer())
23 viz = GepettoVisualizer(model, collision_model, visual_model)
24 
25 # Initialize the viewer.
26 try:
27  viz.initViewer()
28 except ImportError as err:
29  print("Error while initializing the viewer. It seems you should install gepetto-viewer")
30  print(err)
31  sys.exit(0)
32 
33 try:
34  viz.loadViewerModel("pinocchio")
35 except AttributeError as err:
36  print("Error while loading the viewer model. It seems you should start gepetto-viewer")
37  print(err)
38  sys.exit(0)
39 
40 # Display a robot configuration.
41 q0 = pin.neutral(model)
42 viz.display(q0)
43 
44 # Display another robot.
45 viz2 = GepettoVisualizer(model, collision_model, visual_model)
46 viz2.initViewer(viz.viewer)
47 viz2.loadViewerModel(rootNodeName = "pinocchio2")
48 q = q0.copy()
49 q[1] = 1.0
50 viz2.display(q)
51