SD Card Deck and Flow Deck not working together

Discussions about all things Bitcraze
Post Reply
simplexsigil
Beginner
Posts: 13
Joined: Thu Feb 01, 2018 3:42 pm

SD Card Deck and Flow Deck not working together

Post by simplexsigil »

Hello,

we are trying to log various data of the Crazyflie highfrequently (1000 Hz) to an SD Card and started by using a config file as created by this script:
https://github.com/bitcraze/crazyflie-f ... nctions.py

This works fine if we only attach the SD Card Deck on the top of the crazyflie. However, if we additionally use the Flow Deck at the bottom, no log files are created on the SD Card. The logging frequency does not seem to matter, this also appears if we only log a few times per second.

We tested using a log config on the SD Card which does not log anything (only the ticks) and that seems to work so far as the log files are written then (but do not contain any useful data).

Does anyone know why this might happen? Are there known incompatibilities between the Flow Deck and the SD Card deck in combination with logging to the SC Card?
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: SD Card Deck and Flow Deck not working together

Post by arnaud »

Hi,

Both decks are using the SPI bus, so it is possible that there is some collision happening there. There is a ticket on github tracking a very similar problem (with the loco-deck), I just updated it to add the flow deck in it as well: https://github.com/bitcraze/crazyflie-f ... issues/270


So, it works find if you are logging only timestamps at any rate but not if you are logging data as well? If so, it might fail when writing too long lines.
simplexsigil
Beginner
Posts: 13
Joined: Thu Feb 01, 2018 3:42 pm

Re: SD Card Deck and Flow Deck not working together

Post by simplexsigil »

I made further tests, it looks a lot as if the SD Card Deck and other Decks are intensively competing for resources (task runtime and memory). Depending on the configuration, various errors can occur (Some just occur randomly):
- The Crazyflie seems to be working fine, but logging only is available for a few seconds and then just stops (when using flow deck and adapting other parameters, so it does at least not restart with an error)
- The Crazyflie has problems with memory allocation due to insufficient heap size (when the buffer is 200 for example. 120 seems to be working fine)
- The Crazyflie has a mutex problem (the assert in task.c:3495 fails - this also means it will drop out of the air, if it does not happen right at the start)
- The Crazyflie can not handle a task waiting for less than a millisecond (seems to be occurring sometimes, when frequency is set to 333 hz - error in task.c:832 - Assert fails)




Test Setting:
Which data should be logged?
* Acceleration ([Y]es / [n]o): y
* Gyroscope ([Y]es / [n]o): y
* Barometer ([Y]es / [n]o): n
* Magnetometer ([Y]es / [n]o): n
* Stabilizer ([Y]es / [n]o): y
* Control ([Y]es / [n]o): y
* Z-Range ([Y]es / [n]o): n

Enter the log frequency [1-1000]: 500
Enter buffer size [0-255]: 120
Filename [max. 10 letters]: 500hzbuff


Results:
First run (20 seconds SD only):
Tick span: 4103 to 19653 -> OK

Second run (20 seconds SD only):
Tick span: 4106 to 21199 -> OK


First run (20 seconds SD + FD):
Tick span: 4078 to 5238 -> Abborted logging without indication

Second run (20 seconds SD + FD):
Error shown on console:
SYS: Assert failed at src/lib/FreeRTOS/tasks.c:3495

