Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QQuaternion rotation of accelerometer data
Forum Updated to NodeBB v4.3 + New Features

QQuaternion rotation of accelerometer data

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 1.7k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    viniltc
    wrote on last edited by
    #1

    Hi All,

    I need to rotate the accelerometer data from the sensor coordinate frame to the world coordinate frame.

    I did the following Quaternion multiplication (v' = qvq*), where v' is the rotated accelerometer vector.

    My quaternion are in the form of (q0, q1, q2, q3), where q0 is the scalar component.

    QQuaternion q; 
    q.setScalar(q0);
    q.setX(q1);
    q.setY(q2);
    q.setZ(q3);
    
    QVector3D aVector(ax,ay,az); // acceleration vector 
    QVector3D qRotated = q.rotatedVector(vector); // this is v'
    

    However, this does not seems working, I have difficulty in understanding if it's due to the my quaternion values or the way I'm dealing with the rotation. Does anybody have some idea?

    kshegunovK N 2 Replies Last reply
    0
    • V viniltc

      Hi All,

      I need to rotate the accelerometer data from the sensor coordinate frame to the world coordinate frame.

      I did the following Quaternion multiplication (v' = qvq*), where v' is the rotated accelerometer vector.

      My quaternion are in the form of (q0, q1, q2, q3), where q0 is the scalar component.

      QQuaternion q; 
      q.setScalar(q0);
      q.setX(q1);
      q.setY(q2);
      q.setZ(q3);
      
      QVector3D aVector(ax,ay,az); // acceleration vector 
      QVector3D qRotated = q.rotatedVector(vector); // this is v'
      

      However, this does not seems working, I have difficulty in understanding if it's due to the my quaternion values or the way I'm dealing with the rotation. Does anybody have some idea?

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      @viniltc said in QQuaternion rotation of accelerometer data:

      I have difficulty in understanding if it's due to the my quaternion values

      Probably. How are these numbers obtained? Can you provide an example of the actual numbers as well?

      Read and abide by the Qt Code of Conduct

      V 1 Reply Last reply
      1
      • kshegunovK kshegunov

        @viniltc said in QQuaternion rotation of accelerometer data:

        I have difficulty in understanding if it's due to the my quaternion values

        Probably. How are these numbers obtained? Can you provide an example of the actual numbers as well?

        V Offline
        V Offline
        viniltc
        wrote on last edited by
        #3

        @kshegunov Hi

        That's generated by the IMU sensor, I then normalized the quaternion as follows:

         double q_mag=sqrt(q0*q0 + q1*q1 + q2*q2 + q3*q3);
           q0/=q_mag;
           q1/=q_mag;
           q2/=q_mag;
           q3/=q_mag;
        

        I tried to visualize the quaternion rotation, using a cube model, which looks ok. A typical value of quaternion is below:

        q0 =  0.450496
        q1 = -0.00253865
        q2 = -0.0104597
        q3 = -0.892714
        
        kshegunovK 1 Reply Last reply
        0
        • V viniltc

          @kshegunov Hi

          That's generated by the IMU sensor, I then normalized the quaternion as follows:

           double q_mag=sqrt(q0*q0 + q1*q1 + q2*q2 + q3*q3);
             q0/=q_mag;
             q1/=q_mag;
             q2/=q_mag;
             q3/=q_mag;
          

          I tried to visualize the quaternion rotation, using a cube model, which looks ok. A typical value of quaternion is below:

          q0 =  0.450496
          q1 = -0.00253865
          q2 = -0.0104597
          q3 = -0.892714
          
          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #4

          What are you trying to do exactly, it's not that clear from the description. The quaternion you get has what meaning with relation to the vector? Is the vector sampled directly and the quaternion is the sensor's orientation? That's how I read the question. If so then you invert the quaternion and apply it to the vector to get the latter in the global reference (i.e. the one that the sensor's in).
          Inverting a quaternion is trivial - conjugating and normalizing it (to the square length) it just entails flipping the imaginary components' signs.

          I did the following Quaternion multiplication (v' = qvq*), where v' is the rotated accelerometer vector.

          When, how? Is the v' the unknown or the known?

          Read and abide by the Qt Code of Conduct

          V 1 Reply Last reply
          1
          • V viniltc

            Hi All,

            I need to rotate the accelerometer data from the sensor coordinate frame to the world coordinate frame.

            I did the following Quaternion multiplication (v' = qvq*), where v' is the rotated accelerometer vector.

            My quaternion are in the form of (q0, q1, q2, q3), where q0 is the scalar component.

            QQuaternion q; 
            q.setScalar(q0);
            q.setX(q1);
            q.setY(q2);
            q.setZ(q3);
            
            QVector3D aVector(ax,ay,az); // acceleration vector 
            QVector3D qRotated = q.rotatedVector(vector); // this is v'
            

            However, this does not seems working, I have difficulty in understanding if it's due to the my quaternion values or the way I'm dealing with the rotation. Does anybody have some idea?

            N Offline
            N Offline
            normvcr
            wrote on last edited by
            #5

            @viniltc Of course, you need to very careful that you have the definitions correct for the sensor and world coordinate frames. For example, is the world frame Earth-centred rotating, or is it x-east, y-north, z-upward pointing, at the point below the sensor? Is the sensor x-forward, y-starboard, z-down? There are many variations of this that vendors can use, and documentation is often skimpy.

            V 1 Reply Last reply
            2
            • kshegunovK kshegunov

              What are you trying to do exactly, it's not that clear from the description. The quaternion you get has what meaning with relation to the vector? Is the vector sampled directly and the quaternion is the sensor's orientation? That's how I read the question. If so then you invert the quaternion and apply it to the vector to get the latter in the global reference (i.e. the one that the sensor's in).
              Inverting a quaternion is trivial - conjugating and normalizing it (to the square length) it just entails flipping the imaginary components' signs.

              I did the following Quaternion multiplication (v' = qvq*), where v' is the rotated accelerometer vector.

              When, how? Is the v' the unknown or the known?

              V Offline
              V Offline
              viniltc
              wrote on last edited by
              #6

              @kshegunov Hi

              What I'm aiming to do is to compensate gravity from the accelerometer data. The acceleration vector (QVector3D aVector(ax,ay,az)) is sampled directly from the sensor.

              What I then need to do is to transfer from local sensor from to the world frame using quaternion.

              So I did this:

              QQuaternion q; // quaternion
              q.setScalar(q0);
              q.setX(q1);
              q.setY(q2);
              q.setZ(q3);
              
              QVector3D aVector(ax,ay,az); // acceleration vector 
              QVector3D qRotated = q.rotatedVector(vector); // convert acceleration from local frame to world frame
              

              then the next step is to subtract the gravity component from acceleration

              QVector3D g(0,0,1);
              QVector3D result = qRotated-g; 
              

              @kshegunov said in QQuaternion rotation of accelerometer data:

              Inverting a quaternion is trivial - conjugating and normalizing it (to the square length) it just entails flipping the imaginary components' signs.

              So you suggest to invert quaternion first and rotate the acceleration, something like following?

              QVector3D qRotated = q.inverted().rotatedVector(vector);
              
              1 Reply Last reply
              0
              • N normvcr

                @viniltc Of course, you need to very careful that you have the definitions correct for the sensor and world coordinate frames. For example, is the world frame Earth-centred rotating, or is it x-east, y-north, z-upward pointing, at the point below the sensor? Is the sensor x-forward, y-starboard, z-down? There are many variations of this that vendors can use, and documentation is often skimpy.

                V Offline
                V Offline
                viniltc
                wrote on last edited by viniltc
                #7

                @normvcr thanks for your feedback.
                I have a basic understanding of IMU. I was in an assumption that the world frame always the same (East, North, Up) .

                My requirement is to use IMU as a shoulder sensor. My confusion is, how the quaternion rotation will affect based on the different conventions of world frame?

                I can confirm my IMU frame looks like this from the datasheet:

                imu_orient.JPG

                kshegunovK 1 Reply Last reply
                0
                • V viniltc

                  @normvcr thanks for your feedback.
                  I have a basic understanding of IMU. I was in an assumption that the world frame always the same (East, North, Up) .

                  My requirement is to use IMU as a shoulder sensor. My confusion is, how the quaternion rotation will affect based on the different conventions of world frame?

                  I can confirm my IMU frame looks like this from the datasheet:

                  imu_orient.JPG

                  kshegunovK Offline
                  kshegunovK Offline
                  kshegunov
                  Moderators
                  wrote on last edited by kshegunov
                  #8

                  @viniltc said in QQuaternion rotation of accelerometer data:

                  I can confirm my IMU frame looks like this from the datasheet

                  Okay this gives enough info about the vector you get. It's sampled in that coordinate system. I still have no idea what the quaternion is supposed to represent. If it's the orientation of the sensor in relation to the fixed reference frame (i.e. "world"), then just inverting the quaternion and applying it to the vector should be sufficient. Did you try that?

                  So you suggest to invert quaternion first and rotate the acceleration, something like following?

                  Yes.

                  Read and abide by the Qt Code of Conduct

                  1 Reply Last reply
                  3
                  • V Offline
                    V Offline
                    viniltc
                    wrote on last edited by
                    #9

                    @kshegunov , @normvcr Thanks a lot for your feedback. This got solved. It was too late to realise that the sign of the quaternion values was wrong in my case :)

                    1 Reply Last reply
                    1

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved