Skip to main content
Visitor II
October 16, 2021
Question

trying to run dt0103 example calibration code to evaluate lsm303ah

  • October 16, 2021
  • 3 replies
  • 923 views

I translated the matlab code to C and verified the simulated case has the same results in the matlab and C version. I'm running linux on a am3358. I'm trying to replace the simulated case with data from the lsm303ah readings and run the calibration. I don't think I can just use the direct outputs, integer counts or if it should have the sensitivity values applied.

    This topic has been closed for replies.

    3 replies

    ST Employee
    October 18, 2021

    Hi @SHeit.1​ ,

    yes, you have to feed the algorithm with physical units, and not LSB ones. For this reason, I suggest you to check the conversion formulas in C in lsm303agr_reg.c and lsm303ah_reg.c.

    // For LSM303AGR
    float_t lsm303agr_from_fs_2g_hr_to_mg(int16_t lsb)
    {
     return ((float_t)lsb / 16.0f) * 0.98f;
    }
     
    // For LSM303AH
    float_t lsm303ah_from_fs2g_to_mg(int16_t lsb)
    {
     return ((float_t)lsb * 0.061f);
    }

    Consider that these algorithm are generic, applying to the different e-Compasses LSM303AGR and LSM303AH, that have different sensitivities.

    I suggest you also to check the X-CUBE-MEMS1 function pack, and especially the library MotionEC real-time E-Compass library and the "calibration" libraries MotionAC and MotionMC.

    If my reply answered your question, please click on Select as Best at the bottom of this post. This will help other users with the same issue to find the answer faster.

    -Eleon

    SHeit.1Author
    Visitor II
    October 18, 2021

    I have tried that and the resulting magnetic estimations basically match my mag inputs.

    In the simulation section, test.m I started off by filling in the mve and av with my compass data, with the asjustments suggested. but that would just produce a "Hard iron estimated" of what my actual mag input values are. Now I'm thinking that I need to apply some of the logic that the simulation data is doing to the mve and av. for example do I need to put the points read into the quat2rotm to produce a rotation matrix . I know I don't want to apply the errors to my readings, they should already have errors in them.

    Second

    we are running on a ti-am3358 running linux. I already have a driver that reads the compass. I don't think the other suggestions are feasible for the short term prototype.

    ST Employee
    October 20, 2021

    Hi @SHeit.1​ ,

    Are you considering the most complex case (design tip, p.5), and the related code?

    2D calibration in a tilted plane (any rotation axis, not only vertical) and compensation of magnetometer installation error (roll and pitch) and hard-iron effects (offset); this is the most complex case and accelerometer data is essential.

    -Eleon