Projects

Double Trouble - Biped Robot

There's two two-legged robots to build!

Oliver Higgins

Issue 13, July 2018

This article includes additional downloadable resources.
Please log in to access.

Log in

Building a walking robot becomes easy with this simple and fun biped.

BUILD TIME: 1.5 hours
DIFFICULTY RATING: BEGINNER / Intermediate

child working on robot

Let’s take a moment to understand robots. There are many different types available, to work with and design, and each comes with their own unique set of positives and negatives. Car or tank track-style robots are very easy to get going, but are limited in the scope of what they can do or the terrain the can traverse. The quad and hexapod-style robots are very cool, but require some complicated math to get them to move, not to mention the increased cost of build due to the large number of servos required. There are self-balancing robots, which are interesting but only serve a limited function; and then there are bipeds.

Biped robots are difficult. There’s a good reason you won’t readily find bipedal locomotion in nature (humans are a weird exception). Walking upright on two legs is a form of controlled falling, and so requires complex control of many different muscles and constant adjustments to maintain the centre of balance.

In the case of our “walking” robot, we are making it shuffle around with short steps to help keep it upright. Having said that, due to its weight distribution, it is more than capable of balancing itself on one foot, if required – thanks to its large, oversized feet. Each foot has quite a large surface area, which means that the robot can easily accommodate itself when shifting its weight around; even though it may appear to be walking.

HOW IT WORKS

Our little biped robot is quite simple. It uses four servos: two on each leg. One servo to drive the ankle articulation, and the other servo to pivot the hip joint. In keeping things simple, we are not using a middle “knee” joint. The basic design is based upon the open source Otto DIY project.

We have developed two builds using this concept. The basic Arduino Nano version remains fairly close to the original design, while the Wemos D1 Mini version utilises the ESP8266 to enable wireless control of the robot. The Nano can be programmed with ArduinoBlocks, or with the Arduino IDE. The Wemos version does require using the Arduino IDE if you wish to write your own code.

We have included more variation in the servos that can be used, which are contained in the STL files provided. The two types of hobby servos are plastic or metal geared. We prefer the metal-geared versions, but they do come at an additional cost. The head is the same for both builds, however we’ve created one that is a little bit higher if you feel you need more room to house the electronics. At times, this article may seem a bit “chicken and the egg”, requiring the case and electronics to be assembled together. We do recommend that you read the entire article before starting to build, to avoid unexpected challenges along the way.

The Fundamental Build:

This project is a little different to other projects, as we need to build the body before we get stuck into building the circuit. Some parts require wiring to your main board also, however the physical build is similar for both microcontrollers, so described once.

Parts Required:Jaycar
4 × SG90 Servos or 4 x MG90 ServosYM2758/YM2765
4 × AA Battery HolderPH9200
4 x AA BatteriesSB2902
1 × Toggle SwitchST0335
Female Header StripHM3230
3D Printed Chassis-

BUILDING THE BODY

For this first section where we build the body, it doesn’t matter which microcontroller you’re going to use. However, you will need to calibrate the servos as you go, which we'll demonstrate along the way also.

While the 3D printed case is the same for the Autonomous and WiFi controlled versions, there are differences in the servo motors between plastic and metal geared versions. You can use either type of servo, but you must ensure you print the correct case files for what you're planning to use, as they are not entirely the same. With that in mind, we have provided MG90 and SG90 STL files for printing whichever version you would like.

The differences are only minor, so the reference images can still be used for metal or plastic versions. It's just some minor differences in dimension, not discernable in the reference photos.

Some aspects of the fit will vary depending on the quality of your 3D printer and the speed of the overall print etc. You can roughly check-fit all the pieces such as the head to body, feet to legs etc, and look for any areas that may need some attention. A small flat file is a handy tool for cleaning up any artifacts from the printing process. Once that's complete, we can get on to construction.

