Making the Unit Very Mobile - Controlling Legged Movement

Exclusive offer: get 50% off this eBook here
BeagleBone Robotic Projects

BeagleBone Robotic Projects — Save 50%

Create complex and exciting robotic projects with the BeagleBone Black with this book and ebook

£16.99    £8.50
by | December 2013 | Open Source

In this article by Richard Grimmett, author of the book BeagleBone Robotic Projects, the author has explained how to control the robot.

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

Mission briefing

We've covered creating robots using a wheeled/track base. In this article, you will be introduced to some of the basics of servo motors and using the BeagleBone Black to control the speed and direction of your legged platform. Here is an image of a finished project:

Why is it awesome?

Even though you've learned to make your robot mobile by adding wheels or tracks, this mobile platform will only work well on smooth, flat surfaces. Often, you'll want your robot to work in environments where it is not smooth or flat; perhaps, you'll even want your robot to go upstairs or over curbs. In this article, you'll learn how to attach your board, both mechanically and electrically, to a platform with legs, so your projects can be mobile in many more environments. Robots that can walk: what could be more amazing than that?

Your objectives

In this article, you will learn:

  • Connecting the BeagleBone Black to a mobile platform using a servo controller
  • Creating a program in Linux to control the movement of the mobile platform
  • Making your mobile platform truly mobile by issuing voice commands

Mission checklist

In this article, you'll need to add a legged platform to make your project mobile. So, here is your parts' list:

  • A legged robot: There are a lot of choices. As before, some are completely assembled, others have some assembly required, and you may even choose to buy the components and construct your own custom mobile platform. Also, as before, I'm going to assume that you don't want to do any soldering or mechanical machining yourself, so let's look at a several choices that are available completely assembled or can be assembled by simple tools (screwdriver and/or pliers).

    One of the easiest legged mobile platforms is one that has two legs and four servo motors. Here is an image of this type of platform:

    You'll use this platform in this article because it is the simplest to program and because it is the least expensive, requiring only four servos. To construct this platform, you must purchase the parts and then assemble it yourself. Find the instructions and parts list at http://www.lynxmotion.com/images/html/build112.htm. Another easy way to get all the mechanical parts (except servos) is to purchase a biped robot kit with six degrees of freedom (DOF). This will contain the parts needed to construct your four-servo biped. These six DOF bipeds can be purchased by searching eBay or by going to http://www.robotshop.com/2-wheeled-development-platforms-1.html.

  • You'll also need to purchase the servo motors. For this type of robot, you can use standard size servos. I like the Hitec HS-311 or HS-322 for this robot. They are inexpensive but powerful enough. You can get those on Amazon or eBay. Here is an image of an HS-311:

  • You'll need a mobile power supply for the BeagleBone Black. Again, I personally like the 5V cell phone rechargeable batteries that are available almost anywhere that supplies cell phones. Choose one that comes with two USB connectors, just in case you want to also use the powered USB hub. This one mounts well on the biped HW platform:

  • You'll also need a USB cable to connect your battery to the BeagleBone Black, but you can just use the cable supplied with the BeagleBone Black. If you want to connect your powered USB hub, you'll need a USB to DC jack adapter for that as well.
  • You'll also need a way to connect your batteries to the servo motor controller. Here is an image of a four AA battery holder, available at most electronics parts stores or from Amazon:

  • Now that you have the mechanical parts for your legged mobile platform, you'll need some HW that will take the control signals from your BeagleBone Black and turn them into a voltage that can control the servo motors. Servo motors are controlled using a control signal called PWM. For a good overview of this type of control, see http://pcbheaven.com/wikipages/How_RC_Servos_Works/ or https://www.ghielectronics.com/docs/18/pwm. You can find tutorials that show you how to control servos directly using the BeagleBone Black's GPIO pins, for example, here at http://learn.adafruit.com/controlling-a-servowith-a-beaglebone-black/overview and http://www.youtube.com/watch?v=6gv3gWtoBWQ. For ease of use I chose to purchase a motor controller that can talk over USB and control the servo motor. These protect my board and make controlling many servos easy. My personal favorite for this application is a simple servo motor controller utilizing USB from Pololu that can control 18 servo motors. Here is an image of the unit:

    Again, make sure you order the assembled version. This piece of HW will turn USB commands into voltage that control your servo motors. Pololu makes a number of different versions of this controller, each able to control a certain number of servos. Once you've chosen your legged platform, simply count the number of servos you need to control, and chose the controller that can control that number of servos. One advantage of the 18 servo controller is the ease of connecting power to the unit via screw type connectors.

  • Since you are going to connect this controller to your BeagleBone Black via USB, you'll also need a USB A to mini-B cable.

Now that you have all the HW, let's walk through a quick tutorial on how a two-legged system with servos works and then some step-by-step instructions to make your project walk.

Connecting the BeagleBone Black to the mobile platform using a servo controller

Now that you have a legged platform and a servo motor controller, you are ready to make your project walk!

Prepare for lift off

Before you begin, you'll need some background on servo motors. Servo motors 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 DC motor world, you generally want your motors to spin with continuous rotation speed that you control. In the servo world, you want your motor to move to a specific position that you control.

Engage thrusters

To make your project walk, you first need to connect the servo motor controller to the servos. There are two connections you need to make: the first to the servo motors, the second to the battery holder. In this section, you'll connect your servo controller to your PC to check to see if everything is working.

  1. First, connect the servos to the controller. Here is an image of your two-legged robot, and the four different servo connections:

  2. In order to be consistent, let's connect your four servos to the connections marked 0 through 3 on the controller using this configuration: 0 – left foot, 1 – left hip, 2 – right foot, and 3 – right hip. Here is an image of the back of the controller; it will tell you where to connect your servos:

  3. Connect these to the servo motor controller like this: the left foot to the top O connector, black cable to the outside (–), the left hip to the 1 connector, black cable out, right foot to the 2 connector, black cable out, and right hip to the 3 connector, black cable out. See the following image for a clearer description:

  4. Now you need to connect the servo motor controller to your battery. If you are using a standard 4 AA battery holder, connect it to the two green screw connectors, the black cable to the outside, and the red cable to the inside, as shown in the following image:

  5. Now you can connect the motor controller to your PC to see if you can talk with it.

Objective complete – mini debriefing

Now that the HW is connected, you can use some SW provided by Polulu to control the servos. It is easiest to do this using your personal computer. First, download the Polulu SW from http://www.pololu.com/docs/0J40/3.a and install it based on the instructions on the website. Once it is installed, run the SW, and you should see the following screen:

You first will need to change the configuration on Serial Settings, so select the Serial Settings tab, and you should see a screen as shown in the following screenshot:

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

Now you can use the sliders to control the servos. Make sure that the servo 0 moves the left foot, 1 the left hip, 2 the right foot, and 3 the right hip.

You've checked the motor controllers and the servos, and you'll now connect the motor controller up to the BeagleBone Black control the servos from it. Remove the USB cable from the PC and connect it into the powered USB hub. The entire system will look like the following image:

Let's now talk to the motor controller by downloading the Linux code from Pololu at http://www.pololu.com/docs/0J40/3.b. Perhaps, the best way is to log in to your Beagle Bone Black by using vncserver and a vncviewer window on your PC. To do this, log in to your BeagleBone Black using PuTTY, then type vncserver at the prompt to make sure vncserver is running.

  1. On your PC open the VNC Viewer application, enter your IP address, then press connect. Then enter your password that you created for the vncserver, and you should see the BeagleBone Black Viewer screen, which should look like this:

  2. Open a Firefox browser window and go to http://www.pololu.com/docs/0J40/3.b. Click on the Maestro Servo Controller Linux Software link. You will download the file maestro_linux_100507.tar.gz to the Download directory.
  3. Go to your download directory, move this file to your home directory by typing mv maestro_linux_100507.tar.gz .. and then you can go back to your home directory.
  4. 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:

The document README.txt will give you explicit instructions on how to install the SW. Unfortunately you can't run MaestroControlCenter on your BeagleBone Black. Our version of windowing doesn't support the graphics, but you can control your servos using the UscCmd command-line application. First type ./UscCmd --list and you should see the following:

The unit sees your servo controller. If you just type ./UscCmd you can see all the commands you could send to your controller:

Notice you can send a servo a specific target angle, although 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 most likely move to its full angle position. Type ./UscCmd --servo 0, 0 and it will stop the servo from trying to move. In the next section, you'll write some SW that will translate your angles to the commands that the servo controller will want to see.

If you didn't run the Windows version of Maestro Controller and set the serial settings to USB Chained, your motor controller may not respond.

BeagleBone Robotic Projects Create complex and exciting robotic projects with the BeagleBone Black with this book and ebook
Published: December 2013
eBook Price: £16.99
Book Price: £27.99
See more
Select your format and quantity:

Creating a program in Linux to control the mobile platform

Now that you can control your servos using basic commands, let's control them using a program.

Prepare for lift off

So, you know that you can talk to your servo motor controller and set your servos. In this section, you'll create a Python SW program that will let you talk to your servos a bit more intuitively. You'll issue commands that tell a servo to go to a specific angle, and it will go to that angle. You can then add a set of such commands to allow your legged mobile robot to lean left, lean right, or even take a step forward.

Engage thrusters

Let's start with a simple program that will make your legged mobile robot's servos go to 90 degrees. This should be somewhere close to the middle of the 180 degrees you can set. However, the center, maximum, and minimum values can vary from servo to servo, so you may need to calibrate these values. To keep things simple, we will not cover that here. The following is the code:

