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 position your hand so that the servos are set 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 5, Building a Robot That Can Walk. Here is the basic code to control the servos:
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 USB.def setAngle(ser, channel, angle):
: This function converts your desired setting of servo and angle into the serial command that...