Errors with TocCache, and

Post here to get support
Post Reply
erlingrj
Beginner
Posts: 23
Joined: Mon May 12, 2014 12:17 pm

Errors with TocCache, and

Post by erlingrj »

Im using the VM v. 0.4 Ive updated all repos, Ive flashed the newest firmware to the cf.

However, I can't even write the simplest programs without encountering loadsof errors.

For instance this simple script:

Code: Select all

import cflib.crtp
from cflib.crazyflie import Crazyflie
import time

# Initialize the low-level drivers (don't list the debug drivers)
cflib.crtp.init_drivers(enable_debug_driver=False)
# Scan for Crazyflies and use the first one found
print "Scanning interfaces for Crazyflies..."
available = cflib.crtp.scan_interfaces()
print "Crazyflies found:"
for i in available:
    print i[0]

if len(available)>0:
    cf = Crazyflie()
    
    def _connected(link_uri): 
        
        cf.commander.send_setpoint(0, 0, 0, 20000)
        time.sleep(0.1)
        cf.commander.send_setpoint(0,0,0,0)
        cf.close_link()
    
    cf.connected.add_callback(_connected)

    cf.open_link(available[0][0])

else:
    print "No crazyflies nearby"
Generates this warning:
WARNING:cflib.crazyflie.toccache:Could not save cache, no writable directory
WARNING:cflib.crazyflie.toccache:Could not save cache, no writable directory
and this:
No handlers could be found for logger "cflib.crazyflie.toccache"
And half the times I run it, also these:
Exception in thread Thread-104 (most likely raised during interpreter shutdown):
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 808, in __bootstrap_inner
File "/usr/lib/python2.7/threading.py", line 1080, in run
File "/home/bitcraze/projects/crazyflie-pc-client/lib/cflib/crazyflie/__init__.py", line 295, in <lambda>
File "/home/bitcraze/projects/crazyflie-pc-client/lib/cflib/crazyflie/__init__.py", line 253, in _no_answer_do_retry
<type 'exceptions.AttributeError'>: 'NoneType' object has no attribute 'debug'
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: Errors with TocCache, and

Post by arnaud »

The latest version of the virtual machine 0.5 and it now pull software from github instead of bitbucket, github is where development now takes place.

I have never seen most of these errors. I tried your code in the VM 0.5 and it works, I only got
No handlers could be found for logger "cflib.crazyflie.toccache"
to get rid of it you need to import the logging subsystem:

Code: Select all

import logging
logging.basicConfig(level=logging.ERROR)
This is my working code (placed in ~/projects/crazyflie-clients-python/examples):

Code: Select all

import sys
sys.path.append("../lib")
import cflib.crtp
from cflib.crazyflie import Crazyflie
import time

import logging
logging.basicConfig(level=logging.ERROR)

# Initialize the low-level drivers (don't list the debug drivers)
cflib.crtp.init_drivers(enable_debug_driver=False)
# Scan for Crazyflies and use the first one found
print "Scanning interfaces for Crazyflies..."
available = cflib.crtp.scan_interfaces()
print "Crazyflies found:"
for i in available:
	print i[0]

if len(available)>0:
	cf = Crazyflie()

	def _connected(link_uri):
	   
	    cf.commander.send_setpoint(0, 0, 0, 20000)
	    time.sleep(0.5)
	    cf.commander.send_setpoint(0,0,0,0)
	    time.sleep(0.5)
	    cf.close_link()

	cf.connected.add_callback(_connected)

	cf.open_link(available[0][0])

else:
	print "No crazyflies nearby"
Note that it is needed to wait a bit before disconnecting so that the last setpoint have time to be sent.
erlingrj
Beginner
Posts: 23
Joined: Mon May 12, 2014 12:17 pm

Re: Errors with TocCache, and

Post by erlingrj »

Thank you for fast replies on both my questions. The "No handlers"-issue is now gone. I'll swith over to the VM 0.5 and see what happens, I'm trying, without luck, to access the values for pitch and roll by using a similar code as the one you guys uploaded as an example of logging: basiclog.py

I suspect that errors in my code somehow has messed up something in the toc and/or the log, so now Ill try to reinstall the VM and hopefully it all goes away.

I have however another question about the logging. Im trying to access the values for pitch and roll and have made this class based on basiclog.py:

Code: Select all

