Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculate g-force from acceleration for 1 second interval

Tags:

php

gopro

I have extracted a CSV file with accelerometer data (in m/s2) from GoPro metadata file (github library).

One second of accelerometer contains ~200 samples of data on 3 axis. A sample of this file looks like this:

accelerometer data sample

In PHP, for each instantaneous value on X axis, I convert m/s2 like this:

function convert_meters_per_second_squared_to_g($ms2) {
    // 1g = 9.80665 m/s2
    return $ms2 * 0.101971621297793; // 1 / 9.80665 == 0.101971621297793
}

Sample code for 200 rows (1 second) of CSV file:

$acc_x_summed_up = 0;
if (($handle = fopen($filepath, "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        list ($millis, $acc_x, $acc_y, $acc_z) = $data;

        $acc_x_summed_up += $acc_x;
    }
}

$g_force = convert_meters_per_second_squared_to_g($acc_x_summed_up);

But how do I show the g-force value for each second on X axis? I tried to sum up the values and convert them, but the result is clearly wrong, as I get values up to 63 G.

[ UPDATE: ]

  1. The instant g-force values (all 3 axis, separated) are displayed on a graph (using highcharts). The gopro video file is displayed (using YouTube javascript API) side-by-side with the graph and played real time.
  2. The graph and video are already working fine side by side. Only the g-force values are wrong.
    Note: The video file has a g-force overlay (embeded in it) showing 2 axis (x,y).
  3. I have rewarded @Joseph_J just because it seemed a good solution and because I'm forced to give the reward (over the weekend) by SO system. Thanks everyone for your answers!
like image 399
Binar Web Avatar asked Apr 25 '18 13:04

Binar Web


People also ask

What is the formula for calculating g-force?

To convert revolutions per minute (RPM) to relative centrifugal force (RCF), or g force, use the following formula: RCF = (RPM)2 × 1.118 × 10-5 × r. Relative centrifugal force is dependent on the speed of rotation in RPM and the distance of the particles from the center of rotation.

How fast is 4 G's of acceleration?

So for example experiencing 4g is to undergo an acceleration equivalent to 4 times the acceleration due to gravity, where 4g is 4x9. 8 m/s2.

How fast is 1.5 g-force?

On Earth, the gravitational acceleration is about 9.8 m/s2. 1.5g would be then 14.7 m/s2.


2 Answers

I believe you are treating each instantaneous value as if it has occurred over 1 second, rather than instantaneously.

I'd say your best bet is to do each calculation by multiplying $acc_x by the resolution of your data divided by gravity's acceleration. So in your case, the resolution of your data is 5ms or one two-hundredth of a second, meaning your calculation should be $acc_x * 0.005/9.80665.

Using the information you provided, the 63G result that you got should be more like 0.315G. This seems more appropriate, though I'm not sure the context of the data.

EDIT: I forgot to mention that you should still sum all values that you receive from $acc_x * 0.005/9.80665 over 200 values, (you can choose to do this in blocks, or do it in running, doing in blocks will be less taxing on the system, but running will be more accurate). Pointed out by @Joseph_J

EDIT 2: As per your request of a source, I could not find much from calculating the average acceleration (and therefore g-force), but you can use the same principal behind average velocity from velocity over time graphs, however, I did find a scenario similar to yours here: Source and Source 2

Hope this helps!

like image 184
Joshua Nicholl Avatar answered Oct 23 '22 03:10

Joshua Nicholl


As per my comment, summing it up doesn't work because force is not additive over time. What you want is to calculate the average acceleration:

function convert_meters_per_second_squared_to_g($acc_array) {
    $acc_average = array_sum($acc_array)/count($acc_array);
    return $acc_average * 0.101971621297793;
}

$acc_x_array = [];
if (($handle = fopen($filepath, "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        list ($millis, $acc_x, $acc_y, $acc_z) = $data;

        $acc_x_array[] = $acc_x;
    }
}

$g_force = convert_meters_per_second_squared_to_g($acc_x_array);
like image 33
Terry Avatar answered Oct 23 '22 03:10

Terry