Skip to content

Commit 00db775

Browse files
authored
Fix USB connection to CF (#312)
Adding a USB reset seems to fix the USB connection to the Crazyflie when trying to connect multiple times. Fixes #264
1 parent 997cdd4 commit 00db775

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

cflib/crtp/usbdriver.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,16 @@ def connect(self, uri, link_quality_callback, link_error_callback):
7070
"""
7171

7272
# check if the URI is a radio URI
73-
if not re.search('^usb://', uri):
73+
uri_data = re.search('^usb://([0-9]+)$',
74+
uri)
75+
if not uri_data:
7476
raise WrongUriType('Not a radio URI')
7577

7678
# Open the USB dongle
7779
if not re.search('^usb://([0-9]+)$',
7880
uri):
7981
raise WrongUriType('Wrong radio URI format!')
8082

81-
uri_data = re.search('^usb://([0-9]+)$',
82-
uri)
83-
8483
self.uri = uri
8584

8685
if self.cfusb is None:

cflib/drivers/cfusb.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"""
2828
import logging
2929
import os
30+
import platform
3031

3132
import libusb_package
3233
import usb
@@ -90,6 +91,9 @@ def __init__(self, device=None, devid=0):
9091
self.dev = None
9192

9293
if self.dev:
94+
if platform.system() == 'Linux':
95+
self.dev.reset()
96+
9397
self.dev.set_configuration(1)
9498
self.handle = self.dev
9599
self.version = float(
@@ -118,7 +122,7 @@ def scan(self):
118122
return [('usb://0', '')]
119123
return []
120124

121-
def set_crtp_to_usb(self, crtp_to_usb):
125+
def set_crtp_to_usb(self, crtp_to_usb: bool):
122126
if crtp_to_usb:
123127
_send_vendor_setup(self.handle, 0x01, 0x01, 1, ())
124128
else:

0 commit comments

Comments
 (0)