Reading Data, what am i doing wrong?

Post here to get support
Post Reply
Silvers
Beginner
Posts: 1
Joined: Tue Jan 21, 2014 11:00 pm

Reading Data, what am i doing wrong?

Post by Silvers »

First i tried this example Code from the Wiki

Code: Select all

gyroconf = LogConfig("Gyro", 10)
        gyroconf.addVariable(LogVariable("gyro.x", "float"))
        gyroconf.addVariable(LogVariable("gyro.y", "float"))
        gyroconf.addVariable(LogVariable("gyro.z", "float"))
 
        
        gyrolog = crazyflie.log.newLogPacket(gyroconf)
 
        if (gyrolog != None):
            gyrolog.data_received.addCallback(gyroData)
            gyrolog.startLogging()
        else:
            print "gyro.x/y/z not found in log TOC"
This did not work because addVariable is missing. So i looked into the libs and now wrote this code.

Code: Select all

gyroconf = LogConfig("Gyro", 10)
        gyroconf.add_variable(LogVariable("gyro.x", "float"))
        gyroconf.add_variable(LogVariable("gyro.y", "float"))
        gyroconf.add_variable(LogVariable("gyro.z", "float"))
 
        
        gyrolog = self.crazyflie.log.add_config(gyroconf)
 
        if (gyrolog != None):
            gyrolog.data_received.addCallback(gyroData)
            gyrolog.start()
        else:
            print "gyro.x/y/z not found in log TOC"
 
It crashes here :

Code: Select all

 gyrolog = self.crazyflie.log.add_config(gyroconf)
The error is:

Code: Select all


Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/cflib/crazyflie/__init__.py", line 323, in run
    cb[4](pk)
  File "/usr/local/lib/python2.7/dist-packages/cflib/crazyflie/toc.py", line 205, in _new_packet_cb
    self._toc_fetch_finished()
  File "/usr/local/lib/python2.7/dist-packages/cflib/crazyflie/toc.py", line 156, in _toc_fetch_finished
    self.finished_callback()
  File "/usr/local/lib/python2.7/dist-packages/cflib/crazyflie/__init__.py", line 135, in _param_toc_updated_cb
    self.connectSetupFinished.call(self.link_uri)
  File "/usr/local/lib/python2.7/dist-packages/cflib/utils/callbacks.py", line 56, in call
    cb(*args)
  File "float.py", line 42, in connectSetupFinished
    gyrolog = self.crazyflie.log.add_config(gyroconf)
  File "/usr/local/lib/python2.7/dist-packages/cflib/crazyflie/log.py", line 393, in add_config
    var = self.toc.get_element_by_complete_name(name)
  File "/usr/local/lib/python2.7/dist-packages/cflib/crazyflie/toc.py", line 90, in get_element_by_complete_name
    return self.get_element_by_id(self.get_element_id(complete_name))
  File "/usr/local/lib/python2.7/dist-packages/cflib/crazyflie/toc.py", line 98, in get_element_id
    [group, name] = complete_name.split(".")
AttributeError: LogVariable instance has no attribute 'split'
Could anyone please tell me what i am doing wrong?

Best regards,
Silvers
marcus
Bitcraze
Posts: 659
Joined: Mon Jan 28, 2013 7:02 pm
Location: Sweden
Contact:

Re: Reading Data, what am i doing wrong?

Post by marcus »

Hi,

The API doc is unfortunately still not updated :-(

eldraco has ported the examples (more info here) to the new API and they are available here.

The problem might be that the add_vabiable call should not use a LogVariable as argument, but instead two strings (second being optional) where you first specify the complete name of the variable to log (i.e gyro.x) and then the type (i.e float).

Like this (from the example):

Code: Select all

       # Log Accelerometer
        self.logAccel = LogConfig("Accel",200)
        self.logAccel.add_variable("acc.x", "float")
        self.logAccel.add_variable("acc.y", "float")
        self.logAccel.add_variable("acc.z", "float")

        self.crazyflie.log.add_config(self.logAccel)

        if self.logAccel.valid:
            self.logAccel.data_received_cb.add_callback(self.print_accel_data)
            self.logAccel.start()
        else:
            logger.warning("Could not setup log configuration for accelerometer after connection!")
/Marcus
Post Reply