Note that we need to "home" the servos along the way. Failing to home the servos along the way may result in damage to the servos, the printed parts, or both. However before homing, you will need to decide which microcontroller you want to use. The pin connections for the Arduino Compatible Nano, and the Wemos D1 are different.

Once you have decided between the Autonomous and WiFi version, you can proceed with calibration. As we noted at the start of this project, you will need steps completed between the electronics and printed parts concurrently, so it's best to read through everything before attempting your build.

INSTALL & HOME THE HIP SERVOS

Take the 3D printed body section and place down with the open part facing up, take our first servo and place it inside the cavity, there is only one alignment possible. You will see that the top part of the servo has notch or bump that aligns with the hole. Now repeat with a second servo on the opposing side of the housing. Once in place use the provided screws with the servo to screw in place. Be mindful to avoid over-tightening them, as doing so may damage the body.

With these two servos in place we need to calibrate or “home” them. This ensures the initial position is where we need it, so the legs can twist the way we need them to.

nano version

NANO VERSION: Connect the right hip servo to Pin 2, and the left hip servo to Pin 3.

wifi version

WIFI VERSION: Install the right hip servo data pin to D5, and the left servo data pin to D6. Note that the servos must connect to 5V, not 3.3V on the Wemos.

description

HOMING: In each of the directories, you’ll find a folder called OTTO_ServoHome. Open this in the Arduino IDE and make sure that your microprocessor is connected. Upload and run the sketch. You will hear the servos move into position then “detach”. Note: they will not hold position, so if you move them now you’ll need to reset the device to get them to move back again).

Some servo motors will automatically hold positiong due to the amount of force required to drive the gearbox from the servo-arm side. However these hobby-style servo motors are easily moved by hand (though will have enough friction to hold your robot in certain poses while not powered up).

INSTALL THE LEGS

With the hip servos in place and aligned, we’ll need to add on the legs. At the bottom of each leg, there is a small recess to place in the control horn that came with the servo. To get a snug fit, this may require some filing. Place them into the slot and trim any excess off the end using pliers. Align the leg to the hip, being mindful that the large gap in the leg goes to the back. With some patience, place a screw into the control horn and then place the leg assembly onto the hip servo. Do not over-tighten as there needs to be some degree of movement. Simply securing it will be enough. Repeat this for the other leg.

legs

INSTALL & HOME THE FEET

With both legs in place, we need to add the second set of servos. Place the servo cable in first and exit through the triangle like the gap on the inside of the leg, pass the cable through the slit in the lower section of the body.

home and the feet

Align the servo so that the notch in the top control area is facing in. They will need to run along behind the servo, but there is enough space. Once in place use one of the screws that are supplied with the servo to secure. We now need to connect and align our ankle servos.

ARDUINO COMPATIBLE NANO VERSION: Connect the right leg to Pin 4, the left leg to Pin 5.

WIFI VERSION: Connect the right servo data pin to D8 and the left servo data pin to D7.

Place the feet onto the leg. Place the large hole over the servo and then push to snap the pivot point into the hole. It may require a little bit of force. However don't screw them in yet.

feet

With the feet in place, re-run the align function if needed, and then screw the control horns in place. Once done, trim the excess off. With this lower section complete, open the OTTO_Basic in either the NANO or the Wemos directories. This is a good starting point for all the functions we can call from the OTTO library.

The code is set to run the robot through a series of moves (e.g. walk forward, back, moonwalk), and can be used to test that your calibration is correct.

Depending on your wiring and placement, you may find there is limited space. We have created an extra STL file called big_head.stl which is a few millimetres higher, to give more clearance if you find that you need it.

Battery holdER and batteries

This process is the same for both versions, while it's not yet required, it's described here to be applied to both builds.

In order for our robots to operate, we need a battery source, and at minimum we need 5V so we will be using four 1.5V AA to give us 6V. If at any point you have issues with testing servos, then this may well solve them.

Take the four AA battery holder, a switch and two connectors with female ends.

