JetRacer ROS AI Kit Tutorial IV: Configure Multi-machine Communication
From Waveshare Wiki
JetRacer ROS Kit User Guide
- JetRacer ROS Kit Tutorial I: How to assemble the JetRacer
- JetRacer ROS Kit Tutorial II: How to Install the Jetson Nano Image
- JetRacer ROS Kit Tutorial III: How to install Ubuntu Virtual Image
- JetRacer ROS Kit Tutorial IV: How to congifure multi-machine communication
- JetRacer ROS Kit Tutorial V: Robot Movement Control
- JetRacer ROS Kit Tutorial VI: View Node Topics With ROS
- JetRacer ROS Kit Tutorial VII: Robot Odometer Calibration
- JetRacer ROS Kit Tutorial VIII: Start the Camera Node
- JetRacer ROS Kit Tutorial IX: Enable the Lidar Node
- JetRacer Main Page
Introduction
- Before configuring multi-machine communication, you need to understand the following three systems:
- PC host: It is generally our commonly used computer, and the system is generally Windows system, which is mainly used to remotely log in to jetson nano via SSH to start the robot control node.
- Ubuntu virtual machine: The Ubuntu system virtual machine installed by VMware software on our PC host mainly realizes ROS graphical display and remote control of the robot, which is more intuitive and convenient.
- jetson nano robot: This is our JetRacer. It adopts jetson nano as the main control and is also an ubuntu system. It is mainly used to realize various nodes such as robot cameras, lidar, and chassis control.
- jetson nano robot installs the ROS robot system and sets it as the host. The Ubuntu virtual machine is also installed in the ROS robot system and set as a slave machine.
- 【Note: We need to ensure that the above three systems are connected to the same LAN, and the IP addresses are on the same network segment, otherwise normal communication cannot be performed.】
- 【Note: In the following tutorials, the default virtual machine refers to the Ubuntu virtual machine, and the robot refers to the jetson nano robot.】
Step 1: Set Variables to Realize Multi-machine Communication
- In the previous tutorial, we supported the IP address and hostname of the robot and virtual machine. If you are not sure, you can run the following command to check.
ifconfig #Get the IP address of the virtual machine hostname #Get the hostname of the virtual machine
- Using our image, the robot hostname is nano-4gb-jp451, and the virtual machine hostname is ubuntu.
- We need to add environment variables to the robot and the virtual machine respectively and set the robot as the host. The virtual machine is set as a slave.
- Note: The environment variables have been added using the image we have configured and do not need to be added again; this step is what you need to add when you configure the image yourself.
- ROS_MASTER_URI changes to point to the ROS host, running the roscore master node independently.
- ROS_HOSTNAME variable is the current ROS hostname.
- 【The editor can be nano or vim, just choose one of them according to your preference.】
sudo apt install nano #install nano editor
Robot
- On the robot side, add the following text at the end of the ~/.bashrc file, and replace nano-4gb-jp451 if the actual hostname is another name.
sudo nano ~/.bashrc Add at the end: export ROS_MASTER_URI=http://nano-4gb-jp451:11311 #Set the robot as the host export ROS_HOSTNAME=nano-4gb-jp451 After the addition is complete, run the following command to take effect: source ~/.bashrc
Virtual Machine
- On the virtual machine side, add the following text at the end of the ~/.bashrc file, ROS_MASTER_URI is set to point to the robot as the host, and ROS_HOSTNAME is set to the virtual machine hostname.
sudo nano ~/.bashrc Add at the end: export ROS_MASTER_URI=http://nano-4gb-jp451:11311 #Point to the robot host export ROS_HOSTNAME=ubuntu After the addition is complete, run the following command to take effect: source ~/.bashrc
Step 2: Configure the Hosts File to Specify the IP Address
- Under normal circumstances, after adding environment variables, ROS should be able to communicate normally online. If there are multiple devices with the same name in the LAN, there may be problems such as failure to connect normally or to view topics but not receive topic information. At this point, you need to add hosts to specify the address.
- We need to add honst file settings to the robot and the virtual machine respectively. Please fill in the following settings according to your actual IP address and hostname.
Robot
- Open the terminal on the robot and enter the following command, add the IP address and hostname of the Ubuntu virtual machine to the /etc/hosts file of jetson nano, the password is jetson.
sudo nano /etc/hosts
- As shown in the figure below, modify the line below 127.0.1.1 nano-4gb-jp451.localdimain nano-4gb-jp451 to the IP address and hostname of the Ubuntu virtual machine 【if this line is commented out, you need to uncomment.】
- After changing, press Ctrl + x, exit by y, enter, and save it to exit.
Virtual Machine
- Open the terminal on the virtual machine and enter the following command to open the /etc/hosts file and add the robot IP address.
sudo nano /etc/hosts
- As shown in the figure below, change the line below 127.0.1.1 ubuntu to the IP and hostname of jetson nano. If this line is commented out, it needs to be uncommented.
- After modification, press Ctrl+x, exit y, press Enter, save changes, and exit.
Step3: Check ROS Multi-machine Communication
- Connect the robot to open the terminal by SSH, and enter the following command to start the robot master node.
roscore #Start the robot master node
【The following roslaunch command will also automatically start the master node, but the purpose of starting the master node alone here is to keep connected to the virtual machine all the time, otherwise the master node will be automatically closed when the chassis node is closed, resulting in the virtual machine being disconnected.】
- Open the Ubuntu virtual machine terminal, and enter the following command in the terminal.
rostopic list
- The following normally shows that the two nodes are likely to be able to communicate normally online.
- The robot side saves the startup state of the master node and does not close it. Open a new terminal to run the example receiving node.
rosrun rospy_tutorials listener
- Run the following command on the virtual machine side to start the example sending node.
rosrun rospy_tutorials talker
- After the virtual machine sends the program. The robot side will receive the sent data.
So far, multi-machine communication is normal. You can also exchange commands between the robot and the virtual machine to test sending the topic from the robot to the virtual machine.