Introduction
The Raspberry Pi is an ARM-based mini PC that is amongst other applications used for prototyping and development of robotics. In this article we will explain how to connect your Xsens MTi device to a Raspberry Pi, and how to easily communicate with it by using our MT Software Development Kit (MT SDK).
Raspberry Pi boards run on ARM Cortex CPUs, which means that they are not compatible with the regular Xsens Device API. Fortunately, Xsens has made a large part of the API open source, allowing users to develop applications for ARM-based platforms as well. Xsens provides C++ example codes as well as a ROS driver that make use of this open source API.
We have used the Raspberry Pi 4 Model B for this article, but the guidelines can also be used for other Raspberry Pi models. Xsens has tested the following motion trackers with the Raspberry Pi:
- MTi 1-series Development Kit (USB, UART)
- MTi 600-series Development Kit (USB, UART)
- MTi 10-series (USB)
- MTi 100-series (USB)
Setup
Start by downloading the latest MT Software Suite for Linux from our website and unpack the .tar.gz package at your desired location. Then, install the MT SDK:
sudo ./mtsdk_linux-xxx_xxxx.x.x.sh
This article will cover two hardware interfaces of the Raspberry board: USB and TTL UART. If possible, we recommend using USB as a starting point, to verify that your hardware and software can detect and communicate with external sensors. Simply connect your MTi to one of the USB ports of the Raspberry using the USB cable included in your Development Kit.
1. C++ example codes
Inside the MT SDK you will find an examples folder. Open it and navigate to the xda_public_cpp folder. You will find two example codes:
- example_mti_receive_data: Scans for, and connects with MTi devices, configures their outputs, and prints/logs the received data.
- example_mti_parse_logfile: Opens a .mtb log file and parses its contents.
In this folder, open a terminal and build the example codes:
sudo make
Note: If you are using the MTi 10-series or MTi 100-series with a direct USB cable, make sure to have libusb installed, and build the examples using:
sudo make HAVE_LIBUSB=1
You should end up with two executable files, one for each example code. Upon executing example_mti_receive_data your connected MTi should be detected automatically. We refer to the Troubleshooting section of this article if the MTi is not detected.
2. ROS driver
Inside the MT SDK you will find the xsens_ros_mti_driver. Simply follow the README.txt file inside this folder or our guidelines at http://wiki.ros.org/xsens_mti_driver to install and launch the ROS driver. Your MTi should be detected automatically, and a variety of data topics are available to subscribe to. We refer to the Troubleshooting section of this article if the MTi is not detected.
Note: the ROS driver publishes data, but unlike the C++ example code, it does not actually configure the outputs of the MTi. Use the C++ example code or a PC with our GUI MT Manager to configure the MTi such that it outputs the data that are required for your application.
Serial hardware interfaces
Next to the plug-and-play USB interface, Raspberry Pi boards offer various other interfaces that allow you to communicate with MTi devices. For this article we used the mini UART interface that is accessible via the GPIO pins 14 (TXD) and 15 (RXD). We also used the 5V/3V3 and Ground pins to power the MTi.
Note: The configuration and availability of the UART interface varies between Raspberry Pi models. For this article we first had to enable the mini UART. Refer to this article for more information.
Note: The UART interface of an MTi 1-series Development Board will be disabled when the board is powered at 5V. Use the 3.3V output of the Raspberry instead.
In Ubuntu, this UART port will show up as /dev/ttyS0. By default, the ROS driver and C++ example code do not scan this location. Fortunately, it is easy to modify the source code such that it scans for your specific location:
Open example_mti_receive_data.cpp (in case of the C++ example code) or xsens_ros_mti_driver/src/xdainterface.cpp (in case of the ROS driver) and replace the following lines:
XsPortInfoArray portInfoArray = XsScanner::scanPorts();
XsPortInfo mtPort;
for (auto const &portInfo : portInfoArray) { if (portInfo.deviceId().isMti() || portInfo.deviceId().isMtig()) { mtPort = portInfo; break; } }
with
XsPortInfo mtPort = XsScanner::scanPort("/dev/ttyS0",XBR_230k4);
...where in this case we scan "/dev/ttyS0" for an MTi device that is configured at a baud rate of 230400 bps.
Alternatively, the ROS driver also allows you to configure the desired port and baud rate manually without modifying the source code. To do so, uncomment and modify the following lines in the file xsens_mti_node.yaml, located at xsens_ros_mti_driver/param:
# port: '/dev/ttyS0' # baudrate: 921600
You should now be able to detect and access the MTi via the UART interface.
Troubleshooting
“No MTi device found.” or “Could not open port.”
- Ensure that you have the rights to access the port of the MTi (e.g. /dev/ttyUSB0). If you are using the C++ example code, you can check this by executing the code with sudo. Possibly you are not in the right group to access the port of the MTi. See MTSDK.README, located in your MT SDK folder, for further guidelines on changing group access permissions.
- If you are using the MTi 10-series or MTi 100-series with a direct USB cable, make sure to have libusb installed, and build your code as:
sudo make HAVE_LIBUSB=1
- If you are using a robust MTi 600-series with a USB dongle, make sure to have the relevant drivers installed.
- If you are not using the USB port or if you are using a custom serial-to-USB converter, try specifying the exact port and baud rate at which your MTi is communicating. See paragraph Serial hardware interfaces of this article.
My USB-connected MTi does not show up as /dev/ttyUSB#.
- If you are using the MTi 10-series or MTi 100-series with a direct USB cable, then it is not necessary for the MTi to show up as /dev/ttyUSB#. Make sure to have libusb installed, and build your code as:
sudo make HAVE_LIBUSB=1
The MTi should now be recognized whenever you launch the ROS driver or C++ example code.
- If you are using the MTi 10-series or MTi 100-series with a direct USB cable, then it is not necessary for the MTi to show up as /dev/ttyUSB#. Make sure to have libusb installed, and build your code as:
The data I am receiving never reaches the expected data output rate (e.g. 400 Hz).Still facing challenges? Don’t hesitate to contact our Field Application Engineers for further support.
- We have noticed that the ROS node can cause a high CPU load, leading to lower data output rates. This issue has been fixed in ROS nodes available in MTSS2019.3.2 and later. We recommend migrating to the latest version.
- If you have connected the MTi via the USB interface, we recommend enabling the low latency mode using setserial. See this page for more details.
Still facing challenges? Don’t hesitate to contact our Field Application Engineers for further support.
Top Comments