Roomba robot with uarm

roombauarm

This is my Roomba robot with a uarm.

The uarm and the Roomba are controlled by a Raspberry Pi. An Arduino Leonardo is used to drive the Roomba serial interface. The Raspberry Pi uses a MoPi to control its power and act as an on/off switch. The Raspberry Pi and the Arduino are driven by the Roomba battery. Currently the uArm has is using a separate battery pack for the power to its servo shield, but it could probably take power from the Roomba battery as well. It is quite a good robot for fetching things and can do some light housework, but unfortunately it is not strong enough to fetch my beer, so that project is ongoing.

I have had quite a lot of problems with the uarm servos and have had to have several replaced: they tend to seize up if they are ever driven to their limits, however briefly.  I also have problems with the uarm base: the motor tends to slip when rotating the robot.

Here is the python program that moves the robot and controls the arm:

import serial
import time

def getch():
    import sys, tty, termios
    fd = sys.stdin.fileno()
    old_settings = termios.tcgetattr(fd)
    try:
        tty.setraw(sys.stdin.fileno())
        ch = sys.stdin.read(1)
    finally:
        termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
    return ch

def baud(hz):
  ser.write(chr(129) + chr(hz))

def forward():
  ser.write(chr(137) + chr(speed >> 8 & 0xff) + chr(speed & 0xff) + chr(0x80) + chr(0))

def backward():
  ser.write(chr(137) + chr(-speed >> 8 & 0xff) + chr(-speed & 0xff) + chr(0x80) + chr(0))

def stop():
  ser.write(chr(137) + chr(0) + chr(0) + chr(0) + chr(0))

def arc(r):
  ser.write(chr(137) + chr(speed >> 8 & 0xff) + chr(speed & 0xff) + chr(radius >> 8 & 0xff) + chr(radius &0xff))

def spinleft():
  ser.write(chr(137) + chr(speed >> 8 & 0xff) + chr(speed & 0xff) + chr(0) + chr(1))

def spinright():
  ser.write(chr(137) + chr(speed >> 8 & 0xff) + chr(speed & 0xff) + chr(0xff) + chr(0xff))

def motors(m=7):
  ser.write(chr(138) + chr(m))

def dock():
  ser.write(chr(143))

def control():
  ser.write(chr(130))

def start():
  ser.write(chr(128))

def sleep():
  ser.write(chr(133))

def safe():
  ser.write(chr(131))

def full():
  ser.write(chr(132))

def spot():
  ser.write(chr(134))

def max():
  ser.write(chr(136))

def clean():
  ser.write(chr(135))

def updatesensors():
  ser.write(chr(142) + chr(1))
  time.sleep(0.5)
  sensors = ser.read(10)
  while len(sensors) == 10:
    temp = ser.read(10)
    if len(temp) == 0:
      break
    sensors = temp
  return sensors

def sense():
  sensors = updatesensors()
  if len(sensors) == 10:
    print ord(sensors[0])

def step():
  sensors = updatesensors()
  if len(sensors) == 10:
    #print 'sensor 0 = ',ord(sensors[0])
    if ord(sensors[0]) & 0x01:
      #print 'spin left'
      spinleft()
      motors()
      time.sleep(1)
    elif ord(sensors[0]) & 0x02:
      #print 'spin right'
      spinright()
      time.sleep(1)
    else:
      forward()
  else:
     print 'No sensor value ',len(sensors)

def help():
  print 'arrow keys to move robot, s to stop'
  print 'u and d for shoulder up and down'
  print 'e and f for elbow up and down'
  print 'w and x for wrist left and right'
  print 'g and o for grabber close and open'
  print 'm and n for motors on and off'
  print 'p for spot, h for dock, c for control'
  
def set_position(rotation, stretch, height, wrist, catch):
  ser1.write(chr(0xFF) + chr(0xAA) + chr(rotation >> 8 & 0xff) + chr(rotation & 0xff) + chr(stretch >> 8 & 0xff) + chr(stretch & 0xff) + chr(height >> 8 & 0xff) + chr(height & 0xff) + chr(wrist >> 8 & 0xff) + chr(wrist & 0xff) + chr(catch))

#main
ser = serial.Serial('/dev/ttyACM0', 115200, timeout=0)
ser1 = serial.Serial('/dev/ttyUSB0', 9600, timeout=0)
speed = 200

rotation = 0
stretch = 0
height = 0
wrist = 0
catch = 0

while 1:
  sensors = updatesensors()
  set_position(rotation, stretch, height, wrist, catch)
  catch = 0
  k = getch()

  if k == "l": rotation -= 1
  elif k == "r": rotation += 1
  elif k == "u": height += 1
  elif k == "d": height -= 1
  elif k == "f": stretch += 1
  elif k == "b": stretch -= 1
  elif k == "o": catch = 1
  elif k == "g": catch = 2
  elif k == chr(3) or k == 'q': break
  elif k == "?": help();
  elif k == 's': stop()
  elif k == 'm': motors()
  elif k == 'n': motors(0)
  elif k == 'p': spot()
  elif k == 'c': control()
  elif k == 'h': dock()
  elif k == 'z': sense()
  elif ord(k) == 27:
    dummy = getch()
    k = getch()
    if ord(k) == 65: forward()
    elif ord(k) == 66: backward()
    elif ord(k) == 68: spinleft()
    elif ord(k) == 67: spinright()
    else:
      print 'Unrecognized special key ',ord(k)
  else:
    print 'Unrecognised key ',ord(k)
Advertisements
This entry was posted in Arduino, Raspberry PI, robotics, uarm and tagged , , , , . Bookmark the permalink.

One Response to Roomba robot with uarm

  1. datadazer says:

    The day I can build a robot that can fetch my beer will be the best day ever. Very cool build!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s