Beispiel #1
0
    def scan(self):
        interfaces = scan_interfaces()

        for i in enumerate(interfaces):
            interfaces[i[0]][0] = interfaces[i[0]][0].replace(
                "radio://0", "radio://" + str(self.radio))
        self.sig_foundURI.emit(interfaces)
Beispiel #2
0
 def gui_scanForDrones(self):
     '''
     Scan the radio channel looking for drones.
     Returns a list of all the available drones
     '''
     drones = radioChannel.scan_interfaces()
     self.drones = self.removeDuplicatedDrones(drones)
Beispiel #3
0
    def __init__(self, ble=False, sim_vel=np.array([0., 0., 0.])):
        print("[CrazyFlie] Attaching CrazyFlie Plug with Keyboard handle")

        if ble:
            link = BLEDriver()
            inter = link.scan_interface()[0][0]
            # inter = "e0:c3:b3:86:a6:13"
            link.connect(inter)
            self._cf = Crazyflie(link=link, rw_cache="./")
            self.rate = 0.05
            print("[CrazyFlie] Connected to Crazyflie on bluetooth {}.".format(
                inter))
        else:
            crtp.init_drivers()
            self.inter = crtp.scan_interfaces()
            self._cf = Crazyflie(rw_cache="./")
            self._cf.open_link(self.inter[0][0])
            time.sleep(1)  # wait for a while to let crazyflie fetch the TOC
            self.rate = 0.01
            print("[CrazyFlie] Connected to Crazyflie on radio {}.".format(
                self.inter))

        self.roll = 0
        self.pitch = 0
        self.yaw = 0
        self.hover_thrust = 36330
        self.tilt_angle = 10

        self.x_dot = 0.0
        self.y_dot = 0.0
        self.z_dot = 0.0
        self.yaw_rate = 0.0
        self.step = 0.1
        self.max_xyz_speed = 0.4
        self.max_yaw_rate = 90.

        self.x, self.y, self.z = 0, 0, 0.5

        self.running = True

        self.roll_calib_offset = 0
        self.pitch_calib_offset = 0

        signal.signal(signal.SIGINT, self.interrupt_handle)
        # tty.setcbreak(sys.stdin)
        self.keyboard_handle = Listener(on_press=self.on_press,
                                        on_release=self.on_release)
        self.keyboard_handle.start()

        # unlocking thrust protection
        self._cf.commander.send_setpoint(0, 0, 0, 0)
        self.sim_vel = sim_vel

        # if self.sim_vel is not None:
        self.hover_thread_flag = True
        self.hover_thread = threading.Thread(target=self.hover_threaded)
Beispiel #4
0
def getLink():
    print "Scanning for Crazyflies..."
    crazyfliesFound = scan_interfaces()
    
    if crazyfliesFound:
        for i in crazyfliesFound:
            print "Found: ", i[0]
            return i[0]
    else:
        print "No Crazyfly found"
        return False
Beispiel #5
0
def getLink():
    print "Scanning for Crazyflies..."
    crazyfliesFound = scan_interfaces()

    if crazyfliesFound:
        for i in crazyfliesFound:
            print "Found: ", i[0]
            return i[0]
    else:
        print "No Crazyfly found"
        return False
Beispiel #6
0
    def scanRadioChannel(self):
        '''
        NOT GUI INTENDED
        Scan the radio channel looking for drones.
        If no drones are found, restarts the scan. Until the end of time.
        '''
        print('Scanning interfaces for Crazyflies...')

        numberDronesFound = 0
        restartScanIn = 1  #seconds
        while (numberDronesFound == 0):
            availableDrones = radioChannel.scan_interfaces()
            availableDrones = self.removeDuplicatedDrones(availableDrones)

            numberDronesFound = len(availableDrones)
            if numberDronesFound == 0:
                print('No Crazyflies found, restarting scan...\n')
                time.sleep(restartScanIn)
            #   return self.scanRadioChannel()

        else:
            #Select all available drones, display them, let the user choose which to connect to
            print('Crazyflies found:', numberDronesFound)

            droneList = range(numberDronesFound)
            for i in droneList:
                print(i, ") - ", availableDrones[i][0])

            try:
                chosen = int(
                    input("Choose the Drone you want to connect to\n"))
            except ValueError:
                print("I know you can do better than that :)\n")
                return self.scanRadioChannel()

            if chosen not in droneList:  #Now we need to check whether the input refers to a valid listed drone
                print("Bad choice indeed... I'll give you a second chance\n")
                return self.scanRadioChannel()

            #Set the URI into the class variable droneURI
            #Avoid situations like: correctly find a drone to connect to but no Link/URI has been received.
            #This is usually due to low battery drone
            if (availableDrones[0][int(chosen)] != ""
                    or availableDrones[0][int(chosen)] != None):
                self.droneURI = availableDrones[0][int(chosen)]
            else:
                numberDronesFound = 0
Beispiel #7
0
def main():
    if not start_only_voice_control:
        uri = args['uri']
        logging.basicConfig()
        crtp.init_drivers(enable_debug_driver=False)

        # the command queue for the crazyflie
        crazyflieCommandQueue = Queue()

        # set up the crazyflie
        cf = crazyflie.Crazyflie(rw_cache='./cache')
        control = ControllerThread(cf, crazyflieCommandQueue)
        control.start()

        # start the web interface to the crazyflie
        server = Process(target=run_server,
                         args=("0.0.0.0", control_port, crazyflieCommandQueue))
        server.start()

        # start the path planning server
        pathPlanner = Process(target=run_path_planner,
                              args=("0.0.0.0", planning_port,
                                    crazyflieCommandQueue, room_config))
        pathPlanner.start()

        # connect to the crazyflie
        if uri is None:
            print('Scanning for Crazyflies...')
            available = crtp.scan_interfaces()
            if available:
                print('Found Crazyflies:')
                for i in available:
                    print('-', i[0])
                uri = available[0][0]
            else:
                print('No Crazyflies found!')
                sys.exit(1)

        print('Connecting to', uri)
        cf.open_link(uri)

        handle_keyboard_input(control, server)

        cf.close_link()

    if start_voice_control or start_only_voice_control:
        start_command_loop(f'{control_url}:{control_port}', voice_api)
