• Stars
    star
    2,041
  • Rank 22,668 (Top 0.5 %)
  • Language
    Python
  • License
    MIT License
  • Created over 9 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Robotics Toolbox for Python

Robotics Toolbox for Python

A Python Robotics Package Powered by Spatial Maths QUT Centre for Robotics Open Source

PyPI version Anaconda version PyPI - Python Version

Build Status Coverage PyPI - Downloads License: MIT

A Python implementation of the Robotics Toolbox for MATLABยฎ

Contents


Synopsis

This toolbox brings robotics-specific functionality to Python, and leverages Python's advantages of portability, ubiquity and support, and the capability of the open-source ecosystem for linear algebra (numpy, scipy), graphics (matplotlib, three.js, WebGL), interactive development (jupyter, jupyterlab, mybinder.org), and documentation (sphinx).

The Toolbox provides tools for representing the kinematics and dynamics of serial-link manipulators - you can easily create your own in Denavit-Hartenberg form, import a URDF file, or use over 30 supplied models for well-known contemporary robots from Franka-Emika, Kinova, Universal Robotics, Rethink as well as classical robots such as the Puma 560 and the Stanford arm.

The Toolbox contains fast implementations of kinematic operations. The forward kinematics and the manipulator Jacobian can be computed in less than 1 microsecond while numerical inverse kinematics can be solved in as little as 4 microseconds.

The toolbox also supports mobile robots with functions for robot motion models (unicycle, bicycle), path planning algorithms (bug, distance transform, D*, PRM), kinodynamic planning (lattice, RRT), localization (EKF, particle filter), map building (EKF) and simultaneous localization and mapping (EKF).

The Toolbox provides:

  • code that is mature and provides a point of comparison for other implementations of the same algorithms;
  • routines which are generally written in a straightforward manner which allows for easy understanding, perhaps at the expense of computational efficiency;
  • source code which can be read for learning and teaching;
  • backward compatability with the Robotics Toolbox for MATLAB

The Toolbox leverages the Spatial Maths Toolbox for Python to provide support for data types such as SO(n) and SE(n) matrices, quaternions, twists and spatial vectors.


Getting going

You will need Python >= 3.6

Using pip

Install a snapshot from PyPI

pip3 install roboticstoolbox-python

Available options are:

  • collision install collision checking with pybullet

Put the options in a comma separated list like

pip3 install roboticstoolbox-python[optionlist]

Swift, a web-based visualizer, is installed as part of Robotics Toolbox.

From GitHub

To install the bleeding-edge version from GitHub

git clone https://github.com/petercorke/robotics-toolbox-python.git
cd robotics-toolbox-python
pip3 install -e .

Tutorials

Do you want to learn about manipulator kinematics, differential kinematics, inverse-kinematics and motion control? Have a look at our tutorial. This tutorial comes with two articles to cover the theory and 12 Jupyter Notebooks providing full code implementations and examples. Most of the Notebooks are also Google Colab compatible allowing them to run online.

Code Examples

We will load a model of the Franka-Emika Panda robot defined by a URDF file

