Projects

Four On The Floor Robot

Legs Over Wheels!

Oliver Higgins

Issue 8, February 2018

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

Log in

There are some truly awesome things you can do in the world of robotics, but you don’t get much more awesome than a walking multi-legged robot. This doesn’t have to be the daunting task that it would appear to be and we are going to show you how.

BUILD TIME: 2-3hrs
DIFFICULTY RATING: advanced

All robots are cool, but nothing is cooler than seeing a multi-legged walking robot. There is an element of something that should not work and can strike an unnatural fear of something manmade that resembles our arachnid friends. The multi-legged robot does have advantages in the field, allowing it to traverse much more difficult terrain then that of a tank track styled robot. This style of robot is fraught with issues. You need a minimum of 4 legs to achieve stable walking without considerable accelerometer-based subsystems, and while there are two and even one-legged robots in existence, they come at significant expense. Our goal here is to achieve an easy to build low-cost multi-legged robot that we can use to explore the capabilities of the quadruped multi-legged robot.

ACKNOWLEDGEMENTS: This project could not be completed without the previous work of Regis and the code provided by the Sunfounder Group. These projects serve as a base for our quadruped, which we have built to adhere to local requirements.

THE BROAD OVERVIEW

NANO/UNO/MEGA

To make this project as accessible as possible, we have designed the top of the chassis to accommodate the Arduino NANO, the UNO and the Mega2560. The code will also work on all three of these without the need for any pin assignment changes. The footprint itself would fit a micro such as the WEMOS D1 – IoT Spider swarm anyone? The Intel-powered 101 will also fit this provision, as one of its lesser-known features is a neural learning network.

SERVOS

“Servo” is short for “servo motor” or “servo mechanism” and they are comprised of a two-wire DC motor, a gear train, a potentiometer, an integrated circuit, and an output shaft. There are three wires that exit out from the motor casing: one is for power, one is for ground, and one is a control input line. This makes the control of objects much easier, as all we need to do is feed the servo a Pulse Width Modulation (PWM) signal and the motor will turn to the position we have designated. In the case of this project, we are using 12 SG90 servo motors. These are very low cost and as such make projects like this much more cost-effective. One drawback however, is the fact that they have plastic gears and a small motor. For the most part, this is okay, given that a servo draws current based on the load it is subjected to, but if you mechanically overload them it is easy to burn out the motor or strip the plastic gears. The MG90 is a metal-geared version in a similar package. It has a higher torque rating and would appear to be more responsive than the SG90. The problem is that it’s average cost at time of print of an MG90 is ~US$6.75 compared to ~US$2.75. On a project like this, that equates to nearly two thirds’ more expensive. Of course, if we were to build a bigger version or were building the robot out of aluminium rather the plastic, then the MG90 would be a much better investment.

ROBOTIC KINEMATICS

The study of robotic movement is known as “robotic kinematics”. It applies to the study of the geometry of kinematic movements. A robot is made up of chains of joints and movement, all of which must work together to create a movement or function. A fundamental tool in robot kinematics is the kinematics equations of the kinematic chains that form the robot. These non-linear equations are used to map the joint parameters to the configuration of the robot system. Kinematics equations are also used in biomechanics of the skeleton and computer animation of articulated characters. There are several subsections here, including forward kinematics, inverse kinematics and velocity kinematics. In short, what does this mean? We can apply the study of the movement and chains to create predictable paths using non-lineal equations. The good thing about such a complex area of study is that a considerable amount of open source libraries exist to allow us to create some truly awesome robots.

JOYSTICK AND BUILT-IN BUTTON

The joystick that we will be using is comprised of two potentiometers to measure the X and the Y movement. This gives us two values, which allow us to plot a point in space. The values are read independent of each other so you do not have to read both the X and Y, nor do you have to implement them together. In this case, we have one joystick that controls forward movement on the X-axis but pans the servo on the Y. These controllers allow us to specify a precision level of accuracy and then feed to the robot. The alternative is to use a button, and this could easily be allocated to “Go forward” or “Turn right”. Our joystick has built-in buttons by pushing or clicking it down. The buttons read high and will float unless you specify the use of the internal pull-up resistor.

HOW IT WORKS

The hardware technology of the robot itself is quite simple. We have 12 servos, divided into 4 groups, 1 for each leg. Each leg operates as a group of three servos to enable forward, backward and turning motion. The final software to upload also has the function to allow the robot to wave, shake hands and sit.

schematic for build

THE BUILD

