Welcome Guest,Register Now
Log In

ANT Forum

Welcome guest, please Login or Register

   

How to Exploit the Gyro and Accelerometer data from .fit file from a Garmin Virb XE Action Camera

Rank

Total Posts: 2

Joined 2016-05-08

PM

I am trying to figure out how to interpret and use the gyro and accelerometer data from the .fit file produced by my Virb XE? Perhaps someone can offer me some tips or advice? Here's what I think I understand as well as what I would like to know.

I want to extract some of the location and motion data for my videos to be able to use the information in other applications. Using the FitCSVTool I extracted the timestamp_correlation, record, gyroscope_data and accelerometer_data messages from a .fit file into four separate csv files. In theory (I think) this should give me what I need to calculate the location and attitude of my Virb XE for any point in time in a video.

The location part seems a no-brainer - add the time offset in seconds for each record point to the start time of the recording (from the timestamp_correlation info) and convert the semicircles to decimal degrees. Done.

But how do I calculate the correct time offset for any gyro or accelerometer sample? For example, my gyroscope_data output csv files contain the following fields (and the accelerometer_data file contains similar fields):
timestamp[s], sample_time_offset[ms], gyro_x[counts], gyro_y[counts], gyro_z[counts], timestamp_ms[ms]

I get that the timestamp[s] field is the offset in seconds of each gyro sample from the start time, but how do I use the array of values in the sample_time_offset[ms] field and the timestamp_ms[ms] field? I imagine I will combine them in some way to obtain the milliseconds of offset of each of the 30 samples in the xyz array. Correct? For each sample is the correct offset calculated by summing each component? In other words, if i is the index of the xyz samples do I simply sum the parts:
timestamp[s] + timestamp[ms] + sample_time_offset[ms](i)


Once I understand how to represent the time offset I can build a 4-dimensional array of offset, gyro_x, gyro_y and gyro_z values and from that I can obtain a discrete gyro (or accelerometer) sample for any moment in the video by fetching the values from the array:
offset(i), gyro_x(i), gyro_y(i) and gyro_z(i)

Do I understand all this correctly so far? But how do I interpret the values in the gyro_x, gyro_y and gyro_z as well as the accel_x, accel_y and accel_z fields? The units are in counts. Is there a documented method to convert these to something I can use in other formulas or applications?      
RankRank

Total Posts: 44

Joined 2013-04-07

PM

krgorton - 09 May 2016 07:58 AM
fit file produced by Virb XE

Hi krgorton,

I have a request:
Would you please upload the fit file as an attachment? (packed in a zip file)

Thank you
     
Rank

Total Posts: 2

Joined 2016-10-25

PM

I'm trying to do the exact thing. Did you find any more information about converting the counts?

krgorton - 09 May 2016 07:58 AM
I am trying to figure out how to interpret and use the gyro and accelerometer data from the .fit file produced by my Virb XE? Perhaps someone can offer me some tips or advice? Here's what I think I understand as well as what I would like to know.

I want to extract some of the location and motion data for my videos to be able to use the information in other applications. Using the FitCSVTool I extracted the timestamp_correlation, record, gyroscope_data and accelerometer_data messages from a .fit file into four separate csv files. In theory (I think) this should give me what I need to calculate the location and attitude of my Virb XE for any point in time in a video.

The location part seems a no-brainer - add the time offset in seconds for each record point to the start time of the recording (from the timestamp_correlation info) and convert the semicircles to decimal degrees. Done.

But how do I calculate the correct time offset for any gyro or accelerometer sample? For example, my gyroscope_data output csv files contain the following fields (and the accelerometer_data file contains similar fields):
timestamp[s], sample_time_offset[ms], gyro_x[counts], gyro_y[counts], gyro_z[counts], timestamp_ms[ms]

I get that the timestamp[s] field is the offset in seconds of each gyro sample from the start time, but how do I use the array of values in the sample_time_offset[ms] field and the timestamp_ms[ms] field? I imagine I will combine them in some way to obtain the milliseconds of offset of each of the 30 samples in the xyz array. Correct? For each sample is the correct offset calculated by summing each component? In other words, if i is the index of the xyz samples do I simply sum the parts:
timestamp[s] + timestamp[ms] + sample_time_offset[ms](i)


