morgil / madgwick_py

A Python implementation of Madgwick's IMU and AHRS algorithm.
GNU Lesser General Public License v3.0
178 stars 60 forks source link

Output Data #2

Open flyboy74 opened 7 years ago

flyboy74 commented 7 years ago

I am trying to learn motion processing and have managed to write myself a driver for the MPU9250 9DOF sensor and now I need to implement Madgwick's filter to get accurate orientation. I see your MadgwickAHRS class with the update method but don't understand how the method returns the result.

csvance commented 6 years ago

I had the same problem, here is the code snippet I used to get the position data back:

        heading = MadgwickAHRS()
        while True:
            ninedofxyz = self._ninedof.read()
            heading.update(ninedofxyz[0], ninedofxyz[2], ninedofxyz[1])
            ahrs = heading.quaternion.to_euler_angles()
            roll = ahrs[0]
            pitch = ahrs[1]
            yaw = ahrs[2]

However, the angles returned seem to be mostly nonsense so far. I think most likely I need to convert my gyroscope readings to rad/s and make sure everything is being sampled at the correct interval.

EDIT: after converting to correct units it seems to be working better now.

Mattioli commented 6 years ago

@csvance did you get the code to work fine? I'm using a visualizer to represent the object orientation to guarantee that the output is correct, but the differences on the movement and the visualizer are too big. Do you have any tips on which parameters/stuff you looked up to get everything working?

Thanks for the help.

csvance commented 6 years ago

My problem was with how I was handling the gyroscope data from the IMU I was using. Everything was extremely unstable because (1) my unit conversion was not working as intended (2) I failed to calibrate my Gyroscope. The results should be usable if you make sure the data coming from your gyroscope is sane and calibrated, the accelerometer and magnetometer data gets normalized in Madgwick, so unless they are unstable you shouldn't have any problems with them.

I ended up using ROS for my application which includes a Madgwick node and everything works just fine.

Mattioli commented 6 years ago

Thanks for the answer! I've just found a mistake in my code and the results seem way better now.

agamemnonc commented 4 years ago

My problem was with how I was handling the gyroscope data from the IMU I was using. Everything was extremely unstable because (1) my unit conversion was not working as intended (2) I failed to calibrate my Gyroscope. The results should be usable if you make sure the data coming from your gyroscope is sane and calibrated, the accelerometer and magnetometer data gets normalized in Madgwick, so unless they are unstable you shouldn't have any problems with them.

I ended up using ROS for my application which includes a Madgwick node and everything works just fine.

Can you please clarify what you mean by "sane and calibrated"? I suppose you mean that gyroscope data must be converted to radians, but how do you calibrate? Thanks!

CHOIBYUNGHUN commented 3 years ago

@csvance thank you!! would you don't mind if you upload your code?? it really hard to me ㅠㅠ