Skip to content
This repository has been archived by the owner on Jul 23, 2020. It is now read-only.

main: Add IIO buffering compass support #15

Closed
wants to merge 3 commits into from
Closed

main: Add IIO buffering compass support #15

wants to merge 3 commits into from

Conversation

elad661
Copy link
Contributor

@elad661 elad661 commented Mar 24, 2015

This (kinda) works on the thinkpad twist, with the only issue is the values returned from the compass are not even remotely accurate :)

The numbers returned from the compass are always larger than 360 (at least on my device), and they never show the correct heading.

(I initially thought calculating it manually from the magn_x and magn_y channels would work better for me, but it turns out they're less accurate and I was reading the numbers wrong)

I also tried using the scale value the sensor has, but that's even worse - the scale is 0.000001, which is very unhelpful... I think it is very likely that the hardware I have is just plainly bad, and that the code itself works as intended.

@hadess
Copy link
Owner

hadess commented Mar 25, 2015

Can you contact the linux-iio mailing-list to talk about the units and values reported by the driver? I couldn't find anything useful in Documentation/ABI/testing/sysfs-bus-iio

Elad Alfassa added 3 commits April 17, 2015 15:36
In most IIO sensor types, _scale and _offset is added to the scan element base
name, for example:
in_accel has in_accel_scale and in_accel_offset

For compasses, this is different. Instead of being named
in_rot_from_north_magnetic_tilt_scale aand similar, the _scale and_offset
attributes are named in_rot_scale and in_rot_offset.

This commit adds a workaround to special-case the attribute naming for this
type of sensor.
@elad661
Copy link
Contributor Author

elad661 commented Apr 17, 2015

Sorry for the long delay.

I've split up the commits as requested and fixed up the indentations errors.

I also figured out that to get the actual value in degrees out of the compass all I had to do is to divide it by 10, and changed heading to int because I don't think fractions of degrees would be useful for anyone.

@hadess
Copy link
Owner

hadess commented May 19, 2015

I would actually prefer to keep heading as a float. Heading is a gdouble in geoclue:
http://cgit.freedesktop.org/geoclue/commit/?id=6808be68f3f3f07bd98a47099d66d49f85dfbf37

About the "divide by 10", that value should be in one of the sysfs files, see the "Find the scale" section in iio-buffer-utils.c

@elad661
Copy link
Contributor Author

elad661 commented May 19, 2015

It would make sense the scale would be in the sysfs files, but it's not... in_magn_scale and in_rot_scale both return 0.000001

if it helps I can ask why it's like this on the iio mailing list.

@hadess
Copy link
Owner

hadess commented May 19, 2015

That would be helpful, yes.

@hadess
Copy link
Owner

hadess commented May 19, 2015

Note that you'll also need to:

  1. add a .set_polling driver method
  2. add support for compasses in monitor-sensor.c

@hadess
Copy link
Owner

hadess commented Jun 3, 2015

Merged with plenty of fixes from Zeeshan and myself. Will follow up on the couple of TODO items in other issues.

@hadess hadess closed this Jun 3, 2015
@zeenix
Copy link
Contributor

zeenix commented Jun 3, 2015

👍

Thanks. Me and Matthias tested on the only hardware we had at hackfest and seems the value we were getting was out of scale (16xxxx something). Looking at the code, it seems we still need that to be fixed in the kernel? It's been a long time since I did any kernel programming but I could give it a go if I had the hardware. :(

Oh and it seems you want geoclue to transform the magnetic to true heading. :) You found some formula somewhere to do that, right?

@elad661
Copy link
Contributor Author

elad661 commented Jun 3, 2015

@zeenix I found a Python implementation: https://github.com/cmweiss/geomag/blob/master/geomag/geomag/geomag.py

It seems to use the magnetic model from NOAA: http://www.ngdc.noaa.gov/geomag/WMM/

@elad661
Copy link
Contributor Author

elad661 commented Jun 3, 2015

@zeenix I also found a C implementation (which seems to be under public domain): http://www.ngdc.noaa.gov/geomag/WMM/soft.shtml

@zeenix
Copy link
Contributor

zeenix commented Jun 3, 2015

@elad661 👍 Interesting! I'll look into them. The python code went quite above my head though. :)

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

Successfully merging this pull request may close these issues.

None yet

3 participants