Ubuntu 16.04LTS に ROS をインストールして、小さなタートルのサンプルをテストする

1. 参考資料

Ubuntu に ROS Kinetic をインストールする
ROS は、sudo rosdep init 初期化問題を解決するための科学的インターネット アクセスなしで ubuntu16.04 をインストールします

次に、ROS をインストールするための主要な手順

1. ROSのバージョンを選択します

ROS インストール オプション

  • Ubuntuのバージョンが異なり、インストールするROSのバージョンも異なりますので必ずバージョンを合わせてください
  • ROS の Kinetic バージョンは python2.7 に対応しており、Python バージョンを変更すると ros が使用できなくなる可能性があります。
  • ~/.bashrcanaconda と ros の環境変数設定をファイル内に同時に存在させることはできず、一度に使用できるのは 2 つの環境変数のうち 1 つだけです。
  • 1 つのターミナルでは、ROS 用と anaconda 用に 1 つの環境変数のみを開くことができます。ROS を実行するために anaconda の python3 環境を開くと、多くの ROS パッケージが正常に呼び出すことができません;
    kinetic は ROS の古いバージョンであり、デフォルトで python2.7 に基づいて実行され、Ubuntu16.04 に適しています。この記事では、Kinetic バージョンの ROS をインストールする例として Ubuntu16.04LTS システムを取り上げます。
ROSのバージョン Ubuntuのバージョン Pythonのバージョン
ROSキネティック Ubuntu16.04LTS Python2.7
ROSメロディック Ubuntu18.04LTS
ROS ノエティック Ubuntu20.04LTS

ここに画像の説明を挿入

2. Ubuntu ソフトウェア リポジトリを構成する

Ubuntu ソフトウェア ウェアハウス (リポジトリ) を設定し、「制限付き」、「ユニバース」、「マルチバース」にチェックを入れます。

ここに画像の説明を挿入

3. 設定sources.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. キーを設定する

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

5.ROSのインストール

# 更新源
sudo apt update

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

6.rosdepの初期化

ROS の使用を開始する前に、rosdep を初期化する必要があります。rosdep は、特定のソース コードをコンパイルするときにいくつかのシステム依存関係をインストールできます。また、一部の ROS コア機能コンポーネントに必要なツールでもあります。

# 初始化 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. 環境変数を構成する

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

3. ROS Turtlesim の小さなカメのサンプルをテストする

Ubuntu 18.04.1 LTSにROS Melodicをインストールする方法の詳細なプロセス

ROS で小さなタートルを実行する手順は次のとおりです。

1.ロススコアを起動する

# 打开新终端,启动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.リトルタートルノードを開始します

# 打开新终端,启动小海龟节点
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. リトルタートルモーションコントロールノードを起動します

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

ここに画像の説明を挿入

4. 分析手順

  • rosrun: ROS パッケージ内のノードを実行します。
  • turtlesim: これは、ロボット制御をデモンストレーションするための ROS のソフトウェア パッケージです。
  • turtlesim_node: これは、turtlesim パッケージ内のノードであり、画面上に小さなカメを描画するために使用されます。
  • turtle_teleop_key: これは、turtlesim パッケージの別のノードであり、キーボードの矢印キーを使用して小さなカメの動きを制御できます。

を実行するとrosrun turtlesim turtlesim_node、コンピュータは画面上に小さなカメを描画するノードを開始します。を実行するとrosrun turtlesim turtle_teleop_key、コンピュータは別のノードを起動し、キーボードを通じて小さなカメの動きを制御します。

4. よくある質問

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

ここに画像の説明を挿入

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

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

Q: キーの設定に失敗しました

(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

質問: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失败

解決

  1. rosdistro機能パッケージをダウンロードします

    git clone https://github.com/ros/rosdistro.git
    
  2. ファイルを変更します20-default.list

    ファイルを変更しrosdistro/rosdep/sources.list.d/20-default.list、URL をローカル ファイル アドレスに変更します。

    # 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
    

    着替える

    # 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. ファイルを変更しますsources_list.py

    ファイルを変更し/usr/lib/python2.7/dist-packages/rosdep2/sources_list.py、URL をローカル ファイル アドレスに変更します。

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

    着替える

    DEFAULT_SOURCES_LIST_URL = 'file:///home/yoyo/Downloads/rosdistro/rosdep/sources.list.d/20-default.list'
    
  4. ファイルを変更しますrep3.py

    ファイルを変更し/usr/lib/python2.7/dist-packages/rosdep2/rep3.py、URL をローカル ファイル アドレスに変更します。

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

    着替える

    REP3_TARGETS_URL = 'file:///home/yoyo/Downloads/rosdistro/releases/targets.yaml'
    
  5. ファイルを変更します__init__.py

    ファイルを変更し/usr/lib/python2.7/dist-packages/rosdistro/__init__.py、URL をローカル ファイル アドレスに変更します。

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

    着替える

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

質問: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

質問:程序“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

おすすめ

転載: blog.csdn.net/m0_37605642/article/details/131920325