Robotic Arm Control over USB on linux

(0 comments)

In the junkpil.. I mean in the lot of incoming hardware was a new toy. A usb controller toy robot arm. Quick googling revealed it is pretty common toy and there were already some solutions on how to control it without using the original software.

In one hour the robot arm was moving by command.


# ROBOT ARM CONTROL PROGRAM
#
# http://tampere.hacklab.fi
# http://vaasa.hacklab.fi
#
# //kengu
# //2014-04-21
#
# robotic arm movement ideas and basis from
# http://martinsant.net/?page_id=983
#
# keyboard control based on
# http://content.gpwiki.org/index.php/Python:Pygame_keyboard_input
#
# also some ideas from
# http://stackoverflow.com/questions/16044229/how-to-get-keyboard-input-in-pygame
# http://stackoverflow.com/questions/14580935/pygame-keydown-event-line-not-updating-position
#

# uses pygame

import usb.core, usb.util, time
import pygame
from pygame.locals import *

# Allocate the name 'RoboArm' to the USB device
RoboArm = usb.core.find(idVendor=0x1267, idProduct=0x0000)

# Check if the arm is detected and warn if not
if RoboArm is None:
raise ValueError("Arm not found")

# Create a variable for duration
Duration=1

# Define a procedure to execute each movement
def MoveArm(Duration, ArmCmd):
# Start the movement
RoboArm.ctrl_transfer(0x40,6,0x100,0,ArmCmd,1000)
# Stop the movement after waiting specified duration
time.sleep(Duration)
ArmCmd=[0,0,0]
RoboArm.ctrl_transfer(0x40,6,0x100,0,ArmCmd,1000)

pygame.init()
screen = pygame.display.set_mode((640, 480))
pygame.display.set_caption('Robot arm control')
#pygame.mouse.set_visible(0)

datastring = 0
rotate = 0
done = False

while not done:

MoveArm(0.01,[datastring,rotate,0])

for event in pygame.event.get():
if (event.type == KEYUP) or (event.type == KEYDOWN):
datastring = 0
rotate = 0

keys = pygame.key.get_pressed()
if keys[K_a]:
datastring +=128

if keys[K_q]:
datastring +=64

if keys[K_s]:
datastring +=32

if keys[K_w]:
datastring +=16

if keys[K_d]:
datastring +=8

if keys[K_e]:
datastring +=4

if keys[K_f]:
datastring +=2

if keys[K_r]:
datastring +=1

if keys[K_g]:
rotate = 1

if keys[K_t]:
rotate = 2

# print event
# print keys
if (event.key == K_ESCAPE):
done = True

#MoveArm(1,[0,0,1]) #Light on
#MoveArm(1,[0,0,0]) #Light off
#MoveArm(1,[64,0,1]) #Shoulder up
#MoveArm(1,[128,0,0]) #Shoulder down
#MoveArm(1,[16,0,0]) #Elbow up
#MoveArm(1,[32,0,0]) #Elbow down
#MoveArm(1,[4,0,0]) #Wrist up
#MoveArm(1,[8,0,0]) # Wrist down
#MoveArm(1,[1,0,0]) #Grip close
#MoveArm(1,[2,0,0]) #Grip open
#MoveArm(1,[0,1,0]) #Rotate base anti-clockwise
#MoveArm(1,[0,2,0]) #Rotate base clockwise

Currently unrated

Comments

There are currently no comments

New Comment

required

required (not published)

optional

required