We deal with the errors of the accelerometer, gyroscope, M7, digital compass and other sensors in the iPhone 5S and not only



    Many have heard about the problem with uncalibrated sensors in the new iPhone 5S - the “level” tool built into the native iOS 7 compass shows a deviation of several degrees if the device is placed on a flat surface, for example, a table.

    In short, to one degree or another, the problem of sensor orientation has always been present on all iOS devices. Previously, the problem was not observed so often in view of the lack of a built-in mobile OS application that allows level measurement. A similar problem occurs on other mobile devices equipped with an accelerometer, since the principles are the same everywhere - every developer who has had to deal with various motion and orientation sensors should be familiar with this firsthand.

    I have been developing applications using accelerometer, gyroscope and digital compass sensors, exactly since the API became available to developers almost from the very beginning - as the author of one of the most popular iOS compasses, I encountered problems with calibrating the accelerometer and the accuracy of other sensors a few years ago.

    The way to solve the problem is quite trivial and has already been laid in most of both application and gaming applications that use gravity, motion and magnetic field sensors in one way or another - calibration, which any developer who respects himself and his users should take care of. Depending on how difficult the application is and what tasks it solves, from the technical point of view of the developer, the implementation of the solution can be both simple and complex. But the principle is the same for everyone.

    I invite developers and application users to figure out how it works, where these errors come from, why you don’t have to worry too much about accelerometer problems and why you don’t need to run to the store to replace a “defective” device - the new device is unlikely to be much better, but problems with sensor errors are solved in other ways.

    As it was

    more than four years ago, I was faced with the task of developing not an ordinary analogue of a two-dimensional compass, which was bundled with iOS, but a compass using augmented reality, functioning in three-dimensional space and with high accuracy of combining virtual labels superimposed on video in real time.

    To combine the virtual label of an object with its actual position in the picture received from the camera, you must use all motion sensors available in the mobile device.

    An accelerometer is needed to determine the gravity vector or, in simple terms, to find out which part of the device is looking down. A digital compass sensor or magnetometer is needed for orientation to the cardinal points, to find out which side the device is facing north. Later, a gyroscope appeared that determines the rotation of the device and, accordingly, allows to significantly increase the accuracy of full orientation in three-dimensional space.

    As the application developed and the opportunity to use new sensors appeared, the individual flaws inherent in the sensors almost immediately appeared.

    As it turned out in all the devices, the sensors give out unequal data, varying within a certain error, somewhere there are more deviations, somewhere less - while a variety of different non-obvious factors affect the sensor readings.

    The initial reaction of those who did not have experience in this area at that time was similar to that described in the articles about the incorrectly installed sensor in the iPhone 5S, but further study of the issues made me change my mind and continue developing without expecting that the manufacturer could and would fix something, but considering the features of each of the desired sensors.

    As a result, a fairly accurate tool suitable for real use was obtained from a high-tech toy with problems with accuracy - most importantly, you need to know how to use it correctly, which directly follows from the characteristics of each sensor, which I write in details below.

    Accelerometer

    Since, unlike the standard compass working in only one orientation, my application should have worked in any of the possible ones, already in the early stages, even before the appearance of the gyroscope, one very strange feature of the accelerometer was discovered.

    It turned out that in addition to the fact that in each device the accelerometer has a slight deviation, within the same physical device this deviation is different for different device orientations - for example, in the usual portrait orientation, the deviation from the real axis of gravity can be 1 °, while , when rotated 180 °, in an inverted portrait can be 4 °.

    The solution was to add the ability to calibrate the accelerometer separately for each of the six possible orientations, and the appearance of the gyroscope provided new opportunities - the calibration of motion sensors, respectively, in one form or another, is already available in every decent application that uses them.

    Game developers had to take it a little easier - in games it’s enough to support one or two device orientations, but it’s still impossible to just ignore the need to give the user the ability to use calibration even using a gyro sensor.

    In the "level" built into the compass of iOS 7, calibration is carried out simply by tapping the screen - just touch the screen and the current position of the device will be considered as the reference or "zero" position.

    Compass and GPS / GLONASS (although it would seem)

    Before the appearance of the gyroscope, the sensor responsible for the orientation in the horizontal plane on the cardinal points was the digital compass sensor - the most sensitive to external factors of all sensors and, accordingly, having the greatest problems with accuracy.

    The compass is calibrated continuously at the driver level as the device rotates - the more data the device receives, the more accurate the result will be, but there will still be an error.

    An absolute solution to the problem of compass accuracy, unfortunately, is almost impossible only with calibration. Although it improves accuracy. In iOS 7, the built-in compass has even more severe calibration than in previous versions of the OS. Now the calibration screen closes the entire screen until the user performs the necessary actions. In older versions, there was a small message that did not overlap the screen.

    Even compass calibration and constant data filtering will not particularly help in conditions of an inhomogeneous magnetic field - after all, after calibrating the compass, a person usually rotates around his own axis, and not around the device’s axis, which when rotated 90 ° shifts the device in space by about half a meter, where other magnetic conditions.

    Near strong magnetic fields, metal objects, live wires, the magnetometer readings are unstable due to the very high sensitivity to electromagnetic radiation - this is especially noticeable in rooms and machines, which are more and more modern the more and more they are filled with all kinds of electronic filling.

    In addition, if the compass is required to show geographical north, then the accuracy of determining the location with GPS and GLONASS comes into play, since the coordinates are used to determine the magnetic declination or the difference between the directions to the magnetic and server poles at a specific point on the globe.

    The magnetic compass works well and accurately on the street in field conditions where there is no magnetic interference - but even so, compass calibration is desirable with every azimuth measurement.

    The direction to the north pole is most accurately determined with good GPS accuracy, also usually on the street.

    To further improve the accuracy where it is needed, for example, if you need to correctly aim Wi-Fi or radio antennas at each other, or make any accurate measurements, you already need deeper support on the application side, as described below.

    Gyroscope, gyrocompass and car mode.

    In a room, in a car, in a boat or in any other vehicle, and also when higher accuracy and orientation stability are required, a conventional magnetic compass is not suitable - orientation is required either in the direction of travel or in the gyroscope.

    Accordingly, in my application I implemented both of these features - for use in various vehicles there is a “car” mode and a “gyrocompass” mode for everything else.

    With the car mode, everything is simple - the driving course is used, which depends only on the accuracy of GPS and GLONASS, and, accordingly, the direction is determined quite accurately while driving, on bicycles, cars, boats, airplanes and so on.

    With a gyrocompass, the situation is both easier and somewhat more complicated.

    In the gyrocompass mode, you can precisely set the initial one or correct the current direction using any external landmark - the sun, moon, stars, geographical objects, the mossy side of the tree, orient yourself using maps or using other methods.

    This is done simply for the user. The marker superimposed on the video in real time or the arrow pointing to the object on the compass dial is combined with the actual position of the object or with the direction to it. All complex math based on thousands of lines of formulas remains invisible at the application level.

    Approximately the same actions are performed by pilots or personnel serving modern military aircraft, ships - checking and subsequent calibration of inertial navigation systems is carried out at the beginning of the flight and during it, which is also facilitated by the fixed location of the sensors, while our mobile devices are almost in constant motion.

    It would seem that a gyrocompass is an ideal solution to the problem of compass accuracy and orientation to the cardinal points, but there are pitfalls here too.

    In industrial and military systems of inertial navigation, in contrast to what is today in mobile devices, a whole complex, an array of sensors are used to accurately determine the position in space, which allows you to compensate for errors and errors in the readings.

    In mobile devices, usually only one copy of each sensor is present, which makes error compensation impossible and leads to the accumulation of errors.

    The more time elapses from the moment of calibrating the gyrocompass, or rather, if you look from a technical point of view, from the moment of determining the reference "zero" position, the greater the accumulated error, which is expressed in the periodic displacement of the gyroscope orientation.

    The video below illustrates the problem.

    The compass in the “gyrocompass” mode is shot on the video. It is configured exactly to the server and is running on a device that is stationary on the table. Despite the fact that the device is stationary over time, a shift occurs. At 00:09 it shifts from 0 ° to 359 °. At 01:21 it decreases to 358 °. At 03:03 we already see the azimuth of 357 °.



    The accumulation of errors occurs due to the discrete nature of the sensors, which can miss events at some points, such as, for example, in the video above, the smallest vibrations of the power supply fans in the monitor and the computer located next to the table affect the gyroscope readings. Sensors, of course, progress with time, get higher resolution, but discreteness of data remains. Accordingly, such insignificant things as a heartbeat and pulse can influence the readings.

    Micromechanical systems of such sensors are also affected by such non-obvious factors as ambient temperature - although the temperature is not available to ordinary developers, it is taken into account to correct sensor data at the level of the OS drivers.

    In this case, the gyro orientation is much more accurate than the compass sensor - when turned 180 °, the sensor reports that the rotation was the same 180 °, not 150 °, as, for example, the compass can say under interference.

    It’s just worth keeping in mind that the gyro has such a feature and take this into account when using the device as a tool or when developing your own applications and games.

    But what about the new M7 motion coprocessor?

    With the announcement of the M7, I hoped that mobile devices would become closer to larger inertial navigation systems, but, unfortunately, this new coprocessor solves slightly different tasks.

    First of all, the M7 is designed to reduce battery consumption when using GPS and other sensors. Less time is spent on calculating data from satellites due to the fact that this calculation does not start from scratch when the application starts. Additionally, data from other sensors is collected in the background, even when the application is not running, which also helps to reduce battery consumption.

    For example, in a video illustrating the situation with the accumulation of errors in the gyroscope above, the compass in gyrocompass mode works on the new iPhone 5S already using the M7.

    Can I trust mobile devices?

    The answer is yes, knowing and considering the features of the sensors used.

    The developers will draw their own conclusions on their own.

    For users who were interested in reading to the end, I allow myself to give some advice.

    Change the device is not particularly necessary. It may not be better. And who said that the surface of the table used is strictly perpendicular to the gravity vector?

    In games with tactile control, if the error of the accelerometer or gyroscope is clearly noticeable, look in the settings or in the pause mode of the calibration menu.

    In all relevant applications that implement the “level” tool, there should be a calibration specifying a “zero” position - naturally, it is also in the built-in application.

    The magnetic compass only works well when hiking in nature. You should not expect from the device to accomplish the impossible trying to absolutely accurately determine the direction next to a computer, speakers, heating battery or in any vehicle. Use those specifically designed for this application and the modes that are most appropriate for the task.

    When using a magnetic compass, remember that the readings are relevant only immediately after calibration, until the device has been moved to any significant distance - turning 90 ° along the axis of the spine may already require re-calibration.

    When using applications such as “level” or “gyrocompass”, remember that the sensor readings are relevant for about one to two minutes, which is enough to take a measurement - to avoid the accumulation of errors, repeat the calibration before each measurement to increase the accuracy of measurements.

    PS Ovechayut questions in the comments.

    Also popular now: