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))) + minTarget) commandByte = chr(0x84) channelByte = chr(channel) lowTargetByte = chr(scaledValue & 0x7F) highTargetByte = chr((scaledValue...