(7) ROS multi-machine communication

1. Introduction

Before introducing ROS multi-machine communication, first introduce the steps and process of using the car. In addition to the car, you need to prepare an Ubuntu system computer or Ubntu virtual machine for remote control. The "pc" will be used as the remote control below. The code name of the Ubuntu computer

Two, control mode

1. Operation process

  • ① Power on the car, the car will send out a wifi
  • ② Log in to the car terminal remotely via SSH
  • ③ Enter the launch command for mapping or navigation in the car terminal to turn on the mapping and navigation functions
  • ④ At the same time, use the rviz tool on the "PC" side to view the specific results

2. There are three reasons for using "pc" remote control

  • ① As the input of control information

  • ② The effect can be viewed remotely

  • ③ From a practical point of view, you can connect a keyboard and a display to the car, and you don’t need to do remote input and information viewing. You can do some input and adjustments when the car is stationary, but when the car is moving, these operations are not It's too convenient. Another important reason is that opening the rviz tool on the car will consume a lot of resources of the car's ros master control (the ros master control resources on the car are limited)

7. Terminal classification
① SSH to remotely log in to the terminal of the car: the launch file is the terminal running on the car

② The local terminal of the "pc" machine: rbiz is the local terminal that runs "pc"

Three, network connection

There are two steps to build ros multi-machine communication

  • ① All ros masters need to be in the same network
  • ② Set the environment variables for multi-machine communication in the bashrc file
    Insert picture description here

Four, software settings

Behind the same network

1. Set the environment variables for multi-machine communication.
1. This environment variable is set in a bashrc file in the home directory.
2. It should be noted that both the ros slave and host's'bashrc' files need to be set.
3. The environment variables here It is two lines of ip address
4. As shown in the figure, you can see that both ip addresses of the host are 192.168.0.100.
5. One ip address of the slave is: 192.168.0.100, and the other ip address is: 192.168.0.120
Insert picture description here

2. How to set

  • "ROS_MASTER_URI": the ip address of the ros host

  • "ROS_HOSTNAME": the ip address of the current computer

  • Because the network for multi-machine communication is provided by the ros host, the "ROS_MASRTER_URI" and "ROS_HOSTNAME" of the ros host are both 192.168.0.100

  • The ros slave connected to the wifi, its "ROS_MASTER_URI" address is 192.168.0.100 (that is, an ip address of the ros master), and its "ROS_HSOTNAME" is the local ip of the ros slave

If you use your own environment, there are no two sentences in the bashrc file by default, you need to add them manually

3. Check the ip address of the car and "pc"
① Input in the terminal of the car

ip a

You can see its local ip address shi192.168.0.100
and then we check the bashrc file on the side of the car, we can see that its two ips are the same

② Enter in the "pc" terminal

ip a

You can see its local ip address shi192.168.0.140
and then we check the bashrc file on the "pc" side, we can see that the ros host ip is the same as that of the car, and the local ip address is the same as the one viewed

Five, matters needing attention

1. The operation of the ros slave program depends on the rosmaster of the ros master

  • rosmaster is the node manager, rosmaster is required when ros programs and tools are running
  • rosmaster is opened by roscore
  • When the launch file is opened, it will automatically detect whether roscore is already running. If roscore does not exist, roscore will be automatically opened.
  • If you use the rosrun command to open the node, you need to manually open roscore
  • There is only one rosmaster running the ros function
  • In multi-machine communication, only one rosmater is needed
  • This rosmater is provided by the ros master, so the slave programs and tools depend on the rosmater of the ros master

2. Is it possible to run roscore first and then rviz on the "pc" side

No, only after the ros host is connected to roscore, "pc" can run rviz

3. The local ip address of the slave is not set correctly, it has been allowed to access the rosmaster, but the control information cannot be input

Souece is needed after changing the address, but the "souece" command is only valid for the current terminal

soucce .bashrc

4. Multi-machine communication cannot view/subscribe to topics of message data types that do not exist locally

Guess you like

Origin blog.csdn.net/m0_46278925/article/details/115054046