1

I know that my question may be already asked I apologize in advance. I would like to find a python library of a way to visualize the 3D trajectory (position x,y z) of an accelerometer sensor fixed to an object falling from the sky. I only have the time, x(g), y(g) and z(g).

Exemple of data

time;x(g);y(g);z(g)
0,005;-0,048;0;1,056
0,006;0;0;1,104
0,007;-0,048;0;1,056
0,008;0;0,048;1,104
0,009;-0,048;0;1,056
0,01;-0,048;0;1,056
0,011;-0,048;0;1,008

Exemple of curve for z(g)

enter image description here

I found solutions but they all needed data from a gyroscope sensor.

Do you have any ideas / library to create a visualisation of the 3D trajectory (position x,y,z depending of the time) of my object falling ?

Thanks a lot

Ketchup
  • 150
  • 11

1 Answers1

0

First read your data from csv

import pandas as pd
df = pd.read_csv(path , delimiter=";")

Then determine position from acceleration (perform this 3 times for each of x, y and z)

df["v"] = 0
df["s"] = 0

for i in range(1, len(df)):
    #this line calculates velocity using v_final = a * dt + v_initial
    df.loc[i, "v"] = df.loc[i, "a"] * ( df.loc[i, "t"] - df.loc[i-1, "t"] ) + df.loc[i-1, "v"]
    #this calculates position as average velocity multiplied by time
    df.loc[i, "s"] = 0.5 * ( df.loc[i, "v"] + df.loc[i-1, "v"] ) * ( df.loc[i, "t"] - df.loc[i-1, "t"] + df.loc[i-1, "s"])


Then plot it

from matplotlib import pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure()
ax = fig.add_subplot(projection='3d')

ax.scatter(df["s_x"], df["s_y"], df["s_z"])
Banarnia
  • 31
  • 4
  • If you want to include time as well, I would probably do it as an animation. Plotting 4 variables on a 2D screen sounds messy. Details on animation here https://stackoverflow.com/questions/38118598/3d-animation-using-matplotlib Another option would be to change the colour of the points based on time, in which case ax.scatter(df["x(g)"], df["y(g)"], df["z(g)"], c=df["time"]) should do the trick – Banarnia Apr 08 '22 at 12:33
  • I am looking to visualise the position x,y,z of my object, not simply the acceleration – Ketchup Apr 08 '22 at 12:38
  • Ok, so you want to use the linear acceleration equations, will update my answer with details on that. – Banarnia Apr 08 '22 at 12:50
  • Thanks, a presicion of importance, my acceleration data varies a lot and the speed of my objet falling is not constant. I updated my question. – Ketchup Apr 08 '22 at 12:58
  • Thanks for your answer. However when i apply your code to my data I quicky get (after around 4000 observations) infinite value for my position x and z. In this data the object mainly move by the Z axis but not in x and y axis. – Ketchup Apr 08 '22 at 13:30
  • I think now the problem is that the question you provided isn't properly reproducible. I used df = pd.DataFrame() df["t"] = np.arange(0,4000) df["a"] = np.ones(4000) To create some mock data. Check if this works on your machine. If it does, I imagine the problem is somewhere in your data, which I can't check – Banarnia Apr 08 '22 at 13:39