Initial servo calibration and leg position

Calibrating the servos and getting the initial position of the legs right is quite important in order to get a smooth walking experience.

After setting op your Node.js and Johnny-Five environment create a new directory and add the following script:

var five = require("johnny-five");
var board = new five.Board();

var legs = [
              {
                 id:'FR',
                 lable:'Front right',
                 hip:{ pin:0, offset:0, invert:false },
                 knee:{ pin:1, offset:0, invert:false }
              },
              {
                 id:'FL',
                 lable:'Front left',
                 hip:{ pin:2, offset:0, invert:true },
                 knee:{ pin:3, offset:0, invert:true }
              },
              {
                 id:'BR',
                 lable:'Back right',
                 hip:{ pin:4, offset:0, invert:true },
                 knee:{ pin:5, offset:0, invert:true }
              },
              {
                 id:'BL',
                 lable:'Back left',
                 hip:{ pin:6, offset:0, invert:false },
                 knee:{ pin:7, offset:0, invert:false }
              }
           ];

board.on("ready", function() {

  for(var i = 0; i < legs.length; i++){
    legs[i].hip.servo = new five.Servo({
                          controller: "PCA9685",
                          address: 0x40,
                          invert:legs[i].hip.invert,
                          pin: legs[i].hip.pin
                        });

    legs[i].knee.servo = new five.Servo({
                          controller: "PCA9685",
                          address: 0x40,
                          invert:legs[i].knee.invert,
                          pin: legs[i].knee.pin
                        });
  }

  for(var i = 0 ; i < legs.length; i++){
    legs[i].hip.servo.to(90 + legs[i].hip.offset );
    legs[i].knee.servo.to(90 + legs[i].knee.offset );
  }

  this.repl.inject({
    legs:legs
  });

});

For the next step is best not to have the thighs/femurs attached (to avoid the risk of striping the servos gears).

Edit the pin number in the script (legs.hip.pin, etc) to match your setup’s connections and run the script. This will set all servos to 90 degrees.

Now attach the thighs/femurs. The femurs should form a 90 degrees angle in relation to the body.

The shins should also form a 90 degrees angle, but be aware that the shin is slightly lifted as the angle should be from the tip of the shin to the femur (as seen in the graphic).

Due to the coarseness of the teeth on the servo horns the resulting angles  might be off by a couple of degrees. To get it as close as possible edit the offset values in the script (legs.hip.offset, etc). For example if the front right femur is off by 2 degrees to the left set the offset value to legs.hip.offset = -2.

Run the script again and check (preferably with an angle ruler) that all segments are correctly positioned.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s