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...