Search Unity

getting joint angles from imu quaternions in global coordinate system.

Discussion in 'Physics' started by pvandoorn, Mar 10, 2019.

  1. pvandoorn

    pvandoorn

    Joined:
    Dec 4, 2018
    Posts:
    2
    I have a quaternion expressed in a local coordinate system from an imu (Qimu1). The following code works, rotating an object in Unity according to this quaternion:

    Code (CSharp):
    1. void Update() {
    2.  
    3.        if (Input.GetKeyDown(KeyCode.Space))
    4.        {
    5.            Qoffset1 = Qimu1;
    6.        }
    7.  
    8.        transform.localRotation = Qoffset1 * Quaternion.Inverse(Qimu1);
    Now I have two imu's, one attached to the upperarm and one on the lowerarm. I want to be able to tell something about the angle between them, eg the elbow joint. In such a way that the angles makes sense (for example flexion-extension on X-axis, pro- supination on Y-axis). In Unity i made an arm-model with a joint and tried to implement the following code:

    Code (CSharp):
    1. void Update() {
    2.  
    3.        if (Input.GetKeyDown(KeyCode.Space))
    4.        {
    5.            Qoffset1 = Qimu1;
    6.            Qoffset2 = Qimu2;
    7.        }
    8.  
    9.        upperarm.transform.localRotation = Qoffset1 * Quaternion.Inverse(Qimu1);
    10.        this.transform.localRotation = Qoffset2 * Quaternion.Inverse(Qimu2);
    Now it is really messed up, the rotations look almost random and there is no way that the objects represent the imu's rotations relative to each other. How can i adjust this code so the local quaternions from the imu's are expressed in a global coordinate system and rotations are relative to each other. Hope my problem makes sense and there is someone who had a similar problem who could help. Thanks in advance!
     
  2. jorgecastroguerrero

    jorgecastroguerrero

    Joined:
    May 26, 2020
    Posts:
    2
    estimado Amigo
    Quiero preguntarle si pudiste desarrollar el proyecto?