0% found this document useful (0 votes)
24 views

Python Toolbox ICRA 2021

Uploaded by

Nino Qy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Python Toolbox ICRA 2021

Uploaded by

Nino Qy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Published at ICRA 2021 DOI: 10.1109/ICRA48506.2021.

9561366

© 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.

Not your grandmother’s toolbox – the Robotics Toolbox reinvented for Python

Peter Corke1 , Jesse Haviland1

Abstract— For 25 years the Robotics Toolbox for MATLAB R


has been used for teaching and research worldwide. This paper
describes its successor – the Robotics Toolbox for Python.
More than just a port, it takes advantage of popular open-
source packages and resources to provide platform portability,
fast browser-based 3D graphics, quality documentation, fast
numerical and symbolic operations, powerful IDEs, shareable
and web-browseable notebooks all powered by GitHub and
the open-source community. The new Toolbox provides well-
known functionality for spatial mathematics (homogeneous
transformations, quaternions, triple angles and twists), tra-
jectories, kinematics (zeroth to second order), dynamics and
a rich assortment of robot models. In addition, we’ve taken
the opportunity to add new capabilities such as branched
mechanisms, collision checking, URDF import, and interfaces to
CoppeliaSim, ROS and Dynamixel servomotors. With familiar,
simple yet powerful functions; the clarity of Python syntax;
but without the complexity of ROS; users from beginner to
(a) Puma560, with a velocity ellipsoid, rendered using the default
advanced will find this a powerful open-source toolset for
matplotlib visualizer.
ongoing robotics education and research.