Once I understand how to represent the time offset I can build a 4-dimensional array of offset, gyro_x, gyro_y and gyro_z values and from that I can obtain a discrete gyro (or accelerometer) sample for any moment in the video by fetching the values from the array:
offset(i), gyro_x(i), gyro_y(i) and gyro_z(i)

Do I understand all this correctly so far? But how do I interpret the values in the gyro_x, gyro_y and gyro_z as well as the accel_x, accel_y and accel_z fields? The units are in counts. Is there a documented method to convert these to something I can use in other formulas or applications?
     
Rank

Total Posts: 2

Joined 2016-05-08

PM

I was partially successful. I was able to extract all of the GPS and time offset info, convert it from semi-circles to degrees, render it in the format required by the new multiplexer tool in Esri's latest FMV tools, and produce a MISB spec video that can be run in ArcMap FMV tools.
I was also successful at extracting the accelerometer and gyro metadata to csv files and converting the counts to timestamped sensor values. Unfortunately that's where I hit a wall. I am no engineer or physicist but I came to understand that in order to calculate the look azimuth and angle (where the camera is looking when it's not looking straight ahead and level in the direction of travel) we would need a magnetometer to provide corrections for the gyro and accelerometer data.
Thus my FMV map shows a moving point location on a map that is synced with the video in the FMV video window, but it lacks the FOV bounding box on the map that represents the camera's field of view. It might be possible to finish this last step given a constant azimuth and look angle, but in my case this is never the case. It might also be possible to integrate the VIRB metadata with metadata from other sensors such as if you were to mount the camera on a drone with its own GPS, IMU, gimbal or other devices.
I should also mention that the synced video does tend to have some errors. For example, although the video and GPS log might be nearly perfectly synchronized a the beginning of a video, small offsets may creep in as the video plays so that by the end of a longer video, the video and GPS log may be out of step by a few seconds. The Esri FMV team tells me this is due to the way the video gets encoded from a GPS log.

I would be happy to share the python script and toolbox I used to do this as well as the Q&A chain I exchanged with a Garmin developer where he explained in detail how to convert the contents of a VIRB FIT file to meaningful values. Let me know an email where I can send it if you would like it.
Cheers,
Ken
     
Rank

Total Posts: 2

Joined 2016-10-25

PM

That would be awesome if you can send me all that! In my case the direction of video isn't as important as pulling those acc/gyro values. Also thanks for the heads up on the video, that really stinks it gets out-of-sync.

Unfortunately their PM system just takes me to my own account so can you email me at zachdpl at hotmail.com

I can't thank you enough!

Thanks,
Zach      
Rank

Total Posts: 1

Joined 2017-04-20

PM

It is a bit late but I hope you will see my reply.
I need some advice from you about the bounding box on the map.
I cannot send PM to you so if you do not mind, please contact me at [email protected].
FYI, I use Garmin virb ultra 30 for taking the videos.

Thank you,
Sudarat

     
Rank

Total Posts: 2

Joined 2017-05-12

PM

Hi,

It would be great if you could share your insights on how to convert the contents of a VIRB FIT file to meaningful values Ken. I can be reached at .(JavaScript must be enabled to view this email address)

I'm trying to understand how to interpret the accelerometer, gyrometer and magnetometer data in the Virb FIT files. I have two questions at this point:

1) The 32bit TimeStamps in the Virb FITs do not seem to follow the normal standard. I believe that they all start at 31-12-1989. Is this just a bug?

2) How do I figure out the range of the raw 16 bit values in order to convert them into absolute values in G, degrees/s and Tesla ?

Thanks in advance and Best Regards
Kristian      
Rank

Total Posts: 14

Joined 2017-04-10

PM

o2sen - 19 May 2017 12:24 AM

...
1) The 32bit TimeStamps in the Virb FITs do not seem to follow the normal standard. I believe that they all start at 31-12-1989. Is this just a bug?
...


