class RoboticArm

Attributes

base[R]
elbow[R]
grip[R]
gripper[R]
led[R]
light[R]
shoulder[R]
wrist[R]

Public Class Methods

new() click to toggle source
# File lib/robotic-arm.rb, line 328
def initialize()

  # Get the device object
  usb = LIBUSB::Context.new
  arm = usb.devices(:idVendor => 0x1267, :idProduct => 0x0000).first

  (puts "Arm not found!"; exit) unless arm

  # Take control of the device
  @handle = arm.open
  @handle.claim_interface(0)

  @led      = Led.new      self 
  @wrist    = Wrist.new    self
  @elbow    = Elbow.new    self
  @shoulder = Shoulder.new self
  @base     = Base.new     self
  @grip     = Gripper.new  self
  @register = [OFF,OFF,OFF]
  
  @light, @gripper = @led, @grip  #aliases
end

Public Instance Methods

command(switch, val) click to toggle source

register and invoke the robotic action

# File lib/robotic-arm.rb, line 359
def command(switch, val)

  @register[switch] += val
  handle_command    

  if recording? then
    
    commands = {
        '21' => [:light,    :on],     '2-1' => [:light,    :off],
        '02' => [:gripper,  :open],    '01' => [:gripper,  :close],
       '0-2' => [:gripper,  :stop],   '0-1' => [:gripper,  :stop],
        '04' => [:wrist,    :up],      '08' => [:wrist,    :down],
       '0-4' => [:wrist,    :stop],   '0-8' => [:wrist,    :stop],
       '016' => [:elbow,    :up],     '032' => [:elbow,    :down],              
      '0-16' => [:elbow,    :stop],  '0-32' => [:elbow,    :stop], 
       '064' => [:shoulder, :up],    '0128' => [:shoulder, :down],
      '0-64' => [:shoulder, :stop], '0-128' => [:shoulder, :stop],        
        '12' => [:base,     :left],    '11' => [:base,     :right],
       '1-2' => [:base,     :stop],   '1-1' => [:base,     :stop]        
    }
    
    classname, methodname = *commands[switch.to_s + val.to_s]

    record classname, methodname
  end
end
down(seconds=0) click to toggle source
# File lib/robotic-arm.rb, line 355
def down (seconds=0)  @shoulder.down  seconds  end
inspect() click to toggle source
# File lib/robotic-arm.rb, line 351
def inspect() '#<RoboticArm:>' end
left(seconds=0) click to toggle source
# File lib/robotic-arm.rb, line 352
def left (seconds=0)  @base.left      seconds  end
off() click to toggle source

turn off all active signals

# File lib/robotic-arm.rb, line 388
def off()        
  stop
  @handle.release_interface(0)
end
right(seconds=0) click to toggle source
# File lib/robotic-arm.rb, line 353
def right(seconds=0)  @base.right     seconds  end
stop() click to toggle source

stop all robotic movement

# File lib/robotic-arm.rb, line 395
def stop()
  [wrist, elbow, shoulder, base, grip].each do |motor| 
    motor.stop if motor.moving?
  end
  led.off if led.on?    
  nil
end
up(seconds=0) click to toggle source
# File lib/robotic-arm.rb, line 354
def up   (seconds=0)  @shoulder.up    seconds  end

Private Instance Methods

handle_command() click to toggle source

Send the signal

# File lib/robotic-arm.rb, line 407
def handle_command()

  message = { 
              bmRequestType:  0x40, 
                   bRequest:  6,
                     wValue:  0x100, 
                     wIndex:  0,
                    dataOut:  @register.pack('CCC'), 
                    timeout:  1000
            }
  @handle.control_transfer message
end