Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. [SOLVED] Compass on Android - Magnetometer values problem?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Compass on Android - Magnetometer values problem?

Scheduled Pinned Locked Moved Mobile and Embedded
7 Posts 4 Posters 6.0k Views 1 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.
  • H Offline
    H Offline
    Hawk30100
    wrote on last edited by
    #1

    Hi, I have a short question:

    According to this table: http://qt-project.org/doc/qt-5/compatmap.html the compass feature is not supported for android systems

    Therefore I think it is useless to use the QCompass class.
    But I need a compass!

    According to the "QRotationReading Class":http://qt-project.org/doc/qt-5/qrotationreading.html#details , the values returned by this class does not give you a direction to the magnetic north.

    So I have to use the QMagnetometer and QAccelerator class to build my own compass.

    -Question: Is there something like the SensorManager RotationMatrix and getOrientation function available in Qt?-
    -If not, should I implement it by myself or should I better use the function through JNI?-

    Maybe you have also some other ideas how I could easily build a compass in Qt.

    Edit:

    I just decided to "convert" the needed java methods into c++.
    Now I have another problem!

    You can find the following code snippet in the getRotationMatrix java method:
    @public static boolean getRotationMatrix(float[] R, float[] I,
    float[] gravity, float[] geomagnetic) {
    // TODO: move this to native code for efficiency
    float Ax = gravity[0];
    float Ay = gravity[1];
    float Az = gravity[2];
    final float Ex = geomagnetic[0];
    final float Ey = geomagnetic[1];
    final float Ez = geomagnetic[2];
    float Hx = EyAz - EzAy;
    float Hy = EzAx - ExAz;
    float Hz = ExAy - EyAx;
    final float normH = (float)Math.sqrt(HxHx + HyHy + Hz*Hz);
    ----> if (normH < 0.1f) {
    // device is close to free fall (or in space?), or close to
    // magnetic north pole. Typical values are > 100.
    return false;
    }
    ...
    @

    My problem is that "if (normH < 0.1f) " is always false. (I just added an arrow in the code to show you the line).

    In my opinion the problem is that the magnetometer sensor returns values like this:

    magn[]={ -6.9375e-06 , -9.125e-06 , 6.25e-06 }
    magn[]={ -6.6875e-06 , -9.375e-06 , 6.5e-06 }
    magn[]={ -6.1875e-06 , -9.375e-06 , 6.5e-06 }
    magn[]={ -5.9375e-06 , -8.875e-06 , 6.5e-06 }
    magn[]={ -5.6875e-06 , -9.375e-06 , 6.75e-06 }
    magn[]={ -5.6875e-06 , -9.125e-06 , 6.75e-06 }
    magn[]={ -5.9375e-06 , -8.875e-06 , 6.25e-06 }
    magn[]={ -5.9375e-06 , -8.875e-06 , 6.5e-06 }
    ...

    with the acceleration values:
    accel[]={ -2.10605 , 0.919373 , 9.61426 }
    accel[]={ -2.1435 , 0.880215 , 9.65342 }
    accel[]={ -2.1435 , 0.880215 , 9.61426 }
    accel[]={ -2.10605 , 0.842759 , 9.65342 }
    ...

    normH is always something around this: normH = 0.000110721
    So the getRotationMatrix function will always return false.

    Info: I'm using the QMagnetometer for the values shown as magn[]=...
    setReturnGeoValues doesnt change something.
    The magn values are with setReturnGeoValues(true).

    My questions are:
    Is the magnetometer working properly?
    Do I have to convert the "tiny" values into a different "electromagnetic unit" or something else?

    1 Reply Last reply
    0
    • H Offline
      H Offline
      Hawk30100
      wrote on last edited by
      #2

      The problem was that Qt returns values in T and native android returns values in µT.

      I just wrote an native Android Magnetometer app to verify that my sensor is working. Andorid returns values like: 3.??? or 5.???. Qt returns values like: 3.???e-06 or 5.???e-06

      I dont know why Qt didnt wrote anything about the meausring units in their documentation... (Maybe I was too stupid to find it)
      Android documentated the measuring units for every sensor.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        After a quick look I found the unit here "here":https://qt-project.org/doc/qt-5/qmagnetometerreading.html#details

        Hope it helps

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • A Offline
          A Offline
          AlterX
          wrote on last edited by
          #4

          Hello,
          do you have a working compass object you can share with us?

          Qt Ambassador
          Real-time cooperative teams: http://www.softairrealfight.net
          Free Real-time network platform sdk: https://github.com/AlterX76/Solomon

          https://codereview.qt-project.org/...

          1 Reply Last reply
          0
          • A Offline
            A Offline
            AlterX
            wrote on last edited by
            #5

            I have ported some java code and built Qt native compass (with same interface of QCompass) using QMagnetometer and QAccelerometer.

            Qt Ambassador
            Real-time cooperative teams: http://www.softairrealfight.net
            Free Real-time network platform sdk: https://github.com/AlterX76/Solomon

            https://codereview.qt-project.org/...

            1 Reply Last reply
            0
            • S Offline
              S Offline
              seka
              wrote on last edited by
              #6

              A have a same problem.
              Is someone have a working compass code (get azimuth, pitch and roll) from Magnetometer and Accelerometer?

              1 Reply Last reply
              0
              • A Offline
                A Offline
                AlterX
                wrote on last edited by
                #7

                Yes sure! :)
                Just check my contribution within my sign!

                Qt Ambassador
                Real-time cooperative teams: http://www.softairrealfight.net
                Free Real-time network platform sdk: https://github.com/AlterX76/Solomon

                https://codereview.qt-project.org/...

                1 Reply Last reply
                0

                • Login

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