Windows and virtual machine ROS serial port communication


When I was learning ROS recently, I wanted to simulate real data communication, but I had no hardware, so the communication between ROS and hardware was realized by simulation method, so as to facilitate later learning.
Platform: Ubuntu20.04
ROS: noetic

ROS serial port communication steps

1. Install VSPD (virtual serial port tool) under windows

Please add a picture description

As shown in the figure, add two serial ports COM2 and COM3 that need to communicate through the stand-alone Pair

2. Add a serial port to the VMWare virtual machine

Please add a picture description
As shown in the figure, when the virtual machine is shut down, by adding a new serial port, such as my serial port 2, correspondingly select the COM2 serial port under Windows,

3. Serial communication test tool settings under Windows

Please add a picture description

Since the previously set serial communication groups are COM2 and COM3, and COM2 is used in ROS, COM3 is used to send and receive data in the serial communication tool. The red line in the figure needs to be the same as the communication serial port setting in ROS.

4. ROS communication code

Refer to https://blog.csdn.net/qqliuzhitong/article/details/114384297
COM2 serial port corresponds to /dev/ttyS1 under Ubuntu, pay attention to modify the 17 lines of code as
source code

sp.setPort("/dev/ttyUSB0");

change into

sp.setPort("/dev/ttyS1");

5. Running results

Note: You need to change the permissions of the serial port before running, otherwise you will not be able to open the serial port

sudo chmod 666 /dev/ttyS1

Please add a picture description

Guess you like

Origin blog.csdn.net/xwb_12340/article/details/124845891