Compass App
#1
Hi everyone,

My name is Leonardo and working together with my brother Marco we wrote a very rudimentary Compass app for the Pinephone with Python. To our knowledge, there is no such app available to date. Check the screenshot at the bottom.

We have tested the app in Phosh (Manjaro, Mobian and postmarketOS) and Plasma Mobile (Manjaro). For the moment it only works with "old" (a.k.a. pre-beta edition) Pinephones, which have the original magnetometer chip LIS3MDL. If it is not found, it will just display randomly generated values.

Currently the app is a proof of concept and not intended for daily-driving. That being said, you can get it and try it from

https://gitlab.com/lgtrombetta/pinephone-compass/

For best results, follow the suggestion in the Readme about changing the Sampling Frequency of the magnetometer. Take also into consideration the issue of calibration. We will try to come up with a tool to automatize these tweaks in the future.

We hope the app can be useful to some people. We intend to improve it over time, and of course, we are open to constructive criticism and contributions! Keep in mind though, that this is our first open source project, so please be kind.

Enjoy!


[Image: screenshot.png]


Changelog:

v0.3.1

* Preliminary support for the AF8133J magnetometer (Pinephone Beta edition). Needs custom kernel driver and patches.
* Advertise the app to Phosh as adaptive.

v0.3

* Complete project refactoring:
- Installation now handled by meson build system
* Complete GUI overhaul in GTK3 with:
- Magnetic field readings now shown under the compass card.
- Settings window with graphical calibration tool
- Dark/light theme switch
- About window

v0.2

* Automatic changing of the sampling frequency
* Calibration tool
* Major code refactoring

v0.1

*Initial Release
  Reply
#2
It looks great! Unfortunately I can't test it for now because I only have Beta Edition, but I might work on supporting Beta Edition for your app.

I actually created my own compass app to test my kernel about a few weeks ago. It is only for Beta Edition, but in case someone wondering, my app and kernel fork is here:
https://gitlab.com/awaittrot1/compass-pp
https://gitlab.com/awaittrot1/sunxi64-li...10-af8133j
  Reply
#3
Tested it now, by cloning the repository rather than downloading the release zip.

Looks good, but does not seem to work correctly. I have not tried any calibration. The arrow moves slightly, but points in approximately the same direction regardless of the rotation of the PP. I guess this could be a problem with my magnetometer though, I have not investigated the outputs from my magnetometer directly.

Manjaro edition pinephone, running Mobian. Had to do "apt install python3-matplotlib" to get it running.

Some suggestions:
  • Make the terminal output more readable on the small screen on the PP. Remove some decimal places, and perhaps print x, y, and z on separate lines?
  • Command line option to disable the continuous printing of the magnetometer data, in order for important status information such as the detection of the magnetometer, or loading of calibration data to be clearly visible.
  • It would be great if the application had the ability to set the sampling frequency automatically, but I am sure you already have this on your to-do list Smile
  Reply
#4
@awaittrot Thank you! We were not aware that there was another compass app around, certainly it was not our intention to duplicate effort. We'd be happy to collaborate to produce an app which can work on both versions of the Pinephone.

@threepwood Thanks for the suggestions. The terminal output was there for testing purposes but it should be pretty easy to streamline it a bit and add some arguments to make it more useful.

Indeed the calibration is very important and it is a top priority to write a tool to automatize it. The default values work for me but obviously this is very device-dependent.

About the sampling frequency, as it is now root access seems to be necessary to change it. I'm not sure yet what would be the best way to solve this, but I don't think that asking for permissions in the app each time is a good idea. Maybe somebody with more knowledge about Kernel Drivers and permissions can help here.
  Reply
#5
@threepwood I made the terminal output more readable. Check it out on the devel branch.

For calibration, take note of the minimum and maximum values of each of the raw measurements Bx, By and Bz, as you rotate your phone around each axis (try to do it on the same spot such that the total field intensity B remains roughly constant). Then, compute the average between min and max for each axis and those are the 3 numbers you should put in the compass.conf file.
  Reply
#6
Thumbs Up 
(06-24-2021, 02:58 PM)lgtrombetta Wrote: @threepwood I made the terminal output more readable. Check it out on the devel branch.

