ZaneL / quaternion_sensor_3d_nodejs

30 stars 15 forks source link

3d motion #1

Open CodingArcher opened 3 years ago

CodingArcher commented 3 years ago

Great project.

How would you go about the 3D motion to also display the movement not just on one plane but like in a room so that you can see if the sensor went up or down, Left or right etc?

ZaneL commented 3 years ago

Some of this information could be incorrect, but AFAIK attempting to get position values from an accelerometer will lead you down a long rabbit hole. I did this a while back with a coworker and it "sorta" worked.

We first pulled the quaternion and accelerometer values off the sensor using my library. We then rotated the 3 accelerometer vectors (x, y, z) using the quaternion so that it's aligned to earth's gravity rather than the sensor. Then we filtered the results to remove the high and low frequency noise. Then we did a double integral to transform acceleration into position.

This method works, but the problem is that all accelerometers are noisy and in the process of double integrating, these small errors get added up. For the first few seconds it will work, but after even 10 seconds the errors add up so much that the algorithm thinks that the sensor is 10 feet across the room when it's not.

So in summary, using accelerometers to determine absolute position in 3d space doesn't work. Unless it's in a very particular scenario where the sensor is moving in a cycical pattern, in which case you can reset everything at the crest or trough of the movement and start over.