Parts Required:JaycarAltronics
1 x Arduino NANO or UNO or Mega2560 XC4414 Z6372
1 x Sensor Shield Board For Chosen Micro - -
12 x SG90 Servos (plus horns and screws) YM2758 Z6392
1 x Joystick Module XC4422 Z6363
M3 Nuts and bolts
16x No.4 x 6mm Steel Self-Tapping Screws
Hook Up Wire
Cable Ties
Power/Battery
Rubber Feet
3D PRINTED PARTS:
1 x Lower Body
1 x Upper Body
1 x Arduino Bracket
4 x B section
2 x AL Section
2 x AR Section
2 x CL Section
2 x CR Section
8 x Servo Pivot
1 x Joystick top
1 x Joystick Bottom

BUILDING THE CIRCUIT/BODY

Start by printing out all the required parts. Take the time to print the highest quality parts that you can, as there are some fine tolerances. Remember that there are some parts that are left and right orientation. We used Cura and the Lulzbot printers and were able to print without supports; however, be mindful that there are some overhangs so you may wish to print with supports. You may wish to use a drill to make sure that the boltholes on the chassis are clean, and that the bolts go through easily. Take your time to clean all the holes with a dremal as these will require parts to undergo some mechanical friction.

Start by laying out all the required parts in a basic configuration. Take all the servo motors out and place them in their respective positions. We will assemble one full leg at a time starting with the outside foot section first.

C/B ASSEMBLY

The C section is the foot assembly. It is a long thin piece compared to the others, with a large rectangular section for the foot. Depending on your printer you may need to get a square file and get into the corners of the rectangular piece that the servo will sit into. At this stage also take the time to pre-screw the two small holes in the servo pivot support, as this will make it easier later when joining the pivot to the section. Now be mindful of the orientation of these units as they are right/left. The arc of the foot goes away from the body of the robot. The B sections are the same for all four legs. It is possible with some SG90 to push the servo straight into the rectangle, however because of the three wires protruding from the body, this can be difficult. The best way to do it without damaging the servo is to peel off the stickers from either side then, using a very fine Philips head screwdriver, remove the four long screws from the bottom. You will now be able to remove the bottom plate, which allows you to then slot the servo straight down.

The control horn (top) of the servo goes on the opposite side to the servo pivot support – the horn itself should be facing away from the foot. Place the cover plate and the four screws back into the bottom of the servo. Once you have this done, take the two anchor screws that came with the servo and screw the unit down. Roll the unit over and take the servo pivot and two screws. Screw these in slowly, and you have a completed foot section.

Before you fit the B section make sure that the smaller hole that the servo pivot is sitting in, is clean and that the pivot rotates smoothly. It is worth taking the time to file or Dremel this, as it will lead to smoother walking. Push the servo pivot into the hole on the B section the gently pull back the opposite side of the B section, pushing the top of the servo horn into the hole. Take the servo horn with just one arm and push into the top of the B section where the top of the servo is. It should mate up snugly. If not file or Dremel until it fits. You now have a complete C/B section.

internal view

A/B ASSEMBLY

Take the A section and file the rectanglar hole to ensure that it is square. Remember again, these are left and right. Looking at your A section, you are working with the servo pivot support on the same side.

You may be able to push the servos through the hole but to make sure you do not damage the wires we recommend taking the side stickers and removing the four screws and the bottom plate. Push the servo through, being mindful of the orientation. The top of the servo is on the opposite side of the servo pivot support. The top of the servo itself, should line up with the top of the unit. Screw the base plate and the four screws back into place, then screw down the servo with the two supplied screws. Take the servo pivot and attach to the mounting points with two small screws. You have now completed the A/B/C assembly. Repeat this process for all four legs.

BODY ASSEMBLY

The body comprises of three sections. The bottom and mid sections hold the leg section in place and provide a cavity for our battery. The top section contains spacing to take an Arduino Nano on a breakout shield, the Arduino Uno or the Arduino Mega2560. Both of these will also require a breakout board. The lower and bottoms are simple to print but are mindful of some small overhangs in the top section.

To assemble the body, we start with the middle section. Turn it over from the way it was printed and secure the four servos to each end of the piece, using the supplied servo mounting screws. Please note that the top of the servo where the control horn attaches goes to the outside of the unit. Next, take each leg and push the top of the servo into the larger hole and secure in place with the single armed control horn and the provided screw. Repeat for all four legs.

Next, take the bottom plate and mount it up to the bottom of the midsection. Place a 30mm M3 bolt on each of the four corners and secure with a nut. Do not do the middle two at this stage as we need to place the top section of the robot. To make it easier later, we would recommend securing your chosen Arduino now, although it is not crucial. Place the top on the middle unit and align the middle holes. Depending on your print for the top section, please check the cut-outs at each corner to ensure a good fit. Secure with two more 30mm M3 bolts and the nuts. The structure of your robot is now complete.

servo wiring

WIRE UP THE SERVOS

The fantastic thing about using a breakout board is that it makes using servos so much easier than having to manually wire them in and find ground and power. We need to wire up the servos in a particular order.

JOYSTICK

The joystick module is included with the final program so we can move the robot around. From a wiring perspective, we connect the X, to A0, the Y to A1 and the button to A2. The other two wires are power and ground. Print out the two pieces, and then you will need to bend the five pins up to around 75 degrees. Run the wires through the slot in the joystick case and connect them up. The bottom plate will snap in. You can connect this now if you wish, but it will be easier to calibrate the robot without this in place.

THE CODE / SETUP / OTHER

The bulk of the code in this build is based around the servos. Controlling the servos is quite simple. We select a servo and send it a signal relative the degrees we need it to turn to. The caveat in this, is that we need to know where the 0 point is. Firstly, however, we need to set the servo up. To do this, we need to include the servo library, then declare the servo object, and then attach the pin to the servo.

Servo myservo; 
void setup() { 
  myservo.attach(9);  // attaches the servo on 
// pin 9 to the servo object 

Then it as easy as telling the servo what position you need it to go to.

The next line here is a delay. Now while it is not essential to make this work, it is best practice to give the servo some buffering to finish its mechanical movements.

myservo.write(75);   
delay(15);

We must now calibrate the servo positions before we can move the robot’s limbs.

We need to set all of our servos to the 90-degree position. To do this, load up 008_Quadbot_SETUP_001. Once the program has loaded, you will have servos moving everywhere. Take the time to unscrew each of the servo horns and reset them back into place.

The code for this is a little more complex than the above. We create an array of servos into four groups of three. Once done, we then assign the pin numbers to these groups.

Servo servo[4][3]; 
const int servo_pin[4][3] = { {2, 3, 4}, {5, 6, 7}, {8, 9, 10}, {11, 12, 13} }; 

The code then loops through all of the servos and sets them all to 90 degrees. If your robot starts to lag, jitter or just behave erratically, then check your power supply. There is a lot of current being drawn – more than the average USB port can output. We had the best results using a 2.1A 5V supply.

RUN THE STAND-UP CODE

Once you have the robot configured and standing in a correct position, we need to make it do something interesting. The file 008_Quadbot_WAVE_003 contains a basic implementation, using only the servo library to control the robot. Load it and power up the robot. For some dramatics, fold up the legs. The robot will align all of its limbs out and then stand itself up. Once it is upright, it will push its weight back on one leg and then pick up a front leg to wave. It will then return itself to the standing position. This is done using only the servo write method. It is tedious to work with, as you have to take the time to create each motion you want, then put delays in the software; however, once done it is very easy to call your functions to do the various things you need. This just executes the once. You will need to reset the Arduino each time if you want to repeat it.

The following code is used to go from the 90-degree configuration position to move the legs to the 45-degree position. We address the servos by their array numbers.

  void leg45() { 
  servo[0][2].write(120); 
  delay(100); 
  servo[1][2].write(60); 
  delay(100); 
  servo[2][2].write(60); 
  delay(100); 
  servo[3][2].write(120); 
  delay(100);

To make the robot do some cool stuff and embrace some kinematics, we will be using code developed by Regis and the Sunfounder Group. In the first instance this is a simple stand up, walk, turn, wave. Before installing this code, you need to have the FlexiTimer2 Library installed. We have included it in the files, but you can add it in the Arduino IDE environment easily. Run the walk demo 008_Quadbot_Bench_003 and you will notice considerable amount of code and constants implemented. In this case, the robot tracks each of its limbs positions in space and this leads to much more fluid motions. Once that has been successful, you can connect up the joystick as described and then load and run the control software 008_Quadbot_Bench_005.

Upon activation, the robot will rise slightly. Pushing forward will make it walk forward as pulling back makes it go backwards. Pushing left or right will make it turn on the spot. Please note that forward will override left or right so if you want to turn and walk simultaneously, it will not work with this implementation.

Click on the joystick centre button and the robot will stop and wave, click again and it will shake, click a third time, and it will sit before final fourth click will stand it back up and set it to the ready position.

WHERE TO FROM HERE?

This has laid some pretty cool foundations for bigger projects. If you look at some of its bigger siblings, you have things such as pressure sensors on the feet and positional rotation sensors on the unit. This would not require the internal variables to be used as heavily, as we would know where each part is at any point in time. We do need to find a better alternative to the joystick control. Wireless, IoT, when did Skynet go live? What about a heavier duty version using the MG90 or even one of the bigger metal-geared, high torque, servo-driven…

top view