What I want to introduce is about ROS robots, not soft routers. The R in this article is not Route, but the abbreviation of Robot.
A very important concept in the ROS system is the node . A ROS robot system is composed of many nodes, each of which is an independent software module. When a robot system is complex enough, only a small computer may be overwhelmed. Therefore, multiple nodes must inevitably be run on different machines, and network communication will be used at this time.
1 Introduction to ROS
We have seen some robot operating systems such as Chibios and Nuttx in the past. These systems generally run on a single-chip MCU and can be used to make unmanned vehicles, aerial robots or unmanned submarines. There are many robot projects that use this operating system, and the more famous ones are PX4, Paparazzi UAV, etc. Because it is an embedded operating system, the use and development of this operating system are very difficult.
Today we are going to talk about another "operating system" that is more application-oriented - ROS.
ROS (Robot Operating System) is an "operating system" for robots. ROS is a software system (equivalent to the application layer of an embedded system) that needs to run on a Linux system.
Since it is not a traditional operating system, why is ROS called Operating System? Because ROS encapsulates different robots and sensors. Then, when you want to do laser SLAM mapping, binocular vision scanning or motion planning, you can operate the hardware through the ROS API interface; in terms of operation, it is just like programming based on an operating system.
2 Characteristics of ROS
ROS can realize the functions of a computer cluster operating system. What's more, since the C and Python codes of the application layer can be used across platforms, this computer cluster can even be composed of different architectures such as X86 and ARM. ROS uses a cross-platform modular software communication mechanism. Each function in the ROS system is implemented by its own node, and each node can be distributed and run on different machines. For example, you can combine the PX4 flight control and the Raspberry Pi to form a drone node, connect it to a ROS system composed of an x86 computer cluster through the network, and then let the X86 computer do visual recognition calculations, laser SLAM mapping, and path calculations, so as to expand more advanced functions.
3 ROS version selection
There are currently two common versions of ROS, Kinetic and Melodic, and Melodic is the latest version.
Although Melodic is the latest version, I am often asked how to install ROS Kinetic on Friendly Arm's RK3399. I am also confused. Friendly Arm is already compatible with ROS Melodic, so why would anyone want to install Kinetic?
It turns out that beginners are easily misled by the name and want the Kinetic version. The English name of Melodic sounds like a music player, and it is difficult to associate it with a robot. In contrast, the name Kinetic means dynamics, which sounds more professional than Melodic. However, in fact, Melodic is an upgraded version of Kinetic.
In some cases, after reading the Chinese tutorial of Kinetic, the newbies cannot adapt flexibly and cannot even install the ROS package after switching to Melodic. For this problem, Section 5 of this article will guide you on how to install the Melodic package.
4 ROS Melodic system installation
If it is Ubuntu 18 system, the installation method is very simple, just use the apt command.
sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.ustc.edu.cn/ros/ubuntu/ $DISTRIB_CODENAME main" > /etc/apt/sources.list.d/ros-latest.list'
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
sudo apt-get up<ickey>date
sudo apt-get install ros-melodic-desktop-full
sudo rosdep init
rosdep up.bash
I like to do it this way, write it to the user's bashrc. You don't have to reset it every time you restart next time.
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
5 ROS package installation
Considering that some newbies don't know how to install Melodic software package, this section will explain how to install Melodic software package. The installation example uses the software packages related to drone Mavlink protocol and LiDAR SLAM mapping that everyone is most interested in.
MAVlink is a very common robot communication protocol. In open source drone projects, PX4, Ardupilot, etc. all use this protocol. For ROS to communicate with these robots, you need to install the mavros software package first.
sudo apt-get install ros-melodic-mavros
The robot is equipped with a laser radar. When you need to build a virtual map based on the laser radar data and locate yourself, you need to install the slam gmapping software package first.
sudo apt-get install ros-melodic-slam-gmapping
You are smart enough to have figured out the rules. These packages are installed in the following ways:
sudo apt-get install ros-melodic-包名
If you find a tutorial you need on the ROS Chinese website, but find that the tutorial is old and the corresponding ROS version is relatively low, such as the kinetic version.
You can try to replace kinetic in the installation package name in the apt command in the tutorial with melodic.
6 Network Communication Examples
The ROS system requires a host node, namely the master, and then all the sub-nodes that implement various functions connect to this host node. The master node and sub-nodes can be on the same computer or on different computers (i.e. network communication).
In this section, we will make three nodes, a Master node, a frame listening node, and a sending node.
First is the Master node. For the Master, the host name and host IP are both local, that is, localhost, and no special configuration is required.
roscore
We use the Friendly Arm RK3399 board (model NanoPi M4) to run the Master node, as shown in the screenshot below. The debug print information shows the ROS version and node port number
The above example is on an embedded friendly arm. In fact, it is also OK to run the Master node on an x86 computer. The principle is the same.
The listening node and the sending node can be placed on different computers. All child nodes must be configured with the ROS MASTER URI (note that it is a capital i, with no curve after the vertical line, do not write it as a URL) to connect to the same master node.
Let's take an example of the command code for listening nodes. If we have opened a master node on 192.168.1.116, then the computer with an IP other than 192.168.1.116 needs to enter the following command:
export ROS_MASTER_URI=http://192.168.1.116:11311
rosrun rospy_tutorials listener.py
The above command requires you to enter an IP number, but you can also use the computer's hostname instead. The method is as follows: set up the hosts file of all computers except the master node, and write down the IP corresponding to the hostname, so that the hostname can be resolved. For example, if the master node's computer is NanoPi-M4, and its IP is 192.168.1.111, then the code for the listening node can also be written as follows:
export ROS_MASTER_URI=http://NanoPi-M4:11311
rosrun rospy_tutorials listener.py
The configuration method of the sending node is the same. If hosts have been configured, just write it like this:
export ROS_MASTER_URI=http://NanoPi-M4:11311
rosrun rospy_tutorials talker.py
The following is a test picture, ROS1 sends data, ROS2 listens.
At the beginning, ROS2 has no data
Then ROS1 started sending and sent hello world
ROS2 node receives hello world
7. Network Control
The previous sections explained how to start the master node and child nodes. Let's summarize it in one sentence: In addition to the host node, child nodes that implement various functions need to set ROS_MASTER_URI to the IP and port of the master node before starting.
In this section, we will use ROS to play with network control. The robot to be controlled is the popular turtle robot. Because the master node has been enabled in the previous section, we need to enable two nodes in this section. We have two computers as child nodes, ROS1 and ROS2.
We need to make the following settings for ROS1 and ROS2 respectively:
1. Turtle robot control node (running on ROS2); 2. Network remote control node (running on ROS1).
In ROS1, first set ROS_MASTER_UR and start the turtle robot node. Although it is a virtual simulation platform, not actual hardware, it is sufficient to demonstrate the network control of ROS. In the figure below, ROS2 starts the turtle robot node and displays the simulation image of the robot. At present, it has not received any remote control commands.
Then, set ROS_MASTER_UR on ROS1 and turn on the remote control node. Then, by inputting up, down, left, and right on ROS1, you can control the turtle in ROS2 to move forward or turn.
Try to control it on ROS1. You can find that the turtle on ROS2 starts to move as you operate it.
|