mount-matrix.txt 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. For discussion. Unclear are:
  2. * is the definition of +/- values practical or counterintuitive?
  3. * are the definitions unambiguous and easy to follow?
  4. * are the examples correct?
  5. * should we have HOWTO engineer a correct matrix for a new device (without comparing to a different one)?
  6. ====
  7. Mounting matrix
  8. The mounting matrix is a device tree property used to orient any device
  9. that produce three-dimensional data in relation to the world where it is
  10. deployed.
  11. The purpose of the mounting matrix is to translate the sensor frame of
  12. reference into the device frame of reference using a translation matrix as
  13. defined in linear algebra.
  14. The typical usecase is that where a component has an internal representation
  15. of the (x,y,z) triplets, such as different registers to read these coordinates,
  16. and thus implying that the component should be mounted in a certain orientation
  17. relative to some specific device frame of reference.
  18. For example a device with some kind of screen, where the user is supposed to
  19. interact with the environment using an accelerometer, gyroscope or magnetometer
  20. mounted on the same chassis as this screen, will likely take the screen as
  21. reference to (x,y,z) orientation, with (x,y) corresponding to these axes on the
  22. screen and (z) being depth, the axis perpendicular to the screen.
  23. For a screen you probably want (x) coordinates to go from negative on the left
  24. to positive on the right, (y) from negative on the bottom to positive on top
  25. and (z) depth to be negative under the screen and positive in front of it,
  26. toward the face of the user.
  27. A sensor can be mounted in any angle along the axes relative to the frame of
  28. reference. This means that the sensor may be flipped upside-down, left-right,
  29. or tilted at any angle relative to the frame of reference.
  30. Another frame of reference is how the device with its sensor relates to the
  31. external world, the environment where the device is deployed. Usually the data
  32. from the sensor is used to figure out how the device is oriented with respect
  33. to this world. When using the mounting matrix, the sensor and device orientation
  34. becomes identical and we can focus on the data as it relates to the surrounding
  35. world.
  36. Device-to-world examples for some three-dimensional sensor types:
  37. - Accelerometers have their world frame of reference toward the center of
  38. gravity, usually to the core of the planet. A reading of the (x,y,z) values
  39. from the sensor will give a projection of the gravity vector through the
  40. device relative to the center of the planet, i.e. relative to its surface at
  41. this point. Up and down in the world relative to the device frame of
  42. reference can thus be determined. and users would likely expect a value of
  43. 9.81 m/s^2 upwards along the (z) axis, i.e. out of the screen when the device
  44. is held with its screen flat on the planets surface and 0 on the other axes,
  45. as the gravity vector is projected 1:1 onto the sensors (z)-axis.
  46. If you tilt the device, the g vector virtually coming out of the display
  47. is projected onto the (x,y) plane of the display panel.
  48. Example:
  49. ^ z: +g ^ z: > 0
  50. ! /!
  51. ! x=y=0 / ! x: > 0
  52. +--------+ +--------+
  53. ! ! ! !
  54. +--------+ +--------+
  55. ! /
  56. ! /
  57. v v
  58. center of center of
  59. gravity gravity
  60. If the device is tilted to the left, you get a positive x value. If you point
  61. its top towards surface, you get a negative y axis.
  62. (---------)
  63. ! ! y: -g
  64. ! ! ^
  65. ! ! !
  66. ! !
  67. ! ! x: +g <- z: +g -> x: -g
  68. ! 1 2 3 !
  69. ! 4 5 6 ! !
  70. ! 7 8 9 ! v
  71. ! * 0 # ! y: +g
  72. (---------)
  73. - Magnetometers (compasses) have their world frame of reference relative to the
  74. geomagnetic field. The system orientation vis-a-vis the world is defined with
  75. respect to the local earth geomagnetic reference frame where (y) is in the
  76. ground plane and positive towards magnetic North, (x) is in the ground plane,
  77. perpendicular to the North axis and positive towards the East and (z) is
  78. perpendicular to the ground plane and positive upwards.
  79. ^^^ North: y > 0
  80. (---------)
  81. ! !
  82. ! !
  83. ! !
  84. ! ! >
  85. ! ! > North: x > 0
  86. ! 1 2 3 ! >
  87. ! 4 5 6 !
  88. ! 7 8 9 !
  89. ! * 0 # !
  90. (---------)
  91. Since the geomagnetic field is not uniform this definition fails if we come
  92. closer to the poles.
  93. Sensors and driver can not and should not take care of this because there
  94. are complex calculations and empirical data to be taken care of. We leave
  95. this up to user space.
  96. The definition we take:
  97. If the device is placed at the equator and the top is pointing north, the
  98. display is readable by a person standing upright on the earth surface, this
  99. defines a positive y value.
  100. - Gyroscopes detects the movement relative the device itself. The angular
  101. velocity is defined as orthogonal to the plane of rotation, so if you put the
  102. device on a flat surface and spin it around the z axis (such as rotating a
  103. device with a screen lying flat on a table), you should get a negative value
  104. along the (z) axis if rotated clockwise, and a positive value if rotated
  105. counter-clockwise according to the right-hand rule.
  106. (---------) y > 0
  107. ! ! v---\
  108. ! !
  109. ! !
  110. ! ! <--\
  111. ! ! ! z > 0
  112. ! 1 2 3 ! --/
  113. ! 4 5 6 !
  114. ! 7 8 9 !
  115. ! * 0 # !
  116. (---------)
  117. So unless the sensor is ideally mounted, we need a means to indicate the
  118. relative orientation of any given sensor of this type with respect to the
  119. frame of reference.
  120. To achieve this, use the device tree property "mount-matrix" for the sensor.
  121. This supplies a 3x3 rotation matrix in the strict linear algebraic sense,
  122. to orient the senor axes relative to a desired point of reference. This means
  123. the resulting values from the sensor, after scaling to proper units, should be
  124. multiplied by this matrix to give the proper vectors values in three-dimensional
  125. space, relative to the device or world point of reference.
  126. For more information, consult:
  127. https://en.wikipedia.org/wiki/Rotation_matrix
  128. The mounting matrix has the layout:
  129. (mxx, myx, mzx)
  130. (mxy, myy, mzy)
  131. (mxz, myz, mzz)
  132. Values are intended to be multiplied as:
  133. x' = mxx * x + myx * y + mzx * z
  134. y' = mxy * x + myy * y + mzy * z
  135. z' = mxz * x + myz * y + mzz * z
  136. It is represented as an array of strings containing the real values for
  137. producing the transformation matrix.
  138. Examples:
  139. Identity matrix (nothing happens to the coordinates, which means the device was
  140. mechanically mounted in an ideal way and we need no transformation):
  141. mount-matrix = "1", "0", "0",
  142. "0", "1", "0",
  143. "0", "0", "1";
  144. The sensor is mounted 30 degrees (Pi/6 radians) tilted along the X axis, so we
  145. compensate by performing a -30 degrees rotation around the X axis:
  146. mount-matrix = "1", "0", "0",
  147. "0", "0.866", "0.5",
  148. "0", "-0.5", "0.866";
  149. The sensor is flipped 180 degrees (Pi radians) around the Z axis, i.e. mounted
  150. upside-down:
  151. mount-matrix = "0.998", "0.054", "0",
  152. "-0.054", "0.998", "0",
  153. "0", "0", "1";
  154. ???: this does not match "180 degrees" - factors indicate ca. 3 degrees compensation