Book Image

Raspberry Pi Robotics Essentials

By : Richard Grimmett
Book Image

Raspberry Pi Robotics Essentials

By: Richard Grimmett

Overview of this book

Table of Contents (14 chapters)
Raspberry Pi Robotics Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating a program to control your biped


Now you 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 at specific angles. You can 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 (which should be somewhere close to the middle between the 0 to 180 degrees you can set). Here is the code:

Here is an explanation of the code:

  • #!/usr/bin/python: This first line allows you to make this Python file execute from the command line.

  • import serial: This line imports the serial library. You need the serial library to talk to your unit via the USB.

  • 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, refer to https...