The explanation of the code is as follows:

  • #!/user/bin/python: This first line allows you to make this Python file execute from the command line. This will allow you to call this program from your voice command program. We'll talk about that in the next section.
  • import serial, import time: These next two lines include the serial and time libraries. You need the serial library to talk to your unit via USB, and the time library you will use later to wait between servo commands.
  • The PololuMicroMaestro class holds the methods that will allow you to communicate with your motor controller.
  • The first method, the __init__ method, opens the USB port associated with your servo motor controller.
  • The next method, setAngle, converts your desired setting of servo and angle into the serial command that the servo motor controller needs. The values, such as minTarget, maxTarget, and the structure of the communications, channelByte, commandByte lowTargetByte, and highTargetByte, come from the manufacturer.
  • The last method, close, closes the serial port.
  • Now that you have the class, the __main__ part of the program instantiates an instance of your servo motor controller class so you can call it.
  • Now you can set each servo to the desired position. The default would be to set each servo to 90 degrees. However, the servos were not exactly centered, so I found on my robot that I needed to set each servo to the values shown in this program to be lined up so my robot had both feet on the ground and both hips centered.

Once you have the basic home position set, you can now ask your robot to do some things. Here are some examples in simple Python code:

In this case, you are using your setAngle command to set your servos to manipulate your robot. This set of commands first sets your robot to the home position. Then, you can use the feet to lean to the right, then to the left, then you can use a combination of commands to make your robot step forward with the left foot, and then with the right foot.

Objective complete – mini debriefing

Once you have the program working, you'll want to package all your HW onto the mobile robot. There is no right or wrong way to do this, but I like to use a small piece of transparent plastic because it is easy to cut and drill. Here is what my robot looks like:

Classified intel

By following these principles, you can make your robot do many amazing things. Walk forward, walk backward, dance, turn around—any number of movements are possible. The best way to learn is to try new and different positions with the servos.

Making your mobile platform truly mobile by issuing voice commands

Now that your robot can move, wouldn't it be neat to have it obey your commands?

Prepare for lift off

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.

Engage thrusters

You'll need to modify your voice recognition program, so it will run your Python program when it gets a voice command. You are going 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 come in the same section as your other voice commands, and will look like this:

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

  • else if (strcmp(hyp, "FORWARD") == 0): This checks the word as recognized by your voice command program. If it corresponds with the word FORWARD, you will execute everything inside the if statement. You use { } to tell the system which commands go with this else if clause.
  • system("espeak \"moving robot\""): This executes espeak, which should tell you that you are about to run your robot program.
  • system("/home/ubuntu/maestro_linux/robot.py"): This is the program you will execute. In this case, your mobile platform will do whatever the program robot.py tells it to do.

After doing this, you will need to recompile the program, so type make and the executable pocketsphinx_continuous will be created. Run the program by typing ./pocketsphinx_continuous. Disconnect the LAN cable, and the mobile platform will now take the "forward" voice command and execute your program.

Objective complete – mini debriefing

You should now have a complete mobile platform! When you execute your program, the mobile platform can now move around based on what you have programmed it to do.

Classified intel

You don't have to put all of your capabilities in one program. You can create several programs, each with a different function, and then connect each of the programs to their appropriate voice commands. Perhaps, one command moves your robot forward, a different backwards, another to turn right or left.

Mission accomplished

Congratulations! Your robot should now be able to move around in any way you'd like to program. You can even have the robot dance.

A challenge

You've now built a two-legged robot, and you can easily expand this to robots with even more legs. Here is an image of the mechanical structure of a four-legged robot that has eight DOF, which is fairly easy to create using many of the parts you have used to create your two-legged robot. This is my personal favorite because it doesn't fall over and break the electronics:

You'll need eight servos, and lots of battery. If you look on eBay, you can often find kits for sale for four-legged robots with twelve DOF, but again realize that the battery will need to be much bigger. For these kinds of applications, we often use remote control (RC) batteries. These are nice, as they are rechargeable, but make sure you either purchase one that is 5 to 6 volts, or include a way to regulate the voltage. Here is a picture of this kind of battery, available at most hobby stores:

If you use this type of battery, don't forget a charger. The hobby store can help with choosing an appropriate match.

Summary

In this article we have learned how to control a robot.

resources for article:


further resources on this subject:


BeagleBone Robotic Projects Create complex and exciting robotic projects with the BeagleBone Black with this book and ebook
Published: December 2013
eBook Price: £16.99
Book Price: £27.99
See more
Select your format and quantity:

About the Author :


Books From Packt


 Learning ROS for Robotics Programming
Learning ROS for Robotics Programming

 Robot Framework Test Automation
Robot Framework Test Automation

Instant LEGO MINDSTORMS EV3 [Instant]
Instant LEGO MINDSTORMS EV3 [Instant]

Robotium Automated Testing for Android
Robotium Automated Testing for Android

Building a Home Security System with BeagleBone
Building a Home Security System with BeagleBone

 Raspberry Pi Home Automation with Arduino
Raspberry Pi Home Automation with Arduino

Netduino Home Automation Projects
Netduino Home Automation Projects

BeagleBone Home Automation
BeagleBone Home Automation


Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software