Controlling your hand
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 sets the servos to one end of the range (which should open the hand) and then go the other end of the range (which should close your hand). This program starts with the code you wrote in Chapter 3, Building a Wall-E Robot. Here is the basic code to control the servos:
#!/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))) ...
Get Raspberry Pi Robotic Projects - Third Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.