14 min read

In this article, by Richard Grimmett, author of Mastering BeagleBone Robotics, you’ll build a quadruped, that is, a robot with four legs. You’ll be using 12 servos so that each leg has three points that can move, or three Degrees of Freedom (DOF). In this project, you’ll control 12 servos at the same time, so it will make more sense to use an external servo controller that can supply the control signals and supply voltages for all the 12 servos.

(For more resources related to this topic, see here.)

Since servos are the main component of this project, it is perhaps useful to go through a tutorial on servos and how to control them.

Working of servomotors

Servomotors are somewhat similar to DC motors; however, there is an important difference. While DC motors are generally designed to move in a continuous way—rotating 360 degrees at a given speed—servos are generally designed to move within a limited set of angles.

In other words, in the case of a DC motor, you would generally want your motors to spin with continuous rotation speed that you control. But in the case of a servomotor, you would want your motor to move to a specific position that you control. This is done by sending a Pulse-Width-Modulated (PWM) signal to the control connector of the servo. PWM simply means that you are going to change the length of each pulse of electrical energy in order to control something. In this case, the length of this pulse will control the angle of the servo, as shown in the following diagram:

Mastering BeagleBone Robotics

These pulses are sent out with a repetition rate of 60 Hz. You can position the servo to any angle by setting the correct control pulse.

Building the quadruped platform

You’ll first need some parts so that you can build your quadruped robot. There are several kit possibilities out there, including the one available at www.trossenrobotics.com/p/PhantomX-AX-12-Quadruped.aspx. However, such kits can be expensive, so for this example, you’ll create your own kit using a set of Lynxmotion parts. These are available from several online retailers such as robotshop.com. To build this quadruped, you’ll need four legs, each leg requires two Lynxmotion parts. Here are the parts with their Robotshop part numbers:

Quantity

Description

1

Lynxmotion symmetric quadruped body kit: Mini QBK-02

2

Lynxmotion 3” aluminum femur pair

2

Lynxmotion Robot Leg “A” pair (No servo) RL-01

4

Lynxmotion aluminum multi-purpose servo bracket Two Pack ASB-04

2

Ball bearing with flange: 3mm ID (pair)

Product code: RB-Lyn-317

This last part a bearing you’ll need to connect the leg to the body.

You’ll also need 12 servos of a standard size. There are several possible choices, but I personally like the Hitec servos. They are very inexpensive and you can get them from most hobby shops and online electronic retailers. Now, for a moment on the model of servo: Servos come in different model numbers, primarily based on the amount of torque they can generate.

Torque is the force that the servo can exert to move the part connected to it. In this case, your servos will need to lift and move the weight associated with your quadruped, so you’ll need a servo with enough torque to do this. I suggest that you use eight Hitec model HS-485HB servos. You’ll use these for the servos attached to the end of the leg and for the body. Then you’ll use four Hitec model HS-645MG servos for the middle of the leg; this is the servo that will require the highest amount of torque. You can use the 12 Hitec model HS-645MG servos instead, but they are more expensive than the HS-485 servos, so using two different servos will be less expensive.

Here are the steps required to assemble the quadruped:

  1. Put the two parts of the lower right leg together and insert the servo with the servo mounting screws. It should look like this:

    Mastering BeagleBone Robotics

  2. Now connect this assembly to the interconnect part, like this:

    Mastering BeagleBone Robotics

  3. Complete the leg by connecting two of the servo brackets together at right angles, mounting the HS-645MG on one of the brackets, and then connecting this servo to the interconnect piece, like this:

    Mastering BeagleBone Robotics

  4. Put another right leg together.
  5. Now put two left legs together following the same preceding steps, but in left leg configuration. They look like this:

    Mastering BeagleBone Robotics

  6. The next step is to build the body kit. There are some instructions given at www.lynxmotion.com/images/html/sq3u-assembly.htm, but it should be like the following image:

    Mastering BeagleBone Robotics

  7. Then connect each leg to the body kit. First connect the empty servo bracket to the body using the bearing, as shown in the following image:

    Mastering BeagleBone Robotics

  8. Now connect the other servo to the empty servo bracket and the body, like this:

    Mastering BeagleBone Robotics

After performing all the preceding steps, your quadruped should now look like this:

Mastering BeagleBone Robotics

Now that you have the basic hardware assembled, you can turn your attention to the electronics.

Using a servo controller to control the servos

To make your quadruped walk, you will first need to connect the servomotor controller to the servos. The servo controller you are going to use for this project is a simple servomotor controller utilizing USB from Pololu (Pololu item number 1354, available at pololu.com) that can control 18 servomotors. Here is an image of the unit:

Mastering BeagleBone Robotics

