From Delphi 2007 справочного файла:
ms-help://borland.bds5/devcommon/variables_xml.html
, "Если Вы явно не инициализируете глобальную переменную, компилятор инициализирует ее к 0".
You need Low Pass Filter. There are explanation and simple algorithm on wikipedia
What have you tried? How many readings do you get per second?
I would suggest something along the lines of an average of the last X number of readings to get rid of the "jiggles" and throw away any readings that are wildly different from the current direction to stop any crazy "jumping" of values. Depending on how many readings you are getting, and how much averaging you are doing, your app may lose responsiveness.
The following link might be useful. http://www.chem.uoa.gr/applets/appletsmooth/appl_smooth2.html
If you do get a significant number of completely-wrong values, you probably don't want to just average them. You could try applying a median filter first - take N samples, calculate the median, and throw out anything more than +- some threshold value. You can apply a smoothing filter after that.
I got rid of most of the noise by just using a slower update time. I'm not sure if Android has a built-in filter for these, but it seems to stabalize a lot. Something like:
mSensorManager.registerListener(
mSensorListener,
mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION),
// SENSOR_DELAY_UI, instead of SENDOR_DELAY_FASTEST (or similar)
// seems to iron out a lot of the jitter
SensorManager.SENSOR_DELAY_UI
);
SensorManager offers:
SENSOR_DELAY_FASTEST
: get sensor data as fast as possibleSENSOR_DELAY_GAME
: rate suitable for gamesSENSOR_DELAY_NORMAL
: rate (default) suitable for screen orientation changesSENSOR_DELAY_UI
: rate suitable for the user interface