Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Raspberry Pi Robotic Projects - Third Edition

You're reading from  Raspberry Pi Robotic Projects - Third Edition

Product type Book
Published in Oct 2016
Publisher
ISBN-13 9781786467966
Pages 238 pages
Edition 3rd Edition
Languages
Concepts
Authors (2):
Richard Grimmett Richard Grimmett
Profile icon Richard Grimmett
Jon Witts Jon Witts
Profile icon Jon Witts
View More author details

Table of Contents (13) Chapters

Raspberry Pi Robotic Projects - Third Edition
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
1. Getting Started with the Raspberry Pi 2. Building Your Own Futuristic Robot 3. Building a Wall-E Robot 4. Building a Robotic Fish 5. Creating a Robotic Hand with the Raspberry Pi 6. A Self-Balancing Robot 7. Adding the Raspberry Pi to a Quadcopter

Creating a program in Linux to control Wall-E's arms


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.

Let's start with a simple program that will set Wall-E's arms to an initial position. To access the serial port, you'll need to make sure you have the Python serial library. Type sudo apt-get install python-serial.

Now you'll want to enter your program. Here is the code:

#!/usr/bin/python 
import serial 
import time 
 
def setAngle(ser, channel, angle): 
    minAngle = 0.0 
    maxAngle = 180.0 
    minTarget = 256.0 
    maxTarget = 13120.0 
    scaledValue = int((angle/((maxAngle - minAngle) / (maxTarget - minTarget))) + minTarget) 
    commandByte = chr(0x84) 
    channelByte = chr(channel) 
    lowTargetByte = chr(scaledValue & 0x7F) 
    highTargetByte = chr(scaledValue...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}