Beispiel #8
0
    def run(self):
        self.cf = crazyflie.Crazyflie(ro_cache='./cache/ro/', rw_cache='./cache/rw/')
        crtp.init_drivers()
        available = crtp.scan_interfaces()
        for i in available:
            print "Connecting"
            self.cf.connectSetupFinished.add_callback(self.connected)
            self.cf.open_link(i[0])
            break

        while (self.values.run):
            sys.stdout.write("\rThrust: %d, Roll: %d, Pitch: %d, Yaw: %d            " % (self.values.thrust, self.values.roll, self.values.pitch, self.values.yaw))
            sys.stdout.flush();
            r = self.values.roll + self.base_roll
            p = self.values.pitch + self.base_pitch
            y = self.values.yaw + self.base_yaw
            t = self.values.thrust
            self.cf.commander.send_setpoint(r, p, y, t)
	def connect_to_cf(self, retry_after=10, max_timeout=20):
		"""
		Initializes radio drivers, looks for available CrazyRadios, and attempts to connect to the first available one.
		Doesn't return anything, but raises exceptions if anything goes wrong.
		:param retry_after: Time in seconds after which we should abort current connection and restart the attempt.
		:param max_timeout: Time in seconds after which we should give up if we haven't been able to establish comm. yet
		"""
		logging.info("Initializing drivers.")
		crtp.init_drivers(enable_debug_driver=False)

		logging.info("Setting up the communication link. Looking for available CrazyRadios in range.")
		available_links = crtp.scan_interfaces()
		if len(available_links) == 0:
			raise Exception("Error, no Crazyflies found. Exiting.")
		else:
			logging.info("CrazyFlies found:")  # For debugging purposes, show info about available links
			for i in available_links:
				logging.info("\t" + i[0])
			link_uri = available_links[0][0]  # Choose first available link

		logging.info("Initializing CrazyFlie (connecting to first available interface: '{}').".format(link_uri))
		self.crazyflie = Crazyflie(ro_cache="cachero", rw_cache="cacherw")  # Create an instance of Crazyflie
		self.crazyflie.connected.add_callback(self.on_cf_radio_connected)  # Set up callback functions for communication feedback
		self.crazyflie.disconnected.add_callback(self.on_cf_radio_disconnected)
		self.crazyflie.connection_failed.add_callback(self.on_cf_radio_conn_failed)
		self.crazyflie.connection_lost.add_callback(self.on_cf_radio_conn_lost)

		cnt = 0  # Initialize a time counter
		while self.cf_radio_connecting and cnt < max_timeout:
			if cnt % retry_after == 0:
				if cnt > 0:  # Only show warning after first failed attempt
					logging.warning("Unable to establish communication with Crazyflie ({}) after {}s. Retrying...".format(link_uri, retry_after))
					self.crazyflie.close_link()  # Closing the link will call on_disconnect, which will set cf_radio_connecting to False
					self.cf_radio_connecting = True  # Reset cf_radio_connecting back to True
				self.crazyflie.open_link(link_uri)  # Connect/Reconnect to the CrazyRadio through the selected interface
			time.sleep(1)  # Sleep for a second (give time for callback functions to detect whether we are connected)
			cnt += 1  # Increase the "waiting seconds" counter

		if cnt >= max_timeout:
			self.crazyflie.close_link()
			raise Exception("Unable to establish communication with CrazyFlie after {}s. Given up :(".format(max_timeout))
		elif not self.cf_radio_connected:
			raise Exception("Something failed while attempting to connect to the CrazyFlie, exiting.")
    while True:

        sys.stdout.write("\r" + str(leap_controller.read_input()))
        sys.stdout.flush()

    try:
        sys.stdin.readline()
    except KeyboardInterrupt:
        pass
    finally:
        pass
        # controller.remove_listener(listener)

if __name__ == '__main__':

    crtp.init_drivers(enable_debug_driver=False)
    available = crtp.scan_interfaces()

    for i in available:
        print(i[0])

    if len(available) > 0:
        print("available", available[0][0])
        leap_controller = LeapController(available[0][0])
    else:
        print('No Crazyflies found, cannot run example')



Beispiel #11
0
            print('Bye!')
            break
        else:
            print('Unhandled key', ch, 'was pressed')


if __name__ == "__main__":
    logging.basicConfig()
    crtp.init_drivers(enable_debug_driver=False)
    cf = crazyflie.Crazyflie(rw_cache='./cache')
    control = ControllerThread(cf)
    control.start()

    if URI is None:
        print('Scanning for Crazyflies...')
        available = crtp.scan_interfaces()
        if available:
            print('Found Crazyflies:')
            for i in available:
                print('-', i[0])
            URI = available[0][0]
        else:
            print('No Crazyflies found!')
            sys.exit(1)

    print('Connecting to', URI)
    cf.open_link(URI)

    handle_keyboard_input(control)

    cf.close_link()
Beispiel #12
0
 def scan(self):
     self.sig_foundURI.emit(scan_interfaces())
Beispiel #13
0
    def scan(self):
        interfaces = scan_interfaces()

        for i in enumerate(interfaces):
            interfaces[i[0]][0] = interfaces[i[0]][0].replace("radio://0", "radio://"+str(self.radio))
        self.sig_foundURI.emit(interfaces)