Logging time onto sd card

Post here to get support
khorium
Beginner
Posts: 7
Joined: Thu Mar 25, 2021 10:21 pm

Logging time onto sd card

Post by khorium »

Hello!

I am trying to instrument the firmware code and log time stamps onto a uSD card. Primarily I want to use the Event trigger framework to log things in the stabilizer.c file. I have a few problems which I would be very grateful if anyone could help me a bit with.

1) The guide https://www.bitcraze.io/documentation/r ... card-deck/ mentions that one should start/stop logging with the usd.logging boolean. But I don't know how to get access to usd, it seems to be declared as a parameter group in usddeck.c only, but one must be able to access it in some other way?

2) I can't log anything to the SD . By that I mean that after changing the firmware as I describe below and running python scripts like flowsequenceSync.py from the crazyflie-lib-python repo, no new file appears on the sd-card. And I have made sure to insert the SD card correctly before starting the crazyflie (and I have an attached flow deck if that is of interest). This might be due to not being able to set usd.logging to 0, but if it should work without that I don't get what I missed. Here is what I have added:

In stabilizer.c I added

Code: Select all

// Imports and declares the myLoopEvent
#include "eventtrigger.h"
EVENTTRIGGER(myEvent, uint8, var1)
at the end of the import statements. In the while(1) loop I changed the first part to

Code: Select all

// The sensor should unlock at 1kHz
    sensorsWaitDataReady();	// no change

    // Sets the value of the var1 variable
    eventTrigger_myEvent_payload.var1 = tick;

    // Trigger the event
    eventTrigger(&eventTrigger_myEvent);

    if (healthShallWeRunTest())	// No change 
where the first and last line is just included as reference to where in the code I am.

Then I changed in the config.txt file which should be config for the SD card. I changed it to:

Code: Select all

1     # version
512   # buffer size in bytes
log   # file name
1     # enable on startup (0/1)
on:fixedFrequency
1     # frequency
1     # mode (0: disabled, 1: synchronous stabilizer, 2: asynchronous)
"second"	# Just write "second" once per second
on:myEvent	# Do just want to log the payload really
"loop"
and also put a copy of it on the SD card. The idea here was primarily to log the event and its payload, but also to try and log "second" on a fixed frequency and "loop" every time the event occured. I also enabled logging on startup as I could not get how to set usd.logging to 1 in the code.

Are there any glaring issues with this?

3) Finally I would also later want to log the time stamps at different parts of the code. Is there an easy way to access some time value, like a hardware tick? I have not looked super much, but have only found the software tick in FreeRTOS so far, which maybe is not optimal to use as a clock.



As I said I would be very grateful if anyone had any input :)
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: Logging time onto sd card

Post by tobias »

I can help you with part of it at lease. I guess you already read the documentation here?

1. Start with a standard example just to get going.
2. Check that the sd card is initialized correctly with the console prints in the cfclent.
3. Add your variables and event-triggers

All events (groups) are timestamped with a micro second timestamp already so no need to do that.
khorium
Beginner
Posts: 7
Joined: Thu Mar 25, 2021 10:21 pm

Re: Logging time onto sd card

Post by khorium »

Thank you for your answer :)

I had not realized I could see so much from the cfclients console. I had mainly flown it with the python scripts as I don't have a controller I can use in the VM.

Looking at the console print outs one can see that the initialization fails. I tried adjusting the mount of the deck, as well as removing the flow deck in case it would interfere, but it changed nothing. In case it might be useful these were the print outs I got:

Code: Select all

