Running sample code

Firmware/software/electronics/mechanics
Post Reply
Nacho_ac
Beginner
Posts: 4
Joined: Tue Jul 23, 2013 2:45 pm

Running sample code

Post by Nacho_ac »

Hello.
I'm not programmer but I have some experience with visual Basic and C and this is my first contact with pyton.
I have tried unsuccesfully to run the following code that I have found in the wiki.

Code: Select all

import logging
 
import cflib.crtp
from cfclient.utils.logconfigreader import LogConfig
from cfclient.utils.logconfigreader import LogVariable
from cflib.crazyflie import Crazyflie
 
logging.basicConfig(level=logging.DEBUG)
 
 
class Main:
    """
    Class is required so that methods can access the object fields.
    """
    def __init__(self):
        """
        Connect to Crazyflie, initialize drivers and set up callback.
 
        The callback takes care of logging the accelerometer values.
        """
        self.crazyflie = Crazyflie()
        cflib.crtp.init_drivers()
 
        self.crazyflie.connectSetupFinished.add_callback(
                                                    self.connectSetupFinished)
 
        self.crazyflie.open_link("radio://0/10/250K")
 
    def connectSetupFinished(self, linkURI):
        """
        Configure the logger to log accelerometer values and start recording.
 
        The logging variables are added one after another to the logging
        configuration. Then the configuration is used to create a log packet
        which is cached on the Crazyflie. If the log packet is None, the
        program exits. Otherwise the logging packet receives a callback when
        it receives data, which prints the data from the logging packet's
        data dictionary as logging info.
        """
        # Set accelerometer logging config
        accel_log_conf = LogConfig("Accel", 10)
        accel_log_conf.addVariable(LogVariable("acc.x", "float"))
        accel_log_conf.addVariable(LogVariable("acc.y", "float"))
        accel_log_conf.addVariable(LogVariable("acc.z", "float"))
 
        # Now that the connection is established, start logging
        self.accel_log = self.crazyflie.log.create_log_packet(accel_log_conf)
 
        if self.accel_log is not None:
            self.accel_log.dataReceived.add_callback(self.log_accel_data)
            self.accel_log.start()
        else:
            print("acc.x/y/z not found in log TOC")
 
    def log_accel_data(self, data):
        logging.info("Accelerometer: x=%.2f, y=%.2f, z=%.2f" %
                        (data["acc.x"], data["acc.y"], data["acc.z"]))
 
Main()


It should conect to the crazyflie and turn the motors on, but doesn't work.
This is the error report.

Code: Select all

Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>> 
DEBUG:cflib.crazyflie:Adding callback on port [5] to [<bound method Log._new_packet_cb of <cflib.crazyflie.log.Log instance at 0x02458DA0>>]
DEBUG:cflib.crazyflie:Adding callback on port [0] to [<bound method Console.incoming of <cflib.crazyflie.console.Console instance at 0x028039E0>>]
DEBUG:cflib.crazyflie:Adding callback on port [2] to [<bound method _ParamUpdater._new_packet_cb of <_ParamUpdater(Thread-2, initial daemon)>>]
INFO:cflib.crazyflie:Callback->Connection initialized[radio://0/10/250K]
INFO:cflib.crazyflie:We are connected[radio://0/10/250K], request connection setup
DEBUG:cflib.crazyflie.toc:[5]: Start fetching...
DEBUG:cflib.crazyflie:Adding callback on port [5] to [<bound method TocFetcher._new_packet_cb of <cflib.crazyflie.toc.TocFetcher instance at 0x02807170>>]
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [5]
>>> DEBUG:cflib.crazyflie:ExpectAnswer: No answer on [5], do retry
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [5]
WARNING:cflib.crazyflie:ExpectAnswer: ERROR! Older timer whas running while scheduling new one on [5]
DEBUG:cflib.crazyflie:ExpectAnswer: No answer on [5], do retry
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [5]
WARNING:cflib.crazyflie:ExpectAnswer: ERROR! Older timer whas running while scheduling new one on [5]
DEBUG:cflib.crazyflie:ExpectAnswer: No answer on [5], do retry
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [5]
WARNING:cflib.crazyflie:ExpectAnswer: ERROR! Older timer whas running while scheduling new one on [5]
INFO:cflib.crazyflie:Callback->Connected to [radio://0/10/250K]
WARNING:cflib.crazyflie.log:Error no LogEntry to handle block=3
ERROR:cflib.crazyflie.toc:Got packet that was not on TOC channel, TOC fetch will probably not succeed
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [5], cancelling timer
WARNING:cflib.crazyflie.log:Error no LogEntry to handle block=4
ERROR:cflib.crazyflie.toc:Got packet that was not on TOC channel, TOC fetch will probably not succeed
WARNING:cflib.crazyflie.log:Error no LogEntry to handle block=3
ERROR:cflib.crazyflie.toc:Got packet that was not on TOC channel, TOC fetch will probably not succeed
WARNING:cflib.crazyflie.log:Error no LogEntry to handle block=4
ERROR:cflib.crazyflie.toc:Got packet that was not on TOC channel, TOC fetch will probably not succeed
WARNING:cflib.crazyflie.log:Error no LogEntry to handle block=3
ERROR:cflib.crazyflie.toc:Got packet that was not on TOC channel, TOC fetch will probably not succeed
WARNING:cflib.crazyflie.log:Error no LogEntry to handle block=4
ERROR:cflib.crazyflie.toc:Got packet that was not on TOC channel, TOC fetch will probably not succeed
WARNING:cflib.crazyflie.log:Error no LogEntry to handle block=3
ERROR:cflib.crazyflie.toc:Got packet that was not on TOC channel, TOC fetch will probably not succeed
WARNING:cflib.crazyflie.log:Error no LogEntry to handle block=4
ERROR:cflib.crazyflie.toc:Got packet that was not on TOC channel, TOC fetch will probably not succeed
WARNING:cflib.crazyflie.log:Error no LogEntry to handle block=3
ERROR:cflib.crazyflie.toc:Got packet that was not on TOC channel, TOC fetch will probably not succeed
WARNING:cflib.crazyflie.log:Error no LogEntry to handle block=4
ERROR:cflib.crazyflie.toc:Got packet that was not on TOC channel, TOC fetch will probably not succeed
WARNING:cflib.crazyflie.log:Error no LogEntry to handle block=3
ERROR:cflib.crazyflie.toc:Got packet that was not on TOC channel, TOC fetch will probably not succeed
WARNING:cflib.crazyflie.log:Error no LogEntry to handle block=4
ERROR:cflib.crazyflie.toc:Got packet that was not on TOC channel, TOC fetch will probably not succeed
WARNING:cflib.crazyflie.log:Error no LogEntry to handle block=3
ERROR:cflib.crazyflie.toc:Got packet that was not on TOC channel, TOC fetch will probably not succeed
WARNING:cflib.crazyflie.log:Error no LogEntry to handle block=4
ERROR:cflib.crazyflie.toc:Got packet that was not on TOC channel, TOC fetch will probably not succeed
WARNING:cflib.crazyflie.log:Error no LogEntry to handle block=1
ERROR:cflib.crazyflie.toc:Got packet that was not on TOC channel, TOC fetch will probably not succeed
WARNING:cflib.crazyflie.log:Error no LogEntry to handle block=2
ERROR:cflib.crazyflie.toc:Got packet that was not on TOC channel, TOC fetch will probably not succeed
WARNING:cflib.crazyflie.log:Error no LogEntry to handle block=3
ERROR:cflib.crazyflie.toc:Got packet that was not on TOC channel, TOC fetch will probably not succeed
WARNING:cflib.crazyflie.log:Error no LogEntry to handle block=4
ERROR:cflib.crazyflie.toc:Got packet that was not on TOC channel, TOC fetch will probably not succeed
WARNING:cflib.crazyflie.log:Error no LogEntry to handle block=3
ERROR:cflib.crazyflie.toc:Got packet that was not on TOC channel, TOC fetch will probably not succeed
WARNING:cflib.crazyflie.log:Error no LogEntry to handle block=4
ERROR:cflib.crazyflie.toc:Got packet that was not on TOC channel, TOC fetch will probably not succeed
WARNING:cflib.crazyflie.log:Error no LogEntry to handle block=3
ERROR:cflib.crazyflie.toc:Got packet that was not on TOC channel, TOC fetch will probably not succeed
WARNING:cflib.crazyflie.log:Error no LogEntry to handle block=4
ERROR:cflib.crazyflie.toc:Got packet that was not on TOC channel, TOC fetch will probably not succeed
WARNING:cflib.crazyflie.log:Error no LogEntry to handle block=3
ERROR:cflib.crazyflie.toc:Got packet that was not on TOC channel, TOC fetch will probably not succeed
WARNING:cflib.crazyflie.log:Error no LogEntry to handle block=4
ERROR:cflib.crazyflie.toc:Got packet that was not on TOC channel, TOC fetch will probably not succeed
ERROR:cflib.crazyflie.toc:Got packet that was not on TOC channel, TOC fetch will probably not succeed
DEBUG:cflib.crazyflie.toc:[5]: Got TOC CRC, 9 items and crc=0x892049D2
DEBUG:cflib.crazyflie.toc:Requesting index 0 on port 5
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [5]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [5], cancelling timer
WARNING:root:[5]: Was expecting 0 but got 9
DEBUG:cflib.crazyflie.toc:Added element [0]
DEBUG:cflib.crazyflie.toc:[5]: More variables, requesting index 1
DEBUG:cflib.crazyflie.toc:Requesting index 1 on port 5
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [5]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [5], cancelling timer
DEBUG:cflib.crazyflie.toc:Added element [1]
DEBUG:cflib.crazyflie.toc:[5]: More variables, requesting index 2
DEBUG:cflib.crazyflie.toc:Requesting index 2 on port 5
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [5]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [5], cancelling timer
DEBUG:cflib.crazyflie.toc:Added element [2]
DEBUG:cflib.crazyflie.toc:[5]: More variables, requesting index 3
DEBUG:cflib.crazyflie.toc:Requesting index 3 on port 5
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [5]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [5], cancelling timer
DEBUG:cflib.crazyflie.toc:Added element [3]
DEBUG:cflib.crazyflie.toc:[5]: More variables, requesting index 4
DEBUG:cflib.crazyflie.toc:Requesting index 4 on port 5
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [5]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [5], cancelling timer
DEBUG:cflib.crazyflie.toc:Added element [4]
DEBUG:cflib.crazyflie.toc:[5]: More variables, requesting index 5
DEBUG:cflib.crazyflie.toc:Requesting index 5 on port 5
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [5]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [5], cancelling timer
DEBUG:cflib.crazyflie.toc:Added element [5]
DEBUG:cflib.crazyflie.toc:[5]: More variables, requesting index 6
DEBUG:cflib.crazyflie.toc:Requesting index 6 on port 5
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [5]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [5], cancelling timer
DEBUG:cflib.crazyflie.toc:Added element [6]
DEBUG:cflib.crazyflie.toc:[5]: More variables, requesting index 7
DEBUG:cflib.crazyflie.toc:Requesting index 7 on port 5
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [5]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [5], cancelling timer
DEBUG:cflib.crazyflie.toc:Added element [7]
DEBUG:cflib.crazyflie.toc:[5]: More variables, requesting index 8
DEBUG:cflib.crazyflie.toc:Requesting index 8 on port 5
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [5]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [5], cancelling timer
DEBUG:cflib.crazyflie.toc:Added element [8]
WARNING:cflib.crazyflie.toccache:Could not save cache, no writable directory
DEBUG:cflib.crazyflie:Removing callback on port [5] to [<bound method TocFetcher._new_packet_cb of <cflib.crazyflie.toc.TocFetcher instance at 0x02807170>>]
DEBUG:cflib.crazyflie.toc:[5]: Done!
INFO:cflib.crazyflie:Log TOC finished updating
DEBUG:cflib.crazyflie.toc:[2]: Start fetching...
DEBUG:cflib.crazyflie:Adding callback on port [2] to [<bound method TocFetcher._new_packet_cb of <cflib.crazyflie.toc.TocFetcher instance at 0x02825288>>]
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling timer
DEBUG:cflib.crazyflie.toc:[2]: Got TOC CRC, 27 items and crc=0x27A2C4BA
DEBUG:cflib.crazyflie.toc:Requesting index 0 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling timer
DEBUG:cflib.crazyflie.toc:Added element [0]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 1
DEBUG:cflib.crazyflie.toc:Requesting index 1 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling timer
DEBUG:cflib.crazyflie.toc:Added element [1]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 2
DEBUG:cflib.crazyflie.toc:Requesting index 2 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling timer
DEBUG:cflib.crazyflie.toc:Added element [2]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 3
DEBUG:cflib.crazyflie.toc:Requesting index 3 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling timer
DEBUG:cflib.crazyflie.toc:Added element [3]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 4
DEBUG:cflib.crazyflie.toc:Requesting index 4 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling timer
DEBUG:cflib.crazyflie.toc:Added element [4]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 5
DEBUG:cflib.crazyflie.toc:Requesting index 5 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling timer
DEBUG:cflib.crazyflie.toc:Added element [5]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 6
DEBUG:cflib.crazyflie.toc:Requesting index 6 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: No answer on [2], do retry
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
WARNING:cflib.crazyflie:ExpectAnswer: ERROR! Older timer whas running while scheduling new one on [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling timer
DEBUG:cflib.crazyflie.toc:Added element [6]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 7
DEBUG:cflib.crazyflie.toc:Requesting index 7 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling timer
DEBUG:cflib.crazyflie.toc:Added element [7]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 8
DEBUG:cflib.crazyflie.toc:Requesting index 8 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling timer
DEBUG:cflib.crazyflie.toc:Added element [8]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 9
DEBUG:cflib.crazyflie.toc:Requesting index 9 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling timer
DEBUG:cflib.crazyflie.toc:Added element [9]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 10
DEBUG:cflib.crazyflie.toc:Requesting index 10 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling timer
DEBUG:cflib.crazyflie.toc:Added element [10]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 11
DEBUG:cflib.crazyflie.toc:Requesting index 11 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling timer
DEBUG:cflib.crazyflie.toc:Added element [11]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 12
DEBUG:cflib.crazyflie.toc:Requesting index 12 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling timer
DEBUG:cflib.crazyflie.toc:Added element [12]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 13
DEBUG:cflib.crazyflie.toc:Requesting index 13 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling timer
DEBUG:cflib.crazyflie.toc:Added element [13]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 14
DEBUG:cflib.crazyflie.toc:Requesting index 14 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling timer
DEBUG:cflib.crazyflie.toc:Added element [14]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 15
DEBUG:cflib.crazyflie.toc:Requesting index 15 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling timer
DEBUG:cflib.crazyflie.toc:Added element [15]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 16
DEBUG:cflib.crazyflie.toc:Requesting index 16 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling timer
DEBUG:cflib.crazyflie.toc:Added element [16]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 17
DEBUG:cflib.crazyflie.toc:Requesting index 17 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling timer
DEBUG:cflib.crazyflie.toc:Added element [17]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 18
DEBUG:cflib.crazyflie.toc:Requesting index 18 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling timer
DEBUG:cflib.crazyflie.toc:Added element [18]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 19
DEBUG:cflib.crazyflie.toc:Requesting index 19 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling timer
DEBUG:cflib.crazyflie.toc:Added element [19]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 20
DEBUG:cflib.crazyflie.toc:Requesting index 20 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling timer
DEBUG:cflib.crazyflie.toc:Added element [20]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 21
DEBUG:cflib.crazyflie.toc:Requesting index 21 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling timer
DEBUG:cflib.crazyflie.toc:Added element [21]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 22
DEBUG:cflib.crazyflie.toc:Requesting index 22 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling timer
DEBUG:cflib.crazyflie.toc:Added element [22]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 23
DEBUG:cflib.crazyflie.toc:Requesting index 23 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling timer
DEBUG:cflib.crazyflie.toc:Added element [23]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 24
DEBUG:cflib.crazyflie.toc:Requesting index 24 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling timer
DEBUG:cflib.crazyflie.toc:Added element [24]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 25
DEBUG:cflib.crazyflie.toc:Requesting index 25 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling timer
DEBUG:cflib.crazyflie.toc:Added element [25]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 26
DEBUG:cflib.crazyflie.toc:Requesting index 26 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling timer
DEBUG:cflib.crazyflie.toc:Added element [26]
WARNING:cflib.crazyflie.toccache:Could not save cache, no writable directory
DEBUG:cflib.crazyflie:Removing callback on port [2] to [<bound method TocFetcher._new_packet_cb of <cflib.crazyflie.toc.TocFetcher instance at 0x02825288>>]
DEBUG:cflib.crazyflie.toc:[2]: Done!
INFO:cflib.crazyflie:Param TOC finished updating
INFO:cflib.crazyflie:Callback->Connection setup finished [radio://0/10/250K]
WARNING:cflib.crazyflie.toc:Unable to find variable [acc.x]
WARNING:cflib.crazyflie.log:Log: acc.x not in TOC, this block cannot be used!
acc.x/y/z not found in log TOC
I have tried both under windows, and using the VM and the error reports i are similar
Could somebody tell me what is wrong?
alate
Beginner
Posts: 3
Joined: Tue Jul 09, 2013 10:19 pm

Re: Running sample code

Post by alate »

I'm not sure what is wrong, but try taking a look at this thread: http://forum.bitcraze.se/viewtopic.php?f=6&t=161

The original poster made improvements to the same sample code, and I had no issue running his version.
gmoshe27
Beginner
Posts: 5
Joined: Wed Jul 24, 2013 2:36 am

Re: Running sample code

Post by gmoshe27 »

I had a very similar problem with that example code. I wrote a simple app that sends the thrust command every 0.1 second. The way I got it to work was to not log try to log the acceleration.

I have the 6-DOF version of the crazyflie and instead of acc.x/y/z, I logged & printed the roll, pitch and yaw. Give this a shot.

Code: Select all

def connectSetupFinished(self, linkURI):
    # Set accelerometer logging config
    accel_log_conf = LogConfig("Stabalizer", 100)
    accel_log_conf.addVariable(LogVariable("stabilizer.roll", "float"))
    accel_log_conf.addVariable(LogVariable("stabilizer.pitch", "float"))
    accel_log_conf.addVariable(LogVariable("stabilizer.yaw", "float"))
    accel_log_conf.addVariable(LogVariable("stabilizer.thrust", "uint16_t"))

    # Now that the connection is established, start logging
    self.accel_log = self.crazyflie.log.create_log_packet(accel_log_conf)

    if self.accel_log is not None:
        self.accel_log.dataReceived.add_callback(self.log_accel_data)
        self.accel_log.start()
    else:
        print("pitch, roll or yaw not found in log TOC")
 
def log_accel_data(self, data):
    logging.info("Stabalizer: roll=%.2f, pitch=%.2f, yaw=%.2f, thrust=%d" %
        (data["stabilizer.roll"], data["stabilizer.pitch"], data["stabilizer.yaw"], data["stabilizer.thrust"]))
Nacho_ac
Beginner
Posts: 4
Joined: Tue Jul 23, 2013 2:45 pm

Re: Running sample code

Post by Nacho_ac »

Thanks to both.
I know I'm yet far to undestand fully python code, but I should be able to run a program.
At least I have been able to run succesfully your code, Gmoshe. I'll take it as starting point. Thanks.

P.D. Sorry about my english.
gmoshe27
Beginner
Posts: 5
Joined: Wed Jul 24, 2013 2:36 am

Re: Running sample code

Post by gmoshe27 »

No problem Nacho! I'm glad it helped!! I was frustrated like you were and I ended up digging into the crazyflie client source code to find what parameters the device actually logs and returns for that application. I don't know why the 6-DOF is not returning acceleration parameters, or if those parameters are not available in the firmware for this model. Maybe one of the awesome Bitcraze guys can answer that before I start digging into the firmware code too ;)

Either way, the cflib and cfclient source is very pretty and easy to read. I was impressed with it and you can learn a lot just by digging through the source.
https://bitbucket.org/bitcraze/crazyflie-pc-client

Good luck!
gmoshe27
Beginner
Posts: 5
Joined: Wed Jul 24, 2013 2:36 am

Re: Running sample code

Post by gmoshe27 »

Just to let you know, I did some more digging around to see why the accelerometer was not available for logging. If I had to guess, the accelerometer at one point in time was logged, but not anymore. It's probably just wrapped up into the roll, pitch and yaw values for simplicity. That Main application is likely out-of-date and the author might want to update it.

If you run the following code in the same test application, you will see that the only values in the TOC for logging are the thrust, yaw, roll, pitch, motor gain and pm.vbat, which I'm guessing is the battery? If you're wondering, I spent some time looking through the cfclient and cflib to figure this out. It was a little confusing at first, but what tipped me off was that the actual UI has a logging configuration tab that will display the values as I printed them.

Code: Select all

# I left out the imports for brevity
class Main:
    def __init__(self):
        self.crazyflie = Crazyflie()
        cflib.crtp.init_drivers()
        self.crazyflie.connectSetupFinished.add_callback(
                                                    self.connectSetupFinished)
        self.crazyflie.open_link("radio://0/10/250K")

    def connectSetupFinished(self, linkURI):
        self.output_toc()

    def output_toc(self):
        logging.info("printing the TOC")
        toc = self.crazyflie.log.toc

        for group in toc.toc.keys():
            for param in toc.toc[group].keys():
                toc_element = toc.toc[group][param]
                logging.info("name=%s.%s, index=%d, pytype=%s, ctype=%s" %
                    (group, param, toc_element.ident, toc_element.pytype, toc_element.ctype))

Main()
Nacho_ac
Beginner
Posts: 4
Joined: Tue Jul 23, 2013 2:45 pm

Re: Running sample code

Post by Nacho_ac »

I can see. Your code works again.
Thanks again Gmoshe. This virtual Beer is for you.
Image
I'm yet a bit lost but I can see a bit of light at the end of the tunnel.
Only a question more.
Aside the wiki page (where I found de first code), where can I find some documentation about the crazyflie library? I thing I found a page with some like a dictionary, but I'm unable to find it again. :(
gmoshe27
Beginner
Posts: 5
Joined: Wed Jul 24, 2013 2:36 am

Re: Running sample code

Post by gmoshe27 »

Nacho, thanks for the virtual beer! The wiki where you found the sample application is very sparse in terms of the programming API. That page that you found, which I'll like below, is just enough to get you started, but the real useful documentation is in the source code. You pretty much have to read it and figure it out to understand it. That snippet I posted above took me around one or two hours of digging through the source and reading the debug output until I realized I could just look at what the UI was doing. However, because of it, I now understand just a little bit more about the crazyflie and how the libraries work. Before your question, I didn't really understand the whole table of contents concept.

http://wiki.bitcraze.se/projects:crazyf ... tils:pylib

Good luck, and truly the best source of materials right now is the source code. Checkout the crazyflie PC client source and the libraries cflib and crtp libs that bitcraze wrote. All you need to do is clone the project to your local hard drive.
Make sure you have Mercurial installed, and on the command line, enter:

% hg clone https://bitbucket.org/bitcraze/crazyflie-pc-client

To download mercurial, which is a source control framework: http://mercurial.selenic.com/wiki/Download
Nacho_ac
Beginner
Posts: 4
Joined: Tue Jul 23, 2013 2:45 pm

Re: Running sample code

Post by Nacho_ac »

Hi Gmoshe.
I'm agree that the best way to learn is studying and modifying working codes.
I have installed de virtual machine, so I have allready the repository cloned and mercurial installed.
I also have discovered the pyton pydoc, that describes a bit the craziflie libraries.
I know crazyflie is not the best way to introduce myself in the world of robotics, but is so exiciting...
Hope to learn a bit at least
Thanks again.
Post Reply