Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cflib/crazyflie/link_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def start(self):
"""
if self._ping_thread_instance is None or not self._ping_thread_instance.is_alive():
self._stop_event.clear()
self._ping_thread_instance = Thread(target=self._ping_thread)
self._ping_thread_instance = Thread(target=self._ping_thread, name='ping_thread')
self._ping_thread_instance.start()

def stop(self):
Expand Down
24 changes: 20 additions & 4 deletions cflib/crazyflie/param.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
the parameters that can be written/read.

"""
import copy
import errno
import logging
import struct
Expand Down Expand Up @@ -295,7 +296,9 @@ def _connection_requested(self, uri):

def _disconnected(self, uri):
"""Disconnected callback from Crazyflie API"""
self.param_updater.close()
if self.param_updater is not None:
self.param_updater.close()
self.param_updater = None

# Do not clear self.is_updated here as we might get spurious parameter updates later

Expand All @@ -307,6 +310,9 @@ def request_param_update(self, complete_name):
"""
Request an update of the value for the supplied parameter.
"""
if self.param_updater is None:
self.param_updater = _ParamUpdater(self.cf, self._useV2, self._param_updated)
self.param_updater.start()
self.param_updater.request_param_update(
self.toc.get_element_id(complete_name))

Expand Down Expand Up @@ -519,7 +525,7 @@ def new_packet_cb(pk):
class _ExtendedTypeFetcher(Thread):

def __init__(self, cf, toc):
Thread.__init__(self)
Thread.__init__(self, name='ExtendedTypeFetcherThread')
self.daemon = True
self._lock = Lock()

Expand Down Expand Up @@ -573,6 +579,9 @@ def _close(self):
self.request_queue.get(block=False)
except Empty:
pass
self.request_queue.put(None) # Make sure we exit the run loop
self._should_close = True
self._cf.remove_port_callback(CRTPPort.PARAM, self._new_packet_cb)

# Then force an unlock of the mutex if we are waiting for a packet
# we didn't get back due to a disconnect for example.
Expand All @@ -584,6 +593,8 @@ def _close(self):
def run(self):
while not self._should_close:
pk = self.request_queue.get() # Wait for request update
if pk is None:
continue
self._lock.acquire()
if self._cf.link:
self._req_param = struct.unpack('<H', pk.data[1:3])[0]
Expand All @@ -598,7 +609,7 @@ class _ParamUpdater(Thread):

def __init__(self, cf, useV2, updated_callback):
"""Initialize the thread"""
Thread.__init__(self)
Thread.__init__(self, name='ParamUpdaterThread')
self.daemon = True
self.wait_lock = Lock()
self.cf = cf
Expand All @@ -616,7 +627,9 @@ def close(self):
self.request_queue.get(block=False)
except Empty:
pass

self.request_queue.put(None) # Make sure we exit the run loop
self._should_close = True
self.cf.remove_port_callback(CRTPPort.PARAM, self._new_packet_cb)
# Then force an unlock of the mutex if we are waiting for a packet
# we didn't get back due to a disconnect for example.
try:
Expand All @@ -640,6 +653,7 @@ def _new_packet_cb(self, pk):
if self._useV2:
release_pattern = pk.data[:2]
if pk.channel == READ_CHANNEL:
pk = copy.deepcopy(pk) # Dont modify the original packet
pk.data = pk.data[:2] + pk.data[3:]
else:
release_pattern = pk.data[:1]
Expand Down Expand Up @@ -677,6 +691,8 @@ def request_param_update(self, var_id):
def run(self):
while not self._should_close:
pk = self.request_queue.get() # Wait for request update
if pk is None:
continue
self.wait_lock.acquire()
if self.cf.link:
if self._useV2:
Expand Down
2 changes: 1 addition & 1 deletion cflib/crtp/radiodriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ class _RadioDriverThread(threading.Thread):
def __init__(self, radio, inQueue, outQueue,
radio_link_statistics_callback, link_error_callback, link, rate_limit: Optional[int]):
""" Create the object """
threading.Thread.__init__(self)
threading.Thread.__init__(self, name='RadioDriverThread')
self._radio = radio
self._in_queue = inQueue
self._out_queue = outQueue
Expand Down