Cut the two headers leaving enough to bare the ends and solder.

Connect the red wire to one side of the switch and the other to the wire with the header. Solder both and cover with heat shrink.

Connect the black wire from the battery to the header, solder and heat shrink.

Build 1 (Nano):

Autonomous Biped Robot

ADDITIONAL Parts Required:Jaycar
1 x Arduino Nano or CompatibleXC4414
1 × Nano Breakout Board-
1 x Ultrasonic SensorXC4442
4 x M3 x 5mm Screws (Optional)HP0440
fritzing

To build the autonomous unit, we need an Arduino Nano or compatible board and breakout shield, sometimes known as sensor shield. It really makes connecting to the Arduino Nano simpler, by providing three-pin sets for power and data. If you don't have access to a shield, you can still wire directly to the same data pins if you can get power to all servos. We'll also need an ultrasonic sensor for obstacle avoidance.

If you have put together your main chassis already, then you should have already connected the servos; however, if not then you need to connect each on as per the diagrams above.

Once your servos are connected, place the printed headpiece upside down onto the table. Take the ultrasonic sensor and push the two sensors into the “eye” holes. The output pins need to be aligned up from the table. You will see a small indent between the two “eyes”; this is for the crystal, which you will see on the sensor itself.

With the ultrasonic sensor in place, run four connector wires out, then connect the "trig" to pin 8 (on the sensor shield it's labelled as "S" on pin 8. The "echo" connector then goes to pin 9 (also the "S" pin in that row).

The Vcc and GND pins from the ultrasonic are then connected to V and G respectively, in Row 8.

Place the Nano board & shield into the head. This will push into the ultrasonic sensor, but it will help keep it all firmly in place. Once you have it located, place four small screws into the four points of the board. Connect the battery to the board and test with battery power to ensure it is functioning (ie, there's an LED on the nano).

We have made a small 6mm hole in the base of the body. Remove the switch nut and push through the hole, securing it on the other side with the nut. Be mindful that with a toggle switch we do not want the toggle to be rubbing against the legs.

Place the battery pack into the body between the hip servos, and then clip the body together.

putting together

THE CODE / SETUP

Up to this point, some code has been required to “home” the servos. If this is your first time using Arduino or Arduino Blocks, please see our Secret Code column, where we go into greater depth.

For this Arduino Nano version, Arduino Blocks will work without issue, however you do still need to have the Arduino IDE installed.

Using Arduino Blocks, start a new project, select “OTTO DIY Robot” from the dropdown, then give your project a name. We return the regular Arduino Blocks screen, but you will see two important items.

First, you will see the little OTTO robot up the top next to the name of your project. This indicates that the correct code set is being used. Next, you’ll see the OTTO palette is now available. Opening this will reveal a host of blocks you can use to control the robot.

screenshot A

We are going to build a walking/avoidance program. Under “Logic”, select the “if” block and drop it into the loop block. Underneath this block in the palette is the “compare” block. Select this and snap it to the “if” block we just dropped. Change the sign from “=“ to “<”

Go to the “Math” block and select the block at the top that just has “0”. Drop it onto the right-hand side of the “Compare” block we just dropped. Change the value of this block to “20”.

Go to the OTTO palette and select the “Get distance” block. Snap into place on the left-hand side of the “Compare” block. Find the first block on the list which reads “Move home speed normal amplitude 20” and drop into the “if” block, change the home to “walk backward”.

Repeat this process and change the second one to “turn left”. Finally, for the third time, select the move block again, and snap it underneath the original “if” block, changing it from “home” to “walk forward”. We have included this in the files as Otto_Avoid.

This is our basic walk and avoid program, where the robot will move forwards and with each loop it will check to see if there is an object in front. If the object is within 20cm, then the robot will walk backwards and turn around before walking away again.

AN IMPORTANT NOTE ABOUT LIBRARIES

One of the most significant issues you will find here is that the Autonomous and the WiFi versions of this project require different pinouts and therefore require different libraries.

These libraries cannot co-exist in the Arduino IDE. If you do decide to build one and then change to build the other, you must remove the old libraries and then add the new libraries. Depending on your system, you will at least need to restart the Arduino IDE, if not reboot the entire system in order to trigger a refresh.

Build 2 (Wemos):

WiFi Controlled Robot

ADDITIONAL Parts Required:Jaycar
1 × Wemos D1 or Similar ESP8266-Based BoardXC3802
1 × Suitable Prototype BoardXC3850
1 x Ultrasonic SensorXC4442
1 × Solid Core Hookup Wire PackWH3025
fritzing
Note: Connections to WiFi Mini shown, use the breakout image references if using the breakout board.

This upgraded WiFi version is based on the ESP8266. These are commonly available as a Wemos D1, or WiFi Mini, or various other names, depending on where you purchase it from.

Ultimately at their core, they're all based around the same ESP8266, just be aware that they may not have precisely the same pinouts.

With the addition of WiFi, we can set it up as a wireless access point. Using your smartphone or tablet, you can then drive (that is, walk) your biped robot around!

One major difference with an ESP8266-based board is that they run on 3.3V. This isn't a major issue, but it can make wiring a little more complex. If we try and run the servo motors from 3.3V, they're not going to go too far at all.

However the Wemos board does include a voltage regulator to reduce our 6V from the battery pack, to the 3.3V it requires to run. This is handy, as you can connect everything to the 6V pack directly, while the Wemos will protect itself from the higher voltage.

PROTOTYPE BOARD BREAKOUT BOARD

ESP8266 chips themselves aren't always terribly friendly to use, but the awesome D1 / WiFi Mini packages make it easier, and often have an available prototyping shield we can use to build our project on. This gives us a solderable, hard-wearing platform to work with. Awesome!

First, you'll usually need to solder up the prototyping board. Install the header pins to connect on top of your D1 board. From there, we're going to use a similar approach to the Nano breakout board, which provides us with easy-to-use power + data pin headers.

Depending on where you purchased your prototype board, you may or may not have header strip included. If you don't, you may need additional header strip, which is not included in the parts list. If you already have your header strip, you're in luck!

We need to start by creating a breakout board. In this case, we are using the XC3850 prototype board from Jaycar Electronics. You'll find these breakout boards in various incarnations from a variety of retailers. Place the header pins onto the board (see image). We have borrowed some ideas from the Arduino servo breakout boards, and so have the ground, power and signal rails all in a row. In addition, we have lined up the power and ground for the ultrasonic sensor, and the power in for the battery. The Wemos D1 Mini has a built-in 3.3V regulator, so we can feed it 5V to 6V from the batteries without issue. The batteries also feed the servos directly.

With the headers in place, run a piece of solid wire across all the header pins from the battery header. Then from the other end connect to the 5V connector for the Wemos. Repeat for the ground.Starting from the top, solder and connect from D5 to D8.

Finally, we need to connect the ultrasonic trigger to D2 and the echo to D3, as well as power. The prototype shield does make life easier for distributing power, but it's not entirely essential.

Attach the servos as per the image, connecting the hips and ankles, and connect the battery. If you still have the auto-homing code loaded on your Wemos, you may see the servos reset their positioning when attaching power.

THE CODE / SETUP

Using the Wemos D1 Mini (or equivalent), we have set up the system to operate as a wireless access point (AP), with Arduino providing a web server interface also. By doing this, we can operate the robot anywhere, even without a WiFi network.

You'll need to locate the "wifi_ap.ino" in the digital resources, and compile it to your Wemos.

The code below has been truncated for clarity. Please see the full code in the provided files.

Our code starts out with the normal importing of the libraries into the system. We then move to our defined functions for making the robot do various functions. These are all called later from the main loop. Below is an example of the basic syntax used to make the robot move, dance or home itself. The only line here that interacts with the robot is the final line, which calls the otto object to home the servos.

The first line is a serial output to give us feedback that the command is working. The next four lines are all designed to tell the system that the command has been received and is being executed correctly.

void handleHOME() {
  Serial.println("Home");
  String message;
  message += "{ "success": ";
  message += "1 }";
  server.send(200, "text/plain", message );
  Otto.home();
}

From the declarations we move on to the setup function of the code. In this case, we need to setup and start the access point. In this instance, we have given it the name of DIYODE-AP and the password of “12341234”; of course, you can change this. We then start the server object. The final line outputs the default IP address to the serial monitor.

WiFi.mode(WIFI_AP);
WiFi.softAP("DIYODE-AP", "12341234");
server.begin(); // Start the HTTP Server
Serial.print("Please connect to http://192.168.4.1/");

After this, we then attach our commands to our URLs. In this case whenever the AP receives the URL that is “/home” it will call the “handleHOME” function that we discussed earlier. This is repeated for the various commands we will be using.

server.on("/home", handleHOME);

For the final part of our setup, we start the Otto object and assign the pins used for the servos before homing them.

//Set the servo pins
Otto.init(PIN_YL, PIN_YR, PIN_RL, PIN_RR, true);
Otto.home();
delay(50);

This is one of the simplest main loops we have ever done; it simply waits for the server to see what command it has been sent. This executes because of the server.on functions that we wrote earlier. After a slight delay, the code will repeat, to listen again.

void loop() {
  server.handleClient();
  delay(100);
{

We have included a basic web app to use as the robot’s control. It is located in the web app directory. When you extract and open the file, you’ll see we have a basic move forward, back, left and right, as well as other fun functions.

With the code loaded and your smartphone at the ready, it's time to power everything up and drive (or is that walk?) our robot!

Note that you can use any WiFi capable device with a modern web browser. That includes smartphones, tablets, and laptops.

TESTING

With your device connected to your regular WiFi, use your favourite web browser to navigate to https://diyode.io/013html - this will load the web app into your browser. To make it easy to find later if required, save it to your home screen or bookmark bar.

You will have a prompt labelled SETUP, asking for an IP address. Don't do anything with that just yet. We need to connect to your robot's WiFi network first.

web app

Go to your device's WiFi settings (that is the control device, not the robot) and locate DIYODE-AP, which should auto-discover, and click/tap connect. When prompted, enter the password we set "12341234". You can change this in your code to something more difficult, but in reality, we're not controlling spacecraft here.

Give everything a few seconds to settle down, and go back to your web browser. Click / tap "Continue". The IP address required should be the same as what we have defaulted here, unless you changed it in the code. This is one benefit of using the Wemos as the access point rather than going through your router - everything is a little more predictable.

THE REMOTE CONTROL

We have built a few "standard" functions such as moving forward or backward. We also have a few fun functions to make our robot do a few funny actions such as flap feet, or moon everyone.

The responsiveness of the remote control is rather good. This is one additional benefit of the access point method of connection. Using a standard WiFi router would simply increase latency, which would in turn reduce the response time of our robot.

It should be noted however that the remote control triggers specific routines (such as take steps forward, flap feet), and these routines must finish before a new routine can be started.

It is possible to change this behaviour, but it increases the complexity of the code significantly, and introduces new challenges with servo positioning also. Allowing routines to complete automatically resolves many of these issues.

remote control

WHERE TO FROM HERE?

There is so much more than you can do with this framework. The very idea with the Otto framework is to modify, change, update and share. There any many different sensors and “things” that exist, and there many different variations of this project that could incorporate them all!

Touch sensors, buzzers and sound sensors are all supported right out of the box; even Bluetooth modules are supported with the standard build.

Perhaps you can scale-up the robot to be a personal companion, then train him to go and fetch a drink from the fridge with a preset routine? Then again - he would need some arms. We'll leave those considerations with you!