Hi everyone,
I’m working on a project using an ESP32 with two ICM-20948 IMUs to measure paddle motion. I’ve implemented a full 6-pose accelerometer calibration and I’m logging the following data at ~80 Hz:
-
Calibrated accelerometer (after bias + scale)
-
Calibrated gyroscope
-
Quaternions (from the ICM-20948, no magnetometer)
Later, in MATLAB, I rotate the acceleration into the global frame using the quaternions and remove gravity. However, the results still don’t look correct, and I’m now trying to understand whether the issue comes from my Arduino acquisition code or from the MATLAB processing stage.
Before I post on MATLAB Answers, I’d like to confirm with you if my data acquisition pipeline looks correct and whether I’m handling the calibrated acceleration properly at firmware level.
What I do on the ESP32
-
Read accel & gyro using the ICM20948_WE library
-
Apply my calibration parameters (bias + gain) obtained from a 6-pose routine
-
Log calibrated accel (in g), calibrated gyro, and quaternions
-
No magnetometer is involved at this stage
Below is a reduced version of the code, showing only the important parts (IMU setup, calibration application, data read & logging). I removed the webserver UI and SD details to keep it short:
// [...] shortened sample – includes: setupIMU(), reading IMU, applying bias & gain, logging data
// Example of how accel is corrected before logging:
acc.x = (acc.x - A_BIAS_x) * A_GAIN_x;
acc.y = (acc.y - A_BIAS_y) * A_GAIN_y;
acc.z = (acc.z - A_BIAS_z) * A_GAIN_z;
// Similar for gyro
// Quaternions taken directly from the IMU library (normalized before sending)
// Logged format per sample:
// q0,q1,q2,q3, ax,ay,az, gx,gy,gz
(If helpful, I can share the full code file.)
My questions
-
Does this acquisition pipeline appear correct for later removal of gravity using quaternions?
(i.e., apply accel calibration on the ESP32, then rotate to global frame & subtract gravity in MATLAB) -
Is there anything missing or commonly recommended to do before logging the calibrated acceleration?
e.g., re-ordering quaternion components, additional filtering, converting to m/s² instead of g before logging, etc. -
Since I’m not using the magnetometer (on purpose), I know yaw will drift over time —
but for short recordings, is logging the IMU quaternion still reliable enough for gravity removal and linear acceleration estimation?
Any advice is appreciated — I’ve spent quite a bit of time validating both firmware and MATLAB processing, and I want to ensure the data I’m logging is correct before proceeding with further debugging.
Thanks in advance!