Make sure that you order the assembled version. This piece of hardware will turn USB commands from the BeagleBone Black into signals that control your servomotors. Pololu makes a number of different versions of this controller, each able to control a certain number of servos. In this case, you may want to choose the 18-servo version, so you can control all 12 servos with one controller and also add an additional servo to control the direction of a camera or sensor. You could also choose the 12-servo version. One advantage of the 18-servo controller is the ease of connecting power to the unit via screw-type connectors.

There are two connections you’ll need to make to the servo controller to get started: the first is to the servomotors and the second is to a battery.

First, connect the servos to the controller. In order to be consistent, let’s connect your 12 servos to the connections marked 0 through 11 on the controller using the configuration shown in the following table:

Servo Connector

Servo

0

Right front lower leg

1

Right front middle leg

2

Right front upper leg

3

Right rear lower leg

4

Right rear middle leg

5

Right rear upper leg

6

Left front lower leg

7

Left front middle leg

8

Left front upper leg

9

Left rear lower leg

10

Left rear middle leg

11

Left rear upper leg

Here is an image of the back of the controller. This will tell us where to connect our servos:

Mastering BeagleBone Robotics

Now you need to connect the servomotor controller to your battery. For this project, you can use a 2S RC LiPo battery. The 2S means that the battery will have two cells, with an output voltage of 7.2 volts. It will supply the voltage and current needed by your servos, which can be of the order of 2 amperes. Here is an image of the battery:

Mastering BeagleBone Robotics

This battery will come with two connectors: one with large gauge wires for normal usage and a smaller connector used to connect to the battery recharger. You’ll want to build connectors that can connect to the screw-type connectors of the servo controller. I purchased some XT60 connector pairs, soldered some wires to the mating connector of the battery, and screwed these into the servo controller.

Your system is now functional. Now you’ll connect the motor controller to your personal computer to check if you can communicate with it. To do this, connect a mini USB cable between the servo controller and your personal computer.

Communicating with the servo controller via a PC

Now that the hardware is connected, you can use some software provided by Pololu to control the servos. Let’s do this using your personal computer. First download the Pololu software from www.pololu.com/docs/0J40/3.a and install it according to the instructions on the website. Once it is installed, run the software, and you should see something like the following screenshot:

Mastering BeagleBone Robotics

You will first need to change the configuration of the serial settings, so select the Serial Settings tab and you should see this:

Mastering BeagleBone Robotics

Make sure that USB Chained is selected; this will allow you to communicate with and control the motor controller over USB. Now go back to the main screen by selecting the Status tab, and now you can actually turn on the 12 servos. The screen should look like this screenshot:

Mastering BeagleBone Robotics

Now you can use the sliders to actually control the servos. Check that servo 0 moves the right front lower servo, servo 1 moves the right front middle servo, servo 2 moves the right front upper servo, and so on. You can also use this to center the servos. Set all the servos such that the slider is in the middle. Now unscrew the servo horn on each servo until the servos are centered at this location. At the zero degree location of all servos, your quadruped should look like this:

Mastering BeagleBone Robotics

Your quadruped is now ready to actually do something. Now you’ll need to send the servos the electronic signals they need to move your quadruped.

Connecting the servo controller to the BeagleBone Black

You’ve checked the servomotor controller and the servos. You’ll now connect the motor controller to the BeagleBone Black and make sure you can control the servos from it. Remove the USB cable from the PC and connect it to the BeagleBone Black. The entire system will look like this:

Mastering BeagleBone Robotics

Let’s now talk to the motor controller by downloading the Linux code from Pololu at www.pololu.com/docs/0J40/3.b. Perhaps the best way is to log in to your BeagleBone Black using PuTTY, then type wget http://www.pololu.com/file/download/maestro-linux-100507.tar.gz?file_id=0J315. Then move the file by typing mv maestro-linux-100507.tar.gz?file_id=0J315 maestro-linux-100507.tar.gz. Unpack the file by typing tar –xzfv maestro_linux_011507.tar.gz. This will create a directory called maestro_linux. Go to that directory by typing cd maestro_linux and then type ls. You should see something like this:

Mastering BeagleBone Robotics

The README.txt document will give you explicit instructions on how to install the software. Unfortunately, you can’t run MaestroControlCenter on your BeagleBone Black. Your version of Windows doesn’t support the graphics, but you can control your servos using the UscCmd command-line application to ensure that they are connected and working correctly. First, type ./UscCmd –list and you should see something like the following screenshot:

Mastering BeagleBone Robotics

The unit sees our servo controller. By just typing ./UscCmd, you can see all the commands that you can send to your controller, as shown in the following screenshot:

Mastering BeagleBone Robotics