Note that I currently only work with the FIT-data via the CSV, using the java-tool. It seems all timestamps use 1989-12-31 00:00:00 as a starting point. In Python I used the datetime-module to successfully reconstruct the actual date + time of day for each logged event (I asked about this here https://www.thisisant.com/forum/viewthread/6739/). The SDK documentation mentions this in the "FIT File Types Description" pdf, IIRC. Time in general seems to be a complex entity due to historically changing standards and reference points, so maybe that's why a relatively recent starting point was chosen?

---

On topic, I am also interested in exploiting the orientational raw data for further analysis/visualisation (VIRB Ultra30). Extracting other data from the csv has worked well so far (e.g. generating 10Hz gpx-files from the gps messages for a specific video clip).

Currently looking through internet guides and the SDK documentation (pp 53+ in "FIT File Types Description") on how to interpret raw analog-to-digital data for gyros etc but any pointers in the right direction would be helpful. It seems any conversion would be done via the "three_d_sensor_calibration" messages?

According to the documentation the "sample_time_offset" millisecond values correspond to each, respective x, y, z sample (arrays delimited by a pipe/"|") and presumably should be added to the timestamp + timestamp_ms in the same row.      
Rank

Total Posts: 1

Joined 2018-02-15

PM

Any chances anyone of you would share a converted .fit file which holds acceleration data (and optionally 10 Hz GPS data)?

@krgorton / Ken:
Would you share your code to extract such data from the .fit file?
Maybe you can upload it to github.com under a MIT or APACHE licence so that the community can work on improving it together? If you only share it via email, feel free to contact me via: eenuep ...@g mail - com

Cheers!      
Rank

Total Posts: 9

Joined 2018-02-28

PM

krgorton - 25 October 2016 08:32 AM

I was also successful at extracting the accelerometer and gyro metadata to csv files and converting the counts to timestamped sensor values.


How did you do that?

At page 43, section 6.3 of the document Flexible and Interoperable Data Transfer Protocol Rev 2.3 provided in the SDK package, there is an equation that should be used to convert count to an understandable unit of measure.
However I don't understand how should do with the matrix... like, should I calculate the determinat of the matrix at samo point? what do I need to divide by the calibration_factor?

I'm no mathematician and I don't know java (so any answer like "use the java plugin" is useless to me).

Any suggestion?      
Rank

Total Posts: 1

Joined 2016-10-05

PM

Hi

I'm also currently dealing with the conversion from their "counts-array" to actual usable gyroscope or accelerometer data. I decoded all messages in my "Virb Ultra 30" fit file and found the following message which might perhaps be useful for the conversion process:
three_d_sensor_calibration (167type4length66 bytes):
  
timestamp (253-1-UINT32): 2
  gyro_cal_factor 
(1-1-UINT32original namecalibration_factor): 5
  calibration_divisor 
(2-1-UINT32): 82 counts (82)
  
level_shift (3-1-UINT32): 32768
  offset_cal 
(4-3-SINT32): {-1320, -34}
  orientation_matrix 
(5-9-SINT32): {0.0000 (0), -1.0000 (-65535), 0.0000 (0), 0.0000 (0), 0.0000 (0), -1.0000 (-65535), -1.0000 (-65535), 0.0000 (0), 0.0000 (0)}
  sensor_type 
(0-1-ENUM): gyroscope (1


When I look up the fields (in the profile.xlsx) which might help us converting the values I find:
- gyro_cal_factor, deg/s, Gyro calibration factor, Calibration factor used to convert from raw ADC value to degrees, g, etc.
- calibration_divisor, counts, Calibration factor divisor
- level_shift, Level shift value used to shift the ADC value back into range

- offset_cal, Internal calibration factors, one for each: xy, yx, zx (doesn't seems to fit in the conversion, as they state it is an internal calibration factor, should we assume that this already happened "internally"???). I attached a Excel workbook doing the conversion for all my gyro records.

When I look a bit further and pick a counts value, let's say 32745 counts.

When we use the knowledge above, here is my attempt to convert to degrees/s
32745 - level_shift = -23 counts
-23/calibration_divisor = -23 counts /82 counts = -0.2804878049
-0.2804878049*gyro_cal_factor = -0.2804878049*5 deg/s = -1.4024390244 deg/s

Which seems reasonable? Any thoughts or suggestions? I included an excel workbook with the conversion for the averages of the 30 values for x,y and z gyro data of a couple of timestamp records of a Garmin Virb fit file.

Cheers
Jelle      

File Attachments