Exemplo n.º 1
0
Arquivo: Main.py Projeto: bgrayd/Aries
def xboxInputUpdater():
    global xboxValues
    for event in xbox_read.event_stream(deadzone=12000):
        if event.key=='X1' or event.key=='X2' or event.key=='Y1' or event.key=='Y2':
            value = int(math.log10(math.fabs(event.value))/JOYSTICKSCALAR * event.value/math.fabs(event.value))
            xboxValues[event.key] = value
        elif event.key=="LT" or event.key=="RT":
            value = (event.value>=128)
            xboxValues[event.key] = value
        else:
            xboxValues[event.key] = event.value
def setStep(w1, w2, w3, w4):
    GPIO.output(motorPin1, w1)
    GPIO.output(motorPin2, w2)
    GPIO.output(motorPin3, w3)
    GPIO.output(motorPin4, w4)

def off():
  setStep(0,0,0,0)
  time.sleep(delay)

if __name__ == "__main__":
  temp = ""
  pForward = Process(target=forward)
  while True:
   for event in xbox_read.event_stream(deadzone=12000):
    temp = str(event)
    print temp
    
    input_state_L = GPIO.input(lbutton)
    input_state_R = GPIO.input(rbutton)
    print ("{0}  ,  {1}").format(input_state_L, input_state_R)
    
    if(temp == "Event(A,1,0)"):
        input_state_L = 0
    else:
        input_state_L = 1
    
    print ("{0}  ,  {1}").format(input_state_L, input_state_R)

    if (input_state_L == False and input_state_R == False):
Exemplo n.º 3
0
def signal_handler(signal, frame):
	#print "Stopping RobotArm Controller"
	sys.exit(0)

# Capture Ctrl+C so we can shut down nicely
signal.signal(signal.SIGINT, signal_handler)

#print "Starting RobotArm Controller"
#print "Press Ctrl+C at any time to quit"

# Create our RobotArm
arm = RobotArm.RobotArm()
#GPIO.output(greenLightPin,GPIO.HIGH)

# Our main event loop
for event in xbox_read.event_stream(deadzone=DEADZONE):
	#print "Xbox event: %s" % (event)	

	#Special case for LB and RB to control wrist
	if(event.key=='LB'):
		direction=1
	elif(event.key=='RB'):
		direction=2

	# Special-case the B button, if it's been pressed, then toggle the light
	elif(event.key=='B'):
		if(event.value>0):
			arm.toggleLight()
		continue
	
	# Special-case the A button, if it's being held, then we want the light
Exemplo n.º 4
0
    GPIO.output(motorPin1, w1)
    GPIO.output(motorPin2, w2)
    GPIO.output(motorPin3, w3)
    GPIO.output(motorPin4, w4)


def off():
    setStep(0, 0, 0, 0)
    time.sleep(delay)


if __name__ == "__main__":
    temp = ""
    pForward = Process(target=forward)
    while True:
        for event in xbox_read.event_stream(deadzone=12000):
            temp = str(event)
            print temp

            input_state_L = GPIO.input(lbutton)
            input_state_R = GPIO.input(rbutton)
            print("{0}  ,  {1}").format(input_state_L, input_state_R)

            if (temp == "Event(A,1,0)"):
                input_state_L = 0
            else:
                input_state_L = 1

            print("{0}  ,  {1}").format(input_state_L, input_state_R)

            if (input_state_L == False and input_state_R == False):
