Robotics Toolbox for Python

repository·main·Indexed 25 days ago

https://github.com/petercorke/robotics-toolbox-python

A high-productivity Python framework for robotics research and education. It provides tools for serial-link manipulator kinematics and dynamics, mobile robot motion models, path planning, and localization. The library supports Denavit-Hartenberg form, URDF imports, and over 50 pre-supplied models, leveraging spatialmath-python for spatial mathematics. It includes integration with the Swift browser-based 3D simulator and a Dynamixel backend for servo interaction.

Tokens
20.1K
Snippets
46
Records
150
Agent score
86%

What's inside roboticstoolbox-python

  1. Overview of Robotics Toolbox for Python capabilities

    main

    The Robotics Toolbox for Python is a high-productivity framework for robotics research and education. It provides tools for:

    • Serial-link Manipulators: Kinematics and dynamics representation. Supports Denavit-Hartenberg form, URDF imports, and over 50 pre-supplied models (e.g., Franka-Emika, Kinova, Universal Robotics, Puma 560).
    • Fast Kinematics: Optimized implementations for forward kinematics, Jacobian computation, and numerical inverse kinematics.
    • Mobile Robots: Motion models (unicycle, bicycle), path planning (bug, distance transform, D*, PRM), kinodynamic planning (lattice, RRT), and localization/mapping (EKF, particle filter, SLAM).
    • Spatial Maths: Leverages the spatialmath-python library for SO(n), SE(n), quaternions, twists, and spatial vectors.
  2. Overview of Robotics Toolbox for Python (RTB-P)

    main
    The Robotics Toolbox for Python (RTB-P) is a library designed for the kinematics, dynamics, motion planning, and control of both arm-type (serial-link manipulator) and mobile (wheeled) robots. It is a modular and extensible Python rewrite of the original Robotics Toolbox for MATLAB (RTB-M).
  3. Overview of the Dynamixel backend

    main

    The Dynamixel backend is a component for interacting with Robotis Dynamixel servos. Note that this backend is currently still under development.

    Key components include:

    • dynamixel_io.py: Provides the interface to communicate with a chain of Dynamixel servos using the Robotis API.
    • dyndata.py: A utility to scrape the Robotis website to build a data structure containing parameters for all Dynamixel models.
    • dynamixel.json: The resulting data structure containing Dynamixel parameters in JSON format.
  4. Understand the fknm C++ extension for fast kinematics

    main

    The fknm extension is a nanobind-based C++/C extension designed to accelerate the 'hot path' of the Exponential Transform Stack (ETS). It provides high-performance implementations for:

    • Forward kinematics
    • Jacobians
    • Hessians
    • Inverse Kinematics (IK) using Newton-Raphson, Gauss-Newton, and Levenberg-Marquardt algorithms

    This extension is used by ETS and Robot objects. It is optional: roboticstoolbox.ets.fknm acts as a facade that automatically falls back to a pure-Python implementation if the compiled extension is unavailable (e.g., in Pyodide/WASM environments or when using symbolic/SymPy inputs).

  5. Supported robot model types in Robotics Toolbox

    main

    The Robotics Toolbox supports three distinct types of robot models, all of which inherit from the abstract Robot superclass. Depending on your needs, you can use:

    • Denavit-Hartenberg (DH) models: Defined using standard or modified DH parameters. These support optional 3D meshes for visualization and optional dynamic parameters.
    • ETS models: Defined using a sequence of elementary transformations (rotations and translations). This is a quick and intuitive method for describing a robot.
    • URDF models: Defined using the Unified Robot Description Format (XML). The toolbox includes pre-defined models for robots like the Puma560, Franka-Emika Panda, Universal Robots, and Interbotix hobby-class robots.
  6. Use the Spatial Math Toolbox for Python (SMTB-P) for 3D transformations

    main

    The Robotics Toolbox for Python uses the Spatial Math Toolbox for Python (SMTB-P) to represent rigid-body transformations, rotations, and poses. While you can use low-level functions from spatialmath.base, it is recommended to use abstraction classes like SE3, SO3, SE2, SO2, Twist3, Twist2, and UnitQuaternion for type safety and cleaner syntax.

    Key features include:

    • Composition: Use the * operator to compose transformations.
    • Inversion: Use the .inv() method or the / operator.
    • Exponentiation: Use the ** operator for repeated composition.
    • Extraction: Easily extract Euler angles (.eul()), rotation submatrices (.R), or translation (.t).
    • Visualization: Use .plot() to display a 3D coordinate frame.
  7. Install the rtb-data package

    main

    The rtb-data package contains large data files (robot models, STL files, and datasets) used by the Robotics Toolbox for Python. You do not need to install it separately; it is automatically installed as a dependency when you install the main roboticstoolbox-python package.

    pip install roboticstoolbox-python
  8. Plan paths using occupancy grids

    main

    For navigation among obstacles, the Toolbox provides several planners that operate on an occupancy grid. The DistanceTransformPlanner is one option. Other available planners include Dstar, PRM, Lattice, Dubins, ReedsShepp, CurvaturePoly, and QuinticPoly. These planners allow you to trade off computation time, path optimality, and vehicle kinematic constraints.

    import numpy as np
    from roboticstoolbox import DistanceTransformPlanner
    
    # Create an occupancy grid with a wall-like obstacle
    occgrid = np.zeros((10, 10))
    occgrid[3:7, 5] = 1
    
    # Plan a path to the goal
    dx = DistanceTransformPlanner(occgrid=occgrid, goal=(8, 8))
    dx.plan()
    path = dx.query(start=(1, 1))
    print(path.shape)
  9. Add ARTE robot models to rtb-data

    main

    You can extend the available robot models by manually adding ARTE (A robotics toolbox for education) models to the rtb-data repository structure.

    1. Obtain the full ARTE robot models from the ARTE website or view the supported robots list.
    2. Download and unzip the models.
    3. Organize the files into the rtb-data/rtbdata/meshes/ directory using the following folder structure: MANUFACTURER/MODEL.
    4. Ensure the folder contains the .stl files named according to the link index (e.g., link0.stl, link1.stl, etc.).
    5. Create a corresponding class in the parent folder to interface with these meshes.