Walker Leg Sequencing Example

Let's explore a naive method of sequencing legs for walking robots.

There are many different ways to control legs for a walking robot. The simplest approach is to have each leg follow a repeating pattern called a gait sequence. The main downside is that the robot doesn't know what surface it's walking on, so it will struggle over uneven terrain. But for getting a robot moving and for simple remote-controlled robots, this approach works well to start with.

Let's start with a single leg

We're going to look at where the leg should move to. Getting the leg to actually move to that target is called inverse kinematics, which is a different topic.

Below you'll see a red circle representing where the leg should move and a black circle representing the robot's body.

There are 4 distinct phases to the leg's movement:
  1. Lift - the leg lifts from the ground
  2. Swing - the leg swings forward in the direction of travel
  3. Land - the leg lands on the ground
  4. Retract - the leg pulls back toward the body

You'll notice the circle representing the leg gets bigger when it's in the air. This is just a visual effect since we're working in 2D.

And some more legs...

We're going to start with 4 legs because it's easier to see what's happening with fewer legs.

Now we've added 3 more legs and are running the same movement pattern on each leg.

You might have noticed that the robot would just be moving in a circle without actually going anywhere. We can fix this by adding time offsets to each leg's movement pattern. This makes the legs move in sequence instead of all at once.

However, this adds a new requirement to our movement pattern. The retract phase needs to be longer than the other phases.

How much longer depends on what type of walking pattern you're using. For the simplest "lift one leg at a time" pattern, you need to make sure that when any one leg is in the air, the remaining legs are on the ground.

We've made it clear when the legs are in the air by making the circles unfilled. Now let's see if we can adjust the movement pattern and add the right time offsets.

Crab Walking

Great! That works well for walking in a straight line at a constant speed. But what if we want to go in different directions or change speed?

If we think of each step as an offset from the leg's resting position, we can rotate that offset to move in a different direction. We can also scale the offset based on speed.

We can do this by treating the target position as a vector and rotating it around the center of the robot. This sounds complicated but is actually pretty simple. We use these formulas:

New X = X × cos(angle) - Y × sin(angle)

New Y = X × sin(angle) + Y × cos(angle)

We can also change the speed by multiplying the offset by the speed value.

Turning

We also want to be able to turn - it would be a pretty boring robot if we couldn't do that! Let's think about how a differential drive robot turns: the left side and the right side move at different speeds. We can do the same thing with legs by varying the speed of individual legs.

This is a bit more complicated because we need to know where each leg is in relation to the direction we want to turn.

We use the angle between the leg and the direction we want to turn to figure out if the leg is on the inside or outside of the turn. Then we add or subtract the turning speed depending on whether the leg is on the inside or outside.