Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compass returning inaccurate readings #16

Open
RebelliousX opened this issue Jun 25, 2012 · 7 comments
Open

Compass returning inaccurate readings #16

RebelliousX opened this issue Jun 25, 2012 · 7 comments

Comments

@RebelliousX
Copy link

It seems the compass semi working If I hold the phone in landscape orientation, but doesn't give correct reading. It has been like that since I flashed CM7, I thought it could be magnetic interference.

Z-Device test app shows that Magnetic field Z is way off and even doesn't show on the graph (oscillator, liner or whatever it is called)

Calibrating the compass doesn't change anything. I used different apps all of them the same. It used to be working fine before when I was using Valhalla, if it wasn't just calibrating it would suffice to make it work. But now I can't :/

Google maps doesn't rotate correctly when I start moving in compass mode too..

@maxfierke
Copy link
Member

Can anyone else confirm this is an issue on CM7 or CM9 or both?

@Comp-X
Copy link

Comp-X commented Jun 28, 2012

I can confirm this occurs in maps also and did not occur in Valhalla. I am also unable to calibrate it out and everything else save the compass is working flawlessly. Compass is way off and I believe my GPS is also suffering from these incorrect readings put out by the compass. I can only sometimes get a lock but it still gets with in 30 meters.

@RebelliousX
Copy link
Author

I also upgraded to CM9, still the same.

Also, when I use Compass app made by Catch. As soon as I run it, it displays a message saying that Compass
readings is way off.

@RebelliousX
Copy link
Author

Recently, I noticed that if I hold my phone while the screen is facing the ground above my head, the compass will respond to the moving and rotation of the phone, but still gives incorrect readings. If the screen is facing the sky the compass is stuck at fixed point.

Dunno if it has anything to do with accelerometer affecting it. seems like one of the axes is flipped, I think it is the Z axis. I could be wrong though.

@RebelliousX
Copy link
Author

Latest Changes in official CM9 upstream should fix the Compass, but it doesn't
The compass almost works if the screen is facing the ground, and fixed (that is, not moving) if facing the sky.

Sensor: Add RotationVectorSensor2

Some ICS apps (namely, Google Maps) expects a rotation vector to be
available. Newer devices, this is provided by either Android's
sensor fusion (requires Gyro) or by hardware sensor fusion (MPL).

Older devices will lack this virtual sensor and compass in Google
Maps will not work. To fix this, we can provide our own rotation
vector sensor by converting the values from the orientation sensor.
(They are basically the same information in different formats.)

Thanks to Unhelpful for the help with related math.

Change-Id: I596f5dc44f8797bc280ae5d1e110bb92387c79d1

http://review.cyanogenmod.com/#/c/14609/

Here is a dump of logcat.
http://pastebin.com/vVXTba2B

as you can see, starting from

09-04 02:36:47.496 I/Compass (9642): Compass onCreate

there is

09-04 02:37:29.785 I/Compass (9642): Magnetic Declination: -3.5207634; Expected Field Strength: 54.27791
09-04 02:37:29.785 I/Compass (9642): Lower Abnormal Field Limit: 19.737421; Upper Abnormal Field Limit: 149.26425

I don't call my self expert in Android's world, but correct me if I am wrong or ignore my rants about the code.

I am not saying the following is wrong, since the code is used for many other devices, but it looks weird to me,
CompassSensor::enable(int32_t, int en) A function in CompassSensor.cpp called 3 times. This function uses the private data member mEnabled
without being initialized, as it seems from the constructor the line was commented out to set it to false. Further it was used also in readEvents(sensors_event_t* data, int count) function. I noticed, the person who wrote this code before is using
mEnabled and mHasPendingEvent interchangeably, in my opinion. I could be wrong here.

Also I suspect the latest changes from m4xm4n in this file about setDelay
has something to do with this.

// Kernel driver only support specific values
if (ns < 20000000L) {
val = 1;
} else if (ns < 60000000L) {
val = 20;
} else if (ns < 200000000L) {
val = 60;
} else if (ns < 1000000000L) {
val = 200;
} else {
val = 1000;
}

LogCat shows

CompassSensor::~setDelay(1, 200000000) val = 200

I wonder if delay value supposed to be 60 not 200.

@fbis251
Copy link
Member

fbis251 commented May 22, 2013

Can someone else test this possible fix? It's been mostly working for me since I just restored the old KJ6 driver for compass. I've tested it under AOKP 4.0.4 and it works fine in Google Maps and GPS Test although it's a bit laggy.

fbis251/android_kernel_galaxys4gmtd@78cd493

@Fluidification
Copy link

i am building; will try

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants