Creating a program in Linux so that you can control your quadruped

You now know that you can talk to your servo motor 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. You'll use python as it is very simple and easy to run.

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 0 to 180 degrees you can set.) If you are unfamiliar with the editing code in Linux, the best source is a tutorial on the editor you are using. For nano try http://www.howtogeek.com/howto/42980/the-beginners-guide-to-nano-the-linux-command-line-text-editor/. Here is the code:

Creating a program in Linux so that you can control your quadruped

Here is an explanation of the code:

  1. #!/usr/bin/python:- This first line allows you to make this python file execute from the command line.
  2. import serial:– This line imports the serial library. You need the serial library to talk to your unit via USB.
  3. def setAngle(ser, channel, angle):- This function converts your desired setting of servo and angle into the serial command that the servo motor controller needs. To understand the specifics of the code used to control the servos, see https://www.pololu.com/docs/0J40.
  4. ser = serial.Serial("/dev/ttyACM0", 9600): – This opens the serial port connection to your servo controller.
  5. Now you can set each servo to the middle (home) position:
    for i in range(0, 15):
    setAngle(ser, i, 90)

    The default would be to set each servo to 90 degrees. If your legs 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 you have the python serial library. If you don't, then type apt-get install python-serial. After you have installed the serial library, you can run your program by typing 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 having your quadruped wave. Here is the python code:

Creating a program in Linux so that you can control your quadruped

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

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

Creating a program in Linux so that you can control your quadruped

This program lifts and then moves forward each leg, one at a time, then moves all the legs to the home position, which moves the robot forward. Not the most elegant, but it does work. There are more sophisticated algorithms for walking with your quadruped, see 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 your hardware onto the mobile robot.

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset