Quantcast
Channel: Bashタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 2832

turtlebot3をraspi3B(ubuntu mate18.04-64bit)とros merodicで動作させたい!!

$
0
0

1.はじめに

最近ROSを勉強し始め、その初歩として研究室の備品のturtlebot3 burgerを
turtlebot3 e-manual
https://emanual.robotis.com/docs/en/platform/turtlebot3/pc_setup/
を参考にしながらROS melodicで動作させようとした時の手順やうまくいかない行かなかった部分をまとめました~
※筆者も勉強中なためその都度加筆します

2.環境

  • メインPC

    • 機種 surface pro
    • OS ubuntu18.04LTS (dualboot)
  • turtlebot3 PC

    • 機種 Raspberry Pi 3B
    • OS ubuntu mate 18.04 (ubuntu-mate-18.04.2-beta1-desktop-arm64 + raspi3-ext4)

この辺のインストールについては秀逸な記事が沢山あるので割愛します...
ラズパイに関してはモニターをいちいち繋いでの設定はとても手間なので
SSHを利用してPC上で操作できるようにしましょう

raspi
sudo touch /boot/ssh

そのつぎのコマンドを利用してraspiのipアドレス(だいたい192.から始まるもの)を調べます。

raspi
ifconfig

メインPCとraspiを同一LAN(同じWIFIなど)に接続して
メインPC上からraspiのターミナルを操作できるようにしましょう

メインPC
ssh raspiのユーザー名@raspiのipアドレス

3.インストールと設定

ROS melodicとtutkebot3用のパッケージをインストールしましょう
melodicのインストールについてはありがたいことに
https://github.com/ryuichiueda/ros_setup_scripts_Ubuntu18.04_desktop
なる便利なものがあるため利用しましょう!

3.1 ROS melodicのインストール 
メインPC+raspi
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install-y curl
bash -c"$(curl -SsfL https://git.io/ros-melodic-desktop)"
3.2 ROSの環境設定

この段階ではROSへパスが通っておらず、コマンドなどが利用できないためパスを通しましょう。
その後、ターミナルを起動するたびに設定するのが面倒なのでbashrc(ターミナルを起動するたびに実行させるもの)へ登録しましょう
(これをやっておかないと様々なエラーが起きるのでお忘れなく)

メインPC+raspi
echo"source /opt/ros/melodic/setup.bash">> ~/.bashrc
source ~/.bashrc
source /opt/ros/melodic/setup.bash
3.3 rosinstallの準備

ROS installというビルド用のものやらライブラリをインストールします

メインPC
sudo apt  install python-rosdep python-rosinstall-generator python-wstool python-rosinstall build-essential
3.4 rosdepを設定
メインPC+raspi
sudo apt install python-rosdep
sudo rosdep_init
rosdep update
3.5 workspaceを設定

rosで用いられる作業用スペースを作成します(よく用いられる名前のcatkin_wsで作成します)

メインPC+raspi
source ~/.bashrc
mkdir-p ~/catkin_ws/src
cd ~/catkin_ws/src
catkin_init_workspace
echo"source ~/catkin_ws/devel/setup.bash">> ~/.bashrc
catkin_make
source ~/catkin_ws/devel/setup.bash
3.6 turtlebot3用の依存パッケージをインストール

e-manualに記載されている物をkineticからmelodicに読み替えて実行しましょう
(gmappingをgitから入れると何故かビルドできないためaptで入れましょう)

メインPC
sudo apt-get install ros-melodic-joy ros-melodic-teleop-twist-joy ros-melodic-teleop-twist-keyboard ros-melodic-laser-proc ros-melodic-rgbd-launch ros-melodic-depthimage-to-laserscan ros-melodic-rosserial-arduino ros-melodic-rosserial-python ros-melodic-rosserial-server ros-melodic-rosserial-client ros-melodic-rosserial-msgs ros-melodic-amcl ros-melodic-map-server ros-melodic-move-base ros-melodic-urdf ros-melodic-xacro ros-melodic-compressed-image-transport ros-melodic-rqt-image-view ros-melodic-gmapping ros-melodic-navigation ros-melodic-interactive-markers

次にturtlebot3 のパッケージをダウンロード後、ビルドします

メインPC
cd ~/catkin_ws/src
git clone https://github.com/ROBOTIS-GIT/turtlebot3_msgs.git
git clone -b melodic-devel https://github.com/ROBOTIS-GIT/turtlebot3.git

raspi側にもturtlebot3のパッケージをダウンロードしましょう