from cflib import crtp
import logging
from cflib.crazyflie.log import LogConfig
from cflib.crazyflie import Crazyflie
# Only output errors from the logging framework
logging.basicConfig(level=logging.WARNING)

class Logger:
    ''' First attempt of making a class for accessing the measuremeants made by the crazyflie. The plan is to get thrust, yaw, pitch and roll every 10ms and let
    another program use this information and compansate for the copter getting out of course or being unstable. For exampleclass that this is based on, check out: 
    https://github.com/bitcraze/crazyflie-clients-python/blob/master/examples/basiclog.py'''
    
    def __init__(self,crazyflie):
        
        # Copies the Crazyflie to the logger.
        self._cf = crazyflie
        #The variables which I wanna make accessible to other functions
        self._pitch = 0
        self._roll = 0
        
    
    def _log(self):
        
        #Can only be runned if the Crazyflie is connected.
        
        self._lg_stab = LogConfig(name="Stabilizer", period_in_ms=20)
        self._lg_stab.add_variable("stabilizer.roll", "float")
        self._lg_stab.add_variable("stabilizer.pitch", "float")
        self._cf.log.add_config(self._lg_stab)
        
        if self._lg_stab.valid:
            # This callback will receive the data
            self._lg_stab.data_received_cb.add_callback(self._stab_log_data)
            # Start the logging
            self._lg_stab.start()
        else:
            print("Could not add logconfig since some variables are not in TOC")


    def _stab_log_data(self, timestamp, data, logconf):
        """Callback from when packets arrive, the values are stored in variables and can be used by other functions"""
        self._pitch = data['stabilizer.pitch']
        self._roll = data['stabilizer.roll']
The idea is simple. Connect the cf and initialize the logger like:

log = Logger(cf)
log._log()

And then, if the cf is connected, it should keep updating the variables self._pitch and self._roll every 10ms. I wanna access these variables to calculate what pitch and roll I should apply to the cf to adjust for the unstableness in hovermode, I simply want it to stand still midair. But this doesnt work. Ive tried to debug (ive not used python earlier so im not very good), and found out that the problem is that this: "self._lg_stab.data_received_cb.add_callback(self._stab_log_data)", self._stab_log_data never gets executed, probably because the logConfig never recieves any data and calls the callback. But I cant figure out why, it works with basiclog.py and my script is very similar. If anyone can help with this I would be extremly thankful
erlingrj
Beginner
Posts: 23
Joined: Mon May 12, 2014 12:17 pm

Re: Errors with TocCache, and

Post by erlingrj »

Figured this out myself I think. At least I have an up and running logger now. Now next step is the hovering mode :D
qubitter
Beginner
Posts: 28
Joined: Wed Mar 11, 2015 8:47 pm

Re: Errors with TocCache, and

Post by qubitter »

I have 2 questions. First, how do I implement the python code I am writing on my CF2?

Second, whenever I try to run your code(just to test) in IDLE, I get this error:

Traceback (most recent call last):
File "/Users/myname/Desktop/Creme Brulee/cftest.py", line 3, in <module>
import cflib.crtp
ImportError: No module named 'cflib'
>>>

Please help!
chad
Expert
Posts: 555
Joined: Sun Sep 28, 2014 12:54 am
Location: New York, USA
Contact:

Re: Errors with TocCache, and

Post by chad »

qubitter wrote:I have 2 questions. First, how do I implement the python code I am writing on my CF2?

Second, whenever I try to run your code(just to test) in IDLE, I get this error:

Traceback (most recent call last):
File "/Users/myname/Desktop/Creme Brulee/cftest.py", line 3, in <module>
import cflib.crtp
ImportError: No module named 'cflib'
>>>

Please help!
Hi qubitter, it's best to open new threads for most of the questions you're having. I haven't tried running any client code through IDLE but I'm guessing it doesn't have the paths set up to import these libraries. As far as question 1, what are you trying to accomplish, maybe it will be easier to help you knowing this.
Crazyflier - my CF journal...
4x Crazyflie Nano (1.0) 10-DOF + NeoPixel Ring mod.
3x Crazyflie 2.0 + Qi Charger and LED Decks.
Raspberry Pi Ground Control.
Mac OS X Dev Environment.
Walkera Devo7e, ESky ET6I, PS3 and iOS Controllers.
Post Reply