I've been trying to interface the crazyflie 2.0 with other software.
To begin with I've tried to thread the basiclog example script. I want to store incoming 'flie data in one thread, allowing the main thread to display/pass on/work with the data in real time.
At present the main returning is ending my thread, halting the crazyflie communication. A simple sleep loop propping open the main does not destroy the thread, but does defeat its purpose.
Whilst I'm not experienced in python, I've made a simple numeric calculation persist in a nondaemon thread beyond the main, and then referenced its output. This leads me to believe that there is something in the crazyflie libraries interfering with me.
Any insight would be much appreciated!
My code follows, it's a simple variant of basiclog.py from the client examples
Code: Select all
import sys
sys.path.append("C:\Users\David\Desktop\crazyflie-clients-python\lib")
import cflib.crtp
cflib.crtp.init_drivers(enable_debug_driver=False)
available = cflib.crtp.scan_interfaces()
print "Scan found:"
for i in available:
print i[0]
import threading, Queue, time, logging
from threading import Thread
from threading import Timer
from cfclient.utils.logconfigreader import LogConfig
from cflib.crazyflie import Crazyflie
queue = Queue.Queue(1)
class LoggingExample(threading.Thread):
def __init__(self, link_uri):
super(LoggingExample, self).__init__()
self.daemon = False
global queue
import sys
sys.path.append("C:\Users\David\Desktop\crazyflie-clients-python\lib")
import threading, Queue, time, logging, cflib.crtp
from threading import Timer
from cfclient.utils.logconfigreader import LogConfig
from cflib.crazyflie import Crazyflie
logging.basicConfig(level=logging.ERROR)
self._cf = Crazyflie()
self._cf.connected.add_callback(self._connected)
self._cf.disconnected.add_callback(self._disconnected)
self._cf.connection_failed.add_callback(self._connection_failed)
self._cf.open_link(link_uri)
self.is_connected = True
def _connected(self, link_uri):
self._lg_stab = LogConfig(name="Stabilizer", period_in_ms=10)
self._lg_stab.add_variable("stabilizer.roll", "float")
self._lg_stab.add_variable("stabilizer.pitch", "float")
self._lg_stab.add_variable("stabilizer.yaw", "float")
self._cf.log.add_config(self._lg_stab)
if self._lg_stab.valid:
self._lg_stab.data_received_cb.add_callback(self._stab_log_data)
self._lg_stab.start()
def _stab_log_data(self, timestamp, data, logconf):
try:
task = queue.put("[%d][%s]: %s" % (timestamp, logconf.name, data),False)
queue.task_done()
except Queue.Full:
pass
def _connection_failed(self, link_uri, msg):
self.is_connected = False
def _disconnected(self, link_uri):
self.is_connected = False
LoggingExample(available[0][0])