Using CyberAtom AHRS with Raspberry Pi

This tutorial demonstrates how-to use CyberAtom AHRS device as an orientation sensor with Raspberry Pi.

We will use two example C applications that come with CyberAtom SDK for Raspberry Pi to retrieve system details and quaternion information from connected AHRS device.

Equipment

You are ready to go if equipment is:

  • Raspberry Pi with Raspbian installed. This tutorial was written against Whizzy port,
  • PC running Linux as a host operating system. This tutorial was written with Ubuntu 14.04 used,
  • CyberAtom AHRS device (e.g. X-200 or X-201),
  • cables - depending on you connection

Connectivity

There are few ways on how you can connect CyberAtom device to Raspberry Pi:

  • Using single USB cable between Pi and AHRS device (X-200 only),
  • Use USB-to-serial adapter connecting UART port of CyberAtom device with USB socket at Pi,
  • UART port of CyberAtom connected to native UART port of Pi using bunch of prototyping cables,

Network Connection

This tutorial uses headless operation of the Raspberry and SSH is used to access Raspberry console. Hence you also need a network connection between Raspberry Pi and your host system.

Getting SDK

Now when you have everything completed, you can downloaded latest CyberAtom SDK for Raspberry Pi (Raspbian). At the time of writing, this was version 1.1.0.

Unpack SDK archive content to `sdk` directory in your home directory on the host machine.

Power your Pi on, wait until it boots to Raspbian.

From the host PC use rsync to transfer SDK to your home directory on Raspberry Pi:

$ rsync -a ./sdk pi@YOUR-RASPBERRY-IP:/home/pi

Configure Raspbian

As a next step you can open SSH session to it from your Linux machine:

$ ssh pi@YOUR-RASPBERRY-IP

Note: From now on, the console commands displayed are executed on SSH session of Raspberry Pi.

Building Examples on Pi

The example applications as they are shipped in SDK run out-of-box for direct USB connection between Pi and USB-enabled CyberAtom device like X-200. Controlling X-201 and devices that communicate with serial port is described later down.

This is the simplest connection, using USB cable:

If you have this connection type, you need to configure Raspbian system a bit to enable proper communication:

$ cd sdk/
$ chmod +x configure.sh
$ ./configure.sh

You should be able to see it's USB device details (including values for iManufacturer , iProduct and iSerial fields by executing command:

$ lsusb -v -d ffff:0002

The values foe these fields should look like that:

iManufacturer : Softexor
iProduct : CyberAtom X-200
iSerial : <some numbers> 

Note: if you see the device listed with lsusb but you don't see these values, likely permissions is the problem. Double check that you've successfully run configure.sh script, re-connected device after. You may also try to repeat the lsusb command with root privileges.

Now, you can compile the example application:

$ cd c/examples
$ make

This will give you two executables: `identify` and `quaternion` in working directory.

If you run:

$ ./identify

You should be able to see on a console:

Model: X-200, Firmware: 1.1.0

(or similar depending on your device model and firmware version). If you get this - that means everything went well and you have Raspberry Pi ready to control your CyberAtom device.

Getting Orientation Data

Running the `quaternion` executable will print you quaternion data reported by the device during its operation
that represent spatial orientation of the device in 3D space.

$ ./quaternion
Q: 0.465193, -0.416492, -0.750455, -0.208748
Q: 0.463257, -0.418047, -0.749650, -0.212800
Q: 0.467000, -0.422159, -0.745716, -0.210307
Q: 0.449308, -0.426554, -0.755653, -0.204425
Q: 0.405544, -0.433847, -0.785184, -0.165601
...

Using Other Connection Types

When using other than direct USB connection type as above, each example code needs to be re-edited just a bit to reflect connection method applied.

We're going to change the line where connection object is being created:

IConnectionHandle connection = UsbConnection_create(&e);

If you're using UART-to-USB adapter to connect CyberAtom to Pi and your connection looks like that:

then you create logical connection in your code with:

IConnectionHandle connection =
SerialConnection_create("/dev/ttyUSB0", 57600, &e);
	

Normally, when using UART-to-USB adapter, CyberAtom becomes accessible over /dev/ttyUSB0 device. If you have difficulties with accessing, double check to which device your adapter is being mapped to, e.g. by checking logs using dmesg command. It could very well be /dev/ttyUSB1 or /dev/ttyUSB2 etc.

A simpler alternative is to use UART-to-UART connection between built-in UART port of Raspberry Pi and CyberAtom device, like this one:

For that, you need to ensure that this serial port is not used by the Raspbian for logging.

To do so, as a superuser edit /etc/inittab file and comment out the last, usually, line with /dev/ttyAMA0 port usage configuration, then reboot the system.

When ready, you can change the example code line to use Raspberry Pi built-in serial port:

IConnectionHandle connection =
SerialConnection_create("/dev/ttyAMA0", 57600, &e);

That's it! You can re-compile your examples with `make` and run it same way as described above.

Example lines of code presenting how-to create logical connection utilizing serial port assume your CyberAtom device operates with default 57600 bauds. If not, adopt these values to a proper one.

Summary

A spatial orientation data is probably the primary output you are interested when using CyberAtom device as a 3D orientation sensor.

Source code of both examples: `identify` and `quaternion` explains typical steps to connect and retrieve that information from CyberAtom device using high-level API. Alternative representation of sensor's orientation, in form of Euler angles, is available using just slightly different request/callback functions.

You can get more details on how CyberAtom API works and what other means of control you have over the device by reading the documentation as included in SDK package.

If programming in C is not your strongest preference, you may want to pick from other supported languages like Python or C#.

C++ examples can be compiled on your Raspberry as long as installed g++ compiler supports C++x11 features. You need to have 4.8.3 or greater version. If you don't, there are two options: upgrade your g++ compiler on Raspberry (e.g. some hints are here ), or cross-compile the C++ example application on your host machine using compilers from cloning git repository git://github.com/raspberrypi/tools.git .