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

Поделиться
HTML-код
  • Опубликовано: 18 дек 2024

Комментарии • 26

  • @aknkaragoz9754
    @aknkaragoz9754 6 дней назад +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 7 дней назад +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 7 дней назад

    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  7 дней назад

      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 7 дней назад

      @@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 7 дней назад

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

    • @reddawn87
      @reddawn87 5 дней назад

      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  5 дней назад +1

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

  • @rehan_alammmblogs
    @rehan_alammmblogs 18 часов назад

    Nice ❤

  • @amrzakaria5290
    @amrzakaria5290 6 дней назад

    Good job , Thanks a lot.

  • @TobiKellner
    @TobiKellner 5 дней назад

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

  • @maheshmustapure7668
    @maheshmustapure7668 2 дня назад

    Can you make video on esp32s3 with ov7670 on webserver streaming
    Or something related to that

  • @athulakulasinghe1957
    @athulakulasinghe1957 7 дней назад

    What is best for tvoc and eco2
    ENS160 OR SGP30

  • @sltechgalaxy1677
    @sltechgalaxy1677 7 дней назад

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

  • @ΝΕΚΤΑΡΙΟΣΚΟΥΡΑΚΗΣ
    @ΝΕΚΤΑΡΙΟΣΚΟΥΡΑΚΗΣ 7 дней назад +1

    how much drift after 30 minutes?

  • @cyber_karthik
    @cyber_karthik 7 дней назад

    How to provision esp8266/32 using custom mobile phone

  • @danialothman
    @danialothman 3 дня назад

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

  • @math8149
    @math8149 5 дней назад

    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  5 дней назад +1

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

    • @math8149
      @math8149 5 дней назад

      @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  5 дней назад +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!