Esempio n. 1
0
#!/usr/bin/python

import RPi.GPIO as GPIO
from lib.Adafruit_PWM_Servo_Driver import PWM
from lib import xbox_read
import time
import math

# Initialise the PWM device using the default address
pwm = PWM(0x40,
          debug=True)  #connects to breakout board address 0x40 in debug mode
pwm2 = PWM(0x41, debug=True)
# Default calibration values
#32768 max range in xbox controller analog stick / 255 for triggers

move = 0
move2 = 500  #used for pwm signal max value
servoMin = 500  #used for min value for drive servos
servoMove = 150  #used for min value for camera servos
servoMoveBasket = 400  #used for min value for basket servos
servoMoveArm = 400  #used for min values for arm servos
menu = 1  #used to toggle between camera servos and capture carry servos
pwm.setPWMFreq(50)
pwm2.setPWMFreq(2000)  # Set frequency to 50 Hz

#main loop
while (True):
    for event in xbox_read.event_stream(
            deadzone=6000
    ):  #looks for a button to be pressed sets deadzone (sensitivity) to 6000
        if (event.key == 'Y1' and event.value > 0
Esempio n. 2
0
#!/usr/bin/python

import RPi.GPIO as GPIO
from lib.Adafruit_PWM_Servo_Driver import PWM
from lib import xbox_read
import time

# Initialise the PWM device using the default address
pwm = PWM(0x40, debug=True)

# Initialise the GPIO output channels
GPIO.setmode(GPIO.BCM)
FORWARD = 21
BACKWARD = 17
GPIO.setup(FORWARD, GPIO.OUT)
GPIO.setup(BACKWARD, GPIO.OUT)
direction = None

# Setup direction of travel
def setDirection(new_direction):
    global direction # One global property, cut me some slack
    if direction:
        GPIO.output(direction,False)
    GPIO.output(new_direction,True)
    direction = new_direction

setDirection(FORWARD)

# Default calibration values 
servoMid = 425
servoWidth = 180