Configuring and Displaying the AHRS Module GY-951

2018 has arrived in the blink of an eye. It’s hard to imagine how quickly time flies. I have been consistently producing ROS tutorials for over a year now. I would like to take this opportunity to summarize my journey so far. To date, I have published 72 video tutorials on Youku, with a total of 53,000 views and 1,011 followers. Additionally, I want to inform everyone that all the videos from the ROS class on Youku are now available for download, making it easier for everyone to access them locally.

Configuring and Displaying the AHRS Module GY-951

We have published a total of 46 messages on our WeChat public account, with 2,281 subscribers. The key question is why there are two unknown genders?

Configuring and Displaying the AHRS Module GY-951

Configuring and Displaying the AHRS Module GY-951

The ranking of subscribers by city follows the order of Beijing, Shanghai, Shenzhen, and Guangzhou. Beijing and Shanghai are almost on par, confirming that most users are from first-tier cities!

Configuring and Displaying the AHRS Module GY-951

In the ROS class WeChat group, there are already 129 users who have rewarded the class. I would like to thank all the friends who have supported the ROS class through rewards. Your support has allowed me to continue until now!

Configuring and Displaying the AHRS Module GY-951

Lastly, the ROS class website was successfully launched at the end of November 2017. Although the tutorials on the site are not yet comprehensive, I hope that with continuous maintenance and updates, the tutorials will become more abundant and complete. I hope to provide a good platform for more friends learning ROS to find resources and tutorials!

Configuring and Displaying the AHRS Module GY-951

In the new year, I will do my utmost to maintain the video tutorials of the ROS class on Youku, the WeChat public account, and the website. Your support is my motivation to keep going! Finally, I want to say, 2018, bring it on!

0x00 Introduction to the AHRS Module

In the design of robots, the Inertial Measurement Unit (IMU) is an essential module. However, high-precision IMU modules are very expensive. Generally, the Xsens MTi series IMUs cost over ten thousand yuan. Here, we introduce an affordable IMU module, which is different from IMUs as it is an Attitude and Heading Reference System (AHRS). The price on Taobao is about 80 yuan. Although the output data has some errors, it is sufficient for our general ROS robots. Below are images and relevant parameters of the module:

GY-951 (Three-axis gyroscope + three-axis accelerometer + three-axis digital compass)

Configuring and Displaying the AHRS Module GY-951

Appearance size 2.3cm * 1.7cm
Supply voltage 3-5V
Communication method TTL serial, baud rate 57600
Module chip Processor chip ATMEGA328P
Three-axis gyroscope ITG3205
Three-axis accelerometer ADXL345
Three-axis digital compass HMC5883L
Output data Yaw angle (YAW) ±180°
Roll angle (ROLL) ±180°
Pitch angle (PITCH) ±180°

0x01 Connecting the GY-951 Module

Since the GY-951 module just bought is shown on the left side of the image below, the header pins need to be soldered according to our needs. The right side shows my soldered version:

Configuring and Displaying the AHRS Module GY-951

To send the output data of the module to ROS for processing, we obviously need an adapter module. I am using a USB to TTL converter here, but other modules can also be used. The three models below are the ones I have used that can communicate normally with the GY-951. The only difference is that the other two need an additional mini USB cable, which is different from the micro USB cable used for Android phones, as shown in the image below:

Configuring and Displaying the AHRS Module GY-951

It is important to note that when updating the firmware code of the GY-951, the DTR pin needs to be connected to download the firmware code to the GY-951. During normal communication, the DTR pin does not need to be connected; only VCC, GND, TX, and RX need to be connected. Below is a summary:

GY-951 Module USB Adapter Module Connection Diagram Notes
Normal Communication

VCC

GND

TX

RX

VCC

GND

RX

TX

Configuring and Displaying the AHRS Module GY-951

When connecting, it is important to note that the IMU module and adapter module should be connected correctly.

