Raspberry Pi – Robot Arm Controlled via Bluetooth PS3 Controller

A raspberry pi robot arm I built. Is controlled by a bluetooth ps3 controller with pressure-sensitive control. Can rotate infinitely without wires being twisted because all of the components are rotating as one. This was a very fun project to build, and I hope I can expand upon it later. Video:


And now for some technical information:

Raspberry Pi model B 512MB (http://www.adafruit.com/products/998)
Adafruit Prototyping Pi Plate (http://www.adafruit.com/products/801)
Adafruit 16-Channel 12-Bit PWM/Servo Driver (http://www.adafruit.com/products/815)
Paralax Continuous Rotation Servo (http://www.adafruit.com/products/154)
10,000 mAh Lipo battery pack
4x AA batteries
Bluetooth Dongle
PS3 Controller
Lego Technic Frame

4 thoughts on “Raspberry Pi – Robot Arm Controlled via Bluetooth PS3 Controller

  1. Hello,

    First, grat project and thanks for sharing!
    I have done all in the tutorial, servo’s and controller working in test.
    Only think i cant get to work is the code you posted.
    Problem is that i am no programmer…specially not in Python….
    Can you please help me with the working code?
    Would be great!
    Thanks,
    Eddy

  2. Can you post the tutorial with code as to what you are using to control the servos from the controller? Like node.js, piblaster ?? etc

    • I use a lot of downloaded libraries and such in the code. Here is the tutorial I used to download the libraries and such to connect the pi to a ps3 controller: https://docs.google.com/document/d/1z6bJ98HL0Mkx5gJ0zj70wZER22MLfqQsBr68-bxLPUg/edit
      And you will need to also download pygame. Google for how to do that. I think that’s all. If it doesn’t work or if you have more questions feel free to ask. Here’s the code (a mashup of code I found online):

      #!/usr/bin/env python

      #import modules
      import time
      import os
      import RPi.GPIO as GPIO
      import pygame
      import subprocess
      import sys
      sys.path.append(‘/home/pi/Adafruit-Raspberry-Pi-Python-Code/Adafruit_PWM_Servo_Driver’)
      from Adafruit_PWM_Servo_Driver import PWM

      #GPIO MAPPINGS (They are constants)
      RED_LED = 22
      GREEN_LED = 17
      BLUE_LED = 23

      #setup GPIO
      GPIO.setmode(GPIO.BCM)
      #LEDs
      GPIO.setup(GREEN_LED, GPIO.OUT)
      GPIO.setup(RED_LED, GPIO.OUT)
      GPIO.setup(BLUE_LED, GPIO.OUT)

      def flash_led(color, delay, times):
      for i in range(0,times):
      GPIO.output(color, GPIO.HIGH)
      time.sleep(delay)
      GPIO.output(color, GPIO.LOW)
      time.sleep(delay)

      #start pygame
      pygame.init()

      # Wait for a joystick
      while pygame.joystick.get_count() == 0:
      print ‘waiting for joystick count = %i’ % pygame.joystick.get_count()
      flash_led(GREEN_LED, 1, 5) #replaced time.sleep(10) with 10 seconds of blinking
      pygame.joystick.quit()
      pygame.joystick.init()

      j = pygame.joystick.Joystick(0)
      j.init()

      print ‘Initialized Joystick : %s’ % j.get_name()
      GPIO.output(GREEN_LED, GPIO.HIGH)

      # Key mappings
      PS3_AXIS_O = 17
      PS3_AXIS_X = 18
      PS3_AXIS_LEFT_VERTICAL = 1
      PS3_AXIS_LEFT_HORIZONTAL = 0
      PS3_AXIS_DPAD_UP = 8
      PS3_AXIS_DPAD_RIGHT = 9
      PS3_AXIS_DPAD_DOWN = 10
      PS3_AXIS_DPAD_LEFT = 11

      # PWM channels
      SERVO_ARM_SPIN = 0
      SERVO_ARM_LIFT = 1
      SERVO_CLAW = 2

      #PWM ranges
      SERVO_FULL_CW = 296
      SERVO_STOP = 328
      SERVO_FULL_CCW = 360

      def driveServo(channel, speed):

      #calculate PWM pulse (32 is the range between SERVO_STOP and SERVO_FULL)
      pulse = SERVO_STOP
      if speed != 0:
      pulse = (speed * 32) + SERVO_STOP

      #tell servo what to do
      pwm.setPWM(channel, 0, int(pulse))

      #tell user what we did
      #print “Speed %.3f Pulse %i” % (speed, pulse)

      def processControl(event):

      if event.type == pygame.JOYAXISMOTION:
      #left stick
      if event.axis == PS3_AXIS_LEFT_VERTICAL:
      driveServo(SERVO_ARM_LIFT, event.value)
      elif event.axis == PS3_AXIS_LEFT_HORIZONTAL:
      driveServo(SERVO_ARM_SPIN, event.value)
      #D -Pad
      elif event.axis == PS3_AXIS_DPAD_UP:
      driveServo(SERVO_ARM_LIFT, -event.value)
      elif event.axis == PS3_AXIS_DPAD_DOWN:
      driveServo(SERVO_ARM_LIFT, event.value)
      elif event.axis == PS3_AXIS_DPAD_LEFT:
      driveServo(SERVO_ARM_SPIN, -event.value)
      elif event.axis == PS3_AXIS_DPAD_RIGHT:
      driveServo(SERVO_ARM_SPIN, event.value)
      #O & X buttons
      elif event.axis == PS3_AXIS_O:
      driveServo(SERVO_CLAW, event.value / 3)
      elif event.axis == PS3_AXIS_X:
      driveServo(SERVO_CLAW, -event.value / 3)

      def safeExit(exitString):
      print “Exiting ps3robot.py because: %s” % exitString
      global j
      j.quit()
      GPIO.cleanup()
      exit()

      # Initialise the PWM device using the default address
      pwm = PWM(0x40, debug=True)
      # Set frequency to 50 Hz
      pwm.setPWMFreq(50)

      try:
      # Loop forwever
      while (True):
      # Sleep so we don’t eat up all the CPU time
      time.sleep(0.1)

      # read in joystick events
      events = pygame.event.get()

      # and process them
      for event in events:
      processControl(event)

      except KeyboardInterrupt:
      safeExit(“Keyboard Interrupt”)

      except:
      safeExit(“Other error”)

      #Exit
      safeExit(“Exiting end of program”)

Leave a Reply

Your email address will not be published. Required fields are marked *

*