On smartphone sensors
As Pokémon Go is taking over the planet, some people have discovered that their cheap smartphones are lacking a gyroscope–although smartphones that have at least 2 GB of RAM and Android 4.4 or newer (Pokémon Go’s requirements) should normally include a gyroscope, but Huawei P9 lite doesn’t. And I discovered it wasn’t that clear to me which sensor does what in a smartphone.
First of all, I was puzzled that a gyroscope was even needed. For what it’s worth, all the phones equipped with an accelerometer–which means all the smartphones–can sense their position, they know when you rotate them and which side is up, etc. What’s the deal?
An accelerometer should in theory measure non-gravitational acceleration, that is motion that isn’t constant in speed and direction, and a typical 2-axis accelerometer would measure linear acceleration based on vibration that induces through physical pressure an electrical charge in microscopic crystals. Similar–but much less sensitive–crystals are used in piezoelectric cartridges for turntables, in electronic kitchen scales, and in those blood pressure monitors for personal use, so this technology is dirt cheap. Technically, a 2-axis accelerometer cannot be used to determine the exact orientation of an object. In practice, smartphones have 3-axis accelerometers that however include the gravitational acceleration in their readings, yet despite their lack of precision, they can determine the orientation of an object relative to Earth’s surface, but when the object starts moving, the readings become more difficult to interpret. Distinguishing between an object that accelerates on its own will on a direction and an object that falls because of the gravity is tough business, although software algorithms can surely understand that values close to 9.8 m/s2 on any given direction can only mean one thing.
A gyroscope, using the principles of angular momentum, can determine the exact orientation of an object relative to Earth’s surface–its angular position–and the exact direction of what’s called “down.” As the object rotates, it can sense the tilting or rotation as non-zero readings. Smartphones don’t include the classical types of rotary gyroscopes based on permanently-spinning rotors, but rather “vibrating structure gyroscope” devices that use the Coriolis force to determine the orientation of a tiny resonating mass. Such sensors can use crystal or ceramic piezoelectric transducers–hello, accelerometers!–or silicon transducers.
Here’s a rough schematic taken from SensorWiki.org:
Now, something published by EPSON:
Back to our ship, let’s note that a gyroscope is not mandatory in a smartphone–except for when you’re into augmented reality–because a 3-axis accelerometer is sufficient for most tasks. However, as GSM Arena notes:
With an accelerometer you can either get a really “noisy” info output that is responsive, or you can get a “clean” output that’s sluggish. But when you combine the 3-axis accelerometer with a 3-axis gyro, you get an output that is both clean and responsive in the same time.
Now, let’s talk about the “noisy” part. I have used Ettore Zaffaroni’s Sensors test app on my smartphone and I was horrified by the noise level. Having the smartphone motionless, readings jumped back and forth all the time; please pay attention not only to the computed gravitational acceleration, but also to the values on the axes (yes, the device was motionless):
A funny thing in smartphones is that they usually come with multiple sensors in a single chip. For instance:
- BOSCH BMA050 includes a 3-axis accelerometer and a 3-axis magnetic field sensor (used as a compass, but it’s still 3-axis!); for a gyroscope a different chip is needed, and my phone lacks one
- STMicroelectronics K330 includes a 3-axis accelerometer and a gyroscope; for a magnetic sensor, some devices use a separate Yamaha YAS532 chip
- Capella CM36283 is both a proximity sensor (“near” and “far” are the only outputs) and an ambient light sensor (0 to 10240 lux), but a terrible one
The magnetometer is noisy too, but the compass (“orientation” in this app) is probably using a “cleaned” output that only measures the envelope of the signal, thus only changing rather slowly. Either way, the sensor is pathetic:
As Android developers should already know, it doesn’t matter what physical sensors a smartphone has, as the API can also access virtual sensors creating as a “fusion” of several true sensors. Software-available motion sensors include:
- TYPE_ACCELEROMETER (including gravity)
- TYPE_LINEAR_ACCELERATION (excluding gravity; it requires a gyroscope)
- TYPE_GRAVITY (along each axis; it requires a gyroscope)
- TYPE_GYROSCOPE (rate of rotation around each axis)
- TYPE_GYROSCOPE_UNCALIBRATED (without drift compensation)
- TYPE_ROTATION_VECTOR (around each axis; it requires a gyroscope)
- TYPE_SIGNIFICANT_MOTION (probably to detect a device in free fall)
Position sensors, both real and virtual, include:
- TYPE_GAME_ROTATION_VECTOR (using a gyroscope)
- TYPE_GEOMAGNETIC_ROTATION_VECTOR (using a magnetometer instead of a gyroscope)
- TYPE_MAGNETIC_FIELD (magnetometer)
- TYPE_MAGNETIC_FIELD_UNCALIBRATED (without hard iron calibration)
- TYPE_ORIENTATION (Azimuth, Pitch, Roll)–deprecated since Android 2.2
- TYPE_PROXIMITY (a Hall sensor can show the distance; “near” and “far” can also be implemented using the touchscreen or the ambient light sensor)
Three physical sensors–implemented in one or two chips–are enough to create all but the last of these virtual sensors through software. By the way, Sensor Kinetics is another useful app, should you want to know how your physical (“Three Dimensional Sensors”) and virtual (“Derived 3D Sensors”) are implemented. It lists “Gravity Sensor” (TYPE_GRAVITY), “Linear Acceleration” (TYPE_LINEAR_ACCELERATION) and “Rotation Sensor” (TYPE_ROTATION_VECTOR) as derived 3D-sensors.
But basically Pokémon Go requires TYPE_GAME_ROTATION_VECTOR, which needs a gyroscope–something my phone lacks. I don’t miss a gyroscope, and I am already annoyed that the compass needs to be calibrated every now and then. I’d rather find a barometer and a hygrometer useful, although based on how inaccurate and jerky can be a cheap sensor’s readings…http://ludditus.com/2016/07/15/on-smartphone-sensors/http://ludditus.com/ludditus/wp-content/uploads/2016/07/giroscop-600x360.pnghttp://ludditus.com/ludditus/wp-content/uploads/2016/07/giroscop.pngTechnicalastutenessAs Pokémon Go is taking over the planet, some people have discovered that their cheap smartphones are lacking a gyroscope–although smartphones that have at least 2 GB of RAM and Android 4.4 or newer (Pokémon Go's requirements) should normally include a gyroscope, but Huawei P9 lite doesn't. And I...BérangerBéranger firstname.lastname@example.orgAdministratorHomo Ludditus