VCC and GND should connect to the corresponding pins. When connecting the TX and RX pins, the IMU module should connect oppositely to the adapter module, meaning the IMU module’s TX connects to the adapter module’s RX, and the IMU module’s RX connects to the adapter module’s TX.

Update Firmware

VCC

GND

TX

RX

DTR

VCC

GND

RX

TX

DTR

Configuring and Displaying the AHRS Module GY-951

The only difference when updating the firmware code of the GY-951 is that an additional DTR pin should be connected. Only by connecting the DTR pin can the firmware code be downloaded to the GY-951 through the Arduino IDE.

(At this time, an adapter module with a mini USB interface is required to have a DTR pin)

0x02 Updating the GY-951 Firmware

Since the firmware code of the GY-951 bought from Taobao is relatively old, the first thing to do to ensure the module works properly is to update the firmware code. Here we use the firmware code from the razor_imu_9dof package in ROS. The reason for using the firmware code from this package is that it is designed for SparkFun’s Razor IMU 9DOF (Degree of Freedom) sensor boards, and the sensor modules of this IMU are the same as our GY-951, so the code should be compatible.

Configuring and Displaying the AHRS Module GY-951

Next, download the corresponding code from GitHub using the command: git clone https://github.com/blmhemu/razor_imu_9dof.git. Since this code currently only has a ROS Indigo branch, we need to test it on Indigo first. We need to download the code to the source directory of our ROS workspace, which is generally our own ROS car’s working directory. Here I will demonstrate downloading the source code and analyzing the contents of each directory in my ROS workspace:

Configuring and Displaying the AHRS Module GY-951

Next, I will briefly introduce the functions of each source code file in the firmware code. The Math.ino file does not have any comments indicating its function, which is to perform simple mathematical calculations, such as vector addition, dot product (scalar product), and matrix multiplication:

Configuring and Displaying the AHRS Module GY-951

Next, we need to open the firmware code in the Arduino IDE, directly open the Razor_AHRS.ino file:

Configuring and Displaying the AHRS Module GY-951

Configuring and Displaying the AHRS Module GY-951

Next, we need to configure the code according to the GY-951 module. Simply modify the HARDWARE OPTIONS section in the Razor_AHRS.ino code:

Configuring and Displaying the AHRS Module GY-951

Next, we need to configure the board and processor and port that are suitable for the GY-951, so that we can download the code to the module. Note that for the board, you need to select: Arduino Pro or Pro Mini, processor: ATmega328P (3.3V, 8MHz), and the port should be selected according to your needs. Here, I select ttyUSB0:

Configuring and Displaying the AHRS Module GY-951

Configuring and Displaying the AHRS Module GY-951

Configuring and Displaying the AHRS Module GY-951

Once you click the upload button, the firmware code will be automatically compiled and then uploaded to the GY-951 module. You can check whether the upload is successful from the window at the bottom of the Arduino IDE.

Configuring and Displaying the AHRS Module GY-951

Configuring and Displaying the AHRS Module GY-951

0x03 Configuring ROS Code

Now that the GY-951 module has output data, we still cannot use this data in ROS. We need to package the data into a format that ROS can recognize as IMU data. Next, we will start configuring the relevant ROS code. First, we will analyze the launch file, starting with razor-pub.launch. The content of this file is as follows:

1

2

3

4

5

6

<launch>

<arg name="razor_config_file" default="$(find razor_imu_9dof)/config/my_razor.yaml"/>

<node pkg="razor_imu_9dof" type="imu_node.py" name="imu_node" output="screen">

<rosparam file="$(arg razor_config_file)" command="load"/>

</node>

</launch>

From the arg section, we can see that the razor_config_file parameter needs to be loaded, which is read from the my_razor.yaml file. However, this file does not exist by default, and we need to copy it from the razor.yaml file. We can simply use cp razor.yaml my_razor.yaml to create a copy:

Configuring and Displaying the AHRS Module GY-951

We check the my_razor.yaml file to see its contents and make the necessary modifications. The main part that needs to be changed is the port number:

