In this first series of exercises, we are going to start using the library Pinocchio. We will load in the simulator the model of a simple manipulator arm, the Universal Robot 5, or UR5. This model will be used for a positioning task using simple methods. This set of exercices emphasizes the first part of the class, about direct geometry.
The software Pinocchio is a C++ library provided with a python wrapping that allows us to control it with a python terminal. Let's see how it works.
For this tutorial, you will need Pinocchio, Gepetto GUI, and the description of the ur5 robot.
For this, the easiest way is to add robotpkg apt repository and launch:
We remind you that you can open a python terminal in your own shell. Simply type :
Afterwards you'll just have to type your commands in this newly opened terminal.
To close the python terminal, just type CTRL-D (CTRL-C first to interrupt any on-going execution).
You can also write you command lines in a file and launch this script without entering the interactive mode (ie. without starting a new python terminal). In your shell, just type:
In the following, we will use numpy Matrix
class to represent matrices and vectors. In numpy, vectors simply are matrices with one column. See the following example.
A bunch of useful functions are packaged in the utils of pinocchio.
Specific classes are defined to represent objects of \(SE(3)\), \(se(3)\) and \(se(3)^*\). Rigid displacements, elements of \(SE(3)\), are represented by the class SE3
.
Spatial velocities, elements of \(se(3) = M^6\), are represented by the class Motion
.
Spatial forces, elements of \(se(3)^* = F^6\), are represented by the class Force
.
The kinematic tree is represented by two C++ objects called Model (which contains the model constants: lengths, masses, names, etc) and Data (which contains the working memory used by the model algorithms). Both C++ objects are contained in a unique Python class. load_robot_description can load common robot models without issue into pinocchio. First install the example-robot-data package using: 'sudo apt install robotpkg-example-robot-data'
The code of the RobotWrapper class can also be used to load local URDF's and can be found at /opt/openrobots/lib/python3.10/site-packages/pinocchio/robot_wrapper.py
. Do not hesitate to have a look at it and to take inspiration from the implementation of the class functions.
UR5 is a fixed robot with one 6-DOF arms developed by the Danish company Universal Robot. All its 6 joints are revolute joints. Its configuration is in R^6 and is not subject to any constraint. The model of UR5 is described in a URDF file, with the visuals of the bodies of the robot being described as meshed (i.e. polygon soups) using the Collada format ".dae". Both the URDF and the DAE files are available in the package ‘robotpkg-example-robot-data’
The robot model is available in robot.model
. It contains the names of all the robot joint names
, the kinematic tree parents
(i.e. the graph of parents, 0 being the root and having no parents), the position of the current joint in the parent coordinate frame jointPosition
, the mass, inertia and center-of-gravity position of all the bodies (condensed in a spatial inertia 6x6 matrix) inertias
and the gravity of the associated world gravity
. All these functions are documented and are available in the correponding class dictionnary.
Similarly, the robot data are available in robot.data
. All the variables allocated by the classical rigid-body dynamics algorithms are stored in robot.data
and are available through the python wrapping. Similarly to the model object, the function are documented and are available from the class dictionnary. The most useful in the following will be the placement of the frame associated which each joint output stored in robot.data.oMi
.
For example, the robot end effector corresponds to the output of the last joint, called wrist_1_joint
. The ID of the joint in the joint list can be recovered from its name, and then used to access its placement:
Finally, some recurring datas (used in Model and Data) have been wrapped to functions in some python shortcuts, also available in RomeoWrapper:
nq
.nv
.To display the robot, we need an external program called Gepetto Viewer. If you completed the installation in the previous page, you can launch this program, open a new terminal in an empty workspace.
This will start a server waiting for instructions. We will now create a client that will ask the server to perform some requests (such as creating a window or displaying our robot)
In a python terminal you can now load the visual model of the robot in the viewer:
This will flush the robot model inside the GUI. The argument loadModel=True
is mandatory when you start or restart the GUI. In later call to your scripts, you can set the argument to False
. A side effector of =True
is that it will move the viewpoint inside the GUI to a reference zero position.
You can access the visual object composing the robot model by robot.visual_model.geometryObject
.
Moving one object
Additional objects can be created, like a sphere as follows.
The exhaustive list of the object that can be created is available in the IDL of the GUI: /opt/openrobots/share/idl/gepetto/corbaserver/graphical-interface.idl
Objectives: Display the robot at a given configuration or along a given trajectory
Say we have a target at position [.5, .1, .2]
and we would like the robot to grasp it.
First display a small sphere at this position to visualize it.
Then decide by any mean you want a configuration of the robot so that the end effector is touching the sphere.
At the reference position you built, the end effector placement can be obtained by robot.placement(q, 6)
. Only the translation part of the placement has been selected. The rotation is free.
Optional Say now that the object is a rectangle and not a sphere. Pick the object at a reference position with the rotation that is imposed, so that the end effector is aligned with one of the faces of the rectangle.
Choose any trajectory you want in the configuration space, starting from the reference position built in the previous exercice (it can be sinus-cosinus waves, polynomials, splines, straight lines).
Make a for loop to display the robot at sampling positions along this trajectory. The function sleep in module time (from time import sleep) can be used to slow down the loop.
At each instant of your loop, recompute the position of the ball and display it so that it always "sticks" to the robot end effector.