← Documents Documentation/devicetree/bindings/iio/mount-matrix.txt GitHub 원문 ↗

Linux 6.18.37 · Devicetree Bindings

IIO Mounting Matrix

3차원 sensor frame을 device/world frame으로 회전하는 matrix 정의입니다.

Source pathDocumentation/devicetree/bindings/iio/mount-matrix.txt
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약과 해설

mount-matrix.txt:1-203

Accelerometer, magnetometer와 gyroscope axis convention을 구조화했습니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

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

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

초안의 검토 질문

1-9

이 문서는 논의를 위한 초안이며 다음 사항이 불분명하다고 밝힙니다. 양수/음수 값 정의가 실용적인지 또는 직관에 반하는지, 정의가 모호하지 않고 따라가기 쉬운지, 예제가 올바른지, 다른 device와 비교하지 않고 새 device의 올바른 matrix를 설계하는 HOWTO가 필요한지를 검토해야 합니다.

Sensor frame에서 device frame으로

10-46

Mounting matrix는 3차원 데이터를 생성하는 device가 배치된 세계를 기준으로 그 device의 방향을 정하는 device-tree property입니다. Linear algebra의 transformation matrix를 사용해 sensor frame of reference를 device frame of reference로 변환합니다.

일반적인 component는 (x,y,z) 좌표를 서로 다른 register에서 읽는 식으로 내부 표현을 가지며, 이 표현은 component가 특정 device frame에 대해 정해진 방향으로 장착되어야 함을 전제합니다. Screen과 같은 chassis에 accelerometer, gyroscope 또는 magnetometer를 장착한 device에서는 보통 screen을 (x,y,z) 기준으로 삼습니다. (x,y)는 screen 평면의 축이고 (z)는 screen에 수직인 depth 축입니다.

Screen 기준으로 x는 왼쪽의 음수에서 오른쪽의 양수로, y는 아래의 음수에서 위의 양수로, z는 screen 아래의 음수에서 사용자 얼굴 방향인 screen 앞의 양수로 두는 것이 바람직합니다. Sensor는 frame에 대해 뒤집히거나 좌우가 바뀌거나 임의 각도로 기울어질 수 있습니다.

또 다른 frame은 sensor를 포함한 device와 외부 세계의 관계입니다. 보통 sensor data로 세계에 대한 device 방향을 구합니다. Mounting matrix를 사용하면 sensor와 device 방향이 같아지므로 주변 세계와 관련된 data 자체에 집중할 수 있습니다.

Accelerometer와 gravity projection

47-92

Accelerometer의 world frame은 보통 행성 중심인 gravity center를 향합니다. Sensor의 (x,y,z)는 지표의 해당 지점에서 device를 통과하는 gravity vector의 projection을 나타내므로 device frame에 대한 세계의 위아래를 판별할 수 있습니다. Screen을 행성 표면에 평평하게 두면 gravity vector가 sensor z axis에 1:1로 projection되어 사용자는 screen 밖을 향하는 z에서 9.81 m/s^2, 다른 축에서 0을 기대합니다.

Device를 기울이면 display 밖으로 나오던 g vector가 display panel의 (x,y) plane에도 projection됩니다. 왼쪽으로 기울이면 x가 양수가 되고, device 상단을 지표 쪽으로 향하게 하면 y가 음수가 됩니다.

Accelerometer gravity projection
Device flatx = 0, y = 0, z = +g
Tilt deviceGravity projects onto display plane
Tilt leftx > 0 while z remains > 0
Point top downy < 0
Gravity centerWorld reference below device

원문의 평평한 device와 기울어진 device ASCII 그림을 같은 의미의 단계로 정리합니다.

Screen-oriented accelerometer axes
방향축 값
Device topy = -g
Device bottomy = +g
Device left tiltx = +g
Device right tiltx = -g
Screen frontz = +g

원문의 keypad 형태 axis 그림을 screen 방향과 부호 표로 다시 그렸습니다.

Magnetometer의 지자기 기준

93-128

Magnetometer(compass)의 world frame은 geomagnetic field를 기준으로 합니다. Local Earth geomagnetic frame에서 y는 ground plane에 있고 magnetic North 쪽이 양수입니다. x도 ground plane에 있지만 North axis와 수직이며 East 쪽이 양수입니다. z는 ground plane에 수직이고 위쪽이 양수입니다.

Geomagnetic field가 균일하지 않으므로 극점에 가까워지면 이 정의는 성립하지 않습니다. 복잡한 계산과 empirical data가 필요하므로 sensor와 driver가 이를 처리할 수도 없고 처리해서도 안 되며 user space에 맡깁니다.

채택한 정의에서는 device를 적도에 놓고 상단이 북쪽을 향하며 지표에 똑바로 선 사람이 display를 읽을 수 있을 때 y가 양수입니다.

Magnetometer world axes
양의 방향평면
xEastGround plane
yMagnetic NorthGround plane
zUpGround plane에 수직

원문의 compass ASCII 그림을 local geomagnetic frame 표로 정리했습니다.

Gyroscope와 right-hand rule

129-149

Gyroscope는 device 자체에 대한 움직임을 검출합니다. Angular velocity는 rotation plane에 직교하는 방향으로 정의합니다. Screen이 있는 device를 table에 평평하게 놓고 z axis 주위로 회전하면 right-hand rule에 따라 clockwise rotation은 z axis의 음수, counter-clockwise rotation은 양수가 되어야 합니다.

Gyroscope z-axis rotation
Device lies flatScreen plane is x-y
Rotation axisOrthogonal z axis
Counter-clockwisez angular velocity > 0
Clockwisez angular velocity < 0

원문의 회전 ASCII 그림을 right-hand rule의 방향 흐름으로 다시 그렸습니다.

3x3 mount-matrix와 예제

150-203

Sensor가 이상적인 방향으로 장착되지 않았다면 해당 sensor의 frame에 대한 상대 방향을 표시할 방법이 필요합니다. 이를 위해 sensor node의 `mount-matrix` device-tree property를 사용합니다.

`mount-matrix`는 엄밀한 linear algebra 의미의 3x3 rotation matrix를 제공하여 원하는 기준점에 대한 sensor axis 방향을 맞춥니다. 적절한 단위로 scaling한 sensor 결과에 이 matrix를 곱하면 device 또는 world 기준의 올바른 3차원 vector를 얻습니다. 자세한 내용은 `https://en.wikipedia.org/wiki/Rotation_matrix`를 참조합니다.

Matrix 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

Property는 transformation matrix의 real value를 string array로 표현합니다. Identity matrix는 좌표를 바꾸지 않으며 device가 기계적으로 이상적인 방향으로 장착되어 transformation이 필요 없음을 뜻합니다.

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

Sensor가 X axis를 따라 30도(Pi/6 radian) 기울어져 장착되었다면 X axis 주위로 -30도 rotation하여 보정합니다.

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

마지막 예제는 sensor가 Z axis 주위로 180도(Pi radian) 뒤집혀 장착된 경우라고 설명합니다. 다만 원문 자체의 검토 메모는 제시된 factor가 180도와 일치하지 않고 약 3도 보정을 나타낸다고 지적합니다.

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