The Great Walker

Back in 2021, my biggest project was to design a planar legged robot, and it took me quite far, as I released pylinkage and leggedsnake, two Python modules for a project known as The Great Walker.

Originally, the idea was to use walking mechanisms for parcel delivery. It is strongly inspired by projects such as TrotBot, Ghassaei’s Linkage, and, of course, Jansen’s Strandbeesten. The foundation was that I was not able to find a good Python library to evaluate the performance of an arbitrary linkage, so I decided to create one.

The Great Walker comprises two libraries with the following goals:

  • Create planar linkages
  • Optimize the kinetic model
  • Optimize the dynamic model

It is divided into two Python modules, pylinkage and leggedsnake, as the first one is a generalist linkage creator while the second focuses precisely on legged mechanisms.

Pylinkage

A Python module that allows you to create, optimize, and visualize kinematic, planar linkages. It was pretty fun to do due to the high degree of freedom I wanted to give the users. One of the things I’m most proud of is its pythonicity: you can achieve fairly complex linkages in a few lines of code.

Python

import pylinkage as pl
# Main motor
crank = pl.Crank(0, 1, joint0=(0, 0), angle=.31, distance=1)
# Close the loop
pin = pl.Pivot(
    3, 2, joint0=crank, joint1=(3, 0), 
    distance0=3, distance1=1
)

my_linkage = pl.Linkage(joints=(crank, pin))

locus = my_linkage.step()

Once your linkage is defined, you can visualize it using Matplotlib, which will return a nice static view and an animation. On the static view, you can see the maximum amplitude of joints.

From now one, starts the funny part: the optimization.

Being able to see the performance of a linkage is cool, but what if the computer optimizes it for you? To do so, I introduced a Particle Swarm Optimization (PSO) based on pyswarms. Each linkage configuration is represented by an agent (think of it like a bee) that collaborates with other agents to find the best configuration.

PSO illustration by Wikipedia

So let’s say angles above the [0; 90] degrees range receive a penalty, we get the following result.

Results were good, but as it is only a kinematic optimization, I had to work further to create legged mechanisms.

Leggedsnake

Leggedsnake is a module is specifically designed to create walking linkages. Once you have done a linkage with pylinkage, you can get its dynamic model automatically with leggedsnake. The fun part is to trying to make your mechanism walk immediately, it usually results in utter disaster.

Fortunately, I have included some code that allows you to add more legs without any supplementary effort.

A walking linakge

Now we have something fun, but how can we make it efficient? I then started to evaluate the energetic efficiency of the system as it’s fitness and inserted it in the PSO evaluator. However, since the simulation of a dynamic linkage takes too much time, PSO was inefficient in giving results in a reasonable amount of time. I had to change my optimizer to a Genetic Algorithm (GA).

A Genetic Algorithm is strongly inspired by the transmission of genetic code through a lineage. Each individual has a DNA and a fitness score, and for each generation, we will select the fittest couples to reproduce. Each couple will create a new individual with a recombined version of their DNA.

Here, DNA is a set of dimensions for our linkage, and our score is its mechanical efficiency. With this approach, I needed far fewer evaluations of the score, and it was successful in providing me results in a reasonable amount of time.

This was a very interesting project, and I hope many people will use it or have fun with it. I’m still willing to maintain it,