Sign of g seems wrong
Closed this issue · 4 comments
I've recently been playing with this fantastic library, and all is well, except for the direction of gravity which seems to be off by a sign. Consider the following motion model:
ini lat (deg),ini lon (deg),ini alt (m),ini vx_body (m/s),ini vy_body (m/s),ini vz_body (m/s),ini yaw (deg),ini pitch (deg),ini roll (deg)
31.9965,120.004,0,0,0,0,90,0,0
command type,yaw (deg),pitch (deg),roll (deg),vx_body (m/s),vy_body (m/s),vz_body (m/s),command duration (s),GPS visibility
1,0,0,0,0,0,0,20,1
5,0,0,0,4,0,0,20,1
3,90,0,0,0,0,0,8,1
5,0,0,0,0,0,0,20,1
The object is initially stationary, then moves in a straight line towards the east and after a while makes a 90 degree turn south, keeping its altitude steady throughout the motion. While it moves in a straight line, the x_body axis points east, y_body points south, and z_body points down. When I run the simulation, I get the following results:
- In ref_gyro.csv, I see that the gyro readings are initially zero (for all intents and purposes), and then gyro_z becomes positive, as expected from the prescribed trajectory.
- In ref_accel.csv, I initially see a positive acceleration along x_body, which is then followed by a positive acceleration along y_body, both of which are exactly as expected. However, the acceleration in the z direction is negative (-9.79ms^-2). Maybe my understanding is wrong, but with the z_body axis pointing downwards, I would expect the acceleration from gravity to be positive.
This is with the latest version in master. I'm using demo_no_algo.py with ref_frame=0 in the call to Sim().
Any help with this would be greatly appreciated. I'd also like to take this opportunity to thank you for your work on this very useful library.
Hi pandisv, your question regarding the sign of the Z acceleration is pretty common.
As we know, an accelerometer measures non-gravitational acceleration.
f = a - g
f is the output of the accelerometer;
a is the linear acceleration;
g is the gravity.
When an accelerometer is on a horizontal plan and stationary, a is zero: [0; 0; 0].
In the NED (north-east-down) frame, g = [0; 0; 9.8]. (It is positive here.)
Considering only the Z accelerometer, you can see f_z = -g_z = -9.8m/s^2.
Thanks for your answer. I agree with your comment -- the equation is really f=R(a-g) in your notation, where R is some rotation matrix aligning the body frame to the NED plane, but I still agree with your conclusion that f_z = -9.8m/s^2. That's the point of my bug report -- if you run a simulation of the above turn, the accelerometer reports f_z = +9.8m/s^2, which is wrong, it should be negative. This is what ref_accel.csv looks like:
0.000000000000000000e+00,-1.199521838941635691e-15,9.794839130570458963e+00
Hi, I tried your motion profile. I saw the reproted f_z is around -9.8, which is as expected.
Thanks for the help and feedback. You are indeed correct, it was I who got the signs wrong. Thanks again for all the work you've put into this very useful library!