Ejemplo n.º 1
0
def main ():
    com = communicator ("Translator")
    last_timestamp = 0

    while True:
        msg = com.get_message ("Switcher")
        if msg and msg["time"] > last_timestamp:
            last_timestamp = msg["time"]
            msg = msg["message"]

            send_flight_controls (msg["Pitch"], msg["Yaw"], msg["Roll"], msg["Z"], msg["Arm"], msg["Stabalize"], msg["Calibrate"])

        sleep (.05)
def main ():
	com = communicator ("Pinger_Base")

	pinger = passive_pinger (communicator=com)
	pinger.daemon = True
	pinger.start ()

	while True:
		if pinger.CONNECTED:
			recieve_video ()
		else:
			print "Not Connected!"
		sleep (1)
	def __init__(self):
		self.exit = 0

		self.com = communicator ("Controller")

		self.pitch = 0
		self.roll = 0
		self.yaw = 0
		self.z = 0
		self.arm = 0

		self.control_incrementer = 0.1

		self.run ()
Ejemplo n.º 4
0
def main():
    com = communicator("Translator")

    while True:
        msg = com.get_message("Direction")
        if msg:
            pitch = msg["message"]["Pitch"] * 100
            yaw = msg["message"]["Yaw"] * 100
            roll = msg["message"]["Roll"] * 100
            z = msg["message"]["Z"] * 100
            print pitch
            print yaw
            print roll
            print z
        time.sleep(0.5)
Ejemplo n.º 5
0
def main ():
	com = communicator ("Translator")
	last_timestamp = 0

	while True:
		msg = {"message":0, "time":0}
		msg = com.get_message ("Direction")
		print msg
		if msg and msg["time"] > last_timestamp:
			last_timestamp = msg["time"]
	
			pitch = msg["message"]["Pitch"] * 100
			yaw = msg["message"]["Yaw"] * 100
			roll = msg["message"]["Roll"] * 100
			z = msg["message"]["Z"] * 100

			send_flight_controls (pitch, yaw, roll, z)
		sleep (.5)
Ejemplo n.º 6
0
def main ():
	com = communicator ("AI")

	msg = {"time": 0}
	last_timestamp = 0
	control_vector = {"Yaw": 0, "Pitch": 0, "Z": 0, "Roll": 0}

	while True:
		msg = com.get_message ("Base_Finder")
		i = 0
		if msg:
			if msg["time"] > last_timestamp:
				last_timestamp = msg["time"]

				control_vector["Roll"] = 0.0
				control_vector["Yaw"] = 0.0
				control_vector["Pitch"] = 0.0
				control_vector["Z"] = 0.0

				offset = msg["message"]
				print offset
				print i
				print
				i += 1

				# TODO: Add fuzzy logic here
		
				if offset[0] == 0:
					control_vector["Roll"] = 0.0
				elif offset[0] < 0:
					control_vector["Roll"] = -0.5
				elif offset[0] > 0:
					control_vector["Roll"] = 0.5

				if offset[1] == 0:
					control_vector["Pitch"] = 0.0
				elif offset[1] < 0:
					control_vector["Pitch"] = 0.5
				elif offset[1] > 0:
					control_vector["Pitch"] = -0.5

				print control_vector
				com.send_message (control_vector)
				time.sleep (.1)
Ejemplo n.º 7
0
def main ():
	com = communicator ("Base_Finder")
	processor = Vision_Processor ()
	reciever = video_reciever ("Downward")

	pos = (0, 0, 0)

	while True:
		frame = reciever.get_frame ()

		if frame is not None:
			pos = processor.process_image (frame)
			processor.show_images ()
			if pos:
				#print pos
				com.send_message (pos)

			key = cv2.waitKey (20)
			if key == 1048603 or key == 27:
				cv2.destroyAllWindows ()
				break
Ejemplo n.º 8
0
	def __init__(self):
		self.com = communicator ("Switcher")
		self.last_timestamp = 0
		self.control_msg = {"time": 0}
