Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-66168

Rotation/Tilt Sensor inadequacies

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Duplicate
    • Not Evaluated
    • None
    • 5.10.0
    • Sensors
    • None

    Description

      I understand the mantra "Qt provides what the platform provides" (in a platform agnostic way.)

      However my recent experience with Rotation and tilt left a lot to be desired. I was looking for a sensible way to measure the orientation of the phone. However both rotation and tilt only measure up to 90 degrees. 

      _ 0 (face  up)
      \ 45 (below horizon)
      | 90 
      / 45 (135 really, above horizon)
      - 0 (face down)
      
      

       

      Because the sensor is only returning up to 90, there are two angles for every angle other than 90 despite having a different orientation. There are 2 89s, 2 60s, 2 30s, etc. The user therefore cannot tell if the phone backface is pointing above or below the horizon, which is a pretty big problem for applications wanting to know orientation in the first place.

      Under the mantra "Code less, create more" I argue that Qt should provide sensible orientation readings of -180 to 180. This will allow 45 (below horizon) and 45 (really 135, 45 above the horizon). The solution to this is described in this stack overflow: https://stackoverflow.com/questions/3755059/3d-accelerometer-calculate-the-orientation

      Which I have integrated into my code. (Albeit in a modified version because apparently  the axis change with the device orientation) However, this seems silly that I should have to google and implement this for something that seems like it should be provided. 

      My suggestion is to add to RotationSensoror and/or TiltSensor a setting which allow sensible readings to be obtained. Maybe set a maxAngle: 90 (default) or 180, or some enum, or something else.  In the meantime, ironically, those who are looking to measure tilt or rotation shouldn't actually use tilt or rotation elements, they should use accelerometer. 

      I'm including my janky hack below, for reference. JIRA sucks and killed the indentation. It's jacky because it isn't 100% accurate right by orientation changes. I hope you can do better. 

      Accelerometer {
      OrientationSensor { id: orientation }
      property real roll: 0.0
      property real pitch: 0.0
      property real zz: Math.sign(reading.z) * Math.sqrt(reading.z*reading.z+
      .001*reading.x*reading.x)
      property real landscapePitch: Math.atan2(reading.x, zz) * 180/Math.PI;
      property real landscapeRoll: Math.atan2(-reading.y,
      Math.sqrt(reading.x*reading.x + reading.z*reading.z)) * 180/Math.PI;
      
      // right
      property real portraitPitch: Math.atan2(reading.y, zz) * 180/Math.PI;
      property real portraitRoll: Math.atan2(-reading.x,
      Math.sqrt(reading.y*reading.y + reading.z*reading.z)) * 180/Math.PI;
      id: accel
      active: true
      dataRate: 10
      onReadingChanged: {
      if (orientation.reading.orientation == OrientationReading.TopUp) { // 1
      roll = portraitRoll;
      pitch = portraitPitch;
      } else if (orientation.reading.orientation == OrientationReading.TopDown) {
      // 2
      roll = landscapeRoll;
      pitch = landscapePitch;
      } else if (orientation.reading.orientation == OrientationReading.LeftUp) {
      // 3
      roll = landscapeRoll;
      pitch = 0-landscapePitch;
      console.log("sdsdsdsdsdsds", landscapePitch, pitch)
      } else if (orientation.reading.orientation == OrientationReading.RightUp) {
      // 4
      roll = landscapeRoll;
      pitch = landscapePitch;
      } else if (orientation.reading.orientation == OrientationReading.FaceUp) {
      // 5
      roll = landscapePitch;
      pitch = 0-landscapeRoll;
      } else if (orientation.reading.orientation == OrientationReading.FaceDown) {
      // 6
      roll = portraitRoll;
      pitch = portraitPitch;
      }
      
      console.log("pitch", Math.floor(pitch), "roll",
      Math.floor(roll), orientation.reading.orientation)
      }
      }

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              lpotter Lorn Potter
              scorp1us Jason Hihn
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes