ROS Kinetic Serial Reading Tutorial
Minimal public workflow for exposing ANROT serial output as ROS topics on Ubuntu 16.04 and ROS Kinetic.
- ros
- kinetic
- ubuntu
- tutorial
ROS Kinetic Serial Reading Example
Protocol Support
| Protocol / frame | Support | How this example handles it |
|---|---|---|
0x91 IMUSOL | Supported | Publishes /imu_0x91_package and converts the same data to /IMU_data (sensor_msgs/Imu). |
0x62 GWSOL | Supported | Publishes /imu_0x62_package; each gateway node is stored in node_data[]. |
0x63 GWSOL Compact | Not supported | ch_serial has no 0x63 / 0x93 compact node decoder. |
0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xD1, 0xF0 | Partially supported | The parser handles loose items; non-gateway frames go through the single-device topic, and pressure remains only in the raw package. |
Download and unzip: demo-ros-kinetic-en.zip
This example exposes ANROT serial output as ROS topics on Ubuntu 16.04 / ROS Kinetic. Confirm the serial device first, then build the catkin workspace and verify the published IMU topics.
Environment:
- Ubuntu 16.04
- ROS Kinetic Kame
- USB / USB-UART connection to Hi226, Hi229, CH100, CH104, CH108, or CH110
1. Confirm the serial device
Most Ubuntu 16.04 systems already include CP210x / CH340 USB-UART drivers. Connect the device and check the assigned port:
ls /dev/ttyUSB*
If the port exists but the ROS node cannot open it, grant temporary access:
sudo chmod 666 /dev/ttyUSB0
For long-term use, add the user to the dialout group and log in again.
2. Install the ROS serial package
This example uses the ROS serial package for serial communication.
-
Install the package:
sudo apt-get install ros-kinetic-serial -
Run
roscd serialto confirm the installation path:/opt/ros/kinetic/share/serial
3. If installation fails, see the troubleshooting section at the end of this page.
3. Compile the serial_imu_ws workspace
-
Open a terminal and go to the
/examples/ROS/serial_imu_wsdirectory. -
Run
catkin_make. The build should complete without errors.
4. Modify serial port baud rate and device number
-
The example supports 115200, 460800, and 921600 baud. The default baud rate is 115200, and the default device path is
/dev/ttyUSB0. -
If you need a higher output rate, edit the macro definitions in
serial_imu.cpp.#define IMU_SERIAL ("/dev/ttyUSB0") #define BAUD (115200)
After changing the serial settings, return to the serial_imu_ws directory and run catkin_make again.
5. Display data
This example provides three ways to view data:
- Display all data information for easy viewing of data.
- Print ROS standard imu_msg data
- rviz tool for visualization
- 3D display
5.1: Output IMU raw data
-
Open another terminal and execute:
$ roslaunch imu_launch imu_msg.launch imu_package:=0x91 -
If the execution fails and the corresponding launch file cannot be found, you need to configure the environment and execute it in the current terminal:
$source <serial_imu_ws_dir>/devel/setup.bash -
After successful execution, you can see all the information:
Devie ID: 0 Run times: 0 days 3:26:10:468 Frame Rate: 100Hz Acc(G): 0.933 0.317 0.248 Gyr(deg/s): -0.02 0.30 -0.00 Mag(uT): 0.00 0.00 0.00 Eul(R P Y): 52.01 -66.63 -60.77 Quat(W X Y Z): 0.770 0.066 -0.611 -0.172
5.2: Output ROS standard Imu.msg
-
Configure the module under the windows system to enable quaternion output.
-
Use the CHCenter host computer under Windows for configuration: first connect the module to the PC. Then use the CHCenter tool to connect the corresponding com port, click Tools ---> Configuration Module, in the new window that pops up, click ATCMD, and then enter AT in the input box Command:
AT+SETPTL=0x91, click to send, and ok is displayed at the end of the receiving area, indicating that the configuration is successful, power off and restart the module. Execute theroslaunch imu_launch imu_msg.launchcommand. After the execution is successful, you can see the IMU topic information defined by ROS:header: seq: 595 stamp: secs: 1595829903 nsecs: 680423746 frame_id: "base_link" orientation: x: 0.0663746222854 y: -0.611194491386 z: -0.17232863605 w: 0.769635260105 orientation_covariance: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] angular_velocity: x: 0.0851199477911 y: 0.0470183677971 z: 0.00235567195341 angular_velocity_covariance: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] linear_acceleration: x: 0.93323135376 y: 0.317857563496 z: 0.247811317444 linear_acceleration_covariance: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
5.3: rviz visualization
1. Same as the previous section, enable module quaternion output
2. Open the terminal and execute the roslaunch imu_launch imu_rviz.launch command. After the execution is successful, the rviz tool is opened.
3. First click the Add tag in the lower left corner, and then in the pop-up window, select the By display type tag, and query rviz_imu_plugin; after finding it, select the imu tag below it, and click OK. At this time, we can see the left side of rviz The Imu tab has been successfully added to the display window of . Fill in base_link in FixedFrame. Added /IMU_data to topic. At this time, it can be seen that the coordinate system changes as the sensor changes.
5.4: 3D Display
1. Enable the quaternion output of the module
2. Open the terminal and execute the roslaunch imu_launch imu_display_3D.launch command. After the execution is successful, a 3D graphic display will appear
6. FAQ
1. If it is the first time to install the ROS serial package, it is very likely that it will fail, because I encountered this problem when I installed it. Here is a solution to save everyone’s time.
When executing the command sudo apt-get install ros-kinetic-serial in the terminal, you may be prompted
In order to provide material, serial deliberately entered wrong.
My solution is:
$cd /etc/apt/sources.list.d
$ sudo vi ros-latest.list
After opening this file, generally there is only one available source in this file, which means that it is not commented. Now comment it out, and enter # at the beginning of it to comment.
Then start a new line and enter: deb https://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ xenial main
Then save and close the file. Open a terminal, execute sudo apt-get update, then execute sduo apt-get install ros-kinetic-serial.
- Sometimes a lot of usb devices need to be plugged into the motherboard. In order to facilitate development, a usb port constraint file is usually written. If it is a different type of usb device, it can be distinguished by the id number of the device. If it is the same type of device, their id numbers are the same. At this time, more subdivision information is needed to distinguish different usb devices. Next, let’s learn how to distinguish between usb devices of the same model.
linux@ubuntu:~$ lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 012: ID 10c4:ea60 Cygnal Integrated Products, Inc. CP210x UART Bridge / myAVR mySmartUSB light
Bus 002 Device 011: ID 10c4:ea60 Cygnal Integrated Products, Inc. CP210x UART Bridge / myAVR mySmartUSB light
Bus 002 Device 010: ID 10c4:ea60 Cygnal Integrated Products, Inc. CP210x UART Bridge / myAVR mySmartUSB light
Bus 002 Device 008: ID 0e0f:0008 VMware, Inc.
Bus 002 Device 003: ID 0e0f:0002 VMware, Inc. Virtual USB Hub
Bus 002 Device 002: ID 0e0f:0003 VMware, Inc. Virtual Mouse
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
linux@ubuntu:~$
Observing the above content, it is found that there are three usb devices with exactly the same id numbers. It is not feasible to use simple id numbers to distinguish them, and more device information is required.
linux@ubuntu:~$ ls /dev
agpgart loop3 shm tty32 tty63 ttyS7
autofs loop4 snapshot tty33 tty7 ttyS8
block loop5 snd tty34 tty8 ttyS9
bsg loop6 sr0 tty35 tty9 ttyUSB0
btrfs-control loop7 stderr tty36 ttyprintk ttyUSB1
bus loop-control stdin tty37 ttyS0 ttyUSB2
......(Not all released)
At this point, three usb device files are generated in the dev file, namely: ttyUSB0, ttyUSB1, and ttyUSB2.
Now look at the details of ttyUSB0:
linux@ubuntu:~$ udevadm info --attribute-walk --name=/dev/ttyUSB0
#Through this command you can view the detailed information of the specified port
......
ATTRS{devpath}=="2.2"
ATTRS{idProduct}=="ea60"
ATTRS{idVendor}=="10c4"
ATTRS{ltm_capable}=="no"
ATTRS{manufacturer}=="Silicon Labs"
ATTRS{maxchild}=="0"
ATTRS{product}=="CP2104 USB to UART Bridge Controller"
ATTRS{quirks}=="0x0"
ATTRS{removable}=="unknown"
ATTRS{serial}=="01E34546"
... (There is too much information, so I won't release all of it. You can go and see the detailed information by yourself. Only the information you need to care about this time is released here)
Then there are the details of ttyUSB1:
linux@ubuntu:~$ udevadm info --attribute-walk --name=/dev/ttyUSB1
#Through this command you can view the detailed information of the specified port
......
ATTRS{devpath}=="2.3"
ATTRS{idProduct}=="ea60"
ATTRS{idVendor}=="10c4"
ATTRS{ltm_capable}=="no"
ATTRS{manufacturer}=="Silicon Labs"
ATTRS{maxchild}=="0"
ATTRS{product}=="CP2102N USB to UART Bridge Controller"
ATTRS{quirks}=="0x0"
ATTRS{removable}=="unknown"
ATTRS{serial}=="9c1d818b48aeeb119d082897637728c5"
... (There is too much information, so I won't release all of it. You can go and see the detailed information by yourself. Only the information you need to care about this time is released here)
Finally, the details of ttyUSB2:
linux@ubuntu:~$ udevadm info --attribute-walk --name=/dev/ttyUSB2
#Through this command you can view the detailed information of the specified port
......
ATTRS{devnum}=="27"
ATTRS{devpath}=="2.4"
ATTRS{idProduct}=="ea60"
ATTRS{idVendor}=="10c4"
ATTRS{ltm_capable}=="no"
ATTRS{manufacturer}=="Silicon Labs"
ATTRS{maxchild}=="0"
ATTRS{product}=="CP2104 USB to UART Bridge Controller"
ATTRS{quirks}=="0x0"
ATTRS{removable}=="unknown"
ATTRS{serial}=="02228956"
... (There is too much information, so I won't release all of it. You can go and see the detailed information by yourself. Only the information you need to care about this time is released here)
Through the information of the three serial port devices above, I found the item ATTRS{serial}==“xxxx”, which looks very random. In fact, this is the id number of the hardware, and it is also the unique id number of the hardware. Through this number, give it an alias. In this way, as long as the hardware id number is recognized, a customized one will appear under dev. Port name device file to achieve permanent connection to the port number.
linux@ubuntu:~$ cd /etc/udev/rule.d/
linux@ubuntu:/etc/udev/rules.d$ ls
70-snap.core.rules 70-ttyusb.rules 99-vmware-scsi-udev.rules
#This step is to see what constraint files are there to avoid duplication of file names
linux@ubuntu:~$ sudo vi defined_serial.rules
#This step customizes a serial port constraint file name, suffixed with '.rules'
Then enter the following into this file:
The format is as follows:
KERNEL=="ttyUSB*", ATTRS{serial}=="xxx", ATTRS{idVendor}=="xxx", ATTRS{idProduct}=="xxx", MODE:="0777(port permission)" ,SYMLINK+="(custom name)"
Fill in the corresponding information correctly, finally save and exit the file, and execute:
linux@ubuntu:~$ service udev reload
root privileges required
linux@ubuntu:~$ service udev restart
linux@ubuntu:~$ ls /dev
agpgart loop1 sg1 tty32 tty7 ttyS9
autofs loop2 shm tty33 tty8 ttyUSB0
block loop3 snapshot tty34 tty9 ttyUSB1
BLUETOOCH loop4 snd tty35 ttyprintk ttyUSB2
....
CH110 mcelog tty0 tty40 ttyS13 vcs1
....
Hi226 rfkill tty22 tty54 ttyS27 vfio
....
Now you can see that the custom usb port name has come out. When operating, just operate the corresponding device file directly, and don’t need to pay attention to the port number.