Skip to main content

No project description provided

Project description

Python Industrial Robots

This is an experimental set of python bindings for the also-experimental Industrial Robots library written in Rust.

This is a proof-of-concept for some simple tools related to generating and predicting motion and planning for industrial robots. Currently, it is only wrapping a forward and inverse kinematics solver for the Fanuc LR Mate 200iD, a small, prolific industrial robot arm. The solver itself uses the K library for kinematics, with the robot model painstakingly verified against the R30iB controller's handling of joints and the J2/J3 interaction so that values put into the model matching the controller will produce the same pose and format that the actual controller will report.

In the longer term, if the underlying Rust library proves to be useful, I will likely expand it to perform some amount of motion planning and collision detection and leave it open for others to add robots, and will update these bindings to match as many features as possible.

Simple Use

import numpy
from py_industrial_robots import fanuc_fk, fanuc_ik

# Forward Kinematics
# =============================================

# Specify the joint angles in degrees exactly as they would go into the R30iB
poses = fanuc_fk([0.0, 0.0, 0.0, 0.0, 0.0, 0.0])

The result is a list of six poses, one for each joint. The poses themselves are in the form of lists 16 elements long, representing a 4x4 matrix in row-major order. The last pose is the pose of the robot flange and will match what the controller reports when set to an empty tool frame. The other poses will have origins which lie on the X-Z plane on the axis of the joint, but the orientation of the poses will match the world coordinate system when the robot is at its zero position.

Physical distance units are in millimeters, as that's what the robot itself uses.

Poses can be converted to numpy matrices as follows:

for i, pose in enumerate(poses):
    mat = numpy.matrix(pose).reshape(4, 4)
    print(f"Joint {i} pose:\n{mat}\n")

Inverse kinematics can be performed by passing a pose (in the same list-based, row-major format as they are received) and a list of initial joint angles to the fanuc_ik function. The underlying solver uses a Jacobian based approach. The function will throw an exception if the solver does not find a result. The result will be a list of six joint values in degrees as they would be sent to the R30iB controller.

current_joints = [20.0, 30.0, -10.0, 15.0, 90.0, 12.0]
poses = fanuc_fk(current_joints)

# Get the pose of the robot flange and turn it into a numpy matrix
end_pose = numpy.matrix(poses[-1]).reshape(4, 4)

# Build a transform that moves the current position by x=10, y=20, z=30
transform = numpy.identity(4)
transform[:3, 3] = [10.0, 20.0, 30.0]

# Generate a new desired target pose
target_pose = transform * end_pose

# Convert into the list-based, row-major format
target = list(target_pose.flat)

# Run the IK solver
new_joints = fanuc_ik(target, current_joints)

Note: I currently use lists to move numbers back and forth across the boundary of Python and the compiled Rust binaries because I have yet to figure out how to use the Rust numpy package to create native numpy arrays.

Building

The goal is to be able to cross compile libraries for x86_64 Windows and Linux in a Linux based build environment. I've managed to do that locally with the following.

Prerequisites

  • The Rust toolchain must be installed first
  • MinGW-w64 must be installed. On Debian based systems this is the mingw-w64 package.
  • llvm must be installed, on Debian based systems this is the llvm package.
  • The Windows target must be added to the Rust toolchain. This can be done with rustup target add x86_64-pc-windows-msvc. There is a -gnu version as well, but the default Python Windows binaries are built with MSVC.
  • Python must be installed and maturin must be installed into the Python environment. This can be done with pip install maturin.

Example on Debian/Ubuntu build environment:

sudo apt-get install mingw-w64 llvm curl python3 python3-pip 
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup target add x86_64-pc-windows-msvc

# Install maturin into the Python environment, if you're not in a container you 
probably want to do this in a virtualenv 
pip3 install maturin

Building

# Build for Linux
maturin build --release --strip

# Build for Windows
maturin build --release --strip --target x86_64-pc-windows-msvc

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_industrial_robots-0.1.1.tar.gz (9.5 kB view hashes)

Uploaded Source

Built Distributions

py_industrial_robots-0.1.1-cp37-abi3-win_amd64.whl (196.9 kB view hashes)

Uploaded CPython 3.7+ Windows x86-64

py_industrial_robots-0.1.1-cp37-abi3-win32.whl (185.5 kB view hashes)

Uploaded CPython 3.7+ Windows x86

py_industrial_robots-0.1.1-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ x86-64

py_industrial_robots-0.1.1-cp37-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.3 MB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ s390x

py_industrial_robots-0.1.1-cp37-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.3 MB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ ppc64le

py_industrial_robots-0.1.1-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.1 MB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ ARMv7l

py_industrial_robots-0.1.1-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.1 MB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ ARM64

py_industrial_robots-0.1.1-cp37-abi3-manylinux_2_5_i686.manylinux1_i686.whl (1.2 MB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.5+ i686

py_industrial_robots-0.1.1-cp37-abi3-macosx_11_0_arm64.whl (294.3 kB view hashes)

Uploaded CPython 3.7+ macOS 11.0+ ARM64

py_industrial_robots-0.1.1-cp37-abi3-macosx_10_7_x86_64.whl (321.8 kB view hashes)

Uploaded CPython 3.7+ macOS 10.7+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page