pinocchio  3.2.0
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
display.py
1 # Typical header of a Python script using Pinocchio
2 import gepetto.corbaserver
3 import pinocchio as pin
4 
5 
6 # Example of a class Display that connect to Gepetto-viewer and implement a
7 # 'place' method to set the position/rotation of a 3D visual object in a scene.
8 class Display:
9  """
10  Class Display: Example of a class implementing a client for the Gepetto-viewer server. The main
11  method of the class is 'place', that sets the position/rotation of a 3D visual object in a scene.
12  """
13 
14  def __init__(self, windowName="pinocchio"):
15  """
16  This function connect with the Gepetto-viewer server and open a window with the given name.
17  If the window already exists, it is kept in the current state. Otherwise, the newly-created
18  window is set up with a scene named 'world'.
19  """
20 
21  # Create the client and connect it with the display server.
22  try:
23  self.viewerviewer = gepetto.corbaserver.Client()
24  except: # noqa: E722
25  print("Error while starting the viewer client. ")
26  print("Check whether Gepetto-viewer is properly started")
27 
28  # Open a window for displaying your model.
29  try:
30  # If the window already exists, do not do anything.
31  windowID = self.viewerviewer.gui.getWindowID(windowName)
32  print("Warning: window '" + windowName + "' already created.")
33  print(
34  "The previously created objects will not be destroyed and do not have to be created again."
35  )
36  except: # noqa: E722
37  # Otherwise, create the empty window.
38  windowID = self.viewerviewer.gui.createWindow(windowName)
39  # Start a new "scene" in this window, named "world", with just a floor.
40  self.viewerviewer.gui.createScene("world")
41  self.viewerviewer.gui.addSceneToWindow("world", windowID)
42 
43  # Finally, refresh the layout to obtain your first rendering.
44  self.viewerviewer.gui.refresh()
45 
46  def place(self, objName, M, refresh=True):
47  """
48  This function places (ie changes both translation and rotation) of the object
49  names "objName" in place given by the SE3 object "M". By default, immediately refresh
50  the layout. If multiple objects have to be placed at the same time, do the refresh
51  only at the end of the list.
52  """
53  self.viewerviewer.gui.applyConfiguration(objName, pin.se3ToXYZQUATtuple(M))
54  if refresh:
55  self.viewerviewer.gui.refresh()
def place(self, objName, M, refresh=True)
Definition: display.py:46
def __init__(self, windowName="pinocchio")
Definition: display.py:14