Feature

Qu4druped Robot

Four Legged Walking Robot

Harris Mier

Issue 31, February 2020

Through trial and error, Harris learnt a lot about mechanical design in order to create his walking quadruped robot.

It’s relatively straightforward to design and build a robot that uses motorised wheels or tracks to move, but making a robot that walks without losing its balance can be a little more tricky. We caught up with Harris to learn more about his walking robot, and the challenges he needed to overcome to get his robot walking.

Thank you for talking to us about your quadruped. Firstly, tell us a little about yourself?

I’m a student from the UK, still studying for A levels. I will soon be applying to university where I hope to study Design Engineering at Imperial College London. For about a year I have been developing skills, such as CAD, using electronics and coding, through self-led projects while picking up tips and inspiration from the online community.

Excellent. It’s great to have access to the online community who are always willing to share. What got you interested in electronics, 3D printing, coding, and robotics? 

From a young age I have been interested in making things and when I was older it became obvious that engineering was the career path I wanted to follow. To gain some experience I started to learn to use CAD and the natural progression was to utilise 3D printing. Last year I bought myself a printer and began to produce small projects myself. As for electronics, Arduino boards have made a really easy introduction to electronics. I gained information quickly online, but I found the best way to develop is working it out for myself while working on project specific problems.

Well done. It’s great that you have a career path in mind that appeals to your interests, and easily accessible to learn from home. What inspired you to design your four legged robot? 

Obviously, Boston Dynamics’ Spot was big news - a highly complex and very powerful quadruped robot designed for industry, and I love the concept of sharing work online, specifically for 3D printing through websites such as my mini factory. 

With both in mind, I wanted to produce an open sourced quadruped available to hobbyists and people wanting to learn about engineering. Like myself, I’d love people to develop my work further as there are still problems left unsolved.

Boston Dynamics make some amazing robotics. We always look forward to seeing what incredible abilities their robots can perform next. Tell us about your robot, and what needs to be developed further.  

I’m using an Arduino Nano, the PCA9685 PWM servo driver, and an 18650 battery. There are 2 servo motors in each leg for knee pitch and hip pitch and all eight motors connect directly to the driver board. In my current design, I have included a HC-05 Bluetooth module which I am yet to successfully build into the project. 

We notice you are using the low cost servos with plastic gears. Were these suitable or would you have preferred to use metal geared motors instead? 

My robot uses cheap plastic geared SG90 servo motors, which are weak and unreliable but very affordable. I built two robots using 20 motors in total, and as metal gear servos are well over twice the price, it seemed cost effective to use the cheaper servos, despite the disadvantages.

That does make sense Harris. Costs do quickly add up when you need so many servos. We notice your robot tethered to a USB cable. Is this for control or to provide power? 

As it stands, the onboard 18650 battery provides sufficient power to all the components. As I am yet to integrate Bluetooth into the build, the USB cable is simply a means to communicate with the robot. This leaves an obvious place to develop the project in the future.

The Bluetooth module I plan to use is an HC-05. I would love to have this controlled by a smartphone and that is my goal ultimately. For the time being I will try to connect the module to my computer reliably and use a desktop app made with processing to control the robot. The project is on-going!

We’re sure the online community can come to the rescue to help get your project wireless. What were the most challenging parts of the design process? 

By far the most challenging part was the robot’s balance. I intended to build this robot without any feedback from a gyroscope or accelerometer and therefore I was relying on mechanical design for stability. As a result, making small adjustments to leg positions during the build was frustrating but the end result was a success.

Certainly sounds like you needed a lot of patience to get it to walk properly. We guess this is why you designed your own 3D printed stand to help with testing? 

Yes. The stand helps take load off the motors while uploading code or making fine adjustments to leg positions etc. The stand itself is very simple. I printed it as 8 parts flat on the build plate and assembled it. I posted about the stand I built on my Instagram page for your readers to learn more about it.

3D Printed Stand.

Very clever. A great example of using a 3D printer to make custom objects to make life easier. What CAD software do you use? 

As a student I have access to free student editions of CAD packages. I use Solidworks for my project work but I have also learnt to use Autodesk inventor while working at a company called Engineered Arts, who produce humanoid robots.

I’m personally not a big fan of fusion 360, but I guess that’s just because of its slight differences from the software I’m used to using. 

Some CAD programs are more user friendly than others, but sometimes we need to use the one that’s available or affordable. What 3D printer do you use, and what should our readers know if they plan to print your design for themselves? For example, what parts needed supports?

I use the Wanhao Duplicator i3 Plus, also known as the Monoprice Select Plus. I printed all parts in PLA and made every effort to design parts that do not require support. However, you will notice that on the main chassis and each foot there are small notches that stick out for the upper leg to hook onto. These small sections do require support.

