Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Raspberry Pi Robotic Projects

You're reading from   Raspberry Pi Robotic Projects Work through a mix of amazing robotic projects using the Raspberry Pi Zero or the Raspberry Pi 3

Arrow left icon
Product type Paperback
Published in Oct 2016
Publisher
ISBN-13 9781786467966
Length 238 pages
Edition 3rd Edition
Languages
Concepts
Arrow right icon
Authors (2):
Arrow left icon
Jon Witts Jon Witts
Author Profile Icon Jon Witts
Jon Witts
Richard Grimmett Richard Grimmett
Author Profile Icon Richard Grimmett
Richard Grimmett
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Raspberry Pi Robotic Projects - Third Edition
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
1. Getting Started with the Raspberry Pi FREE CHAPTER 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 $19.99/month. Cancel anytime
Banner background image