Note that although you can send a servo a specific target angle, the target is not in angle values, so it makes it a bit difficult to know where you are sending your servo. Try typing ./UscCmd –servo 0, 10. The servo will move to its maximum angle position. Type ./UscCmd – servo 0, 0 and it will prevent the servo from trying to move. In the next section, you’ll write some Python code that will translate your angles to the commands that the servo controller will want to receive to move it to specific angle locations.

If you didn’t run the Windows version of Maestro Controller and set the Serial Settings to USB Chained, your motor controller might not respond. Rerun the Maestro Controller code and set the Serial Settings to USB Chained.

Creating a program on Linux to control your quadruped

You now know that you can talk to your servomotor controller, and move your servos. In this section, you’ll create a Python program that will let you talk to your servos to move them to specific angles.

Let’s start with a simple program that will make your legged mobile robot’s servos go to 90 degrees (the middle of the 0 to 180 degrees you can set). This particular controller uses bytes of information, so the code will translate the input of the channel and angle to numbers that the controller can understand. For more details, see http://www.pololu.com/docs/0J40. Here is the code to move all the connected servos to the 90 degree point:

Mastering BeagleBone Robotics

Here is an explanation of the code:

  • #! /usr/bin/python: This first line allows you to make this Python file executable from the command line.
  • import serial: This line imports the serial library. You need the serial library to talk to your unit via USB.
  • def setAngle(ser, channel, angle): This function converts your desired setting of servo and angle into the serial command that the servomotor controller needs.
  • ser = serial.Serial(“/dev/ttyACM0”, 9600): This opens the serial port connection to your servo controller.
  • for i in range(0, 15): This is for all 16 servo possibilities.
  • setAngle(ser, i, 90): This allows you to set each servo to the middle (home) position. The default would be to set each servo to 90 degrees. If the legs of your robot aren’t in their middle position, you can adjust them by adjusting the position of the servo horns on each servo.

To access the serial port, you’ll need to make sure that you have the Python serial library. If you don’t, then type sudo apt-get install python-serial. After you have installed the serial library, you can run your program by typing sudo python quad.py.

Once you have the basic home position set, you can now ask your robot to do some things. Let’s start by making your quadruped wave an arm. Here is the Python code that waves the arm:

Mastering BeagleBone Robotics

In this case, you are using the setAngle command to set your servos to manipulate your robot’s front-right arm. The middle servo raises the arm, and the lower servo then goes back and forth between angle 100 and 130.

One of the most basic actions you’ll want your robot to do is to walk forward. Here is an example of how to manipulate the legs to make this happen:

Mastering BeagleBone Robotics

This program lifts and moves each leg forward one at a time, and then moves all the legs to home position, which moves the robot forward. Not the most elegant motion, but it does work. There are more sophisticated algorithms to make your quadruped walk as shown at http://letsmakerobots.com/node/35354 and https://www.youtube.com/watch?v=jWP3RnYa_tw. Once you have the program working, you’ll want to package all of your hardware onto the mobile robot.

You can make your robot do many amazing things: walk forward, walk backward, dance, turn around—any kinds of movements are possible. The best way to learn is to try new and different positions with the servos.

Issuing voice commands to your quadruped

You should now have a mobile platform that you can program to move in any number of ways. Unfortunately, you still have your LAN cable connected, so the platform isn’t completely mobile. And once you have begun the program, you can’t alter the behavior of your program.

You’ll need to modify your voice recognition program so that it can run your Python program when it gets a voice command. You have to make a simple modification to the continuous.c program in /home/ubuntu/pocketsphinx-0.8/src/programs. To do this, type cd /home/ubuntu/ pocketsphinx-0.8/src/programs, and then type emacs continuous.c. The changes will occur in the same section as your other voice commands and will look like this:

Mastering BeagleBone Robotics

The additions are pretty straightforward. Let’s walk through them:

  • else if (strcmp(word, “FORWARD”) == 0): This checks the word as recognized by your voice command program. If it corresponds with the word FORWARD, it will execute everything inside the if statement. We use { } to tell the system which commands go with this else if clause.
  • system(“/home/ubuntu/maestro_linux/robot.py”): This is the program we will execute. In this case, our mobile platform will do whatever the robot.py program tells it to do.

After doing this, you will need to recompile the program, so type make and the pocketSphinx_continuous executable will be created. Run the program by typing ./pocketSphinx_continuous. Don’t forget the ./ at the start of this command or you’ll run a different version of the program. When the program is running, you can disconnect the LAN cable, and the mobile platform will now take the forward voice command and execute your program.

Summary

You now have a robot than can walk! You can also add other sensors, like the ones you discovered for your tracked robot, sensors that can watch for barriers, or even a webcam.

Resources for Article:


Further resources on this subject:


LEAVE A REPLY

Please enter your comment!
Please enter your name here