Ubuntu18.04 version installs ROS and how to deal with errors

The previous articles are some applications based on the installed ROS. Here we install the ROS robot operating system from scratch.
Robot Operating System (Robot Operating System, ROS) is a framework for developing robot software, which contains a series of tools, libraries and conventions , the purpose of which is to simplify the construction of complex and stable robot behavior among a large number of different robot platforms.
ROS follows the Unix software development philosophy, so those with Unix background knowledge will feel very familiar and get started quickly. A notable feature of ROS is that it can be developed in multiple languages, including C++, Python, Lisp, Java, Javascript, Matlab, Ruby, R, etc. Enter the field of robotics.
More importantly, ROS is open source and free, released under the BSD protocol, so it is commercially available without authorization, and because the coupling between ROS modules is very low, self-developed modules can be fine-grained licenses authorized.
Here I will introduce how to install ROS in Ubuntu (a popular and relatively friendly Linux distribution). My version is 18.04. I will focus on the version number here because the following installation is related to your system version.

1. Update the software source

The first is to add the software source to the ros-latest.list file, so that the operating system can know which site to download:

sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu trusty main" > /etc/apt/sources.list.d/ros-latest.list'

We can view the file, the source content has been written into it

cat /etc/apt/sources.list.d/ros-latest.list
deb http://packages.ros.org/ros/ubuntu trusty main

It should be noted here that if you want to install, do not rush to enter the above command, and install it after reading the full text, because the installation of ROS is related to your Ubuntu system version .

2. Set the key

wget http://packages.ros.org/ros.key -O - | sudo apt-key add -
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654

The key here, in the subsequent installation, the second line of command can ignore it, it should not be needed

3. Install the robot development library

Install the complete desktop suite, including libraries and tools needed for robot development

sudo apt-get update
sudo apt-get install ros-indigo-desktop-full python-rosinstall

If an error like the following occurs:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 ros-indigo-desktop-full : Depends: ros-indigo-desktop but it is not going to be installed
                           Depends: ros-indigo-perception but it is not going to be installed
                           Depends: ros-indigo-simulators but it is not going to be installed
                           Depends: ros-indigo-urdf-tutorial but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

E: You are holding a broken package due to an uncorrectable problem. So here is actually a version mismatch!

My Ubuntu distribution is:

uname -v
#161~18.04.1-Ubuntu SMP Fri Feb 10 15:55:22 UTC 2023

You can see that it is the version of 18.04 , and the corresponding version of Ubuntu is listed here:

Ubuntu version ros version
Ubuntu 20.04 noetic
Ubuntu 18.04 melodic
Ubuntu16.04 kinetic
Ubuntu 14.04 indigo

So you need to modify indigo to melodic , and when you install it again, there are still problems:

sudo apt-get install ros-melodic-desktop-full python-rosinstall

报错:E: Unable to locate package ros-melodic-desktop-full

It is found that the reason for the error reported here is not only the problem of version correspondence, but also the choice of software source .
It is also possible to use the lsb_release -sc command to directly obtain the version, which is shown here as bionic

sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu bionic main" > /etc/apt/sources.list.d/ros-latest.list'

Or for better porting on other uncertain systems, enter the following command (recommended):

sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'

View the contents of the ros-latest.list file again :

cat /etc/apt/sources.list.d/ros-latest.list
deb http://packages.ros.org/ros/ubuntu bionic main

Then after sudo apt-get update update, there is no problem to install again

After installing ros , the ros directory will appear under the opt directory , check: ls /opt

nvidia  ros

You can enter the ros and take a look. It is the melodic version. What directories and files are there: cd /opt/ros/melodic

bin     include           local_setup.sh   setup.sh        share
env.sh  lib               local_setup.zsh  _setup_util.py
etc     local_setup.bash  setup.bash       setup.zsh

4. Install dependent packages

rosdep is a dependency management utility for ROS. Rosdep can be used with ROS packages and external libraries. It is a command-line utility for identifying and installing dependencies to build or install packages.

sudo rosdep init

If there is an error like sudo: rosdep: command not found , you need to install the python-rosdep
installation command: sudo apt-get install python-rosdep

rosdep update

If there is an error that cannot be accessed due to the network

ERROR: cannot download default sources list from:
https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list
Website may be down.

Processing method, create a new directory and file:

sudo mkdir -p /etc/ros/rosdep/sources.list.d
cd /etc/ros/rosdep/sources.list.d
sudo gedit 20-default.list

Then paste the following content into the 20-default.list file:

# os-specific listings first
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml osx

# generic
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml
gbpdistro https://raw.githubusercontent.com/ros/rosdistro/master/releases/fuerte.yaml fuerte

# newer distributions (Groovy, Hydro, ...) must not be listed anymore, they are being fetched from the rosdistro index.yaml instead

If you can't access it in the front, the same site inside will also be inaccessible. Modify the hosts file:

sudo gedit /etc/hosts
#在文件末尾添加
151.101.84.133 raw.githubusercontent.com

Then rosdep update , and sometimes try a few more times.

5. The newly opened terminal starts automatically

Finally, add setup.bash to ~/.bashrc , so that the terminal will run automatically every time you start it, so that you can run the commands provided by ROS in the shell

echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc

Otherwise, it would be more troublesome to need source /opt/ros/melodic/setup.bash every time you open the terminal .

6. Check ROS

After ROS is installed, we enter the command: roscore to check whether the node manager can be started normally, as shown in the figure:

Well, no problem, this roscore can be understood as each node needs to interact and must report to it, because ROS is a loosely coupled organization method, if messages are to be transmitted between nodes, roscore is needed to provide connection information , that is to say, when each node starts, it will connect to roscore and register the messages published and subscribed by the node. When a new node appears, roscore will provide it with other nodes with the same message topic, so as to establish a connection relationship. If there is no roscore , the nodes will not be able to communicate.
In addition, we also saw ROS_MASTER_URI=http://YAB:11311/ , where YAB is the host name and 11311 is the default port, so we can access it through this URI.

Now let's open two nodes for testing. The two new nodes are talker and listener . One speaks and one listens, that is, one publishes and one subscribes. Draw a picture to show the relationship between them as follows:

It should be noted that the nodes in the figure periodically call the services provided by roscore to find other nodes. Here, the talker and listener call roscore periodically , and the communication between the two nodes is completed directly. Roscore is only a transient connection.

Now open a terminal separately, and run node:

rosrun rospy_tutorials talker
rosrun rospy_tutorials listener

As shown in the picture:

This listener will always listen to the messages published by the talker . If the talker node is terminated with Ctrl+C , the listener node will also stop displaying information and will still be in the listening state.

Guess you like

Origin blog.csdn.net/weixin_41896770/article/details/132242088