Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
287 views

Peter Corke Robotics Toolbox Python

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

Peter Corke Robotics Toolbox Python

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

This may be the author’s version of a work that was submitted/accepted

for publication in the following source:

Corke, Peter & Haviland, Jesse


(2021)
Not your grandmother’s toolbox – the Robotics Toolbox reinvented for
Python.
In Proceedings of the 2021 IEEE International Conference on Robotics
and Automation (ICRA 2021).
Institute of Electrical and Electronics Engineers Inc., United States of
America, pp. 11357-11363.

This file was downloaded from: https://eprints.qut.edu.au/229002/

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.

License: Creative Commons: Attribution-Noncommercial 4.0

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

Peter Corke1, Jesse Haviland1

Abstract— For 25 years the Robotics Toolbox for MATLAB®


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
ROS. With familiar, simple yet powerful functions; the clarity
of Python syntax; but without the complexity of ROS; users
from beginner to advanced will find this a powerful open-source
toolset for ongoing robotics education and research. (a) Puma560, with a velocity ellipsoid, rendered using the default
matplotlib visualizer.
I. INTRODUCTION
The Robotics Toolbox for MATLAB® (RTB-M) was cre-
ated in 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 to MATLAB such as the addition
of structures, objects, lists (cell arrays) and strings, new
graphics and new tools such as an IDE, debugger, notebooks
(LiveScripts), apps and continuous integration. An adverse
consequence is that many poor early design decisions hinder
ongoing development.
Over time additional functionality was also added, in
particular for vision, and two major refactorings led to
the current state of three toolboxes: Robotics Toolbox for (b) Puma560 rendered using the web-based VPython visualizer.
MATLAB and Machine Vision Toolbox for MATLAB (1999)
both of which are built on the Spatial Math Toolbox for
MATLAB (SMTB-M) from 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
a tutorial fashion.
II. A PYTHON VERSION
The imperative for a Python version has long existed and
the first port was started in 2008 but ultimately failed for
(c) Some popular robots rendered using the Toolbox’s Swift visu-
1Peter Corke and Jesse Haviland are with the Queensland University alizer.
of Technology Centre for Robotics (QCR), Brisbane, Australia
peter.corke@qut.edu.au, j.haviland@qut.edu.au. Fig. 1: The toolbox provides several visualizers
This research was supported by the QUT Centre for Robotics.

978-1-7281-9077-8/21/$31.00 ©2021 IEEE


lack of ongoing resources to complete a sufficient subset of Siconos, iDynTree, and PyDy focus on multibody dynamics
functionality. Several subsequent attempts met the same fate. for model specification, simulation and benchmarking.
The design goals of this Python version are new function- The pybotics [15] robotics toolkit focusses on robot
ality: kinematics but is limited to modified Denavit–Hartenberg
• A superset of the MATLAB Toolbox functionality. notation. A similar work, python-robotics [16], was created
• Build on the Spatial Math Toolbox for Python which due to the author’s inspiration by RTB-M and dissatisfaction
provides objects to represent rotations as matrices in with Python-based alternatives [17]. The package, while far
SO(2) and SO(3) as well as unit-quaternions, rigid- from an RTB-M clone or port, contains useful functionality
body motions as matrices SE(2) and SE(3) as well as for robotics education.
twists in se(2) and se(3), and spatial vectors [5]. Our reinvented toolbox: The Robotics Toolbox for Python,
• Allow kinematic models to be expressed using elemen- promises to encapsulate an extensive scope of robotics, from
tary transform sequences [6], [7], URDF-style rigid- low-level spatial-mathematics to robot arm kinematics and
body trees as well as Denavit-Hartenberg notation (stan- dynamics (regardless of model notation), and mobile robots,
dard and modified). Support branched, but not closed- provide interfaces to graphical simulators and real robots,
loop or parallel, robots. while being pythonic, well documented, and well maintained
• Collision and distance-to-collision checking. with applications in research, education, and industry.
and improved software engineering: III. SPATIAL 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∈S3). 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 problematic ROS constraints on operating >>> from spatialmath.base import *
system and Python versions. >>> T = transl(0.5, 0.0, 0.0)
• Modular approach to interfacing to different graphics
@ rpy2tr(0.1, 0.2, 0.3, order='xyz')
@ trotx(-90, 'deg')
libraries, simulators and physical robots. >>> print(T)
• Support Python notebooks which allows publication of [[ 0.97517033 -0.19866933 -0.0978434 0.5 ]
static notebooks (for example via GitHub) and interac- [ 0.153792 0.28962948 0.94470249 0. ]
[-0.15934508 -0.93629336 0.31299183 0. ]
tive online notebooks (via MyBinder.org). [ 0. 0. 0. 1. ]]
• Use of Unicode characters to make console output richer
There is strong similarity to the equivalent MATLAB case
and easier to read.
apart from the use of the @ operator, the use of keyword
A. Related work arguments instead of keyword-value pairs, and the format
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 animations, 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 matrices or, as in this case, NumPy
simulations, physics simulation, dynamical modelling, and arrays. Firstly, arrays are not typed by the group they
collision detection making them useful robotics toolkits. represent – for example a 3×3 array could be an element
These two packages are written in C++ with Python bindings of SE(2) or SO(3) or an arbitrary matrix.
making them fast and efficient, while still being usable in a Secondly, the operators we need for poses are a sub-
Python environment. However, although both packages are set of those available for matrices, and some operators
feature-rich, they lack the ease of use and intuitive inter-
faces provided by pythonic development-driven applications. 1https://github.com/petercorke/spatialmath-python
may need to be redefined in a specific way. For example, Instance of SE3, SO3, SE2,
X
R4×4,
SO2, Twist3, Twist2 or
SE(3) ∗ SE(3) → SE(3) but SE(3) + SE(3) UnitQuaternion Example expressions:
and equality testing for a unit-quaternion has to respect the Y = X[1]
Y = X[2:]
double mapping. X[2] = Y
Thirdly, in robotics we often need to represent sets or ...
Y = X.pop()
value[0] value[1] value[n-1] X.insert(2) = Y
sequences of poses, for example, all link frames on a robot or del X[2]

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,

We use classes and data encapsulation to address all these


Matching Resulting
SO2, Twist3, Twist2 or
instance instance
UnitQuaternion

issues. SMTB-P provides abstraction classes SE3, Twist3,


