how to calibrate the orientation sensor in android? - java

I'm writing an app in Google Android 2.1 that needs to know which direction (n/w/s/e) the device (HTC Hero) is facing. The sensor and its listener are working great, but the values I get from the sensor are totally crappy. e.g. it tells me I'd be facing north when the device is facing SW or so...
This seems to be a known problem with android devices. The "solutions" I found on the web look like this:
shake the device around
move the device like an eight
tap on the devices back
This is thought to trigger the sensors recalibration. And: the thing with the "moving around" works for me... but that's not very professional I guess...
so - how do I trigger the recalibration of the orientation sensor from the SDK? I need the sensor to be properly calibrated without any fancy stuff that would make users of this app look like complete idiots while they are "manually" recalibrating their phones...
Is there any way to do this "right"?
EDIT:
Or: is there any way to determine PROGRAMMATICALLY, if the device is correctly calibrated or not? As a fallback-option so to speak... then I could warn the user that the device needs "manual" recalibration.

I don't believe there is a way to know programatically if you compass sensor is calibrated correctly unless you use a secondary data source like GPS. If you can use GPS then when the user is moving you can compare the GPS movement with the compass heading and correct. Remember that local magnetic fields can screw up the compass readings and the devices has no idea if you are out in the middle of a forest or next to a transformer.
With these micro devices there is always a bit of skew you'll have to deal with. If you check the values for the accelerometer as well you'll see that at rest they aren't always returning 9.8 m/s^2 (or at least consistently between devices).
In your help you may just need to tell the user to rotate/twist their phone in a figure eight to reset the compass.

I assume you are referring to the Magnetometer inside the Hero.
Callibrating it is a tough one and will/should always require user interaction for a realiable callibration. There are seperate strategies to deal with that. You could ask users to hold there device in north direction and then recallibrate. If the users don't know where north is, you can ask them to direct zhe device towards the sun and based on location and time you can calculate where that is.
Leaving callibration aside, I would guess that your problem is that the readings you get from the sensor are inaccurate. Of course callibration is a prerequisite for accurate readings, but there are also other factors in play.
It is common practice to complement sensor data from one sensor with the data a different sensor to increase accuracy. You could use the GPS to determine a heading when the user is moving. If he's moving slowly however, this is inaccurate as well. You could integrate the data reported by the Accelerometer to guess about orientation changes (not the absolute orientation). But honestly a Gyrometer would be more ideal in this case.
Systems that work like this are sometimes called Inertial Navigation Systems (INS) because they can, given a fixed point in space, determine their subsequent relative position and orientation accurately without further external data. Using a Kalman filter is common practice to recallibrate the system from time to time when an absolute position (e.g. retrieved via GPS) is available.
Although it is unrealistic to implement a full-fledged INS, you can certainly draw a few ideas from how they work to make your orientation readings more accurate.

Related

How to find the distance between bluetooth devices

Description :
I'm trying to find a way to calculate the distance between the application, and nearby Bluetooth devices.
That, or only detect devices that are x meters away from the device with the application.
Tried so far :
I tried using the Bluetooth's signal strength, but it is not reliable, as it has so many variables other than the distance (rotation of the device, objects between the 2 devices, etc). For example, I kept an eye on a device that was still on a table, and the numbers went up by 10 mBw without neither of the devices moving.
I also thought of using GPS for distance calculation, but GPS's accuracy is vary big compared to the accuracy I'm looking for (+-1m).
I look for lowering the strength of the Bluetooth signal before searching (on newer Bluetooth versions), to find less devices within a lower range. But the people who have tried it say it is unreliable because even at the lowest energy for Bluetooth, the Bluetooth was able to find devices that are about 10m away.
Examples around us :
If anyone has an Apple Watch and a Mac, they'd know that it is possible to unlock your Mac by simpley being close to your Mac while wearing your Watch.
Also, car keys. When you get close enough to the car while carrying the key on you, the car is unlocked.
Notes :
Assume all the devices are Android devices with high their hardware. It's a special implementation, not for everyone
A good discussion of techniques for calculating distance using Bluetooth devices is here: https://vimeo.com/171186055#t=40m15s.
With respect to the Apple Watch and Mac, Apple is using Time-of-Flight via peer-to-peer WiFi to determine proximity at that level of accuracy.
Typical automatic remote keyless entry systems utilize radio pulse, not bluetooth. More advanced systems, like Tesla's Phone key, uses Bluetooth on the phone device, but relies on the driver to physically touch the door handle to complete the process.
This might be possible but not much accurately.
You should approach to it like this:-
You should measure the signal strength, and then measure the distance using the speed of bluetooth (it usually travels 1cm in 100ps). Timing it would be difficult though.
Then, using the data you can easily measure the distance ( it is usually less that 10 m but can go farther).
You would get an answer but it would be really an approximate one.
As per me, the exact measuring is not possible.

Know when phone enters building on android device

I was wondering if there is a way for me to detect if the users device is being "obstructed" by a building or roof of some sort. Im developing a very precise location based app and its KEY that my users get alerted if something is wrong with there GPS or something is getting in the way. Physical object.
EDIT: The app ive created strictly takes snapshots too its not something thats constantly going. Just a quick snapshot.
Not directly. You can try calling LocationManager.getGpsStatus and iterating over the list of satelites every so often and looking for a jump in signal to noise ratio since the last reading. Getting a working algorithm is going to take a good amount of work and testing on a variety of devices with different GPS chips.

GPS Location Tracking