Exemplo n.º 5
0
def main():

    global throttle

    # Store controller values
    A = 0
    B = 0
    Y1 = 0
    X1 = 0
    # Declare our threads
    # Don't forget, set the threads as daemon to keep them from persisting
    tForward_stop = threading.Event()
    tForward = threading.Thread(target=forward, args=(1, tForward_stop))
    tForward.daemon = True

    tBackward_stop = threading.Event()
    tBackward = threading.Thread(target=backward, args=(2, tBackward_stop))
    tBackward.daemon = True

    while True:
        for event in xbox_read.event_stream(deadzone=12000):
            #            print str(event)
            input_state_L = GPIO.input(lbutton)
            input_state_R = GPIO.input(rbutton)

            if ((event.key == "A") and (event.value == 1)):
                A = 1
                pass
            elif ((event.key == "A") and (event.value == 0)):
                A = 0
                pass
            elif ((event.key == "B") and (event.value == 1)):
                B = 1
                pass
            elif ((event.key == "B") and (event.value == 0)):
                B = 0
                pass
            elif ((event.key == "Y1")):
                Y1 = event.value
                pass
            else:
                pass

            if (A == 0):
                input_state_L = 1
                pass
            elif (A == 1):
                input_state_L = 0
                pass

            if (B == 0):
                input_state_R = 1
                pass
            elif (B == 1):
                input_state_R = 0
                pass

            if (A == 0) and (B == 0):
                if (Y1 == 0):
                    input_state_L = 1
                    input_state_R = 1
                    pass
                elif (Y1 > 0):
                    throttle = abs(float(32768 / Y1) / 1000.0)
                    input_state_L = 0
                    pass
                elif (Y1 < 0):
                    throttle = abs(float(32768 / Y1) / 1000.0)
                    input_state_R = 0
                    pass

            if (X1 == 0):
                pass
            elif (X1 > 0):
                pass
            elif (X1 < 0):
                pass

#            print ("A = {0} , B = {1}").format(A, B)
#            print ("{0}  ,  {1}").format(input_state_L, input_state_R)

            if (input_state_L == False and input_state_R == False):
                GPIO.output(rled, 1)
                GPIO.output(lled, 1)
                #                print(threading.enumerate())
                try:
                    tForward_stop.set()
                    if (tForward.is_alive() == True):
                        tForward.join()
                    tBackward_stop.set()
                    if (tBackward.is_alive() == True):
                        tBackward.join()
                except:
                    print('error occured')
                    print sys.exc_info()
                off()

            elif (input_state_L == False and input_state_R == True):
                GPIO.output(rled, 0)
                GPIO.output(lled, 1)
                #                print "forward"
                #                print (threading.enumerate())
                try:
                    if (tForward.is_alive() != True):
                        #                        print ('start thread')
                        tForward_stop.clear()
                        #                        print tForward_stop.is_set()
                        tForward = threading.Thread(target=forward,
                                                    args=(1, tForward_stop))
                        tForward.start()
#                        print (threading.enumerate())
                except:
                    print('error occured')
                    print sys.exc_info()
                    pass
            elif (input_state_R == False and input_state_L == True):
                GPIO.output(lled, 0)
                GPIO.output(rled, 1)
                #                print "backward"
                #                print (threading.enumerate())
                try:
                    if (tBackward.is_alive() != True):
                        #                        print ('start thread')
                        tBackward_stop.clear()
                        #                        print tBackward_stop.is_set()
                        tBackward = threading.Thread(target=backward,
                                                     args=(2, tBackward_stop))
                        tBackward.start()


#                        print (threading.enumerate())
                except:
                    print('error occured')
                    print sys.exc_info()
                    pass

            else:
                GPIO.output(lled, 0)
                GPIO.output(rled, 0)
                #                print('button stopped')
                #                print(threading.enumerate())
                try:
                    tForward_stop.set()
                    if (tForward.is_alive() == True):
                        tForward.join()
                    tBackward_stop.set()
                    if (tBackward.is_alive() == True):
                        tBackward.join()
                except:
                    print('error occured')
                    print sys.exc_info()
                off()
def main():

    global throttle

    # Store controller values
    A = 0
    B = 0
    Y1 = 0
    X1 = 0
    # Declare our threads
    # Don't forget, set the threads as daemon to keep them from persisting
    tForward_stop = threading.Event()
    tForward = threading.Thread(target = forward, args=(1, tForward_stop))
    tForward.daemon = True

    tBackward_stop = threading.Event()
    tBackward = threading.Thread(target = backward, args=(2, tBackward_stop))
    tBackward.daemon = True

    while True:
        for event in xbox_read.event_stream(deadzone=12000):
