Risto Ojala

Captain’s log

10 Dec 2022

Gyroscope Visualisation over WLAN with ROS

I’ve been planning a project in which I would utilise gyroscope data, so I decided to play around a bit with a breakout board I had lying around. The 9-DOF IMU breakout board featured an L3G4200D gyro and an LSM303DLHC accelerometer/magnetometer. Originally I was planning on testing out some proper IMU fusion utilising all the available sensors, yet I learned pretty quickly that the board was shot. The accelerometer reported a gravitational acceleration of 9.4 m/s^2, and the magnetometer reported a constant value for the z-axis magnetic field strength, regardless of the orientation. I guess you can’t always get perfect quality when you order the cheapest components, pretty shocking I know… The gyro seemed to work, although it had a notable constant bias in its measurements that had to be corrected out. Some drift is naturally expected, but the datasheet did talk about factory calibration. And I wasn’t exactly pushing the boundaries of precision engineering in my tests, the drift was quite large.

Reading the Gyro

I used a Raspberry Pi 3 running Ubuntu 20 and ROS for reading the gyro. I wired up the I2C-communication, and figured out the gyro I2C address with i2c-tools:

i2cdetect -y 1

Then I created a small ROS-package with a python-based node for reading and publishing the gyro data. The node published the angular velocities, as well as the orientation acquired from integrating the angular velocities. Code for the package is available in my github.

ROS over WLAN

To see a visualisation of the gyro in real-time, I connected my laptop to the ROS session of the Raspberry Pi over WLAN. This is fairly simple to achieve, adding a couple of lines to the .bashrc of both devices. Using the Raspberry Pi as the master, the setup was the following:

Raspberry Pi

export ROS_MASTER_URI=http://<raspi-ip>:11311
export ROS_IP=<raspi-ip>
export ROS_HOSTNAME=<raspi-ip>

Laptop

export ROS_MASTER_URI=http://<raspi-ip>:11311
export ROS_IP=<laptop-ip>
export ROS_HOSTNAME=<laptop-ip>

I also set static IP reservations for both devices in my router’s DHCP configurations.

Visualisation

To visualise the gyro data I used Rviz and rviz_imu_plugin. I used the following one-liner to publish a static transformation between the gyro frame (base_link) and the Rviz frame (map):

rosrun tf2_ros static_transform_publisher 0 0 0 0 0 1 base_link map

Check out the result below!

“Gyro visualisation.