I. I NTRODUCTION
The Robotics Toolbox for MATLAB R (RTB-M) was cre-
ated around 1991 to support the first author’s PhD research
and was first published in 1995-6 [1][2]. It has evolved
over 25 years to track changes and improvements to the
MATLAB language and ecosystem, such as the addition of
structures, objects, lists (cell arrays) and strings, myriad other
improvements to the language, new graphics and new tools
such as IDE, debugger, notebooks (LiveScripts), apps and
continuous integration. An adverse consequence is that many
poor early design decisions hinder development.
Over time additional functionality was also added, in (b) Puma560 rendered using the web-based VPython visualizer.
particular for vision, and two major refactorings led to
the current state of three toolboxes: Robotics Toolbox for
MATLAB R and Machine Vision Toolbox for MATLAB R
(1999) both of which are built on the Spatial Math Toolbox
for MATLAB R (SMTB-M) in 2019 [3]. The code was
formally open sourced to support its use for the third
edition of John Craig’s book [4]. It was hosted on ftp sites,
personal web servers, Google code and currently GitHub
and maintained under a succession of version control tools
including rcs, cvs, svn and git. A support forum on Google
Groups was established in 2008 and currently has over 1400
members.
This paper describes the motivation and design of the
Robotics Toolbox for Python, and illustrates key features in
1 Peter Corke and Jesse Haviland are with the Australian Centre for
Robotic Vision (ACRV), Queensland University of Technology Centre for (c) The Universal Robot family rendered using the Toolbox’s Swift
Robotics (QCR), Brisbane, Australia [email protected], visualizer.
[email protected]. This research was conducted by the Australian
Research Council project number CE140100016, and supported by the QUT Fig. 1: The toolbox provides several visualizers
Centre for Robotics.
a tutorial fashion. making them fast and efficient, while still being usable in a
Python environment. However, although both packages are
II. A P YTHON VERSION
feature-rich, they lack the ease of use and intuitive inter-
The imperative for a Python version has long existed and faces provided by pythonic development-driven applications.
the first port was started in 2008 but ultimately failed for Siconos, iDynTree, and PyDy focus on multibody dynamics
lack of ongoing resources to complete a sufficient subset of for model specification, simulation and benchmarking.
functionality. Subsequent attempts have all met the same fate. The pybotics [15] robotics toolkit focusses on robot kine-
The design goals of this version can be summarised as matics but is limited to Modified Denavit–Hartenberg nota-
new functionality: tion. A similar work, python-robotics [16], was created due
R
• A superset of the MATLAB Toolbox functionality to the author’s inspiration by RTB-M and dissatisfaction with
• Build on the Spatial Math Toolbox for Python which Python-based alternatives [17]. The package, while far from
provides objects to represent rotations as matrices in a RTB-M clone or conversion, contains useful functionality
SO(2) and SO(3) as well as unit-quaternions, rigid- for robotics education.
body motions as matrices SE(2) and SE(3) as well Our reinvented toolbox: The Robotics Toolbox for Python,
as twists in se(2) and se(3), and Featherstone’s spatial promises to encapsulate an extensive scope of robotics, from
vectors [5]. low-level spatial-mathematics to robot arm kinematics and
• Support models expressed using Denavit-Hartenberg dynamics (regardless of model notation), and mobile robots,
notation (standard and modified), elementary transform provide interfaces to graphical simulators and real robots,
sequences [6], [7], and URDF-style rigid-body trees. while being pythonic, well documented, and well maintained
Support branched, but not closed-loop or parallel, robots with applications in research, education, and industry.
• Collision and distance-to-collision checking
and improved software engineering: III. S PATIAL MATHEMATICS
• Use Python 3 (3.6 and greater)
Robotics and computer vision require us to describe po-
• Utilize WebGL and Javascript graphics technologies
sition, orientation and pose in 3D space. Mobile robotics
• Documentation in ReStructured Text using Sphinx and
has the same requirement, but generally for 2D space. We
delivered via GitHub pages. therefore need tools to represent quantities such as rigid-
• Hosted on GitHub with continuous integration using
body transformations (matrices ∈ SE(n) or twists ∈ se(n)),
GitHub actions rotations (matrices ∈ SO(n) or so(n), Euler or roll-pitch-yaw
• High code-quality metrics for test coverage, and auto-
angles, or unit quaternions ∈ S 3 ). Such capability is amongst
mated code review and security analysis the oldest in RTB-M and the equivalent functionality in
• As few dependencies as possible, in particular being
RTB-P makes use of the Spatial Maths Toolbox for Python
able to work with ROS but not be dependent on ROS. (SMTB-P)1 . For example
This sidesteps ROS constraints on operating system and >>> from spatialmath.base import *
Python versions. >>> T = transl(0.5, 0.0, 0.0)
@ rpy2tr(0.1, 0.2, 0.3, order=’xyz’)
• Modular approach to interfacing to different graphics @ trotx(-90, ’deg’)
libraries, simulators and physical robots. >>> print(T)
[[ 0.97517033 -0.19866933 -0.0978434 0.5 ]
• Support Python notebooks which allows publication of [ 0.153792 0.28962948 0.94470249 0. ]
static notebooks (for example via GitHub) and interac- [-0.15934508 -0.93629336 0.31299183 0. ]
[ 0. 0. 0. 1. ]]
tive online notebooks (MyBinder.org).
• Use of Unicode characters to make console output easier There is strong similarity to the equivalent MATLAB R case
to read. apart from the use of the @ operator, the use of keyword
arguments instead of keyword-value pairs, and the format
A. Related work of the printed array. All the “classic” RTB-M functions
There are a number of Python-based packages for robotics, are provided in the spatialmath.base package as well
each reflecting different design approaches or requirements as additional functions for quaternions, vectors, twists and
and with various levels of finish in terms of documentation, argument handling. There are also functions to perform
examples, and continuous integration. interpolation, plot and animate coordinate frames, and create
PythonRobotics [8] and Klampt [9] offer a focus on movies, using matplotlib. The underlying datatypes in all
autonomous navigation and planning. While differing in cases are 1D and 2D NumPy arrays. For a user transitioning
scope to this work, PythonRobotics features excellent docu- from MATLAB the most significant difference is the use of
mentation and code quality, making it an exemplar. 1D arrays – all MATLAB arrays have two dimensions, even
Many packages have a focus on dynamics including if one of them is equal to one.
iDynTree [10], Siconos [11], PyDy [12], DART [13], and However some challenges arise when using arrays,
PyBullet [14]. PyBullet and DART both feature graphical whether native MATLAB R matrices or, as in this case,
simulations, physics simulation, dynamical modelling, and NumPy arrays. Firstly, arrays are not typed and for example
collision detection making them useful robotics toolkits.
These two packages are written in C++ with Python bindings 1 https://github.com/petercorke/spatialmath-python
a 3 × 3 array could be an element of SE(2) or SO(3) or an Instance of SE3, SO3, SE2,
X SO2, Twist3, Twist2 or
arbitrary matrix. UnitQuaternion Example expressions:
Secondly, the operators we need for poses are a sub- Y = X[1]
Y = X[2:]
set of those available for matrices, and some operators X[2] = Y
may need to be redefined in a specific way. For example, Y = X.pop()
value[0] value[1] ... value[n-1] X.insert(2) = Y
SE(3) ∗ SE(3) → SE(3) but SE(3) + SE(3) → R4×4 , del X[2]
can contain zero or more values X *= Y
and equality testing for a unit-quaternion has to respect the
Y = [x.inv() for x in X]
double mapping.
Thirdly, in robotics we often need to represent time
Fig. 2: Any of the SMTB-P pose classes can contain a list
sequences of poses. We could add an extra dimension to
of values
the matrices representing rigid-body transformations or unit-
quaternions, or place them in a list. The first approach Instance of SE3, SO3, SE2,
Matching Resulting
SO2, Twist3, Twist2 or
instance
is cumbersome and reduces code clarity, while the second UnitQuaternion
instance