12345678910111213141516171819202122232425262728293031323334 ## USB portport: /dev/ttyUSB0 ##### Calibration ####### accelerometeraccel_x_min: -250.0accel_x_max: 250.0accel_y_min: -250.0accel_y_max: 250.0accel_z_min: -250.0accel_z_max: 250.0 ### magnetometer# standard calibrationmagn_x_min: -600.0magn_x_max: 600.0magn_y_min: -600.0magn_y_max: 600.0magn_z_min: -600.0magn_z_max: 600.0 # extended calibrationcalibration_magn_use_extended: falsemagn_ellipsoid_center: [0, 0, 0]magn_ellipsoid_transform: [[0, 0, 0], [0, 0, 0], [0, 0, 0]] # AHRS to robot calibrationimu_yaw_calibration: 0.0 ### gyroscopegyro_average_offset_x: 0.0gyro_average_offset_y: 0.0gyro_average_offset_z: 0.0

The part we need to modify is mainly the USB port number. However, when using this port number, you need to pay attention to permission issues. Make sure the current user is in the dialout group. If not, use sudo usermod -aG dialout username to add the current user to the dialout group, as only the root user and users in the dialout group have read and write permissions by default. Therefore, adding your user to the dialout group will solve the issue. After executing this command, you may need to log out or restart your computer for it to take effect permanently.

Configuring and Displaying the AHRS Module GY-951

You can check whether the current user is in the dialout group using the groups command. Since I have already added my user to the dialout group, I do not need to execute it again. If you do not find the dialout group, you can add it using the command mentioned above. Once the permissions are set correctly, we can visualize the actual output data of the GY-951 module using 3D visualization. However, before using the visualization module, you need to install a software using the following command:

sudo apt-get install python-visual

Then you can execute catkin_make in your ROS workspace code to compile, and after compiling, use source devel/setup.bash to execute the ROS code for razor-imu-9dof to display the data in 3D:

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 corvin@workspace:~/project/omniWheelCareRobot/rosCode$ roslaunch razor_imu_9dof razor-pub-and-display.launch... logging to /home/corvin/.ros/log/fc30add4-ec66-11e7-8528-1866da14be59/roslaunch-workspace-16324.logChecking log directory for disk usage. This may take awhile.Press Ctrl-C to interruptDone checking log filedisk usage. Usage is <1GB.started roslaunch server http://192.168.31.186:19943/ SUMMARY========PARAMETERS * /imu_node/accel_x_max: 250.0 * /imu_node/accel_x_min: -250.0 * /imu_node/accel_y_max: 250.0 * /imu_node/accel_y_min: -250.0 * /imu_node/accel_z_max: 250.0 * /imu_node/accel_z_min: -250.0 * /imu_node/calibration_magn_use_extended: False * /imu_node/gyro_average_offset_x: 0.0 * /imu_node/gyro_average_offset_y: 0.0 * /imu_node/gyro_average_offset_z: 0.0 * /imu_node/imu_yaw_calibration: 0.0 * /imu_node/magn_ellipsoid_center: [0, 0, 0] * /imu_node/magn_ellipsoid_transform: [[0, 0, 0], [0, 0, 0], [0, 0, 0]] * /imu_node/magn_x_max: 600.0 * /imu_node/magn_x_min: -600.0 * /imu_node/magn_y_max: 600.0 * /imu_node/magn_y_min: -600.0 * /imu_node/magn_z_max: 600.0 * /imu_node/magn_z_min: -600.0 * /imu_node/port: /dev/ttyUSB0 * /rosdistro: indigo * /rosversion: 1.11.21 NODES / display_3D_visualization_node (razor_imu_9dof/display_3D_visualization.py) imu_node (razor_imu_9dof/imu_node.py) auto-starting new masterprocess[master]: started with pid [16336]ROS_MASTER_URI=http://localhost:11311 setting /run_id to fc30add4-ec66-11e7-8528-1866da14be59process[rosout-1]: started with pid [16349]started core service [/rosout]process[imu_node-2]: started with pid [16360]process[display_3D_visualization_node-3]: started with pid [16367][INFO] [WallTime: 1514531273.567938] Reconfigure request for yaw_calibration: 0[INFO] [WallTime: 1514531273.568119] Set imu_yaw_calibration to 0[INFO] [WallTime: 1514531273.583307] Opening /dev/ttyUSB0...[INFO] [WallTime: 1514531273.587696] Giving the razor IMU board 5 seconds to boot...[INFO] [WallTime: 1514531279.590087] Writing calibration values to razor IMU board...[INFO] [WallTime: 1514531280.710073] Printing set calibration values:ACCEL_X_MIN:-250.00ACCEL_X_MAX:250.00ACCEL_Y_MIN:-250.00ACCEL_Y_MAX:250.00ACCEL_Z_MIN:-250.00ACCEL_Z_MAX:250.00 MAGN_X_MIN:-600.00MAGN_X_MAX:600.00MAGN_Y_MIN:-600.00MAGN_Y_MAX:600.00MAGN_Z_MIN:-600.00MAGN_Z_MAX:600.00 MAGN_USE_EXTENDED:falsemagn_ellipsoid_center:[0.0000,0.0000,0.0000]magn_ellipsoid_transform:[[0.0000000,0.0000000,0.0000000],[0.0000000,0.0000000,0.0000000],[0.0000000,0.0000000,0.0000000]] GYRO_AVERAGE_OFFSET_X:0.00GYRO_AVERAGE_OFFSET_Y:0.00GYRO_AVERAGE_OFFSET_Z:0.00 [INFO] [WallTime: 1514531280.710284] Flushing first 200 IMU entries...[INFO] [WallTime: 1514531284.814904] Publishing IMU data...