import roboticstoolbox as rtb
robot = rtb.models.Panda()
print(robot)

	ERobot: panda (by Franka Emika), 7 joints (RRRRRRR), 1 gripper, geometry, collision
	โ”Œโ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
	โ”‚link โ”‚     link     โ”‚ joint โ”‚   parent    โ”‚              ETS: parent to link               โ”‚
	โ”œโ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
	โ”‚   0 โ”‚ panda_link0  โ”‚       โ”‚ BASE        โ”‚                                                โ”‚
	โ”‚   1 โ”‚ panda_link1  โ”‚     0 โ”‚ panda_link0 โ”‚ SE3(0, 0, 0.333) โŠ• Rz(q0)                      โ”‚
	โ”‚   2 โ”‚ panda_link2  โ”‚     1 โ”‚ panda_link1 โ”‚ SE3(-90ยฐ, -0ยฐ, 0ยฐ) โŠ• Rz(q1)                    โ”‚
	โ”‚   3 โ”‚ panda_link3  โ”‚     2 โ”‚ panda_link2 โ”‚ SE3(0, -0.316, 0; 90ยฐ, -0ยฐ, 0ยฐ) โŠ• Rz(q2)       โ”‚
	โ”‚   4 โ”‚ panda_link4  โ”‚     3 โ”‚ panda_link3 โ”‚ SE3(0.0825, 0, 0; 90ยฐ, -0ยฐ, 0ยฐ) โŠ• Rz(q3)       โ”‚
	โ”‚   5 โ”‚ panda_link5  โ”‚     4 โ”‚ panda_link4 โ”‚ SE3(-0.0825, 0.384, 0; -90ยฐ, -0ยฐ, 0ยฐ) โŠ• Rz(q4) โ”‚
	โ”‚   6 โ”‚ panda_link6  โ”‚     5 โ”‚ panda_link5 โ”‚ SE3(90ยฐ, -0ยฐ, 0ยฐ) โŠ• Rz(q5)                     โ”‚
	โ”‚   7 โ”‚ panda_link7  โ”‚     6 โ”‚ panda_link6 โ”‚ SE3(0.088, 0, 0; 90ยฐ, -0ยฐ, 0ยฐ) โŠ• Rz(q6)        โ”‚
	โ”‚   8 โ”‚ @panda_link8 โ”‚       โ”‚ panda_link7 โ”‚ SE3(0, 0, 0.107)                               โ”‚
	โ””โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

	โ”Œโ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”
	โ”‚name โ”‚ q0  โ”‚ q1     โ”‚ q2  โ”‚ q3    โ”‚ q4  โ”‚ q5    โ”‚ q6   โ”‚
	โ”œโ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ค
	โ”‚  qr โ”‚  0ยฐ โ”‚ -17.2ยฐ โ”‚  0ยฐ โ”‚ -126ยฐ โ”‚  0ยฐ โ”‚  115ยฐ โ”‚  45ยฐ โ”‚
	โ”‚  qz โ”‚  0ยฐ โ”‚  0ยฐ    โ”‚  0ยฐ โ”‚  0ยฐ   โ”‚  0ยฐ โ”‚  0ยฐ   โ”‚  0ยฐ  โ”‚
	โ””โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”˜

The symbol @ indicates the link as an end-effector, a leaf node in the rigid-body tree (Python prompts are not shown to make it easy to copy+paste the code, console output is indented). We will compute the forward kinematics next

Te = robot.fkine(robot.qr)  # forward kinematics
print(Te)

	0.995     0         0.09983   0.484
	0        -1         0         0
	0.09983   0        -0.995     0.4126
	0         0         0         1

We can solve inverse kinematics very easily. We first choose an SE(3) pose defined in terms of position and orientation (end-effector z-axis down (A=-Z) and finger orientation parallel to y-axis (O=+Y)).

from spatialmath import SE3

Tep = SE3.Trans(0.6, -0.3, 0.1) * SE3.OA([0, 1, 0], [0, 0, -1])
sol = robot.ik_LM(Tep)         # solve IK
print(sol)

	(array([ 0.20592815,  0.86609481, -0.79473206, -1.68254794,  0.74872915,
			2.21764746, -0.10255606]), 1, 114, 7, 2.890164057230228e-07)

q_pickup = sol[0]
print(robot.fkine(q_pickup))    # FK shows that desired end-effector pose was achieved

	 1         -8.913e-05  -0.0003334  0.5996
	-8.929e-05 -1          -0.0004912 -0.2998
	-0.0003334  0.0004912  -1          0.1001
	 0          0           0          1

We can animate a path from the ready pose qr configuration to this pickup configuration

qt = rtb.jtraj(robot.qr, q_pickup, 50)
robot.plot(qt.q, backend='pyplot', movie='panda1.gif')

where we have specified the matplotlib pyplot backend. Blue arrows show the joint axes and the coloured frame shows the end-effector pose.

We can also plot the trajectory in the Swift simulator (a browser-based 3d-simulation environment built to work with the Toolbox)

robot.plot(qt.q)

We can also experiment with velocity controllers in Swift. Here is a resolved-rate motion control example

import swift
import roboticstoolbox as rtb
import spatialmath as sm
import numpy as np

env = swift.Swift()
env.launch(realtime=True)

panda = rtb.models.Panda()
panda.q = panda.qr

Tep = panda.fkine(panda.q) * sm.SE3.Trans(0.2, 0.2, 0.45)

arrived = False
env.add(panda)

dt = 0.05

while not arrived:

    v, arrived = rtb.p_servo(panda.fkine(panda.q), Tep, 1)
    panda.qd = np.linalg.pinv(panda.jacobe(panda.q)) @ v
    env.step(dt)

# Uncomment to stop the browser tab from closing
# env.hold()

Run some examples

The notebooks folder contains some tutorial Jupyter notebooks which you can browse on GitHub. Additionally, have a look in the examples folder for many ready to run examples.


Toolbox Research Applications

The toolbox is incredibly useful for developing and prototyping algorithms for research, thanks to the exhaustive set of well documented and mature robotic functions exposed through clean and painless APIs. Additionally, the ease at which a user can visualize their algorithm supports a rapid prototyping paradigm.