Your readers can download the STLs and code from by following the link in my Instagram bio. I will also provide these so they can be downloaded directly from the DIYODE website.

Thank you for sharing your designs Harris. Was your code written from scratch or repurposed from code found online? 

The basis of the code is a combination of information from multiple sources online along with the Adafruit PWM servo driver library. I wrote a simple function that means I can simply state the address of the servo I wish to move and the angle I want it to move to. This function then uses a function from the library to send the corresponding PWM signal to the driver board. This function and everything else was coded from scratch. The walking motion is achieved by effectively panning the required motors through different positions simultaneously. I would love for someone to improve on the code I’ve already done.

We have many code savvy readers who may help you out. Can you go into a little more detail about the code and what our readers should know if they plan to use it?

There is a library made by Adafruit named “Adafruit PWM servo Driver”. Before you start coding for this project you must download the Arduino IDE from their website. Once it has downloaded and you have opened an empty sketch, visit Tools > Manage Libraries > ”Search for the servo driver library” > Install.

This library allows you to send PWM signals (turning Voltage on and off at various time intervals to put it very simply) to the PCA board, in which you have plugged in all your servos, from the Arduino.

#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
#define SERVOMIN  125 // this is the ‘minimum’ pulse length count (out of 4096)
#define SERVOMAX  575 // this is the ‘maximum’ pulse length count (out of 4096)
uint8_t servonum = 0; //for PWMservo library
const int LFT = 0; // start 90 // rest 135 // step forward towards 90
const int LFB = 1; // start 0 // rest 90 // lift to 135 (q)// drop to 65 in forward step
const int RFT = 3; // start 90 // rest 45 // step forward towards 90
const int RFB = 4; // start 180 // rest 90 // lift to 45 (w) // drop to 114 in forward step
const int LBT = 6; // start 90 // rest 135 // step forward towards 90
const int LBB = 7; // start 0 // rest 90 // lift to 135 (e)// drop to 65 in forward step
const int RBT = 9; // start 90 // rest 45 // step forward towards 90
const int RBB = 10; // start 180 // rest 90 // lift to 45 (r)// drop to 114 in forward step
int set_control = 0; // if this is 1 the robot will not repeat phase_1

This is what I have written before the setup code. The SERVOMIN/MAX variables are for the library basically telling it what signal to send to move the servo to 0 degrees and what signal to send to move it to 180 degrees.

All the other variables are specific to my model and are the addresses (the number written on the board in the place you plugged each servo in) of each servo motor. I have written a couple of notes saying to which angle each servo must move in order to achieve different things such as lifting a leg and how far down it must move after stepping forward to maintain balance.

void Position(int number, int degree) {
// takes a desired servo and angle 
int pospwm = map(degree, 0, 180, 125, 575);
//and uses the PWM servo library to execute
pwm.setPWM(number, 0, pospwm );
delay(5);
}
Electronics mounted onto perfboard

This is a function I wrote which makes it much easier to write code for this project. The pwm.setpwm() is from the library I mentioned earlier. This function means you can simply state the servo you wish to move and the position you wish to move it to. And that’s it!