raspi
cd ~/catkin_ws/src
git clone https://github.com/ROBOTIS-GIT/hls_lfcd_lds_driver.git
git clone https://github.com/ROBOTIS-GIT/turtlebot3_msgs.git
git clone https://github.com/ROBOTIS-GIT/turtlebot3.git

その後確認のためにrosserial関連のものをインストールしましょう
(多分インストールされてます。)

raspi
sudo apt install ros-melodic-rosserial-python ros-melodic-tf
 sudo apt install ros-melodic-rosserial-arduino

インストールが終了したら両方のPCでビルドしましょう。
ビルドした時にエラーがでなければ正常にインストールが出来ているとはずです…

メインPC+raspi
source /opt/ros/melodic/setup.bash
cd ~/catkin_ws && catkin_make

root権限を用いずにOpenCRのUSBポートへアクセスするための設定をします

raspi
rosrun turtlebot3_bringup create_udev_rules
3.7 OpenCR

次にOpenCRのファームウェアの書き換えを行いますがraspi3B上のubuntu(64bit)では
opencr_ld_shell_x86 cannot execute binary file exec format error
とエラーが出され書き込めないため、メインPCを使ってshellを走らせましょう(筆者はここで詰まりました…)
OpenCRとメインPCをUSBで接続してから

メインPC
sudo dpkg --add-architecture armhf
sudo apt-get update
sudo apt-get install libc6:armhf
export OPENCR_PORT=/dev/ttyACM0
export OPENCR_MODEL=burger
rm-rf ./opencr_update.tar.bz2
wget https://github.com/ROBOTIS-GIT/OpenCR-Binaries/raw/master/turtlebot3/ROS1/latest/opencr_update.tar.bz2 &&tar-xvf opencr_update.tar.bz2 &&cd ./opencr_update && ./update.sh $OPENCR_PORT$OPENCR_MODEL.opencr &&cd ..

ここでエラーを吐かれた場合にはUSBケーブルとの接続を確認してからもう一度shellを実行しましょう
その際に最後の文はtar -xvf opencr_update.tar.bz2 ....のところから実行しないとopencr_update.tar.bz2 のファイルが増え続けるのでご注意を…

3.8 ネットワーク設定

ROSを分散実行するために必要なネットワーク設定をします
まず初めにifconfigコマンドでipアドレスを調べましょう
その後nano エディタを利用してbashrcを編集します

ファイルの下の方に行くと次のような文があるので書き換えます(ctrl+xで保存できます)

メインPC
export ROS_MASTER_URI=http://メインPCのアドレス:11311
export ROS_HOSTNAME=メインPCのアドレス

その後次のコマンドを実行しましょう

メインPC
export ROS_IP=メインPCのipアドレス
source ~/.bashrc

raspi側でもbashrcの編集を行います
途中までは同じですがipを書き換える部分を

raspi
export ROS_MASTER_URI=http://メインPCのipアドレス:11311
export ROS_HOSTNAME=raspiのipアドレス

とすることに注意です
その後はメインPCと同じようにROS_IPとsource ~/.bashrcを実行しましょう。

4.実行

設定が終わったので実行してみましょう
OpenCRについているスライドスイッチをオンにするのを忘れずに!!

メインPC
roscore
raspi
roslaunch turtlebot3_bringup turtlebot3_robot.launch

これで起動が完了したため、キーボードを使って操作してみましょう(思ったより速いので注意です)

メインPC
export TURTLEBOT3_MODEL=burger
roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch

これでひと通りの設定と起動ができたはずです。
この後はslamを実行したりとできることが沢山あるみたいなので一緒に取り組んでいきましょう!
良いturtlebot3ライフを~~~~

5.トラブルシューティング

エラーが出た場合にはパスが通ってない場合があるため

source /opt/ros/melodic/setup.bash
source ~/catkin_ws/devel/setup.bash

を実行してからビルドし直し、
それでもうまくいかない場合はrqt_graphをつかってトピックが送られているかを確認しましょう
それでもうまくいかない場合にはとても手間ですが

sudo apt-get remove ros-*

を利用してROSをアンインストールしてから再インストールしましょう

6.参考文献

トランジスタ技術 2020年9月号
Raspberry Pi Mouse Simulator's Tutorial
https://raspimouse-sim-tutorial.gitbook.io/project/
turtlebot3 e-manual
https://emanual.robotis.com/docs/en/platform/turtlebot3/pc_setup/


Viewing all articles
Browse latest Browse all 2832

Latest Images

Trending Articles