Giter Site home page Giter Site logo

longde123 / robotics-toolbox-python Goto Github PK

View Code? Open in Web Editor NEW

This project forked from petercorke/robotics-toolbox-python

0.0 1.0 0.0 85.3 MB

Robotics Toolbox for Python

License: MIT License

Python 97.39% Shell 0.07% CMake 0.02% C 2.44% Makefile 0.09%

robotics-toolbox-python's Introduction

Robotics Toolbox for Python

PyPI version PyPI - Python Version Language grade: Python Build Status Coverage License: MIT Binder QUT Centre for Robotics Open Source

A Python implementation of the Robotics Toolbox for MATLAB®

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 will also support 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

Code Example

We will load a model of the Franka-Emika Panda robot defined classically using modified (Craig's convention) Denavit-Hartenberg notation

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

	┏━━━━━━━━┳━━━━━━━━┳━━━━━┳━━━━━━━┳━━━━━━━━━┳━━━━━━━━┓
	┃ aⱼ₋₁   ┃  ⍺₋₁  ┃ θⱼdⱼq⁻    ┃   q⁺   ┃
	┣━━━━━━━━╋━━━━━━━━╋━━━━━╋━━━━━━━╋━━━━━━━━━╋━━━━━━━━┫
	┃    0.00.0° ┃  q10.333-166.0° ┃ 166.0° ┃
	┃    0.0-90.0° ┃  q20.0-101.0° ┃ 101.0° ┃
	┃    0.090.0° ┃  q30.316-166.0° ┃ 166.0° ┃
	┃ 0.082590.0° ┃  q40.0-176.0° ┃  -4.0° ┃
	┃-0.0825-90.0° ┃  q50.384-166.0° ┃ 166.0° ┃
	┃    0.090.0° ┃  q60.0-1.0° ┃ 215.0° ┃
	┃  0.08890.0° ┃  q70.107-166.0° ┃ 166.0° ┃
	┗━━━━━━━━┻━━━━━━━━┻━━━━━┻━━━━━━━┻━━━━━━━━━┻━━━━━━━━┛
	
	┌─────┬───────────────────────────────────────┐
	│toolt = 0, 0, 0.1; rpy/xyz = -45°, 0°, 0° │
	└─────┴───────────────────────────────────────┘
	
	┌─────┬─────┬────────┬─────┬───────┬─────┬───────┬──────┐
	│nameq0q1q2q3q4q5q6   │
	├─────┼─────┼────────┼─────┼───────┼─────┼───────┼──────┤
	│  qz0° │  0°    │  0° │  0°   │  0° │  0°   │  0°  │
	│  qr0° │ -17.2° │  0° │ -126° │  0° │  115° │  45° │
	└─────┴─────┴────────┴─────┴───────┴─────┴───────┴──────┘

T = robot.fkine(robot.qz)  # forward kinematics
print(T)

	   0.707107    0.707107    0           0.088        
	   0.707107   -0.707107    0           0            
	   0           0          -1           0.823        
	   0           0           0           1          

(Python prompts are not shown to make it easy to copy+paste the code, console output is indented)

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

T = SE3(0.8, 0.2, 0.1) * SE3.OA([0, 1, 0], [0, 0, -1])
q_pickup, *_ = robot.ikunc(T)   # solve IK, ignore additional outputs
print(q_pickup)                 # display joint angles

	[ 1.10903519  1.21806211  0.10114796  1.49547496  0.33270093 -0.29437262 -0.8927488 ]

print(robot.fkine(q_pickup))    # FK shows that desired end-effector pose was achieved

	  -1          -1.31387e-11-1.57726e-09 0.0999999    
	  -1.31386e-11 1          -7.46658e-08 0.2          
	   1.57726e-09-7.46658e-08-1           0.5          
	   0           0           0           1

Note that because this robot is redundant we don't have any control over the arm configuration apart from end-effector pose, ie. we can't control the elbow height.

We can animate a path from the upright qz configuration to this pickup configuration

qt = rtb.trajectory.jtraj(robot.qz, q_pickup, 50)
robot.plot(qt.q, movie='panda1.gif')

Panda trajectory animation

which uses the default matplotlib backend. Grey arrows show the joint axes and the colored frame shows the end-effector pose.

Let's now load a URDF model of the same robot. The kinematic representation is no longer based on Denavit-Hartenberg parameters, it is now a rigid-body tree.

robot = rtb.models.URDF.Panda()  # load URDF version of the Panda
print(robot)    # display the model

	┌───┬──────────────┬─────────────┬──────────────┬─────────────────────────────────────────────┐
	│idlinkparentjointETS                     │
	├───┼──────────────┼─────────────┼──────────────┼─────────────────────────────────────────────┤
	│ 0panda_link0- │              │                                             │
	│ 1panda_link1panda_link0panda_joint1tz(0.333) * Rz(q0) │
	│ 2panda_link2panda_link1panda_joint2Rx(-90°) * Rz(q1) │
	│ 3panda_link3panda_link2panda_joint3ty(-0.316) * Rx(90°) * Rz(q2) │
	│ 4panda_link4panda_link3panda_joint4tx(0.0825) * Rx(90°) * Rz(q3) │
	│ 5panda_link5panda_link4panda_joint5tx(-0.0825) * ty(0.384) * Rx(-90°) * Rz(q4) │
	│ 6panda_link6panda_link5panda_joint6Rx(90°) * Rz(q5) │
	│ 7panda_link7panda_link6panda_joint7tx(0.088) * Rx(90°) * Rz(q6) │
	│ 8 │ @panda_link8panda_link7panda_joint8tz(0.107) │
	└───┴──────────────┴─────────────┴──────────────┴─────────────────────────────────────────────┘

We can instantiate our robot inside a browser-based 3d-simulation environment.

env = rtb.backends.Swift()  # instantiate 3D browser-based visualizer
env.launch()                # activate it
env.add(robot)              # add robot to the 3D scene
for qk in qt.q:             # for each joint configuration on trajectory
      robot.q = qk          # update the robot state
      env.step()            # update visualization

URDF Panda trajectory animation

Getting going

Installing

You will need Python >= 3.6

Using pip

Install a snapshot from PyPI

pip3 install roboticstoolbox-python

Available options are:

  • vpython install VPython backend
  • vpython install VPython backend
  • collision install collision checking with pybullet

Put the options in a comma separated list like

pip3 install roboticstoolbox-python[optionlist]

Swift-sim, 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 .

Run some examples

The notebooks folder contains some tutorial Jupyter notebooks which you can browse on GitHub.

Or you can run them, and experiment with them, at mybinder.org.

robotics-toolbox-python's People

Contributors

jhavl avatar petercorke avatar micah-huth avatar samuel-drew avatar suddrey avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.