#            print str(event)
            input_state_L = GPIO.input(lbutton)
            input_state_R = GPIO.input(rbutton)
    
            if  ((event.key == "A") and (event.value == 1)):
                A = 1
                pass
            elif((event.key == "A") and (event.value == 0)):
                A = 0
                pass
            elif((event.key == "B") and (event.value == 1)):
                B = 1
                pass
            elif((event.key == "B") and (event.value == 0)):
                B = 0
                pass
            elif((event.key == "Y1")):
                Y1 = event.value
                pass
            else:
                pass

            if   (A  == 0):
                input_state_L = 1
                pass
            elif (A  == 1):
                input_state_L = 0
                pass

            if   (B  == 0):
                input_state_R = 1
                pass
            elif (B  == 1):
                input_state_R = 0
                pass

            if   (A == 0) and (B == 0):
                if (Y1 == 0):
                    input_state_L = 1
                    input_state_R = 1
                    pass
                elif (Y1  > 0):
                    throttle = abs(float(32768/Y1) / 1000.0)
                    input_state_L = 0
                    pass
                elif (Y1  < 0):
                    throttle = abs(float(32768/Y1) / 1000.0)
                    input_state_R = 0
                    pass

            if   (X1 == 0):
                pass
            elif (X1  > 0):
                pass
            elif (X1  < 0):
                pass

#            print ("A = {0} , B = {1}").format(A, B)
#            print ("{0}  ,  {1}").format(input_state_L, input_state_R)

            if (input_state_L == False and input_state_R == False):
                GPIO.output(rled,1)
                GPIO.output(lled,1)
#                print(threading.enumerate())
                try:
                    tForward_stop.set()
                    if (tForward.is_alive()==True):
                        tForward.join()
                    tBackward_stop.set()
                    if (tBackward.is_alive()==True):
                        tBackward.join()
                except:
                    print('error occured')
                    print sys.exc_info()
                off()
            
            elif (input_state_L == False and input_state_R == True):
                GPIO.output(rled,0)
                GPIO.output(lled,1)
#                print "forward"
#                print (threading.enumerate())
                try:
                    if (tForward.is_alive()!=True):
#                        print ('start thread')
                        tForward_stop.clear()
#                        print tForward_stop.is_set()
                        tForward = threading.Thread(target = forward, args=(1, tForward_stop))
                        tForward.start()
#                        print (threading.enumerate())
                except:
                    print('error occured')
                    print sys.exc_info()
                    pass
            elif (input_state_R == False and input_state_L == True):
                GPIO.output(lled,0)
                GPIO.output(rled,1)
#                print "backward"
#                print (threading.enumerate())
                try:
                    if (tBackward.is_alive()!=True):
#                        print ('start thread')
                        tBackward_stop.clear()
#                        print tBackward_stop.is_set()
                        tBackward = threading.Thread(target = backward, args=(2, tBackward_stop))
                        tBackward.start()
#                        print (threading.enumerate())
                except:
                    print('error occured')
                    print sys.exc_info()
                    pass
            
            else:
                GPIO.output(lled,0)
                GPIO.output(rled,0)
#                print('button stopped')
#                print(threading.enumerate())
                try:
                    tForward_stop.set()
                    if (tForward.is_alive()==True):
                        tForward.join()
                    tBackward_stop.set()
                    if (tBackward.is_alive()==True):
                        tBackward.join()
                except:
                    print('error occured')
                    print sys.exc_info()
                off()
Exemplo n.º 7
0
    #print "Stopping RobotArm Controller"
    sys.exit(0)


# Capture Ctrl+C so we can shut down nicely
signal.signal(signal.SIGINT, signal_handler)

#print "Starting RobotArm Controller"
#print "Press Ctrl+C at any time to quit"

# Create our RobotArm
arm = RobotArm.RobotArm()
#GPIO.output(greenLightPin,GPIO.HIGH)

