Tuesday, 1 April 2014

6 DOF Biped Robot using Dynamixel AX-12A Servos and Arduino

Having mastered driving Robotis Dynamixel AX Servos with an Arduino, I wanted to do something practical with that knowledge. How about building a biped robot?

There are plenty of biped robot kits available, like the Lynxmotion BRAT and the Robotis Bioloid, but I wanted to build something from the parts I already had lying around.

Each of the six Dynamixel AX-12A Servos I recently purchased came supplied with a U shaped bracket and mounting plate. I decided that if I bolted these together I’d get a pretty decent pair of legs. This configuration would give me a total of six degrees of freedom (DOF) - three in each leg - hip and knee joints on the sagittal plane and an ankle joint on the coronal plane.

I cut and drilled a strip of aluminium to form a pelvis and tie the legs together. I had a sheet of 3mm HDPE (the same stuff plastic chopping boards are made from) lying around, so cut this into rectangles to form the feet.

For power, I reused a 5000mAH LiPo battery, which I cable tied to the aluminium pelvis. This placed the centre of gravity nice and high, which is actually useful. On top of that, I taped an Arduino mounted in a plastic case and finally added the CDS55xx Driver Board (to interface the Arduino to the servos).

It's not the prettiest robot, but that completed the mechanical build.


Next came the software part, which turned out to be pretty simple. The key to getting a biped to walk well is developing an efficient walking gait. There are two different ways to approach this:

Static gait - the centre of gravity is projected inside the polygon formed by the robot’s feet. This is the simplest form, although looks artificial.

Dynamic gait - the centre of gravity is not necessarily projected within the polygon of the robot’s feet, however, dynamic balance is maintained. This is far more complex, but results in more natural movement.

For my first experiment, I chose a static gait. As I only had to contend with 6 DOF I decided I could dispense with complex inverse kinematics calculations and do it by hand. And, by keeping the motion of each leg symmetrical it’s easier to keep the centre of gravity central.

I settled on a repeating pattern of four poses that would make up the gait:

- Rotate ankles clockwise, shifting centre gravity to the left and lifting right leg.
- Extend right leg forward and push backwards with left leg.
- Rotate ankles anticlockwise, shifting centre gravity to the right and lifting left leg.
- Extend left leg forward and push backwards with right leg.

Here is a video of the completed biped walking happily across my floor.


Here is the code. Please note, I reference the Dynamixel class as featured in my last blog post.

Biped.ino
#include "Dynamixel.h"
#include "Wire.h"
 
Dynamixel servo;
int velocity = 90;
int centre = 511;
byte c = 0;
byte p = 0;
 
/* Offset array from centre position
 * L_HIP, L_KNEE, L_ANKLE, R_HIP, R_KNEE, R_ANKLE */
int pos[5][6] = {
  {   0,   0,   0,   0,   0,   0 }, // Stand upright
  { -55, -55,  25, -55, -55,  25 }, // Right leg forward
  { -55, -55, -25, -55, -55, -25 }, // Lean right
  {  55,  55, -25,  55,  55, -25 }, // Left leg forward
  {  55,  55,  25,  55,  55,  25 }  // Lean left
};
 
void setup() {
  Serial.begin(1000000);
  delay(5000);
}
 
void loop() {
  if (c < 4)
  {
    update(p++);
    if (p > 4)
    { 
      c++;
      p = 1;
    }
  }
  else update(0);
}
 
void update(byte p)
{
  // Update each servo position.
  for (byte i = 0; i < 6; i++)
    servo.setPos(i + 1, centre + pos[p][i], velocity);
 
  // Wait for motion to complete.
  delay(500);
}

Thanks for reading.
John