I am using IMU data in the next format : [![enter image description here][1]][1]
Here is the whole file : https://github.com/badiaamakhlouf/Awesome_Dataset/blob/main/digit7.csv
I want to extract trajectory data from this IMU data. The trajectory data corresponding to the 3 coordinates of the position and velocity. Actually, I had performed the next steps:
- First, I have integrated the accelerometer data (Acc_x, Acc_y and Acc_z) to get the velocity (Vel_x, Vel_y, Vel_z)
- Second, I had integrated velocity data to find the position data (Pos_x, Pos_y, Pos_z)
- Third, I had plotted the trajectories in 2D but unfortunately I did not get the right plot.
I had performed digit handwriting with my IMU sensor and after plot I did not get any digit format
Here is my Code:
# Iterate through the data points
for i in range(len(timestamps)):
# Calculate acceleration in the body frame
acc_body_x = acc_x[i] * np.cos(pitch[i]) * np.cos(yaw[i]) + acc_y[i] * (
np.cos(roll[i]) * np.sin(yaw[i]) * np.sin(pitch[i]) - np.cos(yaw[i]) * np.sin(roll[i])) + acc_z[
i] * (
np.sin(roll[i]) * np.sin(yaw[i]) + np.cos(roll[i]) * np.cos(yaw[i]) * np.sin(pitch[i]))
acc_body_y = acc_x[i] * np.cos(pitch[i]) * np.sin(yaw[i]) + acc_y[i] * (
np.cos(roll[i]) * np.cos(yaw[i]) + np.sin(roll[i]) * np.sin(yaw[i]) * np.sin(pitch[i])) + acc_z[
i] * (
-np.cos(yaw[i]) * np.sin(roll[i]) * np.sin(pitch[i]) + np.cos(roll[i]) * np.sin(yaw[i]))
acc_body_z = -acc_x[i] * np.sin(pitch[i]) + acc_y[i] * np.cos(pitch[i]) * np.sin(roll[i]) + acc_z[i] * np.cos(
roll[i]) * np.cos(pitch[i])
# Integrate acceleration to calculate velocity
if i == 0:
vel_x.append(0)
vel_y.append(0)
vel_z.append(0)
else:
dt = (timestamps[i] - timestamps[i - 1]) / 1000.0 # Convert timestamp to seconds
vel_x.append(vel_x[-1] + acc_body_x * dt)
vel_y.append(vel_y[-1] + acc_body_y * dt)
vel_z.append(vel_z[-1] + acc_body_z * dt)
# Integrate velocity to calculate position
if i == 0:
pos_x.append(0)
pos_y.append(0)
pos_z.append(0)
else:
pos_x.append(pos_x[-1] + vel_x[-1] * dt)
pos_y.append(pos_y[-1] + vel_y[-1] * dt)
pos_z.append(pos_z[-1] + vel_z[-1] * dt)
This is the second part of my code: first part preprocesses the IMU data and performs sensor fusion using a complementary filter. However, in this part, I have integrated accelerometer data, using the estimated orientation data previously, to estimate velocity and position, plots the 2D trajectories.
I have the next questions:
- The plot does not correspond to the digit 7, which I had write using my sensor and hand and I could not understand the problem in my code?
- I have calculated the orientation estimation because every code I have found in the internet or any article says that you need Orientation estimation to find the trajectory but as you I have not been used it to calculate the position and velocity.
- Is there anything I can improve in my code?