cannot ensure that all elements of the list have the same
type.
a
value[0]
b
value[1]
c
value[2]
d
value[3]
*
e
value[0]
→ ae
value[0]
be
value[1]
ce
value[2]
de
value[3]

We use classes and data encapsulation to address all these


issues. SMTB-P provides abstraction classes SE3, Twist3,
SO3, UnitQuaternion, SE2, Twist2 and SO2. For
a
value[0]
*
b
value[0]
c
value[1]
d
value[2]
e
value[3]
→ ab
value[0]
ac
value[1]
ad
value[2]
ae
value[3]

example, the previous example could be written as


>>> from spatialmath import *
>>> T = SE3(0.5, 0.0, 0.0) a
value[0]
b
value[1]
c
value[2]
d
value[3]
* e
value[0]
f
value[1]
g
value[2]
h
value[3]
→ ae
value[0]
bf
value[1]
cg
value[2]
dh
value[3]
* SE3.RPY([0.1, 0.2, 0.3], order=’xyz’)
* SE3.Rx(-90, unit=’deg’)
>>> print(T) Fig. 3: Overloaded operators support broadcasting.
0.97517 -0.198669 -0.0978434 0.5
0.153792 0.289629 0.944702 0
-0.159345 -0.936293 0.312992 0
0 0 0 1
To support trajectories each of these types inherits list
where composition is denoted by the * operator and the properties from collections.UserList as shown in
matrix is printed more elegantly (and elements are color Figure 2. We can index the values, iterate over the values,
coded at the console or in ipython). SE3.RPY() is a class assign to values. Some constructors take an array-like ar-
method that acts like a constructor, creating an SE3 instance gument allowing creation of multi-valued pose objects, for
from a set of roll-pitch-yaw angles, and SE3.Rx() creates example
an SE3 instance from a pure rotation about the x-axis. >>> R = SE3.Rx(np.linspace(0, pi/2, num=100))
>>> len(R)
Attempts to compose with a non SE3 instance would result 100
in a TypeError. where the instance R contains a sequence of 100 rotation
The orientation of the new coordinate frame may be matrices in SE(3). Composition with a single-valued (scalar)
expressed in terms of Euler angles pose instance broadcasts the scalar across the sequence as
>>> T.eul()
array([ 95.91307498, 71.76037536, -80.34153447]) shown in Figure 3.
The types all have an inverse method .inv() and support
the rotation matrix can be easily extracted
>>> T.R
composition with the inverse using the / operator and integer
array([[ 0.97517033, -0.19866933, -0.0978434 ], exponentiation (repeated composition) using the ** operator.
[ 0.153792 , 0.28962948, 0.94470249], Other overloaded operators include *, *=, **, **=, /, /=,
[-0.15934508, -0.93629336, 0.31299183]])
==, !=, +, -. Supporting classes include Quaternion and
and we can plot the coordinate frame Plucker (for lines in 3D).
>>> T.plot(color=’red’, label=’2’)
All of this allows for concise and readable code. The use of
Similar constructors create objects with orientation ex- classes ensures type safety and that the matrices abstracted by
pressed in terms of an angle-vector pair or orientation and the class are always valid members of the group. Operations
approach vectors. such as addition which are not group operations yield a
Rotation can also be represented by a unit quaternion NumPy array rather than a class instance.
>>> UnitQuaternion.Rx(0.3) These benefits come at a price in terms of execution
0.988771 << 0.149438, 0.000000, 0.000000 >>
>>> UnitQuaternion.AngVec(0.3, [1, 0, 0]) time due to the overhead of constructors and methods which
0.988771 << 0.149438, 0.000000, 0.000000 >> wrap base functions, and type checking. The Toolbox sup-
which again demonstrates several alternative constructors. ports SymPy which provides powerful symbolic support for
The classes are somewhat polymorphic and have the same Python and it works well in conjunction with NumPy, ie.
constructors for canonic rotations, Euler and roll-pitch-yaw a NumPy array can contain symbolic elements. Many the
angles, angle-vector, as well as a random value. SE(n) and Toolbox methods and functions contain extra logic to ensure
SO(n) also support a matrix exponential constructor where that symbolic operations work as expected. While this adds
the argument is the corresponding Lie algebra element. to the overhead it means that for the user, working with
Function/method Execution time
base.rotx() 4.07 µs
The IK procedure for any specific robot can be derived
base.trotx() 5.79 µs symbolically [19] and commonly an efficient closed-form so-
SE3.Rx() 12.3 µs lution can be obtained. Some robot classes have an analytical
SE3 * SE3 4.69 µs
4x4 @ 0.986 µs
solution coded, for example
SE3.inv() 7.62 µs >>> puma.ikine_a(T, config="lun")
base.trinv() 4.19 µs 2) ERobot + ETS notation: A Puma robot can also be
np.linalg.inv() 4.49 µs
specified in ETS format [6] as a sequence of simple rigid-
TABLE I: Spatial math execution performance body transformations, pure translation or pure rotation, with
a constant parameter or a free parameter which is a joint
variable
>>> e = ET.tz(l1) * ET.rz() * ET.ty(l2) * ET.ry()
symbols is as easy as working with numbers. Performance * ET.tz(l3) * ET.tx(l6) * ET.ty(l4) * ET.ry()
on a 3.6 GHz Intel Core i9 is shown in Table I. * ET.tz(l5) * ET.rz() * ET.ry() * ET.rz()
>>> robot = SerialLink(e)
IV. ROBOTICS T OOLBOX and can represent single-branched robots with any combina-
A. Robot models tion of revolute and prismatic joints.
3) ERobot + URDF import: The final approach is to
The Toolbox ships with over 30 robot models, most
import a URDF file. The Toolbox includes a parser with
are purely kinematic but some have inertial and frictional
built-in xacro processor which makes all models from the
parameters or graphical models. Kinematic models can be
ROS universe accessible.
specified in a variety of ways: standard or modified Denavit-
More complex models such as for Panda or Puma are
Hartenberg (DH, MDH) notation, as an ETS string [6], as a
defined by classes but built this way
rigid-body tree, or from a URDF file. >>> panda = rtb.models.URDF.Panda()
1) Denavit-Hartenberg parameters: To specify a kine-
and comprise a list or tree of ELink objects. Standard
matic model using DH notation, we create a new subclass of
operations such as forward and inverse kinematics, and
DHRobot and pass the superclass constructor a list of link
plotting function just like the example above. If the URDF
objects. For example, an IRB140 is simply
model includes Collada graphics models, then Swift is able
>>> robot = DHRobot(
[ to produce a 3-D visualization like that shown in Figure 1a.
RevoluteDH(d=d1, a=a1, alpha=-pi/2), The ERobot class supports branched robots, with multiple
RevoluteDH(a=a2),
RevoluteDH(alpha=pi/2), end-effectors, so the name of the link must be provided to
... the kinematic methods.
], name="my IRB140")

