2021-06-01 Ubuntu 1604 Installation ROS+ROS Initialization Failure Solution


#This article is a compilation of ROS installation on the network and solutions to ROS initialization error problems. It is only used as a personal learning record#

1. ROS Version Selection

ROS currently only supports installation and deployment on Linux systems, and its preferred development platform is Ubuntu. Today, ROS has been updated and released in succession for different versions of Ubuntu developers. To provide the most stable development environment, each version of ROS has a recommended Ubuntu version to run. As shown in the following table:

ROS VersionPreferred Ubuntu Version
NoeticUbuntu 20.04
MelodicUbuntu 18.04
LunarUbuntu 17.04
Kinetic (recommended)Ubuntu 16.04
IndigoUbuntu 14.04
......

This tutorial uses Ubuntu 16.04 as the platform and Kinetic as the ROS version.
If Ubuntu is already installed, you can enter cat/etc/issue in the terminal to determine the Ubuntu version number, and then select the corresponding ROS version. If you do not install the correct version of ROS, a variety of dependency a errors will occur, so be careful when installing.
For more information please refer to ROS Official The website is downloaded and installed.

2. Install ROS

Before a formal installation, check that the Ubuntu initial environment is configured correctly.
Open Ubuntu Settings->Software and Updates->Ubuntu Software->Check the keywords universe,restricted,multiverse. As shown in the diagram:
Once the configuration is complete, you can start installing ROS and open the terminal.
1 Add sources.list

$ 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'

This step of configuration adds mirroring to the list of Ubuntu system sources and suggests using a domestic or mirror source to ensure download speed. This example uses the source of China University of Science and Technology.
(2) Add keys

$ sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116

The public key is a security mechanism of the Ubuntu system and an integral part of the ROS installation.
(3) System Update

$ sudo apt-get update && sudo apt-get upgrade

Update your system to make sure your Debian packages and indexes are up to date.
(4) Installing ROS
There are many function libraries and tools in ROS. Official website provides four default installation methods. Of course, you can install a specific package separately. These four methods include desktop full version installation, desktop version installation, basic version installation, and separate package installation. It is recommended to install a full desktop installation (including ROS, rqt, rviz, Universal Robot Function Library, 2D/3D Emulator, Navigation, and 2D/3D Perception) as follows:
Ubuntu 16.04 Install Kinetic Version

 $ sudo apt-get install ros-kinetic-desktop-full # Ubuntu 16.04

If you don't want to install the full desktop version, you can also try three ways to install it:
Desktop Edition Installation (including ROS, rqt, rviz, and the Universal Robot Function Library)

$ sudo apt-get install ros-kinetic-desktop

Basic installation (including ROS core packages, build tools, and communication-related libraries, without GUI tools)

 $ sudo apt-get install ros-kinetic-ros-base

Separate package installation (this is often used when running ROS without some package dependencies. You can install a specified ROS package and replace the following PACKAGE with the package name)

$ sudo apt-get install ros-kinetic-PACKAGE

For example, if the system hints that slam-gmapping cannot be found, you can:

$ sudo apt-get install ros-kinetic-slam-gmapping

To find available packages, run:

$ apt-cache search ros-kinetic

Dependency issues with packages can also occur during repeated installations of ROS, incorrect installation of packages, and when some packages fail to install, for example:

The following packages have unsatisfactory dependencies: ros-kinetic-desktop-full : 
rely on: ros-kinetic-desktop But it will not be installed;
rely on: ros-kinetic-perception But it will not be installed;
rely on: ros-kinetic-simulators But it will not be installed;
E: Errors cannot be corrected because you require certain packages to remain in place because they break the dependencies between packages.

These problems may be caused by inappropriate incompatibility of your own version, or the mirror source has not been updated, specific settings reference software and updated screenshots. Of course, there may be other reasons, such as update forgot to refresh the environment source, restart a terminal, and so on. The specific cause of the problem can be to go to the search engine to try to solve, or to log on to the ROS Wiki (encyclopedia of ROS) to query to solve their specific problem.

3. Configure ROS

Configuring ROS is a must after installing ROS.
1. Initialize rosdep

$ sudo rosdep init 
$ rosdep update

This step initializes rosdep, which is necessary before using ROS. Rosdep makes it easy to install some system dependencies for certain sources when you need to compile them, as well as tools necessary for certain ROS core functionality components.

Appendix: (Solution for ROS initialization error)

Initialization failure after Ubuntu ROS installation is complete, resolved by creating a configuration file locally.

1. Failed to execute sudo rosdep init
Try it again and again, usually several times, and init will succeed.
If the repetition is unsuccessful, you can try it first by referring to the method provided in the link below.
https://www.cnblogs.com/xuhaoforwards/p/9399744.html
None of the above operations succeeded, so you can refer to the following.
sudo rosdep init The main job of this operation is to https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list , download the file 20-default. List and put it in/etc/ros/rosdep/sources.list.d/under this directory.
20-default. The contents of the list file are as follows:

# 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

Create directory / etc/ros/rosdep/sources with highest privileges. List. D/, and create 20-default in this directory. List this file.
2. Failed to execute rosdep update
The reason for the failure of this step is from raw.githubusercontent.com/Download file failed, mainly due to firewall restrictions on access to this site, students who can access the Internet scientifically do not need to look down.

