Install ROS on Ubuntu 16.04LTS to test the small turtle sample

1. Reference materials

Install ROS Kinetic in Ubuntu
ROS installs ubuntu16.04 without scientific Internet access to solve sudo rosdep init initialization problem

Second, the key steps to install ROS

1. Select the ROS version

ROS installation options

  • The versions of Ubuntu are different, and the versions of ROS to be installed are also different. Be sure to align the versions
  • The Kinetic version of ROS corresponds to python2.7, modifying the python version may cause ros to be unusable;
  • ~/.bashrcThe environment variable settings of anaconda and ros cannot exist in the file at the same time, and only one of the two environment variables can be used at a time;
  • Under one terminal, only one environment variable for ROS and one for anaconda can be opened. Open anaconda's python3 environment to run ROS, many ROS packages cannot be called normally;
    kinetic, as an older version of ROS, runs based on python2.7 by default, and is suitable for Ubuntu16.04. This article takes the Ubuntu16.04LTS system as an example to install the Kinetic version of ROS.
ROS version Ubuntu version python version
ROS Kinetic Ubuntu16.04LTS python2.7
ROS Melodic Ubuntu18.04LTS
ROS Noetic Ubuntu20.04LTS

insert image description here

2. Configure the Ubuntu software repository

Configure the Ubuntu software warehouse (repositories), check "restricted", "universe" and "multiverse".

insert image description here

3. Settingssources.list

# 设置安装源
sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ `lsb_release -cs` main" > /etc/apt/sources.list.d/ros-latest.list'

4. Set the key

# 设置key密钥
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654

5. Install ROS

# 更新源
sudo apt update

# 安装ROS
sudo apt-get install ros-kinetic-desktop-full

6. Initialize rosdep

rosdep needs to be initialized before starting to use ROS. rosdep can install some system dependencies when compiling certain source codes, and it is also a necessary tool for some ROS core functional components.

# 初始化 rosdep
sudo rosdep init
rosdep update
(demo) yoyo@yoyo:/usr/lib/python2.7/dist-packages/rosdistro$ sudo rosdep init
Wrote /etc/ros/rosdep/sources.list.d/20-default.list
Recommended: please run

	rosdep update

(demo) yoyo@yoyo:/usr/lib/python2.7/dist-packages/rosdistro$ rosdep update
reading in sources list data from /etc/ros/rosdep/sources.list.d
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/releases/fuerte.yaml
Query rosdistro index file:///home/yoyo/Downloads/rosdistro/index-v4.yaml
Skip end-of-life distro "ardent"
Skip end-of-life distro "bouncy"
Skip end-of-life distro "crystal"
Skip end-of-life distro "dashing"
Skip end-of-life distro "eloquent"
Skip end-of-life distro "foxy"
Skip end-of-life distro "galactic"
Skip end-of-life distro "groovy"
Add distro "humble"
Skip end-of-life distro "hydro"
Skip end-of-life distro "indigo"
Add distro "iron"
Skip end-of-life distro "jade"
Skip end-of-life distro "kinetic"
Skip end-of-life distro "lunar"
Skip end-of-life distro "melodic"
Add distro "noetic"
Add distro "rolling"
updated cache in /home/yoyo/.ros/rosdep/sources.cache

7. Configure environment variables

# 配置环境变量
echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc
source ~/.bashrc

3. Test the ROS turtlesim small turtle sample

Detailed process of how to install ROS Melodic on Ubuntu 18.04.1 LTS

To run the little turtle in ROS, the steps are as follows:

1. Start roscore

# 打开新终端,启动roscore
roscore
yoyo@yoyo:/usr/lib/python2.7/dist-packages/rosdistro$ roscore
... logging to /home/yoyo/.ros/log/d3752a5e-2ac3-11ee-9ef5-18c04d9e91e3/roslaunch-yoyo-32650.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://yoyo:36853/
ros_comm version 1.12.17


SUMMARY
========

PARAMETERS
 * /rosdistro: kinetic
 * /rosversion: 1.12.17

NODES

auto-starting new master
process[master]: started with pid [32661]
ROS_MASTER_URI=http://yoyo:11311/

setting /run_id to d3752a5e-2ac3-11ee-9ef5-18c04d9e91e3
process[rosout-1]: started with pid [32674]
started core service [/rosout]

2. Start the little turtle node

# 打开新终端,启动小海龟节点
rosrun turtlesim turtlesim_node
(demo) yoyo@yoyo:~$ rosrun turtlesim turtlesim_node
[ INFO] [1690273390.857742853]: Starting turtlesim with node name /turtlesim
[ INFO] [1690273390.860713835]: Spawning turtle [turtle1] at x=[5.544445], y=[5.544445], theta=[0.000000]

3. Start the little turtle motion control node

# 打开新终端,启动小海龟运动控制节点
rosrun turtlesim turtle_teleop_key
yoyo@yoyo:~$ rosrun turtlesim turtle_teleop_key
Reading from keyboard
---------------------------
Use arrow keys to move the turtle.

insert image description here

4. Analysis instructions

  • rosrun: run node in ROS package;
  • turtlesim: This is a software package in ROS for demonstrating robot control;
  • turtlesim_node: This is a node in the turtlesim package, used to draw little turtles on the screen;
  • turtle_teleop_key: This is another node in the turtlesim package, it can control the movement of the little turtle through the arrow keys on the keyboard.

