Sensor Fusion (MPU6050 + HMC5883L) || Kalman Filter || Measure Pitch, Roll, Yaw Accurately

แชร์
ฝัง
  • เผยแพร่เมื่อ 16 ธ.ค. 2024

ความคิดเห็น • 24

  • @aknkaragoz9754
    @aknkaragoz9754 4 วันที่ผ่านมา +5

    Without overstepping, I would like to offer a few suggestions. First, set the filter window size. For example:
    #define WINDOW_SIZE 15
    float pitchBuffer[WINDOW_SIZE] = {0};
    float rollBuffer[WINDOW_SIZE] = {0};
    float azimuthBuffer[WINDOW_SIZE] = {0};
    int bufferIndex = 0;
    // It would be appropriate to keep the WINDOW_SIZE between 5 and 20.
    Then, add a moving average filter. For example:
    void applyMovingAverage(float &pitch, float &roll, float &azimuth) {
    pitchBuffer[bufferIndex] = pitch;
    rollBuffer[bufferIndex] = roll;
    azimuthBuffer[bufferIndex] = azimuth;
    bufferIndex = (bufferIndex + 1) % WINDOW_SIZE;
    pitch = 0;
    roll = 0;
    azimuth = 0;
    for (int i = 0; i < WINDOW_SIZE; i++) {
    pitch += pitchBuffer[i];
    roll += rollBuffer[i];
    azimuth += azimuthBuffer[i];
    }
    pitch /= WINDOW_SIZE;
    roll /= WINDOW_SIZE;
    azimuth /= WINDOW_SIZE;
    }
    add loop:
    azimuth = atan2(correctedY, correctedX);
    azimuth += magneticDeclination;
    // Normalize azimuth to the 0-360 range
    if (azimuth < 0) azimuth += 2 * PI;
    if (azimuth > 2 * PI) azimuth -= 2 * PI;
    azimuth = azimuth * 180.0 / PI; // Convert to degrees
    // Apply moving average filter to pitch, roll, and azimuth
    applyMovingAverage(pitch, roll, azimuth);
    This way, you will be less affected by vibrations and quick direction changes. Please let me know the results if you try it. Best regards.

  • @sulcusulnaris
    @sulcusulnaris 5 วันที่ผ่านมา +3

    It's actually a small wonder that such things can be built into such a small component and that it is robust against vibrations, shocks etc.

  • @reddawn87
    @reddawn87 5 วันที่ผ่านมา

    Wow this could not have come at a better time. I’m struggling with an MPU9250 for a project due on Friday. Can’t get the magnetometer to function properly to
    Measure the rotated angle. Thanks!

    • @HowtoElectronics
      @HowtoElectronics  5 วันที่ผ่านมา

      The MPU9250 has a similar structure, but the register addresses is different. I also had hard time in reading magnetometer reading from MPU9250. Tried multiple MPU9250, none of them.worked.

    • @reddawn87
      @reddawn87 4 วันที่ผ่านมา

      @@HowtoElectronicsoh dear this does not bode well.. possible to do sensor fusion only using the 6050? I just need it to give a reference point for a digital compass.

    • @reddawn87
      @reddawn87 4 วันที่ผ่านมา

      I am able to read the angle but it does not update in the void loop.

    • @reddawn87
      @reddawn87 2 วันที่ผ่านมา

      I got my MPU9250 to work ultimately, ended up using an I2C scanner to find the IMU, then TwoWire to run it in parallel to my oled screen. I used hideakitai's examples to connect and calibrate it first, then managed to work. One thing I discovered, ESP32-S3 has an issue with pin reassignment in V3 of the Board Manager. I had to downgrade to 2.0.14 to get it to work.

    • @HowtoElectronics
      @HowtoElectronics  2 วันที่ผ่านมา +1

      Great man, you discovered so many new things. And I to find out you got it working. Congratulations

  • @amrzakaria5290
    @amrzakaria5290 4 วันที่ผ่านมา

    Good job , Thanks a lot.

  • @TobiKellner
    @TobiKellner 3 วันที่ผ่านมา

    Hey, how complex would it be to integrate (RTK) GPS into this, for a fusion of position and orientation?

  • @sltechgalaxy1677
    @sltechgalaxy1677 5 วันที่ผ่านมา

    very insightfull, make a tutorial to measure position using any imu sensor please

    • @HowtoElectronics
      @HowtoElectronics  5 วันที่ผ่านมา +1

      It's a good idea. I will make one soon.

    • @sltechgalaxy1677
      @sltechgalaxy1677 4 วันที่ผ่านมา

      @HowtoElectronics thank you dear

  • @athulakulasinghe1957
    @athulakulasinghe1957 5 วันที่ผ่านมา

    What is best for tvoc and eco2
    ENS160 OR SGP30

  • @ΝΕΚΤΑΡΙΟΣΚΟΥΡΑΚΗΣ
    @ΝΕΚΤΑΡΙΟΣΚΟΥΡΑΚΗΣ 5 วันที่ผ่านมา +1

    how much drift after 30 minutes?

  • @danialothman
    @danialothman 20 ชั่วโมงที่ผ่านมา

    Make sure pins are not magnetic or else it might disturb the magnetometer

  • @math8149
    @math8149 2 วันที่ผ่านมา

    Nowadays it's hard to get hmc5883.... So please make a video about fusing the sensor of mpu 6050 and qmc5883 sensor... Asap

    • @HowtoElectronics
      @HowtoElectronics  2 วันที่ผ่านมา +1

      QMC5883 and HMC5883 both are same. You can work with any of these....

    • @math8149
      @math8149 2 วันที่ผ่านมา

      @HowtoElectronics you are partially correct.... Register addresses and set mode values aren't the Same.....
      And Thank you so so much... I really needed this video... For a long time, I was expecting someone to use the Kalman filter to fuse the accelerometer gyroscope and magnetometer sensor data... I couldn't see anyone doing it... So thank you again...
      And a small request (I know it's not small),
      If you can make code for an extended kalman filter to Fuse the mpu 6050 data and qmc 5883 data... It would be very useful to me and others as well. I was trying to make a model for EKF for a long time ... But I ended up failing...

    • @HowtoElectronics
      @HowtoElectronics  2 วันที่ผ่านมา +1

      Thank you for your detailed feedback and kind words!
      Regarding the Extended Kalman Filter (EKF) to fuse MPU6050 and QMC5883 data, I understand its importance. I will definitely give it a try, and if I can successfully implement it, I will post a video explaining the process step-by-step. Stay tuned, and I appreciate your patience!

  • @cyber_karthik
    @cyber_karthik 5 วันที่ผ่านมา

    How to provision esp8266/32 using custom mobile phone