So, hardware selected the next job was deciding how to control the USB ports. I selected PyUSB.
How to download and install PyUSB onto my Raspberry Pi.
Download PyUSB from sourceforge using this link http://sourceforge.net/projects/pyusb/
and then open up the console on your Pi and unpack the archive file by typing
sudo unzip pyusb_1.0.0b2.zip
You then need to navigate to the newly created directory by typing
cd pyusb_1.0.0b2
You can now install PyUSB by typing
sudo python setup.py install
This will install the PyUSB library on your Pi. This will then enable you to control the USB ports on your Pi thought Python.
In your Python programs you need to import the library using the following lines.
I then had to find out the Vendor and Product id numbers for the Rocket Launcher and the Robot Arm. After a fair amount of searching I found them.
Rocket Launcher : idVendor=0x2123, idProduct=0x1010
Maplin Robot Arm : idVendor=0x1267, idProduct=0x000
These codes are needed to connect the devices to the Kernel driver. In other words, without these codes the operating system doesn't know which devices are connected.
You're now ready to create a python program to connect the USB device to your Raspberry Pi.
You should now be ready to start to send some commands to the USB devices.
The Rocket Launcher and Robot Arm take commands using a different arrangement of hex values. To make the interface I created a couple of functions which are passed the 'command' and a 'duration' as parameters. This made the basic 'user interface' section easier for pupils to understand.
In the Robot Arm section below, the MoveArm function is passed a tuple consisting of an integer (delay in seconds) and a list of 3 integers which relate to which motor to move and the direction of movement.
Robot arm commands...
[1,0,0] Open the jaws
[2,0,0] Close the jaws
[4,0,0] Raise the wrist
[8,0,0] Lower the wrist
[16,0,0] Raise the elbow
[32,0,0] Lower the elbow
[64,0,0] Raise the shoulder
[128,0,0] Lower the shoulder
[0,1,0] Rotate the base clockwise
[0,2,0] Rotate the base anti-clockwise
[0,0,1] Turn the light on
[0,0,0,] Turn the light off