Open jonathanjfshaw opened 4 years ago
I've identified the bug. As part of the quaternion calculations self.acc gets vector normalized. But when calculating position, we need to use the original un-normalized acc; this is no longer stored on self.acc because of python's passing by reference.
If you modify my script above like this:
def test(q_type):
my_sensor = MyOwnSensor(in_data=copy.deepcopy(in_data), q_type=q_type,
calculate_position=True)
# reset the acc as it has now been overwritten by vector normalized acc
my_sensor.acc = imu['gia']
# Use the true quat not the estimated one, to isolate errors to the position calculations
my_sensor.quat = body['quat']
# redo the position calculations with the proper acc and true quat
my_sensor.calc_position()
print(q_type + " pos")
print(my_sensor.pos[-1])
Then you get:
actual pos
[0.873 0.436 0.218]
analytical pos
[0.873 0.436 0.218]
kalman pos
[0.873 0.436 0.218]
madgwick pos
[0.873 0.436 0.218]
mahony pos
[0.873 0.436 0.218]
These are the lines in imus.py that are corrupting the values of self.acc for madgwick and mahony:
Acc = vector.normalize(self.acc)
Mag = vector.normalize(self.mag)
Why kalman is also affected, I don't know.
I understand little about sensor fusion. But I made the following test script:
I get these results:
All the methods apart from analytical have the position completely wrong despite getting the quaternion mostly right.
If I change the duration so that there's a stationary period after the movement then the results seem like a disaster. Even the analytical method starts making a mess of the position and the other methods are hopelessly wrong even about the quaternion.