For calibration, take note of the minimum and maximum values of each of the raw measurements Bx, By and Bz, as you rotate your phone around each axis (try to do it on the same spot such that the total field intensity B remains roughly constant). Then, compute the average between min and max for each axis and those are the 3 numbers you should put in the compass.conf file.

Checked it now, looks really good.

As for the permission issue when changing the sampling frequency, one possibility is to use a Udev rule. I tried by adding the following to the file "/etc/udev/rules.d/90-accelerometer.rules":
Quote:ATTRS{name}=="lis3mdl", RUN+="/bin/sh -c 'chgrp -R iio /sys%p; chmod -R g=u /sys%p'"

After reloading the device (sudo udevadm control --reload-rules + sudo udevadm trigger /sys/bus/iio/devices/iio:device2) it belongs to the "iio" group, and any member of this group gets write permission to the "sampling_frequency" file.

Not sure if this is a recommended approach though, it would probably be better if this was added officially by the distro. Also I guess you could add some more attributes to the rule in addition to the {name}. For a list of the available attributes you can run:
Quote:udevadm info --attribute-walk --path=/sys/bus/iio/devices/iio:device2

Obviously by replacing 2 with whatever the device number happens to be.

Finally I would like to mention that there is a library "libiio", which I guess could be a convenient alternative to directly reading the files in the /sys directory. I do not have experience with this library myself, but thought I should let you know in case you did not know about it. Python bindings are available here: https://pypi.org/project/pylibiio/
  Reply
#7
(06-23-2021, 10:54 AM)lgtrombetta Wrote: H(snip)
For best results, follow the suggestion in the Readme about changing the Sampling Frequency of the magnetometer. Take also into consideration the issue of calibration. We will try to come up with a tool to automatize these tweaks in the future.(snip)
Firstly thank you!  this is an important basic app to have for daily driver pinephones.
I will put your git on the requested apps debian mobile wiki page!
https://wiki.mobian-project.org/doku.php?id=wishlist
secondly I was reading the hall sensor data sheet when I was having trouble passing the pre-install factory tests and it seems that there is an automated self-calibration feature?
(edit)
A degrees marked rotating compass card for the compass and a digital read of the heading would be nice(the needle is stationary and you read the number of your heading on the card , move the decimal one place left for degrees on aircraft directional gyro i.e 33=330)
[Image: ?u=http%3A%2F%2Fwww.cfinotebook.net%2Fgr...f=1&nofb=1]
If you want to get more interesting once the basic compass works well having a TACAN style rotating compass card and also a second needle for heading to beacon(a GPS 'pin') would be even cooler!  This would be ideal for inside a navigation app where I can run it as a HUD against the window at night and know my heading and the heading to a reference point just like TACAN.
[Image: ?u=https%3A%2F%2Ftse4.mm.bing.net%2Fth%3...%3DApi&f=1]
  Reply
#8
@threepwood thanks a lot! your udev rule works great Smile

I was actually looking into udev rules as a solution for this, without much success so far. I think it should suffice for now, I will add it as part of the setup, which will now require to be run with sudo, but then the app will be able to change the sampling frequency by itself.

I'll check out libiio.

@biketool I'm glad you find the app useful and thank you for including it on the list! Now we have more pressure to really improve it!

I will look into this self-calibration you mention, but I'm not very hopeful. My guess is that it should still require some manual intervention by the user, i.e. rotating the device. Then, there isn't much benefit. At least some basic tool for calibration is an immediate priority.

Thanks for the suggestions, as you say, once the basics are done I'll be happy to add more features!
  Reply
#9
For those interested, the current devel branch has automatic changing of the sampling frequency. You need to run the setup.py only once and grant it root access. From then on, the app will be able to set the frequency without needing root.

I'd appreciate if somebody can test this and let me know if it works.


UPDATE: now there is also a calibration tool available on devel! It will be run at the end of the setup but it can be also run manually: calibration.py.

If all of this works well I will bump the version to v0.2

UPDATE 2: Version 0.2 is now available.
  Reply
#10
Hi everyone,

Version 0.3 is now available!

The GUI is now made with GTK3 and it includes a graphical calibration tool. Also, the installation steps have changed since the project now uses the meson build system. Just follow the instructions from the README:

https://gitlab.com/lgtrombetta/pinephone-compass/
  Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)