Let’s talk about a project I’ve been working on for a long time, and my first published Python package: pylinkage. It’s a lightweight linkage designer and simulator that lets you quickly define and optimize mechanical linkages in code.

Animation of a four-bar linkage

Introduction

Pylinkage dates back to 2018, when I started working on a project on leg mechanisms. At the time there was no simple way to generate mechanical linkages in Python, so I decided to create my own open-source package. The goal: go from linkage definition to mathematical optimization with minimal boilerplate.

I worked on the package for two years to tune it to my specific needs. After my final examination, I revamped it completely, split it into two packages (pylinkage and leggedsnake) and published it in 2021.

Not much happened until 2023, when I had some time to work on it again. I made it more standard and fixed several issues.

For those not familiar with mechanical engineering, a linkage is a mechanism made of interconnected rigid bodies (links) joined together by joints. Linkages transform motion between input and output links based on their geometry.

Features

Here’s what pylinkage offers:

  • Easy linkage creation: define and manipulate mechanical linkages through a straightforward API in just a few lines of code.
  • Multiple joint types: supports several joint configurations to cover a wide range of mechanisms.
  • Built-in visualization: plot your linkage designs and animate their motion using Matplotlib.
  • Linkage analysis: inspect input-output relationships, link lengths, and motion trajectories to guide optimization.

Getting Started

The documentation covers installation, basic usage, and advanced examples with code snippets and visualizations.

pylinkage documentation screenshot

Example

Here’s an example of a linkage designed for a simple reciprocating engine mechanism. You define the linkage geometry, simulate the motion, and analyze the resulting trajectories, all in Python.

Kinematic view of TrotBot.

Contributing

Pylinkage is open-source and welcomes contributions. Feel free to report issues or submit pull requests.

Conclusion

Pylinkage makes it straightforward to design, simulate, and optimize mechanical linkages in pure Python. If you work with linkages, give it a try!