void loop() {
   char incomingByte;
  if (Serial.available() > 0) {
   
incomingByte = (char)Serial.read(); // reads a character from the serial port 
Serial.println(incomingByte);
  }
 if (incomingByte == ‘x’) {
    Serial.println("Reset"); 
   Position(LFT, 90); // these positions set the legs in a straight position, 
  Position(LFB, 0);  // making the assembly easy
  Position(RFT, 90);
  Position(RFB, 180);
  Position(LBT, 90);
  Position(LBB, 0);
  Position(RBT, 90);
  Position(RBB, 180);
  set_control = 0;
    }  
 
 if (incomingByte == ‘z’) {
    Serial.println("Set"); 
  Position(LFT, 135); // these positions ready the robot 
  Position(LFB, 90);  
  Position(RFT, 45);
  Position(RFB, 90);
  Position(LBT, 155);
  Position(LBB, 80); 
  Position(RBT, 40);
  Position(RBB, 90);
  set_control = 0;
    } 
Render of current design.
Render of original design.

This is a portion of the loop. It takes a character from the serial port which can be sent via USB from the serial monitor window. You can use this character to activate any command you want. This could be lifting all the legs or making it wave or making it walk- this however is quite difficult. I will show you the code I wrote to make my robot walk but I’m afraid it is a bit of trial and error.

void Phase_1 () // step LF and RB forwards only, LFT-135-90, LFB-90-135-65
{               //RBT-45-90, RBB-90-45-114
int P1 = 0;
int P1_control = 0; //the function stops when this 
while(P1_control ==0){
for(P1 = 0; P1 < 9; P1 +=1){
Position(LFT,135-(2.5*P1));
Position(RBT,45+(2.5*P1));
Position(LFB,90+(3*P1));
Position(RBB,90-(3*P1));
delay(2);
}
for(P1 = 9; P1 > 0; P1 -=1){
Position(LFT,90+(2.5*P1));
Position(RBT,90-(2.5*P1));
Position(LFB,60+(6*P1));
Position(RBB,115-(6*P1));  
delay(2);
}
P1_control = 1;
}} 

The code shown here is the 2 ‘phases’ that I made. The first phase pans the leg forward moving both the upper leg and lower leg of diagonally opposite legs. This pan code is very simple and you can experiment with it by visiting file > examples > servo > sweep.

The Second phase does the opposite of the first phase while also moving the other pair of legs forward. At this point the motors struggle and the robot becomes unstable, so I include a third phase which is quickly returning all legs to their starting position.

In this sequence the robot steps forward. I got the robot to walk comfortably and somewhat fluid by repeating the stepping sequence without any delay between sequences.

You will find a lot of the numbers in my code are irregular and don’t fit a pattern. This is a result of trial and error and slightly changing the variables multiple of times. Have a go at doing this yourself.

Let’s hope one of our readers can help improve the code for you. It sounds like there was a lot of effort needed to get the leg phasing right? 

After building the robot it took a lot of attempts to make it work. Each attempt involved drastically changing variables, leg positions and speeds. In the end I found the best approach was to plant a pair of legs forward, followed by pulling that pair back while planting the other pair forward, followed by quickly pulling the legs back to the set position. (The pairs I’m referring to are diagonally opposite legs). Repeating these three phases resulted in a sufficient walking motion.

Trial and error is a great way to learn. It’s great that you persisted to get it to walk. We read that your first robot design with quadruped legs didn’t work and you needed a second design with wider feet. Would the first design fall over? 

I’ve learnt a lot about mechanical design through failure in this project.

My first prototype looked like this (based off Boston Dynamics’ Spot). This uses a connector between a motor (housed at the top of the leg) and the foot of the robot. When this top motor moves upwards it lifts the corresponding leg upward.

If the motor positioned in the middle of the leg rotates the foot will be moved forward, the top motor can then be lowered again, and the leg would have completed a step forward.

A good quadruped robot of this simplistic nature should be able to move diagonally opposite legs simultaneously (one pair moves forward as another set moves backwards for a walking motion). This requires the robot to balance comfortably on two legs (a diagonally opposite pair).

I did not achieve this with my first model and what I learnt is you must design the robot to have wide feet for more support and position them near to the centre of mass underneath the robot, which led me to my second prototype.

It can be bitter-sweet when a design fails. It may feel like a waste of time and resources, but what you learn along the way still makes it worthwhile. What would you say were the main challenges of the construction? 

I found two main challenges in construction. Firstly, I wanted the servos to be secured to the feet with screws. However, there is a small space for a screw driver to fit to tighten this screw. To solve this problem, I designed a tool to screw these screws at a 90 degree angle - again this is 3D printable and uses a screw driver head from a standard screw driver kit (I posted about this on my Instagram page).

The only other main challenge I had was a result of the servos not reliably returning to their home position. This could be solved with higher quality motors.

What should our readers know that we haven’t already covered? 

I want this project to be on going. It’s not complete and has many places for improvements. It would be amazing for the 3D printing community to develop my mechanical design to be optimised for printing and the electronic design community to develop its electromechanical control.

Wiring diagram

A project that is continuously evolving can be fun, as long as you have the time. If you were to make it again, what would you change? 

If I was to make a third version I would like to include a gyroscope or accelerometer as well as metal geared servos. I think with these improvements it could be a far more powerful robot. This, however, takes a step away from the simply mechanical robot I aimed to create.

It’s great to see you set a goal before you started to avoid scope-creep, which can make things impractical and expensive. What projects are you working on now?

I’ve just finished work on a hand-held gripper that is stabilised and will always remain flat due to feedback from a gyroscope. The project uses metal gear servos and will therefore use everything I could improve my robot with. I used a product design approach to this project, and developed the ergonomic hand grip using surface modelling on Solidworks. Again, check this out on my Instagram page.

Excellent. We’ll be sure to check out your gripper invention. Finally, what advice do you have for other young makers who are reading this? 

It sounds like a cliché but the best advice I can give is if it doesn’t work, carry on trying until it does. It’s so easy to give up on a frustrating project but I can only say how rewarding it will be to get a successful result after hours of failure. I’m sure this advice will apply to younger creators like myself who are not as experienced and will not be able to jump to a solution as quickly as someone with more experience. 

Thanks for taking the time to tell us about your robot Harris. We look forward to seeing what you design next.

Harris Mier

Harris Mier

17yo School Student