I would like to implement GPS Tracking service. After a search on the web I'm still a bit confused on the best way to practice this feature.
I want to start following the user when he gets a mile away from his home.
I thought that the app will be installed at user's home and using:
locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
I'll get the user's coordinates and compare it with changing coordinates as he travels.
When the user gets away a mile from his home I'll send SMS messages with his maps location every predefined time interval.
I was wondering if there is someone who done something similar before and can recommend a best practice for this task.
Also, how accurate the GPS can be, and what might be the best practice to get distance?
Thanks in advance.
From my experience it is not a good idea to use GPS all the time to track when a user departs from his home location because it burns the battery in no time. I ended up learning the home location by looking at the cell tower IDs over night (assuming the user is at home then). If you reach a certain level of confidence that you know the user's home location you can ask him something like "Are you at home right now?" to be completely sure (although this is somehow creepy for many users).
If you follow this strategy you can start the GPS if the user connects to a new cell tower and save a lot of battery.
Regarding accuracy. You can get the accuracy provided with each Android.Location object. If you are outside, this is usually 5 or 10 meters. But be aware that there is only an 68% chance this value is correct, according to the documentation:
We define accuracy as the radius of 68% confidence. In other words, if you draw a circle centered at this location's latitude and longitude, and with a radius equal to the accuracy, then there is a 68% probability that the true location is inside the circle.
Be carefull, the getLastKnownLocation method will not necessary return the user home position.
You shoud rather get the current position. Most of the time, getLastKnownLocation is used to get a location quickly (avoiding heavy background work).
GPS accuracy depends on many factors:
Weather, quality of the chip, field, ...
But, most of the time, it's more accurate that the network provider.
Here a very good link : http://developer.android.com/guide/topics/location/strategies.html
You will learn a lot with that.

Mechanical safe-cracking using Android audio and orientation sensors

I’m writing an app that helps lock-smiths with safe manipulation, mainly by creating the charts they need on the fly. When trying to gain entry to a safe via manipulation, a detailed analysis of the "wheel-pack" is required and accomplished by charting the relative depth of a “fence” over a “gate”. If all gates are lined up on the pack, the fences lever will drop into the cam gate and the lock will open. If anyone’s interested in a much more detailed explanation, you can find an awesome treatment by Matt Blaze here (starting around 3.3): www.crypto.com/papers/safelocks.pdf
Making the charts is important, and all it really requires is accurately measuring two places on the dial over and over and over, and recording the dial distance between two sounds. So, say the “drop-in” point is between 10 and 15, a sound event might occur at 11.5 and 14.5, or the next time around it might occur at 12 and 15. The lock-smith makes a chart of distance between these numbers and looks for say, a narrowing of numbers, on a chart, or maybe just the lowest place on the chart.
I’m using an old-school radio-shack Telephone Pickup (suction-cup mic) via my Androids headphone jack, to listen for the sound events. And to precisely measure on the dial where the events occur, I’ve simple mounted the phone to the dial with velcro and use SensorManager to figure the distance between the sounds based on how far the phone has been rotated from audio spike-event to spike-event. Which is fine, but I’d like to do it without mounting the phone to the dial. A couple companies used to accomplish it by having a webcam look at the dial itself, but that seems much less accurate than just mounting the phone as I can get more precision using fractional degrees of rotation.
Once you enter the drop-in location, you always will hit one sound, then backup the dial to the next sound, so I was thinking I could simply, listen for the sound event, and then once the dial reverses direction measure to the next sound event, but this would require that the dial move at constant, which won’t happen in real-life. And I guess I could do it by using a dynamixel or servo to move the dial for the locksmith, but again, not a good solution. So my question is if any of you smart folks can think of way that these related rates (distance between sound events and change of dial position) can be quantified without mounting the phone to the dial?
Not a full answer but a few of ideas I can throw at you:
from a control systems engineer point of view I can tell you that the way to accurately measure a rotation without direct access to the shaft is with an encoder.
So maybe you can use Android accessory mode to read an encoder (through an Arduino) that you'll mount on the dial (probably placing a rubber disc on the encoder shaft and touching it against the safe-dial).
This whole effort would be just to avoid sticking the whole phone to the dial and gain some extra precision.
A different approach could be to attach something else on the dial that would generate click noise that you could filter on the sound to differentiate from the safe sound. But that would definitely lower your precision.

Android Camera autofocus when user holds camera still

I'm sure most of you have used an android phone before and taken a picture. Whenever the user changes the mobile phone's position and holds it steady, the camera focusses automatically. I'm having a hard time replicating this in my app. The autofocus() method is being called only once when the application is being launched. I have been searching for a solution these past 3 days and while reading the google documentation I stumbled upon the sensor method calls (such as when the user tilts the mobile forwards or backwards). I could use this API to achieve what I need but it sounds too dirty and too complicated. I'm sure there's another way around it.
All examples on the internet which I have found only focus when the user presses the screen or a button. I have also gone through several questions on SO to hopefully find what I am looking for but I was unsuccessful. I have seen this question and that String is not compatible with my phone. For some reason the only focussing modes which I can use is fixed and auto.
I was hoping someone here would shed some light on the subject because I am at a loss.
Thankyou very much for your time.
Since API 14 you can set this parameter
http://developer.android.com/reference/android/hardware/Camera.Parameters.html#FOCUS_MODE_CONTINUOUS_PICTURE
Yes, camera.autoFocus(callback) is a one-time function. You will need to call it in a loop to have it autofocus continuously. Preferably you would have a motion detection via accelerometer or compass to detect when camera is moved.

Categories