Configuring and Displaying the AHRS Module GY-951

At this point, you can check the list of topics by using rostopic list. You can find the assembled IMU topic and echo it to check the data format and content:

Configuring and Displaying the AHRS Module GY-951

0x04 Displaying IMU Data in Rviz

To display IMU data in Rviz, you need to install an Rviz display plugin in advance. There are two installation methods: the first is to install it directly via apt-get, and the second is to compile it from source. Below, I will introduce both installation methods:

(1) Install directly via apt

This method is the simplest and quickest. We can simply enter in the terminal: sudo apt-get install ros-indigo-imu-tools. Of course, I am installing it under the Indigo system, and everyone needs to choose according to their installed ROS version. For example, in the Kinetic system, you can enter sudo apt-get install ros-kinetic-imu-tools to install it.

(2) Install from source

Since the source code needs to be downloaded via git, you need to ensure that the git-core software package is installed. You can install it directly using sudo apt-get install git-core. Next, download the source code. First, switch to the source directory of the ROS workspace you created, and then start downloading the source code from GitHub:

git clone -b indigo https://github.com/ccny-ros-pkg/imu_tools.git

I am downloading the Indigo branch code here. Everyone should choose according to their ROS version. The source code URL is: https://github.com/ccny-ros-pkg/imu_tools, where you can find more information. Next, before compiling the source code, you need to check the dependencies of the source code and install them to ensure successful compilation. The command to install the dependencies is: rosdep install imu_tools. After installing the dependencies, you can execute catkin_make in the root directory of your workspace.

Configuring and Displaying the AHRS Module GY-951

Once the Rviz plugin for displaying IMU data is installed, you can open Rviz by simply entering rviz in the terminal. Once opened, the first step is to add the plugin we just installed:

Configuring and Displaying the AHRS Module GY-951

After adding the plugin, you can display an xyz coordinate in the center display area of Rviz. Next, we need to configure it to display the information from the GY-951 module in Rviz. Follow the prompts to configure Rviz so that when we shake the GY-951 module, the IMU plugin in Rviz will also move in sync:

Configuring and Displaying the AHRS Module GY-951

Leave a Comment

×