I am building an Android app (for version 8 currently) that uses the magnetic compass. In the application, I have added a check to confirm that the compass is currently giving accurate results and, if it is not, the user gets prompted to perform a 'figure of 8' calibration sequence.
In order to properly test this, I would like to UNcalibrate the compass, so that I can check that the calibration code is actually working correctly. Is there any way to do this reliably?
Related to compass calibration although that refers to a long superseded version of Android.
If you allow the device to sit motionless for a while (with your app not reading the compass), that may do it.
You also might bring something magnetic close to it to throw the magnetometer off.
My understanding of "calibration" is as follows: the hardware (or low level drivers) know that earth's magnetic field is uniform, hence length of resulting magnetic vector should be constant regardless of device orientation. If there is a second magnetic field which rotates with the device, the sum of the two fields will not be constant; they detect this and mathematically subtract out the second field by analyzing how the sum field is distorted. Waving in a figure 8 provides enough sample data at various orientations to accomplish this.
Related
As you all know when compass come near magnetic field its value got disturbance and it went away from its actual value. I have been working on a project in which i have to get device rotation with 95% accuracy. I have tried number of sensors which can be used to get device angle but all have some sort of external factors which make it un-useful for me to use in my case.
For example when i use TYPE_MAGNETIC_FIELD and i came closer to any magnetic thing or electric wires or even my laptop its value adds up error.
when i use TYPE_ORIENTATION (i know its deprecated) its value adds up a Drift Value after some time which makes it unreliable for me to use.
I have also used some other sensors to combine and make it to behave like compass without magnetic field but all of them either become unreliable with magnetic field or adds up some drift after some time.
I have read some of research papers from difference research institutes but i don't think anyone has ever produce rotation angle with 95% accuracy. I want to know if there is any way even with AI algorithm from which we can achieve this case? The end goal is to get a device angle which is 95%> accurate.
What I am trying for :-
I would like to find magnet using my android device.
What I have done yet :-
I am registering my sensor of type magnetic field like this
Sensor magnetometer = mSensorManager
.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
and in onSensorChanged(SensorEvent event) method I am getting x,y,z from event.value if type is magnetic field.
Upto this everything is fine, then I get absolute value from these three values using
Math.sqrt((x*x)+(y*y)+(z*z)) and I get one absolute value.
But I think this is something only related to device because when I keep one magnet closer to my device nothing happens(neither absolute value nor its (x,y,z) changes.
Thanks.
I'd guess your device does not measure your magnet but the magnetic field of the earth. And independent from the orientation of your device when you concatenate the values this way you always get back the same value. Except the returned value is always 0, then you simply measure nothing and it could be a hardware failure.
I am a newbie on Android development too and was interested in creating a similar app, where i get notified when a magnet is brought sufficiently near to my phone.
I used the same formula for calculating the net Magnetic Field, and if u refer to this Android Documentation on Sensor Managers here, u will find that MAX and MIN values for the Earth's Magnetic Field.
My app uses the same range to detect a magnet and it works fine. Depending upon the "promixity" you require, you can tweak the values as you wish.
In case, you don't notice any considerable difference in field values upon bringing a magnet closer, i think, that is some hardware issue.
I am needing to implement a shake recognizer, and I am using the accelerometer on the device to that. However, when I check the values I get from the sensor, it appears that they vary wildly from device to device. For instance, I get a value range of 0-8 as force (after some calculations) on one device, and on the other 0 - 4.
So it looks like they have very different ranges.
Is there anything I can do to make these ranges equal. Or are there some variables that I can use to somehow calculate what a fairly hard shake would be?
According to specification accelerometer should return Measures the acceleration force in m/s2. So it should be calibrated. One thing you could check however is the Sensor class's getMaximumRange() and getResolution()
The physical placement of the chip on the pcb and the securing of the pcb within the device and the construction of the device could all lead to different damping effects in responce to your shaking input force.
You don't say how your processing the sensor data there may well be effects related to sampleing and filtering performed at the driver level.
You clearly need to be flexible in your code with the range of values you expect and test on a good range of devices.
The sensor should be calibrated.
Apparently it isn't. If the gain in the different directions (that is x, y, z) is not significantly different then it is enough to look for sudden changes in the length^2 of the accelerometer vector: x^2+y^2+z^2.
If the gains are also significantly different then you have no choice but to write an app for accelerometer calibration...
By the way, you are not the first one to report gross inaccuracies, see for example Android: the range of z-value in the accelerometer sensor are different on different devices.
I'm making an application that works as a compass..
I'm using the accelerometer and the magnetic field sensors to compute the azimuth angle through, sensor.getOrientation().
I'm searching for something that can improve the magnetic field sensor accuracy, since I'm getting it state of accuracy as UNRELIABLE!
Any one knows anything about this?I'm looking for something that can be either hardcoded or for instance just physically moving the phone until it gets calibrated!
This is not a final answer (I don't know anything for sure), but my understanding from online posts is that waving the phone around in a figure of 8 a few times while the compass is in use is supposed to trigger automatic recalibration. This is what the google maps app suggests, for example. I don't know whether this is dependent on application functionality (something in maps that detects the waving by accelerometer and triggers a recalibration), or something in the android stack, or something specific to per-phone implementations. Try it and see!
Eg discussion: http://androidforums.com/epic-4g-support-troubleshooting/217317-cant-get-compass-calibrate.html
This reference appears to suggest this per-axis / figure-8 rotation process is built-in functionality: http://m.eclipsim.com/gpsstatus/
And here another article that claims this is built-in functionality, and that you don't even need to be running a compass-consuming app for the recalibration to work: http://www.ichimusai.org/2009/06/20/how-to-calibrate-the-htc-magic-compass/
Just a few points
The figure 8 motion works sometimes and not others, I have no idea why, they really need to have some kind of code based way to check if the 8 motion worked (Assuming that the physical motion is actually required)
They also need a way to detect that calibration is required, I looked at the code for the accuracy output (the unreliable constant) and once they send it to you they will not send it again, so for instance if you calibrate but then come within a strong magnetic field it will not resend (not sure why they did that)
One not completely reliable way to detect ongoing issues is that you can also use the magnetic sensor output and do something like field=sqrt(x*x+y*y+z*z) and check that field falls between say 25 and 65 and then ask the user to calibrate if it does not.
The bottom line after testing 18 phones is that I would never depend on a Android based compass with the current crop of phones, accuracy would always be in question.
I have also found even if you are lucky and have a fairly reliable phone you can never be sure that it's calibrated without checking it against a real compass, which kind of defeats the purpose.
NOTE: On a lot of the mis-behaving phones we have found that the sensor writes a calibration file and a tmp file with the same name. If you delete those files and re-boot the phones the calibration file is recreated with zero'd values and the cold start and general calibration problems resolve themselves.
The bad news is that they are stored in /data/misc and require root privileges to get at (thanks Google & Sensor mfg!) so even though I suspect this would solve a lot of problems for a lot of developers it just is not viable from a marketplace app perspective.
I am developing for Android. I'm using Titanium Alloy as development tool with the Titanium Geolocation module.
I have only tested 2 devices [Galaxy Note and S4] against a commercial magnetic compass. Following a calibration process [tilt along the 3 axis] and using 2 different compass apps and the app I'm working on, the Android compass seems accurate enough for basic use ... correlation was good enough for my purpose anyway. I also found the device compass reading to be very sensitive to other magnetic and electrical field interference ... initial mistake I made was to use the compass feature whilst device was in a device protector with a magnetic closure facility [quite common on tabs] ... this interference is particularly strong. I thus need to suggest to users of my app to remove device protectors, keep device free of other electronics and then do standard calibration before initializing the app.
Another option is:
Go To sensors menu: #*0#*
Then if you see a red line in Magnetic Sensor section and a Need for Calibration you should recalibrate your compass.
How;
According those guys;
Turn the Samsung Galaxy Mini S5 around all of its axes until the red
line in the black circle changes color from red to blue. You can also
run through a motion that follows the shape of an 8. It may be that
several attempts are needed to calibrate the compass...
I am trying to replicate how Google Skymap makes use of sensor inputs. I currently use getOrientation and the accelerometer values to determine up and rotation. This works fine whilst the phone is held perpindicular to the horizon, but starts to fail when pointing the phone towards the ground. for example when laid flat on a table, the readings used (accel_x) when spinning the phone does not affect this input, but when held perpindicular the values are useful and I am able to rotate the display based on the values.
(I currently display a basic horizon quad)
I am thinking that I need to make use of more than one value here but am quite at a loss of how to do it.
Any pointers?
Also, is there a 2.1 alternative to Display.getRotation?
Thanks in advance
Note: I am only interested in the roll (in the aviation sense) of the phone, regardless of the pitch in which it is held.