TUTORIAL: Interacting with Movella XSense IMU sensor in C++

Inertial measurement unit (IMU) sensor is important for global navigation satellite system (GNSS) based positioning, velocity and timing (PNT) solutions.

TUTORIAL: Interacting with Movella XSense IMU sensor in C++

Inertial measurement unit (IMU) sensor is important for global navigation satellite system (GNSS) based positioning, velocity and timing (PNT) solutions.

With an IMU sensors, many advantages to improve the accuracy and integrity of a PNT solutions can be obtained.

For example, with IMU sensors, PNT solutions can be verified whether the given solutions are spoofed or authentic. That is, PNT integrity can be verified.

Other examples for the use of IMU is to implement vector tracking algorithm where the code delay and Doppler frequency in the tracking process are the function of user velocities (and also positions). As well as to improve PNT solutions by combining GNSS and IMU sensor measurements. Of course, other advantages can also be obtained by integrating IMU sensors in our GNSS-based PNT solutions.

In this post, we will present a quick practical tutorial on how to integrate the application programming interface (API) from a XSens IMU sensor (from Movella) into a C++ program.

Figure 1 below shows an example of rugged XSens sensor with in-built casing that house the IMU sensor.

By the end of this post, we will be able to set all the API libraries of an XSens IMU sensor as well as to connect and receive data from the IMU sensor.

In this tutorial, we use Microsoft Visual Studio 2017 version and the connection between the XSens IMU sensor and a PC uses USB interface.

Figure 1: An example of XSens IMU sensor used in this tutorial.

READ MORE: Real-time decoding of NAV messages of Septentrio receiver in C programming language


Amazon #Ad - associate link

Setting the XSens API in visual studio C++

The first thing to do is to install the software (Movella software suite) into a PC that we want to use to connect to the XSens sensor.

This software suite installs both the USB driver and the API files used to connect C++ with the XSens IMU sensor. The software suit can be downloaded here.

The XSens API to be used for windows-based C++ programming can be found in “MT Software Suite” installation folder.

The APIs (the “include” and “lib” as well as “dll” files) can be found in:

  • For 32-bit application: folder “MT SDK\Win32\”.
  • For 64-bit application: folder “MT SDK\x64\”.

In this tutorial, we are using 32-bit applications. Hence, we will use the APIs found in folder “MT SDK/Win32/”.

 Setting the XSens API “include” files

The include files are required to be able to compile our C++ code that uses XSens functions and classes.

Figure 2, figure 3 and figure 4 show the steps on how to set or integrate the XSens API “include .h” files into the C++ integrated development environment (IDE).

Note that we set the include files for the “Release”. If we want to work on the “Debug“ mode, we need to set the configuration (figure 3) as “Debug”.

Figure 2: Properties option to set the include and lib files in the visual studio IDE.
Figure 3: The option to set the include path for the XSens “.h” include files.
Figure 4: The option to find the folder where the XSens “.h” include files reside.

Setting the XSens API “lib” files

The “lib” files are required to be able to link the compiled code (.obj) to be an executable file. Without integrating these lib files, the code can still be compiled into an object file but cannot be linked to produce an expected executable file (linking error).

Figure 5 – 9 show the detailed steps of setting the XSens API lib files into the C++ IDE.

Note that in the presented steps, we are using the IDE settings to integrate the lib files.

However, there is another way to integrate the lib files by using “pragma” directive written in the C++ code, such as

#pragma comment(lib, "xsensdeviceapi32.lib")
#pragma comment(lib, "xstypes32.lib")
Figure 5: Option to set the path for the XSens API lib files.
Figure 6: option to find the folder path for the API lib files.
Figure 7: Option to insert the name of the lib files to be included in the linking process.
Figure 8: the API lib files that need to be included.
Figure 9: The list of the included lib files.

Copying the XSens API “dll” files

Finally, the dll files are required to be able to run the executable file produced from the C++ code compilation and linking processes.

These dll files need to be copied into the same folder where the executable file resides. The required dll files are shown figure 10.

Figure 10: The dll files that need to be resided in the same folder of the executable file.

READ MORE: Reading raw binary IQ data in C/C++ with malloc() and pointer


Example C++ codes to control and receive data from XSense IMU sensor

The basic example code can be found in the Movella XSens software suite installation folder.

The full basic example code can be found in:

“MT SDK\Examples\xda_cpp”

And the filename is:

“example_mti_receive_data.cpp”

This section focuses on how we can run the code by using a correct setting in the C++ code.

In this post, important note about common problem to run the example code is presented and the solution given.

By default, the given example code has this snippet of:

XsPortInfoArray portInfoArray = XsScanner::scanPorts();

But there will be a problem in this example as the baud rate is not well defined.

The solution is to manually adjust the baud rate to be the same as the PC COM port baud rate and is minimum of 115000 bit per second. The corrected snippet will be:

XsPortInfoArray portInfoArray = XsScanner::scanPorts(XBR_115k2, 500,false,false);

To set the baud rate of the PC COM port, we need to set it at the COM port assigned in the “device manager”. This baud rate setting is shown in figure 11.

Figure 11: the option to set the baud rate on the COM port used by the XSens.

Another option is to set the baud rate parameter “XBR_115k2” to “XBR_Invalid”. By using this parameter, the API will automatically scan possible baud rates to establish a connection to the XSens IMU sensor.

The output of the example code is shown in figure 12. In figure 12, the quaternion and angular rotation data obtained from the IMU sensor are shown.

Figure 12: an output example of the program receiving IMU data from the XSens IMU sensor.

READ MORE: The problematic aspect of number crunching in programming: Case study in GNSS calculations


Conclusion

In this very practical brief post, a tutorial for the API integration of Movella XSens IMU sensor into C++ programming environment has been presented.

This post focuses on the API integration as well as common setting problems (in the C++ code) to connect, control and receive IMU data between the XSens sensor and an application software written in C++.

Note that the additional include (.h) and library (.lib) path (the API) can be generalised for any external APIs that need to be integrated into windows-based C++ with visual studio IDE.


You may find some interesting items by shopping here.

Amazon #Ad - associate link