(1) You can refer to the method linked below to write the python script's timeout a little longer, such as 120s, and then try again and again.
https://www.cnblogs.com/zxzmnh/p/11758103.html
(2) If the above operation is still invalid, please continue to look down. Analyzing sources_mentioned in the previous link List. Py, gbpdistro_support.py, rep3.py several scripts, found mainly open 20-default. Links in the list fail, that is, you cannot download 20-default.list lists several configuration files. Download these files locally and modify the 20-default. The list script file is OK.
The specific operations are as follows:
A. Will be 20-default. The link in the list opens in the browser and creates a file with the same name, preferably with a directory structure, so it's easier to change the script later. I built the directory directly at / etc/ros/
The corresponding files are provided. Baidu Netdisk: https://pan.baidu.com/s/14bQbLQ6v-j9SfrHPfCu5Nw Extraction Code: hy4o , and unzip to the / etc/ros directory after downloading. Super privileges are required.
b. Modify 20-default.list script file, requires super privileges. You can compare it with the previous script.

# os-specific listings first
#yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml osx
yaml file:///etc/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
 
yaml file:///etc/ros/rosdistro/master/rosdep/base.yaml
yaml file:///etc/ros/rosdistro/master/rosdep/python.yaml
yaml file:///etc/ros/rosdistro/master/rosdep/ruby.yaml
gbpdistro file:///etc/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

Exit save and execute rosdep update.
During the update process, some of the configuration information will be from raw.githubusercontent.com, but after several iterations, you can basically succeed.
(3) After the above two steps or failures, please continue to look down.
sudo open/usr/lib/python2. 7/dist-packages/rosdistro/u Init_u. Py This file, follow the code below to modify.

# index information
 
#DEFAULT_INDEX_URL = 'https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml'
DEFAULT_INDEX_URL = 'file:///etc/ros/rosdistro/master/index-v4.yaml'

After saving, perform rosdep update. If you do not succeed one or two more times, you should see the following successfully completed prints.
(4) If you go to step 3 or make a mistake
Perhaps the local DNS service is contaminated and unavailable https://raw.githubusercontent.com The correct IP for this web address caused the connection to fail. You need to update your DNS server settings and select an external DNS server. Taking ubuntu MATE 16.04 as an example, the path is as follows:
System --> System Management --> Network --> DNS, under this interface, unlock first, then in the DNS server bar, click Add, fill in the dialog box with 8.8.8.8 (google's DNS server), put it in one place (you can drag it up and down), lock it, close it.
Back to the terminal, execute the rosdep update. At this time, there should be no error reporting, there may be timeouts, mainly due to network speed problems, several attempts should appear below the successful printing.

reading in sources list data from /etc/ros/rosdep/sources.list.d
Hit file:///etc/ros/rosdistro/master/rosdep/osx-homebrew.yaml
Hit file:///etc/ros/rosdistro/master/rosdep/base.yaml
Hit file:///etc/ros/rosdistro/master/rosdep/python.yaml
Hit file:///etc/ros/rosdistro/master/rosdep/ruby.yaml
Hit file:///etc/ros/rosdistro/master/releases/fuerte.yaml
Query rosdistro index file:///etc/ros/rosdistro/master/index-v4.yaml
Skip end-of-life distro "ardent"
Skip end-of-life distro "bouncy"
Skip end-of-life distro "crystal"
Add distro "dashing"
Add distro "eloquent"
Add distro "foxy"
Skip end-of-life distro "groovy"
Skip end-of-life distro "hydro"
Skip end-of-life distro "indigo"
Skip end-of-life distro "jade"
Add distro "kinetic"
Skip end-of-life distro "lunar"
Add distro "melodic"
Add distro "noetic"
updated cache in /home/xxxx/.ros/rosdep/sources.cache

(2) ROS Environment Configuration

#For Ubuntu 16.04
$ echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc

Note: The environment configuration of ROS enables the environment variables of ROS to be automatically configured each time you open a new terminal, that is, added to the bash session, because the command source/opt/ros/kinetics/setup. Bash only works on the current terminal, that is, it has a single timeliness. To open a new terminal each time without reconfiguring the environment, add commands to the bash session using echo statements.
(3) Install rosinstall
rosinstall is a stand-alone, common command-line tool in ROS that allows you to download many source trees for an ROS package in one command. Install this tool on ubuntu, run:

$ sudo apt-get install python-rosinstall

At this point, the installation of ROS is finished, and the following tests will be performed to see if the ROS is working properly.

4. Testing ROS

Start the ROS first, enter the code to run the roscore:

$ roscore

If the image below shows, ROS is started normally!

Next, let's test the mascot of the ROS, the little turtle, to simply test if the ROS is working properly, and also to experience the magic and wonder of the ROS!
After starting roscore, reopen a terminal window and enter:

$ rosrun turtlesim turtlesim_node

You also see a sprouting turtle appear on the screen, so what can you do to manipulate the little turtle? Reopen a new terminal, enter:

$ rosrun turtlesim  turtle_teleop_key

Focus the mouse on the third terminal window and use the arrow keys on the keyboard to operate the turtle. If the turtle moves normally and leaves its own track on the screen, as shown below. Congratulations, ROS has been successfully installed, configured and running!

At this point, the installation, configuration and testing of ROS have all ended, and now officially start the wonderful journey of ROS!

Keywords: Linux Ubuntu ROS

Added by mp04 on Wed, 02 Feb 2022 10:33:44 +0200