Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Rotation calibration --Gible Lock problem?? (Real life imu)

Discussion in 'Scripting' started by b3l4tr1x, Sep 3, 2020.

  1. b3l4tr1x

    b3l4tr1x

    Joined:
    Mar 31, 2017
    Posts:
    4
    Hello,

    I want to calibrate rotation on avatar joint in real life imu sensor.
    For example;
    I have imu sensor on my arm and gives me data like tihs:
    Quaternion ang = imu.GetQuaternionValue();


    Vector3 e1 =ang.eulerAngles;
    Debug.log(e1); // (34,53,165)

    if(calibrate) //button
    CalibrateQuat=ang; //this data shout be referance point (0)


    ///////////////// next frame


    Vector3 e1 = imu.GetQuaternionValue().eulerAngles;
    Vector3 e2 = CalibrateQuat.eulerAngles;
    Vector3 rotate= e1 - e2; //this not work well, someting like gimble lock problem
    RightArm.transform.eulerAngles = rotate;

    I can use '-' operator between 2 quaternion , how can i do it?
    Or there is another option to calibrate?

    Note: imu is bno055 ,it works good. (there is no gimble lock with default data)
     
  2. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,531
    Don't use eulerAngles. Gimbal lock is only an issue with eulerAngles.You should do something like:

    Code (CSharp):
    1. if(calibrate)
    2.     CalibrateQuat = Quaternion.Inverse(ang);
    and later just:

    RightArm.transform.rotation = CalibrateQuat * imu.GetQuaternionValue();


    You may need to swap the order of the multiplcation around and depending on your needs you may want to use localRotation instead of rotation.
     
  3. b3l4tr1x

    b3l4tr1x

    Joined:
    Mar 31, 2017
    Posts:
    4
    thanks but still i have problem :(