JetRacer ROS AI Kit Tutorial IV: Configure Multi-machine Communication

From Waveshare Wiki
Revision as of 03:16, 4 November 2022 by Eng52 (talk | contribs) (Created page with "<div class="wiki-pages jet-green-color"> ==Introduction== *Before configuring multi-machine communication, you need to understand the following three systems: **PC host: It is...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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 Jetbot. 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 camera, 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 Ubunntu 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 have supported the IP address and host name 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 host name is nano-4gb-jp45, and the virtual machine host name 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 host name.

[Note: After adding text, you need to run source ~/.bashrc or open a new terminal environment variable to take effect.]

Robot

  • On the robot side, add the following text at the end of the ~/.bashrc file, and replace nano-4gb-jp45 if the actual hostname is another name.
export ROS_MASTER_URI=http://nano-4gb-jp45:11311 #Set the robot as the host
export ROS_HOSTNAME=nano-4gb-jp45

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.
export ROS_MASTER_URI=http://nano-4gb-jp45:11311 #Point to the robot host
export ROS_HOSTNAME=ubuntu

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

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: jetbot
  • [The editor can use nano or vim, choose a text editor according to personal habits]
sudo nano /etc/hosts
  • As shown in the figure below, modify the line below 127.0.1.1 nano-4gb-jp45.localdimain nano-4gb-jp45 to the ip and hostname of the ubuntu virtual machine. [if this line is commented out, you need to uncomment it.]

Multi-machine Communication01.png
Multi-machine Communication02.png

  • If the nano command cannot be executed, please enter the following command to install the nano editor. After installation, you can execute the command again: sudo nano /etc/hosts.
sudo apt install nano #install nano editor
  • After modification, press Ctrl+x, exit y, press Enter, save changes and 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.

Ubuntu Virtual Image05.png

  • After modification, press Ctrl+x, exit y, press Enter, save changes and exit.

Step3: Check ROS Multi-machine Communication

  • SSH connection to the robot to open the terminal, enter the following command to start the robot master node.
roscore #Start the robot master node
Jetbot image09.png

[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, 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.
Jetbot image10.png