summaryrefslogtreecommitdiffstats
path: root/Documentation/devicetree/bindings/iio/mount-matrix.txt
blob: c3344ab509a36c31a0a9977b4f2c5835758101dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
For discussion. Unclear are:
* is the definition of +/- values practical or counterintuitive?
* are the definitions unambiguous and easy to follow?
* are the examples correct?
* should we have HOWTO engineer a correct matrix for a new device (without comparing to a different one)?

====


Mounting matrix

The mounting matrix is a device tree property used to orient any device
that produce three-dimensional data in relation to the world where it is
deployed.

The purpose of the mounting matrix is to translate the sensor frame of
reference into the device frame of reference using a translation matrix as
defined in linear algebra.

The typical usecase is that where a component has an internal representation
of the (x,y,z) triplets, such as different registers to read these coordinates,
and thus implying that the component should be mounted in a certain orientation
relative to some specific device frame of reference.

For example a device with some kind of screen, where the user is supposed to
interact with the environment using an accelerometer, gyroscope or magnetometer
mounted on the same chassis as this screen, will likely take the screen as
reference to (x,y,z) orientation, with (x,y) corresponding to these axes on the
screen and (z) being depth, the axis perpendicular to the screen.

For a screen you probably want (x) coordinates to go from negative on the left
to positive on the right, (y) from negative on the bottom to positive on top
and (z) depth to be negative under the screen and positive in front of it,
toward the face of the user.

A sensor can be mounted in any angle along the axes relative to the frame of
reference. This means that the sensor may be flipped upside-down, left-right,
or tilted at any angle relative to the frame of reference.

Another frame of reference is how the device with its sensor relates to the
external world, the environment where the device is deployed. Usually the data
from the sensor is used to figure out how the device is oriented with respect
to this world. When using the mounting matrix, the sensor and device orientation
becomes identical and we can focus on the data as it relates to the surrounding
world.

Device-to-world examples for some three-dimensional sensor types:

- Accelerometers have their world frame of reference toward the center of
  gravity, usually to the core of the planet. A reading of the (x,y,z) values
  from the sensor will give a projection of the gravity vector through the
  device relative to the center of the planet, i.e. relative to its surface at
  this point. Up and down in the world relative to the device frame of
  reference can thus be determined. and users would likely expect a value of
  9.81 m/s^2 upwards along the (z) axis, i.e. out of the screen when the device
  is held with its screen flat on the planets surface and 0 on the other axes,
  as the gravity vector is projected 1:1 onto the sensors (z)-axis.

  If you tilt the device, the g vector virtually coming out of the display
  is projected onto the (x,y) plane of the display panel.

  Example:

         ^ z: +g                   ^ z: > 0
         !                        /!
         ! x=y=0                 / ! x: > 0
     +--------+             +--------+
     !        !             !        !
     +--------+             +--------+
         !                    /
         !                   /
         v                  v
      center of         center of
       gravity           gravity


  If the device is tilted to the left, you get a positive x value. If you point
  its top towards surface, you get a negative y axis.

     (---------)
     !         !           y: -g
     !         !             ^
     !         !             !
     !         !
     !         !  x: +g <- z: +g  -> x: -g
     ! 1  2  3 !
     ! 4  5  6 !             !
     ! 7  8  9 !             v
     ! *  0  # !           y: +g
     (---------)


- Magnetometers (compasses) have their world frame of reference relative to the
  geomagnetic field. The system orientation vis-a-vis the world is defined with
  respect to the local earth geomagnetic reference frame where (y) is in the
  ground plane and positive towards magnetic North, (x) is in the ground plane,
  perpendicular to the North axis and positive towards the East and (z) is
  perpendicular to the ground plane and positive upwards.


     ^^^ North: y > 0

     (---------)
     !         !
     !         !
     !         !
     !         !  >
     !         !  > North: x > 0
     ! 1  2  3 !  >
     ! 4  5  6 !
     ! 7  8  9 !
     ! *  0  # !
     (---------)

  Since the geomagnetic field is not uniform this definition fails if we come
  closer to the poles.

  Sensors and driver can not and should not take care of this because there
  are complex calculations and empirical data to be taken care of. We leave
  this up to user space.

  The definition we take:

  If the device is placed at the equator and the top is pointing north, the
  display is readable by a person standing upright on the earth surface, this
  defines a positive y value.


- Gyroscopes detects the movement relative the device itself. The angular
  velocity is defined as orthogonal to the plane of rotation, so if you put the
  device on a flat surface and spin it around the z axis (such as rotating a
  device with a screen lying flat on a table), you should get a negative value
  along the (z) axis if rotated clockwise, and a positive value if rotated
  counter-clockwise according to the right-hand rule.


     (---------)     y > 0
     !         !     v---\
     !         !
     !         !
     !         !      <--\
     !         !         ! z > 0
     ! 1  2  3 !       --/
     ! 4  5  6 !
     ! 7  8  9 !
     ! *  0  # !
     (---------)


So unless the sensor is ideally mounted, we need a means to indicate the
relative orientation of any given sensor of this type with respect to the
frame of reference.

To achieve this, use the device tree property "mount-matrix" for the sensor.

This supplies a 3x3 rotation matrix in the strict linear algebraic sense,
to orient the senor axes relative to a desired point of reference. This means
the resulting values from the sensor, after scaling to proper units, should be
multiplied by this matrix to give the proper vectors values in three-dimensional
space, relative to the device or world point of reference.

For more information, consult:
https://en.wikipedia.org/wiki/Rotation_matrix

The mounting matrix has the layout:

 (mxx, myx, mzx)
 (mxy, myy, mzy)
 (mxz, myz, mzz)

Values are intended to be multiplied as:

  x' = mxx * x + myx * y + mzx * z
  y' = mxy * x + myy * y + mzy * z
  z' = mxz * x + myz * y + mzz * z

It is represented as an array of strings containing the real values for
producing the transformation matrix.

Examples:

Identity matrix (nothing happens to the coordinates, which means the device was
mechanically mounted in an ideal way and we need no transformation):

mount-matrix = "1", "0", "0",
               "0", "1", "0",
               "0", "0", "1";

The sensor is mounted 30 degrees (Pi/6 radians) tilted along the X axis, so we
compensate by performing a -30 degrees rotation around the X axis:

mount-matrix = "1", "0", "0",
               "0", "0.866", "0.5",
               "0", "-0.5", "0.866";

The sensor is flipped 180 degrees (Pi radians) around the Z axis, i.e. mounted
upside-down:

mount-matrix = "0.998", "0.054", "0",
               "-0.054", "0.998", "0",
               "0", "0", "1";

???: this does not match "180 degrees" - factors indicate ca. 3 degrees compensation