Page 1 of 1

Adding sensor data logging / general software structure

Posted: Sun Jun 16, 2013 2:40 pm
by alex
Hey guys,

currently digging into the CF Python API. I'm trying to understand the process of adding sensor data output from the copter to the CF Client. Until now I could't manage to find the right place to add the additional client code for adding gyro output as described in the wiki:
On the client side we now add the log configuration, start the logging and then a callback will be called every 10 ms when data arrives from the Crazyflie
I can't find the correct place. This is an essential info for beginners. Especially since the wiki still lacks important information on code and library structure for both the firmware and client.

Please work on this as soon as possible since the learning curve is very frustrating for beginners otherwise.

Thank you.

Re: Adding sensor data logging / general software structure

Posted: Sun Jun 16, 2013 6:06 pm
by TheFrog4u
First of all the wiki is in early stage, but you can contribute to it if you want to.. Secondly there are examples on how to add logging variables: here

Re: Adding sensor data logging / general software structure

Posted: Sun Jun 16, 2013 7:21 pm
by alex
Yes, I know that wiki article as it is what I am talking about. When it goes to implement the client-side code snippet I don't know where to put it into:

http://wiki.bitcraze.se/projects:crazyf ... _variables

Sorry, if I didn't express myself clearly enough.

Re: Adding sensor data logging / general software structure

Posted: Sun Jun 16, 2013 7:58 pm
by foosel
The "Simple Code Example" directly following that section seems to explain it... If I understand that correctly, you'll need to register your "connected" callback with the crazyflie module:

Code: Select all

from cflib.crazyflie import Crazyflie

crazyflie=Crazyflie()
# ...
crazyflie.connectSetupFinished.add_callback(myConnectCallback)
crazyflie.open_link("radio://0/10/250K")

def myConnectCallback(linkUri):
    # setup logging, add callbacks etc

Re: Adding sensor data logging / general software structure

Posted: Mon Jun 17, 2013 6:39 am
by tobias
The wiki can always be improved and it slowly will ;). For the firmware part there is a link to this in top of the wiki page. Was that what you where looking for?

Re: Adding sensor data logging / general software structure

Posted: Fri Jun 21, 2013 4:31 pm
by alex
tobias wrote:The wiki can always be improved and it slowly will ;). For the firmware part there is a link to this in top of the wiki page. Was that what you where looking for?
Thank you, didn't know that. Can't navigate to this place manually, though. :?:
EDIT: Got it!


Ok, thanks for your help. Now I found the right place inside the code file structure of the client. Maybe the answer to my question was so trivial that we talked at cross-purposes the whole time. :D :lol:
screenshot-21062013.png

Re: Adding sensor data logging / general software structure

Posted: Sat Jun 22, 2013 11:46 pm
by alex
Had some very enlightening evenings - just me, TortoiseHG and the firmware/client code... :idea:

Nevertheless, can't get this to work:

main.py

Code: Select all

def connectionDone(self, linkURI):
        self.setUIState(UIState.CONNECTED, linkURI)

        Config().set("link_uri", linkURI)

        lg = LogConfig("Battery", 1000)
        lg.addVariable(LogVariable("pm.vbat", "float"))
        self.log = self.cf.log.create_log_packet(lg)
        if (self.log != None):
            self.log.dataReceived.add_callback(self.batteryUpdatedSignal.emit)
            self.log.error.add_callback(self.loggingError)
            self.log.start()
        else:
            logger.warning("Could not setup loggingblock!")
        
        gyroconf = LogConfig("Gyro", 10)
        gyroconf.addVariable(LogVariable("gyro.x", "float"))
        gyroconf.addVariable(LogVariable("gyro.y", "float"))
        gyroconf.addVariable(LogVariable("gyro.z", "float"))
        self.log = self.cf.log.create_log_packet(gyroconf)
        if (self.log != None):
            self.log.dataReceived.add_callback(gyroData)
            self.log.start()
        else:
            print "gyro.x/y/z not found in log TOC"
 
    def gyroData(data):
        print "Gyrodata: x=%.2f, y=%.2f, z=%.2f" % (data["gyro.x"], data["gyro.y"], data["gyro.z"])
and
stabilizer.c

Code: Select all

LOG_GROUP_START(gyro)
LOG_ADD(LOG_FLOAT, x, &gyro.x)
LOG_ADD(LOG_FLOAT, y, &gyro.y)
LOG_ADD(LOG_FLOAT, z, &gyro.z)
LOG_GROUP_STOP(gyro)

static bool isInit;

static void distributePower(const uint16_t thrust, const int16_t roll,
                            const int16_t pitch, const int16_t yaw);
So far I'm getting some nice graphs choosing the gyro for plotting. :D
But what about the console output of the raw gyro data using the code line above:

Code: Select all

print "Gyrodata: x=%.2f, y=%.2f, z=%.2f" % (data["gyro.x"], data["gyro.y"], data["gyro.z"])
1. There's no console output except the default one from the copter's selt test - is anything wrong with my code?

2. Second question: is creating a log group in stabilizer.c also necessary for getting console output of specific sensor data or is it used solely for telling the client what structures can be used for plotting (log TOC)?

Re: Adding sensor data logging / general software structure

Posted: Mon Jun 24, 2013 11:31 am
by tobias
A first quick answer. The print command from python will end up in the "terminal" console and not the one in cfclient. Could it be that?

Re: Adding sensor data logging / general software structure

Posted: Mon Jun 24, 2013 1:39 pm
by alex
tobias wrote:A first quick answer. The print command from python will end up in the "terminal" console and not the one in cfclient. Could it be that?
Errr, yes, it could! :)
So I simply have to open a new terminal window that prints the desired values? OMG. :o :)

Any input for question no. 2? Is there a correlation between the log group command and the console output or is it only used for distributing the input for the plotter tab?

Re: Adding sensor data logging / general software structure

Posted: Mon Jul 01, 2013 3:30 pm
by marcus
alex wrote:Any input for question no. 2? Is there a correlation between the log group command and the console output or is it only used for distributing the input for the plotter tab?
Adding the log group will allow you to get the variable value on the client side though the logging framework. But if you just want to print the value using printf in the firmware you do not have to add this and the value will end up in the Console in the client.