Here is the related code fragment until the assert fails:
BaseType_t xTaskPriorityDisinherit( TaskHandle_t const pxMutexHolder )
{
TCB_t * const pxTCB = ( TCB_t * ) pxMutexHolder;
BaseType_t xReturn = pdFALSE;

if( pxMutexHolder != NULL )
{
/* A task can only have an inherited priority if it holds the mutex.
If the mutex is held by a task then it cannot be given from an
interrupt, and if a mutex is given by the holding task then it must
be the running state task. */
configASSERT( pxTCB == pxCurrentTCB );




Test Setting:
Which data should be logged?
* Acceleration ([Y]es / [n]o): y
* Gyroscope ([Y]es / [n]o): y
* Barometer ([Y]es / [n]o): y
* Magnetometer ([Y]es / [n]o): y
* Stabilizer ([Y]es / [n]o): y
* Control ([Y]es / [n]o): y
* Z-Range ([Y]es / [n]o): y

Enter the log frequency [1-1000]: 333
Enter buffer size [0-255]: 120
Filename [max. 10 letters]: test2


Results:
First run (20 seconds SD only):
Tick span: 4104 to 19452 -> OK

Second run (20 seconds SD only):
Tick span: 4104 to 19479 -> OK

First run (20 seconds SD + FD):
Tick span: 4079 to 4541 -> abborted early without indication

Second run (20 seconds SD + FD):
Tick span: 4070 to 6860 -> abborted early without indication





Test Setting:
Which data should be logged?
* Acceleration ([Y]es / [n]o): y
* Gyroscope ([Y]es / [n]o): y
* Barometer ([Y]es / [n]o): y
* Magnetometer ([Y]es / [n]o): y
* Stabilizer ([Y]es / [n]o): y
* Control ([Y]es / [n]o): y
* Z-Range ([Y]es / [n]o): y

Enter the log frequency [1-1000]: 1000
Enter buffer size [0-255]: 120
Filename [max. 10 letters]: test3_

Results:
First run (20 seconds SD only):
Tick span: 4102 to 19444 -> OK

Second run (20 seconds SD only):
Tick span: 4102 to 20133 -> OK

First run (20 seconds SD + FD):
Tick span: 4074 to 6452 -> abborted early without indication

Second run (20 seconds SD + FD):
Tick span: 4080 to 22766 -> OK
simplexsigil
Beginner
Posts: 13
Joined: Thu Feb 01, 2018 3:42 pm

Re: SD Card Deck and Flow Deck not working together

Post by simplexsigil »

As seen in the last test setting, even the most demanding config can actually work with the flow deck if you have some luck. But only sometimes.
simplexsigil
Beginner
Posts: 13
Joined: Thu Feb 01, 2018 3:42 pm

Re: SD Card Deck and Flow Deck not working together

Post by simplexsigil »

Is this a problem, that is only known in some settings (some SD cards etc) or can you not log either?

We want to log that frequently, because we want to rebuild the results achieved in this paper using the flow deck for (approximate) localisation instead of a vicon camera system:
https://arxiv.org/pdf/1610.05863.pdf

Do you guys have a proposition, how we could get the necessary sensor data from the Crazyflie with at least 250 hz? cflib only allows for logging at 100 hz and only if it fits into one log block, it is even slower when using multiple log blocks.
simplexsigil
Beginner
Posts: 13
Joined: Thu Feb 01, 2018 3:42 pm

Re: SD Card Deck and Flow Deck not working together

Post by simplexsigil »

Is there a previous firmware version where the SD-Card and Flow deck worked together?
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: SD Card Deck and Flow Deck not working together

Post by arnaud »

Not that I know of, I am not sure we have tested SDcard and flow together extensively.

Thanks for the investigation! Tobias that is our SPI/SDcard expert is currently away and will be back next week, I will forward this thread to him so that we can investigate further.
xintongdu
Beginner
Posts: 1
Joined: Wed Jul 11, 2018 3:46 am

Re: SD Card Deck and Flow Deck not working together

Post by xintongdu »

Hi. I'm also having the same trouble when trying to log uwb measurement with usd card. Are there any updates on this issue?

Thanks!
tungnx94
Beginner
Posts: 11
Joined: Wed Dec 27, 2017 11:49 am

Re: SD Card Deck and Flow Deck not working together

Post by tungnx94 »

Someone found a quick fix on github
" ... I change the SD port from spi1 to spi3. After changing the related driver as well as DMA stream, it can log for any long time while flow deck is working ... "
Which is good news. However I still haven't managed how to do this in code (i.e change which code line with which). Anybody has an idea ?
Post Reply