[SOLVED] Data Logging

Discussions and questions about the Crazyflie Nano Quadcopter
Post Reply
Calvin Chua
Member
Posts: 33
Joined: Sun Mar 01, 2020 1:28 am

[SOLVED] Data Logging

Post by Calvin Chua »

Hi,
Is there a way to modify the basiclogSync.py example to let the quadcopter log more data (12 states variables)

Thanks
kristoffer
Bitcraze
Posts: 630
Joined: Tue Jun 30, 2015 7:47 am

Re: Data Logging

Post by kristoffer »

Hi!
There is a limitation on the number of log variables in one log block (due to the radio packet size), but you can define multiple log blocks and pass an array of log blocks to the SyncLogger in one go

Code: Select all

lg_1 = LogConfig(name='first', period_in_ms=50)
# ... more code to define the log block
lg_2 = LogConfig(name='second', period_in_ms=50)
# ... more code to define the log block

with SyncCrazyflie('usb://0') as scf:
    with SyncLogger(scf, [lg_1, lg_2]) as logger:
        # Do stuff with the log data
        
Calvin Chua
Member
Posts: 33
Joined: Sun Mar 01, 2020 1:28 am

Re: Data Logging

Post by Calvin Chua »

Hi Kris,
I tried your code but it shows error of list object has no attribute of 'default_fetch_as'. Can you show me what I might have done wrongly please?

Code: Select all

import logging
import time

import cflib.crtp
from cflib.crazyflie import Crazyflie
from cflib.crazyflie.log import LogConfig
from cflib.crazyflie.syncCrazyflie import SyncCrazyflie
from cflib.crazyflie.syncLogger import SyncLogger

import numpy as np

# Only output errors from the logging framework
logging.basicConfig(level=logging.ERROR)
URI = 'radio://0/80/2M'


if __name__ == '__main__':
    # Initialize the low-level drivers (don't list the debug drivers)
    cflib.crtp.init_drivers(enable_debug_driver=False)

    lg1 = LogConfig(name='Stabilizer', period_in_ms=10)
    #lg1.add_variable('stabilizer.roll', 'float')
    #lg1.add_variable('stabilizer.pitch', 'float')
    #lg1.add_variable('stabilizer.yaw', 'float')
    #lg1.add_variable('stabilizer.thrust','float')
    lg1.add_variable('stateEstimate.z','float')
    lg1.add_variable('stateEstimate.vz','float')
    lg1.add_variable('stateEstimate.roll', 'float')
    lg1.add_variable('stateEstimate.pitch', 'float')
    lg1.add_variable('stateEstimate.yaw', 'float')
    
    lg2 = LogConfig(name='Stabilizer', period_in_ms=10)
    lg2.add_variable('stateEstimate.x','float')
    lg2.add_variable('stateEstimate.vx','float')
    lg2.add_variable('stateEstimate.y', 'float')
    lg2.add_variable('stateEstimate.vy', 'float')
    lg2.add_variable('stateEstimateZ.quat', 'uint32_t')
    
    
    cf = Crazyflie(rw_cache='./cache')
    
    with SyncCrazyflie(URI, cf=cf) as scf:
        # Note: it is possible to add more than one log config using an
        # array.
        # with SyncLogger(scf, [lg_stab, other_conf]) as logger:

        with SyncLogger(scf,[lg1, lg2]) as logger1:
            endTime = time.time() + 3
            for log_entry1 in logger1: 
                #for log_entry2 in logger2:
                timestamp1 = log_entry1[0]
                data1 = log_entry1[1]
                logconf_name1 = log_entry1[2]
                #print(data['stabilizer.roll'])
                print('[%d][%s]: %s' % (timestamp1, logconf_name1, data1))
                #timestamp1 = log_entry2[0]
                #data1 = log_entry2[1]
                #logconf_name1 = log_entry2[2]
                #print(data['stabilizer.roll'])
                #print('[%d][%s]: %s' % (timestamp1, logconf_name1, data1))
                if time.time() > endTime:
                    break
kristoffer
Bitcraze
Posts: 630
Joined: Tue Jun 30, 2015 7:47 am

Re: Data Logging

Post by kristoffer »

Your code works on my machine :-)

Maybe you have to update crazyflie-lib-python?
Calvin Chua
Member
Posts: 33
Joined: Sun Mar 01, 2020 1:28 am

Re: Data Logging

Post by Calvin Chua »

Just update to cflib 0.12.1 Its now working. Thanks
Post Reply