Publication List

J. Haviland, N. Sรผnderhauf and P. Corke, "A Holistic Approach to Reactive Mobile Manipulation," in IEEE Robotics and Automation Letters, doi: 10.1109/LRA.2022.3146554. In the video, the robot is controlled using the Robotics toolbox for Python and features a recording from the Swift Simulator.

[Arxiv Paper] [IEEE Xplore] [Project Website] [Video] [Code Example]

J. Haviland and P. Corke, "NEO: A Novel Expeditious Optimisation Algorithm for Reactive Motion Control of Manipulators," in IEEE Robotics and Automation Letters, doi: 10.1109/LRA.2021.3056060. In the video, the robot is controlled using the Robotics toolbox for Python and features a recording from the Swift Simulator.

[Arxiv Paper] [IEEE Xplore] [Project Website] [Video] [Code Example]

A Purely-Reactive Manipulability-Maximising Motion Controller, J. Haviland and P. Corke. In the video, the robot is controlled using the Robotics toolbox for Python.

[Paper] [Project Website] [Video] [Code Example]



Toolbox ICRA Paper and Citation Info

Check out our ICRA 2021 paper on IEEE Xplore or get the PDF from Peter's website.

If the toolbox helped you in your research, please cite

@inproceedings{rtb,
  title={Not your grandmotherโ€™s toolbox--the Robotics Toolbox reinvented for Python},
  author={Corke, Peter and Haviland, Jesse},
  booktitle={2021 IEEE International Conference on Robotics and Automation (ICRA)},
  pages={11357--11363},
  year={2021},
  organization={IEEE}
}

Using the Toolbox in your Open Source Code?

If you are using the Toolbox in your open source code, feel free to add our badge to your readme!

For the powered by robotics toolbox badge

Powered by the Robotics Toolbox

copy the following

[![Powered by the Robotics Toolbox](https://raw.githubusercontent.com/petercorke/robotics-toolbox-python/master/.github/svg/rtb_powered.min.svg)](https://github.com/petercorke/robotics-toolbox-python)

For the powered by python robotics badge

Powered by Python Robotics

copy the following

[![Powered by Python Robotics](https://raw.githubusercontent.com/petercorke/robotics-toolbox-python/master/.github/svg/pr_powered.min.svg)](https://github.com/petercorke/robotics-toolbox-python)

Common Issues and Solutions

See the common issues with fixes here.

More Repositories

1

robotics-toolbox-matlab

Robotics Toolbox for MATLAB
MATLAB
1,259
star
2

spatialmath-python

Create, manipulate and convert representations of position and orientation in 2D or 3D using Python
Python
294
star
3

machinevision-toolbox-matlab

Machine Vision Toolbox for MATLAB
MATLAB
202
star
4

spatialmath-matlab

Create, manipulate and convert representations of position and orientation in 2D or 3D using Python
MATLAB
197
star
5

RVC3-python

Code examples for Robotics, Vision & Control 3rd edition in Python
Jupyter Notebook
191
star
6

bdsim

Simulate dynamic systems expressed in block diagram form using Python
HTML
174
star
7

machinevision-toolbox-python

Machine vision toolbox for Python
Jupyter Notebook
148
star
8

RVC3-MATLAB

New toolbox, data and examples for Robotics, Vision & Control: 3rd edition in MATLAB
MATLAB
82
star
9

toolbox-common-matlab

Common code for MATLAB toolboxes for Robotics, Machine Vision
MATLAB
57
star
10

rvc-notation

RVC notation
TeX
19
star
11

ansitable

Quick, easy and pretty display of tabular data or matrices, with optional ANSI color and borders
Python
17
star
12

pgraph-python

Simple graph classes
Python
15
star
13

simple-threads-coder

A simple POSIX threading library for MATLAB Coder
C
9
star
14

help2doc

Convert MATLAB source files to various documentation formats
Python
4
star
15

petercorke.github.io

Static web pages
3
star
16

pybib

Python class to parse/sort/filter bibtex files
Python
2
star
17

tkbibtex

Simple python/tk graphical browser/editor for BibTeX files
Shell
2
star
18

RVC3-test

For testing MATLAB Online access to GH based toolboxes and scripts
MATLAB
2
star
19

robotics-toolbox-julia

Julia port of robotics toolbox
1
star
20

arduIO

Simple and efficient Arduino I/O server and Python client
Python
1
star
21

plane-catcher

Log aircraft flying low and loud over Brisbane's Western suburbs
Python
1
star