Save high frequency accelerometer and gyroscope data to fit file

Hello!

I am trying to save both the accelerometer and gyroscope high frequency data at 25sps to a fit file by creating the corresponding fields in the active session. The documentation shows that a message can only contain 256 bytes of data, and if I try to save the raw values from the SensorData object (32bit Numbers) I end up with 32bits / 8bytes * 25sps * 6axis (gyro+accel) = 600 bytes. Moreover, the limit for an specific data field is 32 bits, and, once again, trying to save the war data from a single axis to a data field in a fit file would require 32bits / 8bytes * 25sps = 100 bytes.

Before committing to do stupid stuff, I wanted to ask whether there is a fancy/optimal way to solve this issue, since I imagine more people will be facing it. I thought about splitting the 25 samples I gather every second into two different data fields to go around the field length limitation, and to cast the data to smaller data types to solve the problem with the overall message length. Nevertheless, it turns out I would need to cast it to DATA_TYPE_SINT8 for it to fit into the 256 bytes requited, and 1 byte of resolution is not enough for my application.

Any help or advice will be highly appreciated.

  • Haven't tried it, but apparently you can save accelerometer, gyroscope and magnetometer data to a FIT file using SensorLogger. What's not clear to me is what the exact sample rate is. According to the officials docs, it's "a standard rate for consumption by the simulator." According to a forum post, it's 25 Hz. I do seem to recall people posting FIT file fragments with up to 25 values per second (as one "array" of data per record, per second). (I think there was also a complaint about how the individual values lacked timestamps, which may have led to the data being less useful as it was possible for there to be less than 25 values in any given record.)

    [https://developer.garmin.com/connect-iq/core-topics/sensors/#loggingaccelerometerdata]

    > However, the logger will always record at a standard rate for consumption by the simulator.

    https://forums.garmin.com/developer/connect-iq/f/discussion/350716/simulator-no-longer-playing-back-gyro-accelerometer-data-from-fit-file

    > In SDK version 6.2.2 I was able to record accelerometer and gyro data using a SensorLogging.SensorLogger with sensors running at 25Hz on my Epix Gen 2 and play it back in the device simulator. In SDK versions 6.3.0 and 6.3.1 this no longer works, either at 25Hz or at the new higher frequency sample rate.

  • Hi! Thank you very much for your answer. I have a couple of comments to it. First, as a side question, how do I check the accelerometer data in the generated .fit file in the simulator? I am testing my app directly in the watch since, even by using the same code, I don't see the accelerometer data in the .fit files generated when I use the simulator (this).

    Regarding the data rate, I am sticking to 25sps, since most garmin devices are the sample rate they use by default. I am testing everything on a Felix 5 and I was not able to save the data to a .fit file by using only the SensorLogger, I needed to manually create the fields in my session and write them in my accelerometes(gyroscope)callback routines. Moreover, by reading here in the "Logging Accelerometer Data" section I understand that the main purpose of SensorLogger is using it back in the simulator, not for real-life applications, am I wrong?

  • Moreover, by reading here in the "Logging Accelerometer Data" section I understand that the main purpose of SensorLogger is using it back in the simulator, not for real-life applications, am I wrong?

    Yes I agree, but it seems like SensorLogger was tailor-made to record sensor data, whereas anything you do with FitContributor will be a workaround, as per the OP.

    First, as a side question, how do I check the accelerometer data in the generated .fit file in the simulator?

    I think you would play it back in the simulator, and whatever app you're testing would behave as though the sensors are receiving that data. You could use System.println() in your sensor callbacks and output the data that the simulated app sees.

    As far as viewing the "raw" FIT data goes, I probably wouldn't rely on FIT2CSV from the Garmin FIT SDK, because it has the unfortunate property of outputting unknown fields as "unknown", instead of the underlying numerical values (which also makes it useless for the supposed use case of converting FIT to CSV, editing the CSV file, and converting that back to FIT.)

    If you want to losslessly decode your FIT file, I suggest:

    - [https://runalyze.com/tool/fit-viewerhttps://runalyze.com/tool/fit-viewer]

    or one of the FIT decoder projects on github, such as:

    - https://github.com/ask77nl/fit-decoder

    - https://github.com/dtcooper/python-fitparse

    - https://github.com/polyvertex/fitdecode

    As far as the data rate goes, I'm just saying I don't think you can control it for SensorLogger, so I hope it's 25 Hz.