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

[new age] IMU support in runtime #668

Open
anastasiia-kornilova opened this issue Jul 18, 2021 · 1 comment
Open

[new age] IMU support in runtime #668

anastasiia-kornilova opened this issue Jul 18, 2021 · 1 comment

Comments

@anastasiia-kornilova
Copy link
Contributor

anastasiia-kornilova commented Jul 18, 2021

In new_age distro IMU sensors were moved from input-device interface to iio linux subsystem, therefore way of communication and event files locations were changed.

How now information from gyro and accel could be accessed?
By default everything related to iio is kept by path /sys/bus/iio/devices/iio\:device<N>. On TRIK board, device 0 is accelerometer, device 1 is gyro.

There are two ways to obtain sensor value:

Way 1 (default)
Read file responsible for every channel. For example, to read accel x-axis someone could use:

cat /sys/bus/iio/devices/iio\:device0/in_accel_x_raw

The same is for other sensor channels.

For our case, that is not the best way to collect all channels data from separate files manually and assign with proper timestamps, so the next method is more relevant.

Way 2 (buffers)
iio provides "buffer" support, which puts all chosen channels and corresponding timestamps to the buffer and then could be read and unpacked.

For that, someone should turn on buffer support and specify channels to put into the buffer

Code below enables buffer support and specify what channels will be available in the buffer. Code below enables buffer support and stores all accel values in the buffer.

echo 1 > /sys/bus/iio/devices/iio\:device0/buffer/enable
echo 1 > /sys/bus/iio/devices/iio\:device0/scan_elements/in_timestamp_en
echo 1 > /sys/bus/iio/devices/iio\:device0/scan_elements/in_accel_x_en
echo 1 > /sys/bus/iio/devices/iio\:device0/scan_elements/in_accel_y_en
echo 1 > /sys/bus/iio/devices/iio\:device0/scan_elements/in_accel_z_en

In order to properly unpack data, check corresponding flags of every channel -- its position in buffer and way of storage (https://www.kernel.org/doc/html/v4.14/driver-api/iio/index.html).

External libraries
Because iio encapsulates common and well-defined logic for every sensor type, maybe it is better to use already existing libs to read data from sensors instead of doing this manually. There are two common of them: libiio looks like the well-developed one.

This issue is about providing IMU data in runtime taking into account the new logic of interaction with IMU

@anastasiia-kornilova
Copy link
Contributor Author

Tiny example on C++ with QSocketNotifier on how to read and cast data from accelerometer buffer
trik-iio.zip

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

No branches or pull requests

1 participant