# Our main event loop
for event in xbox_read.event_stream(deadzone=DEADZONE):
    #print "Xbox event: %s" % (event)

    #Special case for LB and RB to control wrist
    if (event.key == 'LB'):
        direction = 1
    elif (event.key == 'RB'):
        direction = 2

    # Special-case the B button, if it's been pressed, then toggle the light
    elif (event.key == 'B'):
        if (event.value > 0):
            arm.toggleLight()
        continue

    # Special-case the A button, if it's being held, then we want the light
Exemplo n.º 8
0
	def run (self):
		for event in xbox_read.event_stream(deadzone=12000):
                        event = str(event)
                        event = event.replace("Event","")

			print colored(event,'red')
			if event == "(Y,1,0)":
				print("you pressed Y")
				recorvva.send_msg("you pressed Y")
			if event == "(Y,0,1)":
				print("you released Y")
				recorvva.send_msg("you released Y")
			if event == "(X,1,0)":
                                print("you pressed X")
                                recorvva.send_msg("you pressed X")
                        if event == "(X,0,1)":
                                print("you released X")
                                recorvva.send_msg("you released X")
			if event == "(A,1,0)":
                                print("you pressed A")
                                recorvva.send_msg("you pressed A")
                        if event == "(A,0,1)":
                                print("you released A")
                                recorvva.send_msg("you released A")
			if event == "(B,1,0)":
                                print("you pressed B")
                                recorvva.send_msg("you pressed B")
                        if event == "(B,0,1)":
                                print("you released B")
                                recorvva.send_msg("you released B")
			if event == "(RB,1,0)":
                                print("you pressed RB")
                                recorvva.send_msg("you pressed RB")
                        if event == "(RB,0,1)":
                                print("you released RB")
                                recorvva.send_msg("you released RB")
			if event == "(LB,1,0)":
                                print("you pressed LB")
                                recorvva.send_msg("you pressed LB")
                        if event == "(LB,0,1)":
                                print("you released LB")
                                recorvva.send_msg("you released LB")
			if event == "(dr,1,0)":
                                print("you pressed dr")
                                recorvva.send_msg("you pressed dr")
                        if event == "(dr,0,1)":
                                print("you released dr")
                                recorvva.send_msg("you released dr")
			if event == "(du,1,0)":
                                print("you pressed du")
                                recorvva.send_msg("you pressed du")
                        if event == "(du,0,1)":
                                print("you released du")
                                recorvva.send_msg("you released du")
			if event == "(dl,1,0)":
                                print("you pressed dl")
                                recorvva.send_msg("you pressed dl")
                        if event == "(dl,0,1)":
                                print("you released dl")
                                recorvva.send_msg("you released dl")
			if event == "(dd,1,0)":
                                print("you pressed dd")
                                recorvva.send_msg("you pressed dd")
                        if event == "(dd,0,1)":
                                print("you released dd")
                                recorvva.send_msg("you released dd")
			if event == "(TL,1,0)":
                                print("you pressed TL")
                                recorvva.send_msg("you pressed TL")
                        if event == "(TL,0,1)":
                                print("you released TL")
                                recorvva.send_msg("you released TL")
			if event == "(TR,1,0)":
                                print("you pressed TR")
                                recorvva.send_msg("you pressed TR")
                        if event == "(TR,0,1)":
                                print("you released TR")
                                recorvva.send_msg("you released TR")
			if event == "(back,1,0)":
                                print("you pressed back")
                                recorvva.send_msg("you pressed back")
                        if event == "(back,0,1)":
                                print("you released back")
                                recorvva.send_msg("you released back")
			if event == "(start,1,0)":
                                print("you pressed start")
                                recorvva.send_msg("you pressed start")
                        if event == "(start,0,1)":
                                print("you released start")
                                recorvva.send_msg("you released start")
			if event == "(guide,1,0)":
                                print("you pressed guide")
                                recorvva.send_msg("you pressed guide")
                        if event == "(guide,0,1)":
                                print("you released guide")
                                recorvva.send_msg("you released guide")
			if event == "(RT,1,0)":
                                print("you pressed RT")
                                recorvva.send_msg("you pressed RT")
                        if event == "(RT,0,1)":
                                print("you released RT")
                                recorvva.send_msg("you released RT")