Path: blob/master/Documentation/devicetree/bindings/iio/mount-matrix.txt
26308 views
For discussion. Unclear are:1* is the definition of +/- values practical or counterintuitive?2* are the definitions unambiguous and easy to follow?3* are the examples correct?4* should we have HOWTO engineer a correct matrix for a new device (without comparing to a different one)?56====789Mounting matrix1011The mounting matrix is a device tree property used to orient any device12that produce three-dimensional data in relation to the world where it is13deployed.1415The purpose of the mounting matrix is to translate the sensor frame of16reference into the device frame of reference using a translation matrix as17defined in linear algebra.1819The typical usecase is that where a component has an internal representation20of the (x,y,z) triplets, such as different registers to read these coordinates,21and thus implying that the component should be mounted in a certain orientation22relative to some specific device frame of reference.2324For example a device with some kind of screen, where the user is supposed to25interact with the environment using an accelerometer, gyroscope or magnetometer26mounted on the same chassis as this screen, will likely take the screen as27reference to (x,y,z) orientation, with (x,y) corresponding to these axes on the28screen and (z) being depth, the axis perpendicular to the screen.2930For a screen you probably want (x) coordinates to go from negative on the left31to positive on the right, (y) from negative on the bottom to positive on top32and (z) depth to be negative under the screen and positive in front of it,33toward the face of the user.3435A sensor can be mounted in any angle along the axes relative to the frame of36reference. This means that the sensor may be flipped upside-down, left-right,37or tilted at any angle relative to the frame of reference.3839Another frame of reference is how the device with its sensor relates to the40external world, the environment where the device is deployed. Usually the data41from the sensor is used to figure out how the device is oriented with respect42to this world. When using the mounting matrix, the sensor and device orientation43becomes identical and we can focus on the data as it relates to the surrounding44world.4546Device-to-world examples for some three-dimensional sensor types:4748- Accelerometers have their world frame of reference toward the center of49gravity, usually to the core of the planet. A reading of the (x,y,z) values50from the sensor will give a projection of the gravity vector through the51device relative to the center of the planet, i.e. relative to its surface at52this point. Up and down in the world relative to the device frame of53reference can thus be determined. and users would likely expect a value of549.81 m/s^2 upwards along the (z) axis, i.e. out of the screen when the device55is held with its screen flat on the planets surface and 0 on the other axes,56as the gravity vector is projected 1:1 onto the sensors (z)-axis.5758If you tilt the device, the g vector virtually coming out of the display59is projected onto the (x,y) plane of the display panel.6061Example:6263^ z: +g ^ z: > 064! /!65! x=y=0 / ! x: > 066+--------+ +--------+67! ! ! !68+--------+ +--------+69! /70! /71v v72center of center of73gravity gravity747576If the device is tilted to the left, you get a positive x value. If you point77its top towards surface, you get a negative y axis.7879(---------)80! ! y: -g81! ! ^82! ! !83! !84! ! x: +g <- z: +g -> x: -g85! 1 2 3 !86! 4 5 6 ! !87! 7 8 9 ! v88! * 0 # ! y: +g89(---------)909192- Magnetometers (compasses) have their world frame of reference relative to the93geomagnetic field. The system orientation vis-a-vis the world is defined with94respect to the local earth geomagnetic reference frame where (y) is in the95ground plane and positive towards magnetic North, (x) is in the ground plane,96perpendicular to the North axis and positive towards the East and (z) is97perpendicular to the ground plane and positive upwards.9899100^^^ North: y > 0101102(---------)103! !104! !105! !106! ! >107! ! > North: x > 0108! 1 2 3 ! >109! 4 5 6 !110! 7 8 9 !111! * 0 # !112(---------)113114Since the geomagnetic field is not uniform this definition fails if we come115closer to the poles.116117Sensors and driver can not and should not take care of this because there118are complex calculations and empirical data to be taken care of. We leave119this up to user space.120121The definition we take:122123If the device is placed at the equator and the top is pointing north, the124display is readable by a person standing upright on the earth surface, this125defines a positive y value.126127128- Gyroscopes detects the movement relative the device itself. The angular129velocity is defined as orthogonal to the plane of rotation, so if you put the130device on a flat surface and spin it around the z axis (such as rotating a131device with a screen lying flat on a table), you should get a negative value132along the (z) axis if rotated clockwise, and a positive value if rotated133counter-clockwise according to the right-hand rule.134135136(---------) y > 0137! ! v---\138! !139! !140! ! <--\141! ! ! z > 0142! 1 2 3 ! --/143! 4 5 6 !144! 7 8 9 !145! * 0 # !146(---------)147148149So unless the sensor is ideally mounted, we need a means to indicate the150relative orientation of any given sensor of this type with respect to the151frame of reference.152153To achieve this, use the device tree property "mount-matrix" for the sensor.154155This supplies a 3x3 rotation matrix in the strict linear algebraic sense,156to orient the senor axes relative to a desired point of reference. This means157the resulting values from the sensor, after scaling to proper units, should be158multiplied by this matrix to give the proper vectors values in three-dimensional159space, relative to the device or world point of reference.160161For more information, consult:162https://en.wikipedia.org/wiki/Rotation_matrix163164The mounting matrix has the layout:165166(mxx, myx, mzx)167(mxy, myy, mzy)168(mxz, myz, mzz)169170Values are intended to be multiplied as:171172x' = mxx * x + myx * y + mzx * z173y' = mxy * x + myy * y + mzy * z174z' = mxz * x + myz * y + mzz * z175176It is represented as an array of strings containing the real values for177producing the transformation matrix.178179Examples:180181Identity matrix (nothing happens to the coordinates, which means the device was182mechanically mounted in an ideal way and we need no transformation):183184mount-matrix = "1", "0", "0",185"0", "1", "0",186"0", "0", "1";187188The sensor is mounted 30 degrees (Pi/6 radians) tilted along the X axis, so we189compensate by performing a -30 degrees rotation around the X axis:190191mount-matrix = "1", "0", "0",192"0", "0.866", "0.5",193"0", "-0.5", "0.866";194195The sensor is flipped 180 degrees (Pi radians) around the Z axis, i.e. mounted196upside-down:197198mount-matrix = "0.998", "0.054", "0",199"-0.054", "0.998", "0",200"0", "0", "1";201202???: this does not match "180 degrees" - factors indicate ca. 3 degrees compensation203204205