SO3, UnitQuaternion, SE2, Twist2 and SO2. For a
value[0]
b
value[1]
c d
*
e
value[0]
→ ae
value[0]
be
value[1]
ce de
value[2] value[3 value[2] value[3

example, the previous example could be written as


>>> from spatialmath import *
>>> T = SE3(0.5, 0.0, 0.0) a
* b c d e
→ ab ac ad ae

* SE3.RPY([0.1, 0.2, 0.3], order='xyz')


value[0]
value[0] value[1] value[2] value[3 value[0] value[1] value[2] value[3

* 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

-0.159345 -0.936293 0.312992 0


0 0 0 1 Fig. 3: Overloaded operators support broadcasting.
where composition is denoted by the * operator and the
matrix is printed more elegantly (and elements are color assign to values. Some constructors take an array-like ar-
coded at the console or in ipython). SE3.RPY() is a class gument allowing creation of multi-valued pose objects, for
method that acts like a constructor, creating an SE3 instance example
from a set of roll-pitch-yaw angles, and SE3.Rx() creates >>> R = SE3.Rx(np.linspace(0, pi/2, num=100))
>>> len(R)
an SE3 instance describing pure rotation about the x-axis. 100
Attempts to compose with a non SE3 instance results in a
where the instance R contains a sequence of 100 rotation
TypeError.
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()
shown in Figure 3.
array([ 95.91307498, 71.76037536, -80.34153447]) The types all have an inverse method .inv() and support
the rotation matrix can be easily extracted composition with the inverse using the / operator and integer
>>> T.R exponentiation (repeated composition) using the ** operator.
array([[ 0.97517033, -0.19866933, -0.0978434 ], Other overloaded operators include *, *=, **=, /, /=, ==,
[ 0.153792 , 0.28962948, 0.94470249], !=, +, -. The operator @ acts like * but normalizes the result.
[-0.15934508, -0.93629336, 0.31299183]])
Supporting classes include Quaternion and Plucker
and we can plot the coordinate frame (for lines in 3D). Most constructors accept a Python list or
>>> T.plot(color='red', frame='2')
a NumPy array.
Similar constructors create objects with orientation ex- All of this allows for concise and readable code. The use of
pressed in terms of an angle-vector pair, Euler vector, or classes ensures type safety and that the matrices abstracted by
orientation and approach vectors. the class are always valid members of the group. Operations
Rotation can also be represented by a unit quaternion such as addition, which are not group operations, yield a
>>> UnitQuaternion.Rx(0.3) NumPy array rather than a class instance.
0.988771 << 0.149438, 0.000000, 0.000000 >>
>>> UnitQuaternion.AngVec(0.3, [1, 0, 0]) These benefits come at a price in terms of execution
0.988771 << 0.149438, 0.000000, 0.000000 >> time due to the overhead of constructors and methods
which again demonstrates several alternative constructors. which wrap base functions, and type checking. The Toolbox
The classes are generally polymorphic and have the same supports SymPy which provides powerful symbolic support
constructors for canonic rotations, Euler and roll-pitch-yaw for Python and it works well in conjunction with NumPy,
angles, angle-vector, as well as a random value. SEn.Exp() ie. a NumPy array can contain symbolic elements. Many
and SOn.Exp() is the matrix exponential constructor Toolbox methods and functions contain extra logic to ensure
whose argument is the corresponding Lie algebra element. that symbolic operations work as expected. While this also
To support trajectories each of these types inherits list adds to the overhead it means that for the user, working with
properties from collections.UserList as shown in symbols is as easy as working with numbers. Performance
Figure 2. We can index the values, iterate over the values, on a 3.6 GHz Intel Core i9 is shown in Table I.
Function/method Execution time
base.rotx() 4.07 µs 2) ERobot + ETS notation: A Puma robot can also be
base.trotx() 5.79 µs specified in ETS format [6] as a sequence of simple rigid-
SE3.Rx() 12.3 µs body transformations, pure translation or pure rotation, with
SE3 * SE3 4.69 µs
4x4 @ 0.986 µs a constant parameter or a free parameter which is a joint
SE3.inv() 7.62 µs variable
base.trinv() 4.19 µs >>> e = ET.tz(l1) * ET.rz() * ET.ty(l2) * ET.ry()
np.linalg.inv() 4.49 µs * ET.tz(l3) * ET.tx(l4) * ET.ty(l5)
* ET.ry() * ET.tz(l6) * ET.rz() * ET.ry()
TABLE I: Spatial math execution performance * ET.rz()
where l1-l6 are robot dimensions. Note there is no con-
IV. ROBOTICS TOOLBOX straint on the joint variables being about or along the z-axis.
We can promote the ETS to a robot class by
A. Robot models >>> robot = ERobot(e)
The Toolbox ships with over 30 robot models, most An ERobot is a generalization of the robot that represents
are purely kinematic but some have inertial and frictional a directed-graph of ELink objects, allowing for support of
parameters or graphical models. Kinematic models can be branched robots.
specified in a variety of ways: standard or modified Denavit- 3) ERobot + URDF import: The Toolbox includes a
Hartenberg (DH, MDH) notation, as an elementary transform parser with built-in xacro processor which makes all models
sequence [6], as a rigid-body tree, or from a URDF file. from the ROS universe accessible. The import is wrapped
1) Denavit-Hartenberg parameters: To create a kinematic by an ERobot subclass
model using DH notation, we pass a list of link objects to the >>> panda = models.URDF.Panda()
DHRobot constructor. For example, an IRB140 is simply which results in an object with 3D meshes, collision objects,
>>> from roboticstoolbox import * kinematic and dynamic data. All standard operations already
>>> robot = DHRobot( introduced above are provided, but since the robot can
[
RevoluteDH(d=d1, a=a1, alpha=-pi/2), potentially have multiple end-effectors, the name of the end-
RevoluteDH(a=a2), effector link must be provided to the kinematic methods.
RevoluteDH(alpha=pi/2),
... B. Trajectories
], name="my IRB140")
A joint-space trajectory for the Puma robot from the zero-
where only the non-zero parameters are specified. In this case angle to the upright (or READY) joint configuration in 100
we used RevoluteDH objects for a revolute joint described steps is
using standard DH conventions. Other classes available >>> traj = jtraj(puma.qz, puma.qr, 100)
are PrismaticDH, RevoluteMDH and PrismaticMDH. >>> qplot(traj.q)
Parameters such as mass, CoG, link inertia, motor inertia, where puma.qr is an example of a named joint configura-
viscous friction, Coulomb friction, and joint limits can be tion. traj is a trajectory object with elements q = qk, qd =
specified using additional keyword arguments. q̇k and qdd = q̈k . Each element is an array with one row per
We can easily perform standard kinematic operations time step. The trajectory is a fifth order polynomial which
>>> puma = models.DH.Puma560() has continuous jerk. Non-zero initial and final velocities may
>>> T = puma.fkine([0.1,0.2 0.3,0.4,0.5,0.6]) be specified.
>>> sol = puma.ikine_LM(T) Straight line (Cartesian) paths can be generated in a similar
IKsolution(q=array([0.1,0.2,0.3,0.4,0.5,0.6]),
success=True, reason=None, iterations=12, way between two poses in SE(3) by
residual=8.515092622288915e-13) >>> t = np.arange(0, 2, 0.010) # time
>>> puma.plot(sol.q) >>> T0 = SE3(0.6, -0.5, 0.3) # initial pose
>>> T1 = SE3(0.4, 0.5, 0.2) # final pose
where T is an SE3 instance, and ikine LM() is one of >>> Ts = ctraj(T0, T1, t)
several generalised iterative inverse kinematic (IK) solu- >>> len(Ts)
200
tions [18] provided, this one based on Levenberg-Marquadt
minimization. Additional status results are also returned. By The resulting trajectory, Ts, is an SE3 instance with 200
default plot uses matplotlib to produce a “noodle robot” values. For both trajectory types, the number of steps is
plot like that shown in Fig 1a. given by an integer argument or the length of a passed time
The starting point for the solution may be specified, but vector. Inverse kinematics can then be applied to determine
defaults to zero, and this affects both the search time and the corresponding joint angle motion using
>>> sol = puma.ikine_LM(Ts)
the solution found. For a redundant manipulator there is no >>> sol.q.shape
explicit control over the null-space. For a manipulator with (200, 6)
n < 6 DOF an additional argument indicates which of the where sol is an IK solution tuple whose elements are a
6 − n task-space DOF are to be unconstrained in the solution. 2D-array of joint coordinates (one row per timestep) with
Some robot classes have an efficient closed-form analytical the other status as either a 1D-array or list. In this case the
solution coded, for example [19] starting joint coordinates for each inverse kinematic solution
>>> q = puma.ikine_a(T, config="lun") is taken as the result of the previous solution.
C. Symbolic manipulation E. Dynamics
The Toolbox supports SymPy, for example: The new Toolbox supports several approaches to comput-
>>> import spatialmath.base.symbolic as sym ing dynamics. For models defined using standard or modified
>>> phi, theta, psi = sym.symbol('phi theta psi')
>>> rpy2r(phi, theta, psi)
DH notation we use a classical version of the recursive
array([[cos(psi)*cos(theta), sin(phi)*sin(theta)* Newton-Euler [22] algorithm implemented in Python or C2.
cos(psi) - sin(psi)*cos(phi), sin(phi)* For example, the inverse dynamics
sin(psi) + sin(theta)*cos(phi)*cos(psi)],
..., dtype=object) >>> tau = puma.rne(puma.qn, puma.qz, puma.qz)

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.

You might also like