Peter Corke Robotics Toolbox Python
Peter Corke Robotics Toolbox Python
c 2021 IEEE
c 2021 IEEE. Personal use of this material is permitted. Permission from IEEE must be
obtained for all other uses, in any current or future media, including reprinting/republishing
this material for advertising or promotional purposes, creating new collective works, for
resale or redistribution to servers or lists, or reuse of any copyrighted component of this
work in other works.
Notice: Please note that this document may not be the Version of Record
(i.e. published version) of the work. Author manuscript versions (as Sub-
mitted for peer review or as Accepted for publication after peer review) can
be identified by an absence of publisher branding and/or typeset appear-
ance. If there is any doubt, please refer to the published source.
https://doi.org/10.1109/ICRA48506.2021.9561366
2021 IEEE International Conference on Robotics and Automation (ICRA 2021)
May 31 - June 4, 2021, Xi'an, China
Not your grandmother’s toolbox – the Robotics Toolbox reinvented for Python
a trajectory. We could add an extra dimension to the matrices can contain zero or more values X *= Y
Y = [x.inv() for x in X]
representing rigid-body transformations or unit-quaternions,
or place them in a list. The first approach is cumbersome and
Fig. 2: Instances of any SMTB-P class can contain a list of
reduces code clarity, while the second cannot ensure that all
values
elements of the list have the same type. Instance of SE3, SO3, SE2,
* SE3.Rx(-90, unit='deg')
>>> print(T)
0.97517 -0.198669 -0.0978434 0.5 a b c d
* e f g h
→ ae bf cg dh
0.153792 0.289629 0.944702 0 value[0] value[1] value[2] value[3 value[0] value[1] value[2] value[3 value[0] value[1] value[2] value[3
This capability readily extends to forward kinematics is the gravity torque for the robot in the configuration qn.
>>> q = sym.symbol("q_:6") # q = q_1, q_2, ... Inertia, Coriolis/centripetal and gravity terms are com-
>>> T = puma.fkine(q) puted respectively by
however the expression is more complex than it should be, >>> I = puma.inertia(puma.qn)
because the sin αj and cos αj are not precisely 0, -1 or +1 >>> C = puma.coriolis(puma.qn, qd)
due to finite precision of the value math.pi. If the αj >>> g = puma.gravload(puma.qn)
values are set to the symbolic value of π (sympy.S.Pi) from the inverse dynamics using the method of [23]. Forward
then the expressions are greatly simplified dynamics are given by
>>> puma = models.DH.Puma560(symbolic=True) >>> qdd = puma.accel(q, tau, qd)
>>> T = puma.fkine(q)
which we can integrate over time
If we print(puma) we see that the αj values are now >>> q = puma.fdyn(5, q0, mycontrol, ...)
displayed in red to indicate that they are symbolic constants.
uses an RK45 numerical integration from the SciPy package
The x-coordinate of the end-effector is
to solve for the joint trajectory q given the joint-space control
>>> T.t[0]
function called with the signature
0.15005*sin(q_0) - 0.0203*sin(q_1)*sin(q_2)*cos(q_0)
- 0.4318*sin(q_1)*cos(q_0)*cos(q_2) tau = mycontrol(robot, t, q, qd, **args)
- 0.4318*sin(q_2)*cos(q_0)*cos(q_1)
+ 0.0203*cos(q_0)*cos(q_1)*cos(q_2) The fast C implementation is not capable of symbolic
+ 0.4318*cos(q_0)*cos(q_1) operation but the slower Python version rne python is.
SymPy allows any expression to be converted to LATEXor For a 6- or 7-DoF manipulator the torque expressions have
runnable code in a variety of languages including C, Python, thousands of terms yet are computed in less than a second.
Octave/MATLAB. However, subsequent expression manipulation is slow, and
this is an area of future work, as is the automatic generation
D. Differential kinematics of efficient run-time code for manipulator dynamics.
The Toolbox computes Jacobians For the Puma 560 robot, the C version of inverse dynamics
>>> J = puma.jacob0(puma.qn) takes 23 µs while the Python version takes 1.5 ms (65 ×
>>> J = puma.jacobe(puma.qn) slower). With symbolic operands it takes 170 ms (113 ×
in the base or end-effector frames respectively, as NumPy slower) to produce the unsimplified torque expressions.
arrays. At a singular configuration SMTB-P provides a set of classes for spatial velocity,
>>> J = puma.jacob0(puma.qr) acceleration, momentum, force and inertia to support Feath-
>>> np.linalg.matrix_rank(J) erstone’s spatial vector approach to robot dynamics [5].
5
>>> jsingu(J)
joint 5 is dependent on joint 3 V. NEW CAPABILITY
Jacobians can also be computed using symbolic joint vari-
There are several areas of innovation compared to the
ables as for forward kinematics above.
MATLAB version of the Toolbox.
For ERobot instances we can also compute the Hessian
tensor
>>> H = panda.hessian0(panda.qz)
A. Branched mechanisms
in the base frame as a 3D NumPy array in R6×n×n. The RTB-M SerialLink class had no option to ex-
For all robot classes we can compute manipulability m press branching. The equivalent RTB-P class DHRobot is
>>> puma.manipulability(puma.qn) similarly limited, but a new class ERobot is more general
>>> puma.manipulability(puma.qn, method="asada") and allows for branching (but not closed kinematic loops).
for the Yoshikawa [20] and Asada [21] measures, and The robot is described by a set of ELink objects, each of
>>> puma.manipulability(puma.qn, axes="trans") which points to its parent link. The ERobot has references
is the Yoshikawa measure computed for just the task-space to the root and leaf ELinks. This structure closely mirrors
translational degrees of freedom. For ERobot instances we the URDF representation, allowing easy import of URDF
can also compute the manipulability Jacobian models.
>>> Jm = panda.jacobm(panda.qr) 2The same code as used by RTB-M is called directly from Python, and
such that ṁ = J m (q)q̇. does not use NumPy.
B. Collision checking 3D effects using anaglyphs and a Looking Glass light-
RTB-M had a simple, contributed but unsupported, colli- field (holographic) display3 for glasses-free 3D viewing.
sion checking capability. This is dramatically improved in the Animations can be recorded as MP4 files or animated GIF
Python version using PyBullet [14] which supports primitive files (which are useful for inclusion in GitHub markdown
shapes such as Cylinders, Spheres and Boxes as well as mesh documents).
objects. Every robot ELink can have a collision shape in VI. CODE ENGINEERING
addition to the shape used for rendering. We can conveniently
The code is implemented in Python≥3.6 and hosted on
perform collision checks between links as well as between
GitHub with unit-testing performed using GitHub-actions.
whole robots, discrete links, and objects in the world. For
Test coverage is uploaded to codecov.io for visualization
example a 1 × 1 1× box centered at (1, 0, 0) can be tested
and trending, and we use lgtm.com to perform automated
against all, or just one link, of the robot by
code review. The code is documented with ReStructured Text
>>> panda = rtb.models.Panda()
>>> obstacle = rtb.Box([1, 1, 1], SE3(1, 0, 0)) format docstrings which provides powerful markup including
>>> collision = panda.collided(obstacle) cross-referencing, equations, class inheritance diagrams and
>>> collision = panda.links[0].collided(obstacle) figures – all of which is converted to HTML documentation
Additionally, we can compute the minimum Euclidean dis- whenever a change is pushed, and this is accessible via
tance between whole robots, discrete links, or objects GitHub pages. Issues can be reported via GitHub issues or
>>> d, p1, p2 = panda.closest_point(obstacle) patches submitted as pull requests.
>>> d, p1, p2 = \
panda.links[0].closest_point(obstacle)
RTB-P4, and its dependencies, can be installed by either
$ pip install roboticstoolbox-python
which returns the shortest line segment expressed as a length $ conda install -c conda-forge \
and two endpoints – the coordinates of the closest points on roboticstoolbox-python
each of the two bodies. As an example, the work in [24] uses which includes basic visualization using matplotlib. Options
this feature for reactive collision avoidance for manipulators. such as swift, vpython can be used to specify additional
dependencies to be installed.
C. Interfaces The Toolbox adopts a “when needed” approach to many
RTB-M could only animate a robot in a figure, and there dependencies. This reduces Toolbox import time, since it will
was a limited interface to V-REP and a physical robot. only attempt to import a dependency if the user exploits a
The Python version supports a simple, but universal API functionality that requires it. If a required dependency is not
to a robot inspired by the simplicity and expressiveness installed a warning provides instructions on how to install
of the OpenAI Gym API [25] which was designed as a it. This approach applies to the visualizers VPython and
toolkit for developing and comparing reinforcement learning Swift, as well as pybullet and ROS. The Toolbox provides
algorithms. Whether simulating a robot or controlling a real capability to import URDF-xacro files without ROS. The
physical robot, the API operates in the same manner. backend architecture allows a user to connect to a ROS
By default the Toolbox behaves like the MATLAB version environment if required, and only then does ROS have to
with a plot method be installed.
>>> panda.plot(panda.qr)
VII. CONCLUSION
which will plot the robot at the specified joint configurma-
tion, or animate it if q is a multi-row matrix. This uses This paper has introduced and demonstrated in tuto-
the default PyPlot backend which draws a “noodle robot” rial form the principle features of the Robotics Tool-
using matplotlib similar to that shown in Figure 1a. box for Python which runs on Mac, Linux and Win-
The more general solution, and what is implemented inside dows.The code examples are provided with the Toolbox as
plot in the example above, is icra2021.ipynb. The Toolbox is free and open, and
>>> from roboticstoolbox.backends.Swift \ released under the MIT licence. It provides many of the
import Swift essential tools necessary for robotic manipulator modelling,
>>> backend = Swift() simulation and control which is essential for robotics educa-
>>> backend.launch() # create graphical scene
>>> backend.add(panda) # add robot to the scene tion and research. It is familiar yet new, and we hope it will
>>> panda.q = panda.qr # update the robot serve the community well for the next 25 years.
>>> backend.step() # display the scene Currently under development are backend interfaces for
which will open a new browser tab and render the robot. CoppeliaSim and Dynamixel servo chains; symbolic dy-
This interface makes it possible to animate multiple robots namics, simplification and code generation; spatial vector
in the one graphical window, or the one robot in various dynamics; mobile robotics motion models, planners, EKF
environments either graphical or real. localization, map making and SLAM; and a minimalist
The Swift, see Fig. 1c, and VPython, see Fig. 1b, back- block-diagram simulation tool5.
ends provides browser-based 3D graphics based on WebGL. 3https://lookingglassfactory.com
This is advantageous for displaying on mobile devices or 4https://github.com/petercorke/
from a headless control computer. Swift uses three.js to robotics-toolbox-python
provide high-quality 3D animations and can produce vivid 5https://github.com/petercorke/bdsim
REFERENCES [24] J. Haviland and P. Corke, “NEO: A novel expeditious optimisation
algorithm for reactive motion control of manipulators,” IEEE Robotics
[1] P. Corke, “A computer tool for simulation and analysis: the Robotics and Automation Letters, vol. 6, no. 2, pp. 1043–1050, 2021.
Toolbox for MATLAB,” in Proc. National Conf. Australian Robot [25] G. Brockman, V. Cheung, L. Pettersson, J. Schneider, J. Schul-
Association, Melbourne, Jul. 1995, pp. 319–330. man, J. Tang, and W. Zaremba, “OpenAI gym,” arXiv preprint
[2] P. Corke, “A robotics toolbox for MATLAB,” IEEE Robotics and arXiv:1606.01540, 2016.
Automation Magazine, vol. 3, no. 1, pp. 24–32, Sep. 1996.
[3] P. I. Corke, Robotics, Vision & Control: Fundamental Algorithms in
MATLAB, 2nd ed. Springer, 2017, iSBN 978-3-319-54412-0.
[4] J. Craig, Introduction to Robotics: Mechanics and Control,
ser. Addison-Wesley series in electrical and computer engineering:
control engineering. Pearson/Prentice Hall, 2005. [Online]. Available:
https://books.google.com.au/books?id=MqMeAQAAIAAJ
[5] R. Featherstone, Robot Dynamics Algorithms. Kluwer Academic,
1987.
[6] P. I. Corke, “A simple and systematic approach to assigning Denavit-
Hartenberg parameters,” IEEE transactions on robotics, vol. 23, no. 3,
pp. 590–594, 2007.
[7] J. Haviland and P. Corke, “A systematic approach to computing the
manipulator Jacobian and Hessian using the elementary transform
sequence,” arXiv preprint, 2020.
[8] A. Sakai, D. Ingram, J. Dinius, K. Chawla, A. Raffin, and A. Paques,
“PythonRobotics: a Python code collection of robotics algorithms,”
arXiv preprint arXiv:1808.10703, 2018.
[9] K. Hauser, “Klampt module.” [Online]. Available: https://github.com/
krishauser/Klampt
[10] F. Nori, S. Traversaro, J. Eljaik, F. Romano, A. Del Prete,
and D. Pucci, “iCub whole-body control through force regulation
on rigid noncoplanar contacts,” Frontiers in Robotics and AI,
vol. 2, no. 6, 2015. [Online]. Available: http://www.frontiersin.org/
humanoid robotics/10.3389/frobt.2015.00006/abstract
[11] “Siconos.” [Online]. Available: https://github.com/siconos/siconos
[12] G. Gede, D. L. Peterson, A. S. Nanjangud, J. K. Moore, and
M. Hubbard, “Constrained multibody dynamics with Python: From
symbolic equation generation to publication,” in International Design
Engineering Technical Conferences and Computers and Information
in Engineering Conference, vol. 55973. American Society of Me-
chanical Engineers, 2013, p. V07BT10A051.
[13] J. Lee, M. X. Grey, S. Ha, T. Kunz, S. Jain, Y. Ye, S. S. Srinivasa,
M. Stilman, and C. K. Liu, “DART: Dynamic animation and robotics
toolkit,” The Journal of Open Source Software, vol. 3, no. 22, p. 500,
Feb 2018. [Online]. Available: https://doi.org/10.21105/joss.00500
[14] E. Coumans and Y. Bai, “PyBullet, a Python module for physics
simulation for games, robotics and machine learning,” http://pybullet.
org, 2016–2019.
[15] N. Nadeau, “Pybotics: Python toolbox for robotics,” Journal of
Open Source Software, vol. 4, no. 41, p. 1738, Sep. 2019. [Online].
Available: https://doi.org/10.21105/joss.01738
[16] R. Fraanje, “Python Robotics module.” [Online]. Available: https:
//github.com/prfraanje/python-robotics
[17] R. Fraanje, T. Koreneef, A. Le Mair, and S. de Jong, “Python in
robotics and mechatronics education,” in 2016 11th France-Japan &
9th Europe-Asia Congress on Mechatronics (MECATRONICS)/17th
International Conference on Research and Education in Mechatronics
(REM). IEEE, 2016, pp. 014–019.
[18] S. Chiaverini, L. Sciavicco, and B. Siciliano, “Control of robotic sys-
tems through singularities,” in Advanced Robot Control, Proceedings
of the International Workshop on Nonlinear and Adaptive Control:
Issues in Robotics, ser. Lecture Notes in Control and Information
Sciences, vol. 162. Grenoble: Springer, 1991, pp. 285–295.
[19] R. P. Paul, Robot Manipulators: Mathematics, Programming, and
Control. Cambridge, Massachusetts: MIT Press, 1981.
[20] T. Yoshikawa, “Analysis and control of robot manipulators with re-
dundancy,” in Robotics Research: The First International Symposium,
M. Brady and R. Paul, Eds. The MIT press, 1984, pp. 735–747.
[21] H. Asada, “A geometrical representation of manipulator dynamics
and its application to arm design,” Journal of Dynamic Systems,
Measurement, and Control, vol. 105, p. 131, 1983.
[22] W. Armstrong, “Recursive solution to the equations of motion of an n-
link manipulator,” in Proc. 5th World Congress on Theory of Machines
and Mechanisms, Montreal, Jul. 1979, pp. 1343–1346.
[23] M. W. Walker and D. E. Orin, “Efficient dynamic computer simu-
lation of robotic mechanisms,” ASME Journal of Dynamic Systems,
Measurement and Control, vol. 104, no. 3, pp. 205–211, 1982.