where only the non-zero parameters need to be specified. B. Trajectories


In this case we used RevoluteDH objects for a revo- A joint-space trajectory for the Puma robot from the zero-
lute joint described using standard DH conventions. Other angle to the upright (or READY) joint configuration in 100
classes available are PrismaticDH, RevoluteMDH and steps is
PrismaticMDH. Other parameters such as mass, CoG, link >>> traj = rtb.jtraj(puma.qz, puma.qr, 100)
>>> rtb.qplot(traj.j)
inertia, motor inertia, viscous friction, Coulomb friction, and
joint limits can also be specified using additional keyword where puma.qr is an example of a named joint configura-
arguments. tion. traj is a named tuple with elements q = qk , qd = q̇k
We can easily perform standard kinematic operations and qdd = q̈k . Each element is an array with one row
>>> puma = rtb.models.DH.Puma560() per time step, and each row a joint coordinate vector. The
>>> T = puma.fkine([0.1, 0.2, 0.3, 0.4, 0.5, 0.6]) trajectory is a fifth order polynomial which has continuous
>>> q, *_ = puma.ikine(T)
>>> puma.plot(q) jerk. By default, the initial and final velocities are zero, but
ikine() is a generalised iterative inverse kinematic (IK) these may be specified by additional arguments.
solution [18] based on Levenberg-Marquadt minimization, Straight line (Cartesian) paths can be generated in a similar
and additional status results are also returned. The default way between two poses in SE(3) by
>>> t = np.arange(0, 2, 0.010)
plot interface, using matplotlib, produces a “noodle robot” >>> T0 = SE3(0.6, -0.5, 0.0)
plot like that shown in Fig 1a. >>> T1 = SE3(0.4, 0.5, 0.2)
>>> Ts = ctraj(T0, T1, t)
The starting point for the solution may be specified, but >>> len(Ts)
200
defaults to zero, and affects both the search time and the
solution found, since in general a manipulator may have The resulting trajectory, Ts, is an SE3 instance with 200
several joint configurations which result in the same end- values. For both trajectory types, the number of steps is
effector pose. For a redundant manipulator there is no explicit given by an integer argument or the length of a passed time
control over the null-space. For a manipulator with n < 6 vector. Inverse kinematics can then be applied to determine
DOF an additional argument is required to indicate which the corresponding joint angle motion using
>>> qs, *_ = puma.ikine(Ts)
of the 6 − n task-space DOF are to be unconstrained in the >>> qs.shape
solution. (200, 6)
where qs is is an array of joint coordinates, one row per E. Dynamics
timestep. In this case the starting joint coordinates for each The new Toolbox supports several approaches to comput-
inverse kinematic solution is taken as the result of the ing dynamics. For models defined using standard or modified
previous solution. DH notation we use a classical version of the recursive
C. Symbolic manipulation Newton-Euler [22] algorithm implemented in Python or C2 .
As mentioned earlier, the Toolbox supports SymPy. For For example, the inverse dynamics
>>> tau = puma.rne(puma.qn, np.zeros((6,)), np.zeros((6,)))
example:
>>> import roboticstoolbox.base.symbolics as sym is the gravity torque for the robot in the configuration qn.
>>> phi, theta, psi = sym.symbol(’phi, theta, psi’) Inertia, Coriolis/centripetal and gravity terms are com-
>>> rpy2r(phi, theta, psi)
array([[cos(psi)*cos(theta), puted by
sin(phi)*sin(theta)*cos(psi) - sin(psi)*cos(phi), >>> J = puma.inertia(q)
sin(phi)*sin(psi) + sin(theta)*cos(phi)*cos(psi)], >>> C = puma.coriolis(q, qd)
... >>> g = puma.gravload(q)
This capability readily extends to forward kinematics respectively, using the method of [23] from the inverse
>>> q = sym.symbol("q_:6") # q = (q_1, q_2, ... q_5)
>>> T = puma.fkine(q) dynamics. These values include the effect of motor inertia
however the expression is more complex than it should be, and friction.
because the sin αj and cos αj are not precisely 0, -1 or +1 Forward dynamics are given by
>>> qdd = puma.accel(q, tau, qd)
due to finite precision of the value math.pi. If the αj
values are set to the symbolic value of π (sympy.S.Pi) which we can integrate over time
>>> q = puma.fdyn(5, q0, mycontrol, ...)
then the expressions are greatly simplified
>>> puma = rtb.models.DH.Puma560(symbolic=True) uses an RK45 numerical integration from the SciPy package
>>> T = puma.fkine(q)
to solve for the joint trajectory q given the joint-space control
If we display the value of puma we see that the αj values function called as
are now displayed in red to indicate that they are symbolic tau = mycontrol(robot, t, q, qd, **args)
constants. The x-coordinate of the end-effector is The fast C implementation is not capable of symbolic
>>> T.t[0]
0.15005*sin(q_0) - 0.0203*sin(q_1)*sin(q_2)*cos(q_0) operation so a Python version of RNE rne python has
- 0.4318*sin(q_1)*cos(q_0)*cos(q_2) been implemented as well. For a 6- or 7-DoF manipu-
- 0.4318*sin(q_2)*cos(q_0)*cos(q_1)
+ 0.0203*cos(q_0)*cos(q_1)*cos(q_2) lator the torque expressions have thousands of terms yet
+ 0.4318*cos(q_0)*cos(q_1) are computed in less than a second. However, subsequent
SymPy allows any expression to be converted to runnable expression manipulation is slow, and the best strategy is to
code in a variety of languages including C, Python and eliminate the least significant terms and this typically gets
Octave/MATLAB. the expression for the first joint to a hundred or so terms
D. Differential kinematics which is quite manageable. This is an area of active work,
as is the automatic generation of efficient run-time code for
The Toolbox computes Jacobians manipulator dynamics.
>>> J = puma.jacob0(q)
>>> J = puma.jacobe(q) For the Puma 560 robot, the C version of inverse dynamics
in the base or end-effector frames respectively, as NumPy takes 23 µs while the Python version takes 1.5 ms (65×
arrays. At a singular configuration slower). With symbolic operands it takes 170 ms (113×
>>> J = puma.jacob0(puma.qr) slower) to produce the unsimplified torque expressions.
>>> np.linalg.matrix_rank(J)
5 For all robots there is also an implementation of Feather-
>>> jsingu(J) stone’s spatial vector method, rne spatial, and SMTB-P
joint 5 is dependent on joint 3
provides a set of classes for spatial velocity, acceleration,
Jacobians can also be computed for symbolic joint variables momentum, force and inertia.
as for forward kinematics above.
For ERobot instances we can also compute the Hessians V. N EW CAPABILITY
>>> H = puma.hessian0(q)
>>> H = puma.hessiane(q) There are several areas of innovation compared to the
in the base or end-effector frames respectively, as 3D NumPy MATLAB R version of the Toolbox.
arrays in R6×n×n .
A. Branched mechanisms
For all robot classes we can compute manipulability
>>> m = puma.manipulability(q) The RTB-M SerialLink class had no option to express
>>> m = puma.manipulability(q, "asada")
branching. In RTB-P the equivalent class – DHRobot – is
for the Yoshikawa [20] and Asada [21] measures, and similarly limited, but a new class ERobot is more general
>>> m = puma.manipulability(q, axes="trans")
and allows for branching (but not closed kinematic loops).
is the Yoshikawa measure computed for just the task-space The robot is described by a set of ELink objects, each of
translational degrees of freedom. For ERobot instances we which points to its parent link. The ERobot has references
can also compute the manipulability Jacobian
>>> Jm = puma.manipm(q, J, H) 2 The same code as used by RTB-M is called directly from Python, and
such that ṁ = J m (q)q̇. does not use NumPy.
to the root and leaf ELinks. This structure closely mirrors with a Looking Glass light-field (holographic) display3 for
the URDF representation, allowing for easy import of URDF glasses-free 3D viewing. Animations can be recorded as MP4
models. files or animated GIF files (which are useful for inclusion in
GitHub markdown documents).
B. Collision checking
RTB-M had a simple, contributed but unsupported, colli- VI. C ODE ENGINEERING
sion checking capability. This is dramatically improved in the The code is implemented in Python ≥ 3.6 and all code
Python version using PyBullet [14] which supports primitive is hosted on GitHub and unit-testing is performed using
shapes such as Cylinders, Spheres and Boxes as well as mesh GitHub-actions. Test coverage is uploaded to codecov.io
objects. Every robot ELink has a collision shape in addition for visualization and trending, and we use lgtm.com to per-
to the shape used for rendering. We can conveniently perform form automated code review. The code is documented with
collision checks between links as well as between whole ReStructured Text format docstrings which provides pow-
robots, discrete links, and objects in the world. For example erful markup including cross-referencing, equations, class
a 1 × 1 × 1 box centered at (1, 0, 0) can be tested against all, inheritance diagrams and figures – all of which is converted
or just one link, of the robot by to HTML documentation whenever a change is pushed, and
>>> panda = rtb.models.Panda() this is accessible via GitHub pages. Issues can be reported
>>> obstacle = rtb.Box([1, 1, 1], SE3(1, 0, 0))
>>> iscollision = panda.collided(obstacle) # boolean via GitHub issues or patches submitted as pull requests.
>>> iscollision = panda.links[0].collided(obstacle) RTB-P, and its dependencies, can be installed simply by
Additionally, we can compute the minimum Euclidean dis- $ pip install roboticstoolbox-python

tance between whole robots, discrete links, or objects which includes basic visualization using matplotlib. Options
>>> d, p1, p2 = panda.closest_point(obstacle) such as vpython can be used to specify additional depen-
>>> d, p1, p2 = panda.links[0].closest_point(obstacle)
dencies to be installed. The Toolbox adopts a “when needed”
which returns the shortest line segment expressed as a length approach to many dependencies and will only attempt to
and two endpoints – the coordinates of the closest points on import them if the user attempts to exploit a particular
each of the two bodies. functionality. If the dependency is not installed a warning
C. Interfaces provides instructions on how to install them using pip and/or
npm. More details are given on the project home page.4
RTB-M could only animate a robot in a figure, and there
This applies to the visualizers Vpython and Swift, as well as
was limited but not-well-supported ability to interface to V-
pybullet and ROS. The Toolbox provides capability to import
REP and a physical robot. The Python version supports a
URDF-xacro files without ROS. The backend architecture
simple, but universal API to a robot inspired by the simplicity
allows a user to connect to a ROS environment if required,
and expressiveness of the OpenAI Gym API [24] which
and only then does ROS have to be installed.
was designed as a toolkit for developing and comparing
reinforcement learning algorithms. Whether simulating a VII. C ONCLUSION
robot or controlling a real physical robot, the API operates This paper has introduced and demonstrated in tutorial
in the same manner. form the principle features of the Robotics Toolbox for
By default the Toolbox behaves like the MATLAB R Python which runs on Mac, Windows and Linux.The code
version with a plot method is free and open, and released under the MIT licence. It
>>> puma.plot(q)
provides many of the essential tools necessary for robotic
which will plot the robot at the specified joint configur- manipulator modelling, simulation and control which is
mation, or animate it if q is an m × 6 matrix. This uses essential for robotics education and research. It is familiar
the default PyPlot backend which draws a “noodle robot” yet new, and we hope it will serve the community well for
using matplotlib similar to that shown in Figure 1a. the next 25 years.
The more general solution, and what is implemented inside Currently under development are backend interfaces for
plot in the example above, is CoppeliaSim, Dynamixel servo chains, and ROS; sym-
>>> pyplot = roboticstoolbox.backends.PyPlot()
>>> pyplot.launch() bolic dynamics, simplification and code generation; mobile
>>> pyplot.add(puma) robotics motion models, planners, EKF localization, map
>>> puma.q = q
>>> puma.step() making and SLAM; and a minimalist block-diagram sim-
This makes it possible to animate multiple robots in the ulation tool5 .
one graphical window, or the one robot in various environ-
ments either graphical or real.
The VPython backend, see Fig. 1b, provides browser-
based 3D graphics based on WebGL. This is advantageous
for displaying on mobile devices. Swift, see Fig. 1c, is an 3 https://lookingglassfactory.com
Electron app that uses three.js to provide high-quality 3D 4 https://github.com/petercorke/
animations. It can produce vivid 3D effects using anaglyphs robotics-toolbox-python
viewed with colored glasses, and we also adapted it to work 5 https://github.com/petercorke/bdsim
R EFERENCES [24] G. Brockman, V. Cheung, L. Pettersson, J. Schneider, J. Schul-
man, J. Tang, and W. Zaremba, “OpenAI gym,” arXiv preprint
[1] P. Corke, “A computer tool for simulation and analysis: the Robotics arXiv:1606.01540, 2016.
Toolbox for MATLAB,” in Proc. National Conf. Australian Robot
Association, Melbourne, Jul. 1995, pp. 319–330.
[2] ——, “A robotics toolbox for MATLAB,” IEEE Robotics and Automa-
tion 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.

You might also like