Robot Arm with Voice Control - Tutorial (part 3)

Here is part 3 for the robot arm with voice control tutorial. Click here for the first part or here for the second part.

Now that the output has been filtered and tested for confidence, the sentence can now be processed to move the arm:

def process_sentence(sentence_text):
	str1 = remove_tags(sentence_text)
	str2 = str1.replace('sentence1: ','')
	joints = ['ELBOW', 'SHOULDER', 'WRIST', 'GRIP']
	transcribed = str2.split()
	if transcribed[0] in joints:
		movearm(transcribed[0],transcribed[1])
	elif transcribed[0] == "LIGHT":
		ctrl_light(transcribed[1])
	elif transcribed[0] == "BASE":
		rotatebase(transcribed[1])

This function simply sorts the commands and passes them to the correct function. It could probably be written more elegantly, but this works for now. To use the pyusb module, we need to set up the device using the set_configuration() method. This is the complete main() function:

if __name__ == "__main__":
 
    dev = usb.core.find(idVendor=0x1267, idProduct=0x0000)
 
    #exit if device not found
    if dev is None:
        raise ValueError('Can\'t find robot arm!')
 
    #this arm should just have one configuration...
    dev.set_configuration()
 
    child = pexpect.spawn ('julius -input mic -C julian.jconf')
 
    while True:
        try:
            child.expect('please speak')
            process_julius(child.before)
        except KeyboardInterrupt:
            child.close(force=True)
            break

After getting the USB sorted, we can then send the commands to the robot arm by setting the half-nibble to 1 or 2, and then doing a bitwise left shift (which is the same as multiplying by 2^n). We then use pyusb to send the command:

def movearm(joint,direction):
    if (direction == "UP") or (direction == "CLOSE"):
        cval = 1
    elif (direction == "DOWN") or (direction == "OPEN"):
        cval = 2
    #
    if joint == "SHOULDER":
        cbyte = (cval << 6)
    elif joint == "ELBOW":
        cbyte = (cval << 4)
    elif joint == "WRIST":
        cbyte = (cval << 2)
    elif joint == "GRIP":
        cbyte = cval
    else:
        return
    command = (cbyte, 0, 0 )
    #taken parameters from notbrainsurgery's post:
    dev.ctrl_transfer(0x40, 6, 0x100, 0, command, 1000)
    time.sleep(1)
    #stop the arm
    dev.ctrl_transfer(0x40, 6, 0x100, 0, (0,0,0), 1000)

And a similar function for the base:

def rotatebase(direction):
    if (direction == "RIGHT"):
        cval = 1
    elif (direction == "LEFT"):
        cval = 2
    command = (0, cval, 0 )
    dev.ctrl_transfer(0x40, 6, 0x100, 0, command, 1000)
    time.sleep(2)
    #stop the arm
    dev.ctrl_transfer(0x40, 6, 0x100, 0, (0,0,0), 1000)  

And finally, for the LED:

def ctrl_light(light_comm):
    if (light_comm == "ON"):
        cval = 1
    elif (light_comm == "OFF"):
        cval = 0
    command = (0, 0, cval )
    dev.ctrl_transfer(0x40, 6, 0x100, 0, command, 1000)

Finishing up

Now save this python script as robotarm_voicectl.py in the 'voxforge/auto' folder, and run:

sudo python robotarm_voicectl.py

The script needs to be run with root privileges as we need hardware access to the USB subsystem. And as I said earlier, all of the requirements are also available on Windows and OSX, but will require some tweaks (i.e. pexpect is not available on Windows, so an alternative method should be used). Since everything is freely available, there are plenty of future possibilities for modification and tweaking - so happy hacking!

Finally, you can download the python script from: Download

What Next?

Well as you can see in the video, it's not very convenient controlling the arm with repeated commands. So I've come up with a wish list that I'll try to implement progressively:

  1. more autonomy
    • some kind of sensor for proprioception and/or vision (Kinect?) (OpenTLD?)
    • inverse kinematics (ikfast from OpenRave)
  2. faster movement, more lifting weight (motor/gearbox improvements)
  3. operation from wall socket AC adapter (just some soldering which I'll get around to...someday)
  4. Swordfighting. ;-)
Tags: 

Comments

Great article, thank you!

Strictly, you don't have to run the script with root privileges just because you need an access to USB directly. Some Linux distros have preinstalled usb group for that purpose. All you need is to add your user to the group. If your distro doesn't have usb group you may want to add it manually as it is described here: https://www.virtualbox.org/wiki/USB_on_Ubuntu_7.04

Why not make a larger Metal Arm? Very Cool! How did you mess up your arm? That Robotic Arm get cha? lol

what programming language is used plsss i am a total newbie

i am final year student for engineering... i would like to make a cylindrical robotic arm... but i have a problem about motor and servo controller circuit... i dun understand how there function and work... could you send me the motor and servo controller circuit... Tq