stm32duino / LSM6DSV16X

Arduino library to support the LSM6DSV16X 3D accelerometer and 3D gyroscope
BSD 3-Clause "New" or "Revised" License
5 stars 7 forks source link

Connecting LIS2MDL Magnetometer to sensor hub for 9 axis sensor fusion #19

Closed omkaragre closed 2 days ago

omkaragre commented 2 days ago

Is your feature request/improvement related to a problem? Please describe.

The LSM6DSV16X supports sensor hub to connect to lis2mdl magnetometer as given in application note AN5763 and its hard and soft iron calibration in finite state machine note (AN5882) and datasheet. However, there is no example code to use this feature in the library. We want it for Arduino IDE, as we are considering it for an IOT wearable product.

Describe the solution you'd like

We need a code that enables to input

  1. magnetometer address
  2. Its orientation relative to sensor
  3. get raw values of magneto via lsm6dsv16x for host controller to find out hard and soft iron calibration
  4. input field to write registers of LSM for hard and soft iron calibration.
  5. turn on SFLP (Sensor Fusion Low Power)

Describe alternatives you've considered

Manke an code which takes input compass values or raw data or calibrated data from magnetometer and then fuses it in rotation vector using internal SFLP algo or on Host microcontroller. To get True 9 axis rotation vector/quaternion.

We also want a clarification about whether the sensor hub does 9 axis fusion for SFLP as there seems no point of having these features of sensor hub and input of hard and soft iron calibration if it's just going to give raw data of magnetometer. I think there is internal 9 axis algo processing, please clarify that.

Additional context

You can find application notes AN5882 AN5763 and GitHub repo for same sensor where it's written for STM boards. We need it for Arduino IDE. https://github.com/STMicroelectronics/STMems_Standard_C_drivers/blob/master/lsm6dsv16x_STdC/examples/lsm6dsv16x_sensor_hub.c#L186

cparata commented 2 days ago

Hello @omkaragre , unfortunately, the SFLP is only 6-axis (acc+gyro). Even if you could read the values of the LIS2MDL via SensorHub, there is no way to use it with SFLP. So, if in your project you are using an STM32, LSM6DSV16X and LIS2MDL, I suggest to use the MotionFX library that you can find here. But, this library works only on an STM32; if you are using another microcontroller, it does not work. You can read more information about MotionFX here. You can see the examples of this library for 9x fusion and adapt easily to your hardware. Best Regards, Carlo