Clay Murphy | 4ea104f | 2013-10-28 17:44:33 -0700 | [diff] [blame] | 1 | page.title=Base sensors and trigger modes |
| 2 | @jd:body |
| 3 | |
| 4 | <!-- |
| 5 | Copyright 2013 The Android Open Source Project |
| 6 | |
| 7 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | you may not use this file except in compliance with the License. |
| 9 | You may obtain a copy of the License at |
| 10 | |
| 11 | http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | |
| 13 | Unless required by applicable law or agreed to in writing, software |
| 14 | distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | See the License for the specific language governing permissions and |
| 17 | limitations under the License. |
| 18 | --> |
| 19 | <div id="qv-wrapper"> |
| 20 | <div id="qv"> |
| 21 | <h2>In this document</h2> |
| 22 | <ol id="auto-toc"> |
| 23 | </ol> |
| 24 | </div> |
| 25 | </div> |
| 26 | |
| 27 | <h2 id="triggers">Trigger modes</h2> |
| 28 | <p>Sensors can report events in different ways called trigger modes; each sensor |
| 29 | type has one and only one trigger mode associated to it. Four trigger modes |
| 30 | exist:</p> |
Clay Murphy | db20a5c | 2014-06-04 11:19:27 -0700 | [diff] [blame] | 31 | |
Clay Murphy | 4ea104f | 2013-10-28 17:44:33 -0700 | [diff] [blame] | 32 | <h3 id="continuous">Continuous</h3> |
| 33 | <p>Events are reported at a constant rate defined by setDelay(). Example sensors |
| 34 | using the continuous trigger mode are accelerometers and gyroscopes.</p> |
Clay Murphy | db20a5c | 2014-06-04 11:19:27 -0700 | [diff] [blame] | 35 | |
Clay Murphy | 4ea104f | 2013-10-28 17:44:33 -0700 | [diff] [blame] | 36 | <h3 id="on-change">On-change</h3> |
Clay Murphy | db20a5c | 2014-06-04 11:19:27 -0700 | [diff] [blame] | 37 | <p>Events are reported only if the sensor's value has changed. Activating the |
| 38 | sensor also triggers an event, meaning the HAL must return an event immediately |
| 39 | when an on-change sensor is activated. Example sensors using the on-change |
| 40 | trigger mode are the step counter and proximity sensor types.</p> |
| 41 | |
| 42 | <p>Here is how the <code>period_ns</code> parameter affects setDelay(...) and |
| 43 | batch(...). The <code>period_ns</code> parameter is used to set a lower limit |
| 44 | to the reporting period, meaning the minimum time between consecutive events. |
| 45 | Here is an example: If activating the step counter with period_ns = 10 seconds, |
| 46 | walking for 1 minute, and then not walking for 1 minute, the events will |
| 47 | be generated every 10 seconds during the first minute, and no event will be |
| 48 | generated in the second minute.</p> |
| 49 | |
Clay Murphy | 4ea104f | 2013-10-28 17:44:33 -0700 | [diff] [blame] | 50 | <h3 id="one-shot">One-shot</h3> |
| 51 | <p>Upon detection of an event, the sensor deactivates itself and then sends a |
| 52 | single event. Order matters to avoid race conditions. No other event is sent |
| 53 | until the sensor is reactivated. setDelay() is ignored. |
| 54 | <a |
| 55 | href="{@docRoot}devices/sensors/composite_sensors.html#Significant">Significant |
| 56 | motion</a> is an example of this kind of sensor.</p> |
| 57 | <h3 id="special">Special</h3> |
| 58 | <p>See the individual sensor type descriptions for details.</p> |
| 59 | <h2 id="categories">Categories</h2> |
| 60 | <p>Sensors fall into four primary categories:</p> |
| 61 | <blockquote> |
| 62 | <p><em>Base</em> - records core measurements from which all other sensors are derived <br/> |
| 63 | <em>Activity</em> - detects user or device movement<br/> |
| 64 | <em>Attitude</em> - measures the orientation of the device<br/> |
| 65 | <em>Uncalibrated</em> - is identical to the corresponding base sensor except the |
| 66 | dynamic calibration is reported separately rather than applied to the results</p> |
| 67 | </blockquote> |
| 68 | <h2 id="base">Base sensors</h2> |
| 69 | <p>These sensor types are listed first because they are the fundamental sensors |
| 70 | upon which all other sensor types are based.</p> |
| 71 | <h3 id="Accelerometer">Accelerometer</h3> |
| 72 | <p><em>Trigger-mode: Continuous<br/> |
| 73 | Wake-up sensor: No</em></p> |
| 74 | <p>All values are in SI units (m/s^2) and measure the acceleration of the device |
| 75 | minus the force of gravity.</p> |
| 76 | <p>Acceleration sensors return sensor events for all three axes at a constant rate |
| 77 | defined by setDelay().</p> |
| 78 | <ul> |
| 79 | <li>x: Acceleration on the x-axis</li> |
| 80 | <li>y: Acceleration on the y-axis</li> |
| 81 | <li>z: Acceleration on the z-axis</li> |
| 82 | </ul> |
| 83 | <p>Note the readings from the accelerometer include the acceleration due to gravity |
| 84 | (which is opposite the direction of the gravity vector).</p> |
| 85 | <p>Here are examples:</p> |
| 86 | <ul> |
| 87 | <li>The norm of (x, y, z) should be close to 0 when in free fall.</li> |
| 88 | <li>When the device lies flat on a table and is pushed on its left side toward the |
| 89 | right, the x acceleration value is positive.</li> |
| 90 | <li>When the device lies flat on a table, the acceleration value is +9.81, which |
| 91 | corresponds to the acceleration of the device (0 m/s^2) minus the force of |
| 92 | gravity (-9.81 m/s^2).</li> |
| 93 | <li>When the device lies flat on a table and is pushed toward the sky, the |
| 94 | acceleration value is greater than +9.81, which corresponds to the |
| 95 | acceleration of the device (+A m/s^2) minus the force of gravity (-9.81 |
| 96 | m/s^2).</li> |
| 97 | </ul> |
| 98 | <h3 id="Ambient">Ambient temperature</h3> |
| 99 | <p><em>Trigger-mode: On-change<br/> |
| 100 | Wake-up sensor: No</em></p> |
| 101 | <p>This sensor provides the ambient (room) temperature in degrees Celsius.</p> |
| 102 | <h3 id="Geomagnetic">Geomagnetic field</h3> |
| 103 | <p><em>Trigger-mode: Continuous<br/> |
| 104 | Wake-up sensor: No</em></p> |
| 105 | <p>All values are in micro-Tesla (uT) and measure the geomagnetic field in the X, Y |
| 106 | and Z axis.</p> |
| 107 | <p>Returned values include calibration mechanisms so the vector is aligned with the |
| 108 | magnetic declination and heading of the earth's geomagnetic field.</p> |
| 109 | <p>Magnetic field sensors return sensor events for all three axes at a constant |
| 110 | rate defined by setDelay().</p> |
| 111 | <h3 id="Gyroscope">Gyroscope</h3> |
| 112 | <p><em>Trigger-mode: Continuous<br/> |
| 113 | Wake-up sensor: No</em></p> |
| 114 | <p>All values are in radians/second and measure the rate of rotation around the X, |
| 115 | Y and Z axis. The coordinate system is the same as is used for the acceleration |
| 116 | sensor. Rotation is positive in the counter-clockwise direction (right-hand |
| 117 | rule).</p> |
| 118 | <p>That is, an observer looking from some positive location on the x, y or z axis |
| 119 | at a device positioned on the origin would report positive rotation if the |
| 120 | device appeared to be rotating counter clockwise. Note that this is the standard |
| 121 | mathematical definition of positive rotation and does not agree with the |
| 122 | definition of roll given elsewhere.</p> |
| 123 | <p>The range should at least be 17.45 rad/s (ie: ~1000 deg/s).</p> |
| 124 | <p>Automatic gyro-drift compensation is required.</p> |
| 125 | <h3 id="Light">Light</h3> |
| 126 | <p><em>Trigger-mode: On-change<br/> |
| 127 | Wake-up sensor: No</em></p> |
| 128 | <p>The light sensor value is returned in SI lux units.</p> |
| 129 | <h3 id="Proximity">Proximity</h3> |
| 130 | <p><em>Trigger-mode: On-change<br/> |
| 131 | Wake-up sensor: Yes</em></p> |
| 132 | <p>Measures the distance from the sensor to the closest visible surface. As this is |
| 133 | a wake-up sensor, it should wake up the SoC when it is running and detects a |
| 134 | change in proximity. The distance value is measured in centimeters. Note that |
| 135 | some proximity sensors only support a binary "near" or "far" measurement. In |
| 136 | this case, the sensor should report its maxRange value in the "far" state and a |
| 137 | value less than maxRange in the "near" state.</p> |
| 138 | <p>To ensure the applications have the time to receive the event before the |
| 139 | application processor goes back to sleep, the driver must hold a "timeout wake |
| 140 | lock" for 200 milliseconds for every wake-up sensor. That is, the application |
| 141 | processor should not be allowed to go back to sleep in the 200 milliseconds |
| 142 | following a wake-up interrupt.</p> |
| 143 | <h3 id="Pressure">Pressure</h3> |
| 144 | <p><em>Trigger-mode: Continuous<br/> |
| 145 | Wake-up sensor: No</em></p> |
| 146 | <p>The pressure sensor uses a barometer to return the atmospheric pressure in |
| 147 | hectopascal (hPa).</p> |
| 148 | <h3 id="humidity">Relative humidity</h3> |
| 149 | <p><em>Trigger-mode: On-change<br/> |
| 150 | Wake-up sensor: No</em></p> |
| 151 | <p>A relative humidity sensor measures relative ambient air humidity and returns a |
| 152 | value in percent.</p> |