When executing rosrun turtlesim turtlesim_node, the computer will start a node to draw the little turtle on the screen. When executing rosrun turtlesim turtle_teleop_key, the computer will start another node, which will control the movement of the little turtle through the keyboard.

4. FAQ

Q:E:无法定位软件包 ros-noetic-desktop-full

insert image description here

错误原因:
ROS版本与Ubuntu版本不匹配

解决办法:
安装合适的ROS版本

Q: Failed to set the key

(demo) yoyo@yoyo:~$ sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
Executing: /tmp/tmp.N32dAXh9fh/gpg.1.sh --keyserver
hkp://keyserver.ubuntu.com:80
--recv-key
C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
gpg: 下载密钥‘AB17C654’,从 hkp 服务器 keyserver.ubuntu.com
gpg: 密钥 AB17C654:“Open Robotics <[email protected]>”未改变
gpg: 合计被处理的数量:1
gpg:              未改变:1
(demo) yoyo@yoyo:~$ curl -sSL 'http://keyserver.ubuntu.com/pks/lookup?op=get&search=0xC1CF6E31E6BADE8868B172B4F42ED6FBAB17C654' | sudo apt-key add -
程序“curl”尚未安装。 您可以使用以下命令安装:
sudo apt install curl
gpg: 找不到有效的 OpenPGP 数据。
(demo) yoyo@yoyo:~$ sudo apt-key adv --keyserver 'hkp://pgp.mit.edu:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
Executing: /tmp/tmp.LQAFHhtZPo/gpg.1.sh --keyserver
hkp://pgp.mit.edu:80
--recv-key
C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
gpg: 下载密钥‘AB17C654’,从 hkp 服务器 pgp.mit.edu
gpg: 密钥 AB17C654:“Open Robotics <[email protected]>”未改变
gpg: 合计被处理的数量:1
gpg:              未改变:1
错误原因:
无法连接到密钥服务器

解决办法:
wget http://packages.ros.org/ros.key
sudo apt-key add ros.key

Q:ERROR: cannot download default sources list from:

(demo) yoyo@yoyo:~$ sudo rosdep init
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.
错误原因:
无法连接到国外服务器,导致初始化 rosdep失败

Solution

  1. Download the rosdistro feature package;

    git clone https://github.com/ros/rosdistro.git
    
  2. modify the file 20-default.list;

    Modify rosdistro/rosdep/sources.list.d/20-default.listthe file and change the url to a local file address.

    # 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
    

    change into

    # os-specific listings first
    yaml file:///home/yoyo/Downloads/rosdistro/rosdep/osx-homebrew.yaml osx
    
    # generic
    yaml file:///home/yoyo/Downloads/rosdistro/rosdep/base.yaml
    yaml file:///home/yoyo/Downloads/rosdistro/rosdep/python.yaml
    yaml file:///home/yoyo/Downloads/rosdistro/rosdep/ruby.yaml
    gbpdistro file:///home/yoyo/Downloads/rosdistro/releases/fuerte.yaml fuerte
    
    # newer distributions (Groovy, Hydro, ...) must not be listed anymore, they are being fetched from the rosdistro index.yaml instead
    
  3. modify the file sources_list.py;

    Modify /usr/lib/python2.7/dist-packages/rosdep2/sources_list.pythe file and change the url to a local file address.

    DEFAULT_SOURCES_LIST_URL = 'https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list'
    

    change into

    DEFAULT_SOURCES_LIST_URL = 'file:///home/yoyo/Downloads/rosdistro/rosdep/sources.list.d/20-default.list'
    
  4. modify the file rep3.py;

    Modify /usr/lib/python2.7/dist-packages/rosdep2/rep3.pythe file and change the url to a local file address.

    REP3_TARGETS_URL = 'https://raw.githubusercontent.com/ros/rosdistro/master/releases/targets.yaml'
    

    change into

    REP3_TARGETS_URL = 'file:///home/yoyo/Downloads/rosdistro/releases/targets.yaml'
    
  5. modify the file __init__.py;

    Modify /usr/lib/python2.7/dist-packages/rosdistro/__init__.pythe file and change the url to a local file address.

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

    change into

    DEFAULT_INDEX_URL = 'file:///home/yoyo/Downloads/rosdistro/index-v4.yaml'
    

Q:ERROR: default sources list file already exists:

ERROR: default sources list file already exists:
	/etc/ros/rosdep/sources.list.d/20-default.list
Please delete if you wish to re-initialize
错误原因:
重复初始化,导致初始化 rosdep失败

解决办法:
删除20-default.list文件,重新初始化

sudo rm -r /etc/ros/rosdep/sources.list.d/20-default.list
sudo rosdep init
rosdep update

Q:程序“rosrun”尚未安装。 您可以使用以下命令安装:

(demo) yoyo@yoyo:/media/yoyo/U$ rosrun turtlesim turtlesim_node
程序“rosrun”尚未安装。 您可以使用以下命令安装:
sudo apt install rosbash
错误原因:
环境变量未生效

解决办法:
配置环境变量,重新打开终端
echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc
source ~/.bashrc

Guess you like

Origin blog.csdn.net/m0_37605642/article/details/131920325