def controllerXbox(self): # loop around xbox events while True: self.speed = 0 # pygame.event.pump() # if self.pressed[K_ESCAPE]: break for event in xbox_read.event_stream(deadzone=12000): # if either the up/down button is pressed, set the Y axes to if (event.key == 'RT' or event.key == 'LT'): if event.key == 'RT' and event.value > 1: self.speed = int(event.value)/17 self.moveY(0) elif event.key == 'LT' and event.value > 1: self.speed = int(event.value)/17 self.moveY(2) else: self.moveY(1) # if either the left/right button is pressed, set the X axes to if(event.key == 'dl' or event.key == 'dr'): if event.key == 'dl' and event.value == 1: self.moveX(0) elif event.key == 'dr' and event.value == 1: self.moveX(2) else: self.moveX(1) # Runs the move function self.move(self.speed) #if(event.key == 'guide'): break os.system(['clear','cls'][os.name == 'nt'])
def controllerXbox(): try: for event in xbox_read.event_stream(deadzone=12000): # Must build in truning and moving if event.key == 'Y1' and event.value > 1: move(1,(int(event.value) /2200)) if event.key == 'Y1' and event.value < 1: move(2,(int(event.value) /2200)) if event.key == 'X1' and event.value > 1: move(5,(int(event.value) /2200)) if event.key == 'X1' and event.value < 1: move(6,(int(event.value) /2200)) except: print '[...] Error With Controller [...]'
#Set WiringPi pinModes void pinMode(TURN,PWM_OUTPUT); # Default calibration values servoMid = 425 servoWidth = 180 rt_intensity = 0 lt_intensity = 0 steer = servoMid brakeSet = 'no' for event in xbox_read.event_stream(deadzone=12000): # Triggers Brake if event.key=='RT' or event.key=='LT': if event.key=='RT': rt_intensity = event.value else: lt_intensity = event.value brakeSet = yes if rt_intensity or lt_intesity >= 10 else no if brakeSet=='yes': GPIO.output(BRAKE, GRPIO.HIGH) # Left thumbstick controls the steering if event.key=='Y1': speed = int(event.value/32) speed.puts(speed) if event.key=='X2': steer = int( servoMid + (servoWidth*-event.value)/32768 )
def controllerPs3(): for event in xbox_read.event_stream(deadzone=12000): print event
msg[2]=1 msg[3]=value elif key == 'B': msg[2]=2 msg[3]=value elif key == 'X': msg[2]=3 msg[3]=value elif key == 'Y': msg[2]=4 msg[3]=value #print (key , ' ' , value) return 0 try: for event in xbox_read.event_stream(deadzone=12000): if (event.key == 'LT'): lt_intensity = event.value elif (event.key == 'RT'): rt_intensity = event.value elif (event.key == 'Y1'): y1_intensity = event.value elif (event.key == 'X2'): x2_intensity = event.value else: ProcessButtons(event.key , event.value) msg[0] = ProcessValue(x2_intensity) msg[1] = ProcessValue(y1_intensity) #msg[1] = ProcessTriggers() msg[4] +=1 sendData(msg) if msg[4] > 1000:
#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 ): #moves drive servos based on degree of analog stick movement move = 4003 - (3500 * event.value) / 32768 pwm2.setPWM(0, servoMin, move) if (event.key == 'Y1' and event.value < 0): move = 4004 - (3500 * -event.value) / 32768 pwm2.setPWM(2, servoMin, move) if (event.key == 'Y1' and event.value == 0): servoMin = 500 pwm2.setPWM(0, servoMin, move) pwm2.setPWM(2, servoMin, move) if (event.key == 'Y2' and event.value > 0): move = 4003 - (3500 * event.value) / 32768 pwm2.setPWM(1, servoMin, move)