SYS: ----------------------------
SYS: Crazyflie 2.1 is up and running!
SYS: Build 160:b30e380f7082 (2021.01 +160) CLEAN
SYS: I am 0x203937434848501700360058 and I have 1024KB of flash!
CFGBLK: v1, verification [OK]
DECK_CORE: 2 deck(s) found
DECK_CORE: Calling INIT on driver bcFlow2 for deck 0
ZR2: Z-down sensor [OK]
PMW: Motion chip id: 0x49:0xB6
DECK_CORE: Calling INIT on driver bcUSD for deck 1
uSD: mount SD-Card [FAIL].
IMU: BMI088: Using I2C interface.
IMU: BMI088 Gyro connection [OK].
IMU: BMI088 Accel connection [OK]
IMU: BMP388 I2C connection [OK]
ESTIMATOR: Using Kalman (2) estimator
CONTROLLER: Using PID (1) controller
MTR-DRV: Using brushed motor driver
EEPROM: I2C connection [OK].
STORAGE: Storage check [OK].
IMU: BMI088 gyro self-test [OK]
DECK_CORE: Deck 0 test [OK].
DECK_CORE: Deck 1 test [OK].
STAB: Wait for sensor calibration...
SYS: Free heap: 17232 bytes
STAB: Ready to fly.
I also flashed the crazyflie to the original build available straight from the git. I also thought it might possibly be the config.txt file, so I changed it to be more in line with the example on git (basically just removed some variables from being logged):

Code: Select all

1     # version
512   # buffer size in bytes
log   # file name
1     # enable on startup (0/1)
on:fixedFrequency
10     # frequency
1     # mode (0: disabled, 1: synchronous stabilizer, 2: asynchronous)
acc.x
acc.y
acc.z
gyro.x
gyro.y
gyro.z
on:activeMarkerModeChanged
I have mounted the SD-deck on top of the battery (replacing the battery holder) and it is oriented in the correct direction. Are there maybe any standard errors here? I could not find much info about this failing online.

Also, thank you for pointing out that all events are timestamped, that makes it a lot easier :)
kristoffer
Bitcraze
Posts: 630
Joined: Tue Jun 30, 2015 7:47 am

Re: Logging time onto sd card

Post by kristoffer »

It looks like the FAT file system can not be mounted by the Crazyflie.
Have you checked that your micro SD-card is formated with a FAT file system and that it can it be written (not write protected) and read with some other device?
khorium
Beginner
Posts: 7
Joined: Thu Mar 25, 2021 10:21 pm

Re: Logging time onto sd card

Post by khorium »

It is formatted with the exFAT file system it seems.

I can create and modify files on it like I can any other place it seems (from the File Explorer). Or do you mean I should try to write/read with some code, like creating a Python script to write something to it?
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: Logging time onto sd card

Post by arnaud »

I do not think the exFAT file-system is handled by the Crayflie. The SD-card needs to be formatted using the Fat(32) file-system.
khorium
Beginner
Posts: 7
Joined: Thu Mar 25, 2021 10:21 pm

Re: Logging time onto sd card

Post by khorium »

Now it initializes correctly after reformatting it to Fat32, thank you!

I still do not really know how to set the usd.logging variable to 0 in the firmware. But I can do it from the Python scripts I am running and start and stop, which I hope will work fine (now I did it manually with cfclient).

Thank you for your help, and have a good week end :)
jonasdn
Expert
Posts: 132
Joined: Mon Mar 01, 2021 3:13 pm

Re: Logging time onto sd card

Post by jonasdn »

Hi!

You can try the following from your code in the firmware:

Code: Select all

paramSetInt(paramGetVarId("usd", "logging"), 0)
Take care!

Jonas
khorium
Beginner
Posts: 7
Joined: Thu Mar 25, 2021 10:21 pm

Re: Logging time onto sd card

Post by khorium »

Thank you all so much for your help :)

It might be worth adding a line in https://www.bitcraze.io/documentation/r ... card-deck/ about the SD card having to be formatted in Fat32. Or maybe it is somewhere I just missed.

Best regards Kåre
kristoffer
Bitcraze
Posts: 630
Joined: Tue Jun 30, 2015 7:47 am

Re: Logging time onto sd card

Post by kristoffer »

Great that is worked out!

Good feedback, I added info about the required file system to the SD-card deck docs.

- Kristoffer
Post Reply