Ejemplo n.º 9
0
def main ():
    com = communicator ("Controller")

    final_packet = {"Pitch":0, "Yaw":0, "Roll":0, "Z":0, "Arm":0, "Stabalize":0}

    controller =  Controller (["X1", "Y1", "X2", "Y2", "[]", "/\\", "start", "R2", "L2"], ["Yaw", "Z", "Roll", "Pitch", "Unarm", "Arm", "Calibrate", "Stabalize1", "Stabalize2"])

    IS_ARMED = 0
    IS_STABALIZED = 0
    CALIBRATE = 0

    while True:
        inputs = controller.get_values ()

        try:
            # Buttons (0 - 100)
            inputs["Arm"] = controller.map_range (inputs["Arm"], 0, 255, 0.0, 100.0)
            inputs["Unarm"] = controller.map_range (inputs["Unarm"], 0, 255, 0.0, 100.0)
            inputs["Calibrate"] = controller.map_range (inputs["Calibrate"], 0, 1, 0.0, 100.0)
            inputs["Stabalize1"] = controller.map_range (inputs["Stabalize1"], 0, 255, 0.0, 100.0)
            inputs["Stabalize2"] = controller.map_range (inputs["Stabalize2"], 0, 255, 0.0, 100.0)

            # Throttle (0 - 100)
            inputs["Z"] = controller.map_range (inputs["Z"], 0, 255, 100.0, 0.0) / (1.0 / SENSITIVITY) # Reversed

            # Directions (-100 - 100)
            inputs["Yaw"] = controller.map_range (inputs["Yaw"], 0, 255, -100.0, 100.0) / (1.0 / SENSITIVITY) 
            inputs["Pitch"] = controller.map_range (inputs["Pitch"], 0, 255, 100.0, -100.0) / (1.0 / SENSITIVITY)  # Reversed
            inputs["Roll"] = controller.map_range (inputs["Roll"], 0, 255, -100.0, 100.0) / (1.0 / SENSITIVITY) 

            # Have to press hard to prevent accidental arm/unarm/throttle helper/throttle hold
            if inputs["Unarm"] == 100.0:
                inputs["Unarm"] = 100.0
            else:
                inputs["Unarm"] = 0

            if inputs["Arm"] == 100.0:
                inputs["Arm"] = 100.0
            else:
                inputs["Arm"] = 0

            if inputs["Stabalize1"] == 100.0:
                inputs["Stabalize1"] = 100.0
            else:
                inputs["Stabalize1"] = 0
            
            if inputs["Stabalize2"] == 100.0:
                inputs["Stabalize2"] = 100.0
            else:
                inputs["Stabalize2"] = 0

            if inputs["Calibrate"] == 100.0:
                inputs["Calibrate"] = 100.0
            else:
                inputs["Calibrate"] = 0

            if inputs["Stabalize1"] and inputs["Stabalize2"]:
                IS_STABALIZED = 1
            else:
                IS_STABALIZED = 0

            if inputs["Calibrate"]:
                CALIBRATE = 1
            else:
                CALIBRATE = 0

            # Logic so you don't have to hold arm/unarm/etc
            if IS_ARMED and inputs["Unarm"]:
                inputs["Arm"] = 0
                IS_ARMED = 0
                print "UNARMED!" 
            if not IS_ARMED and inputs["Arm"]:
                inputs["Arm"] = 1
                IS_ARMED = 1
                print "ARMED!"

            for key in inputs.keys ():
                if abs (inputs[key]) < 10:
                    inputs[key] = 0.0 

            final_packet = {"Pitch":inputs["Pitch"], "Yaw":inputs["Yaw"], "Roll":inputs["Roll"], "Z":inputs["Z"], "Arm":IS_ARMED, "Stabalize":IS_STABALIZED, "Calibrate": CALIBRATE}

            # Clips small controller movements to zero. Necessary especially for throttle so copter will arm
        
            com.send_message (final_packet)

        except KeyError:
            pass

        print final_packet
    
        # Send 5 commands/sec
        sleep (.1)