LoginSignup
12
11

More than 3 years have passed since last update.

iRobot Create 2でROSを勉強する(1)準備

Last updated at Posted at 2019-10-30

記事の概要

iRobot Create 2は掃除ロボット「ルンバ600シリーズ」から掃除機能を取り除き、趣味や研究用の改造を可能にしたロボットです。

IMG_1793.jpg

お掃除しないルンバをプログラミングして自分だけのロボットが作れるプラットフォーム「iRobot Create 2」が発売開始

このiRobot Create 2を使って、ロボット用のソフトウェアプラットフォームROSの使い方を勉強したいと思います。

本記事では、準備としてルンバ用のROS1ドライバcreate_autonomyをiRobot Create 2で使用する手順を解説します

購入

iRobot Create 2は部品の規格の問題でアメリカでしか販売できなかったiRobor Createを、部品を交換して海外でも販売できるようにしたものです。
価格は199ドルとルンバより安いですが、残念ながら日本では代理店を介して購入するため4万円弱になります。私はAmazonで購入しました。

「ROS2ではじめよう次世代ロボットプログラミング」では3万円前後で購入できるRoomba 643が推奨されています。

iRobot Create 2の改造のしやすさと、Roomba 643では2000円から5000円をかけてケーブルを用意しないといけない手間を考慮して、今回はiRobot Create 2を選択しました。

ROSのインストール

以下の記事を参照してROSをインストールしました。
ROS講座02 インストール

create_autonomyのビルド

create_autonomyをインストールします。
READMEではcreate_ws/srcを作成していますが、私の場合はインストール済みのROSの環境 catkin_ws/src へ移動し、以下を実行します。
皆さんが以降の手順を参照する際は、各位の環境に合わせてパスを変更してください。

$ cd ~/catkin_ws/src
$ git clone https://github.com/AutonomyLab/create_autonomy.git
$ cd ~/catkin_ws
$ rosdep update  
$ rosdep install --from-paths src -i  

次の手順に進む前に、"catkin build"を使用するための準備が必要になります。
READMEを見ると、ビルドには"catkin_make"ではなく"catkin build"を使用しています。

"catkin build"はROSパッケージをビルドするための新しいコマンドで、新規にpython-catkin-toolsをインストールしないと使えません。

(参照)
Catkin buildの使い方

READMEの手順に従い、python-rosdeと一緒にインストールします。

$ sudo apt-get install python-rosdep python-catkin-tools

既に過去に"catkin_make"でビルドを行っている場合は、srcフォルダの中身を退避させた上で、cleanを実行してから"catkin build"を実行して下さい。

$ cd ~/catkin_ws
$ catkin clean
$ cd src
$ catkin build create_autonomy

ビルドエラー1:libcreateがない

私の場合、ビルドすると以下のエラーが出ました。
libcreateがないとのことでした。create_autonomy/issues/56でも同様のエラーが確認されています。

CMake Error at create_autonomy/ca_driver/CMakeLists.txt:4 (find_package):
  By not providing "Findlibcreate.cmake" in CMAKE_MODULE_PATH this project
  has asked CMake to find a package configuration file provided by
  "libcreate", but CMake did not find one.

  Could not find a package configuration file provided by "libcreate" with
  any of the following names:

    libcreateConfig.cmake
    libcreate-config.cmake

  Add the installation prefix of "libcreate" to CMAKE_PREFIX_PATH or set
  "libcreate_DIR" to a directory containing one of the above files.  If
  "libcreate" provides a separate development package or SDK, be sure it has
  been installed.

そこで以下のlibcreateをインストールします。

READMEの手順をそのまま実行します。

インストール

$ sudo apt-get install build-essential cmake libboost-system-dev libboost-thread-dev
$ sudo apt-get install libgtest-dev
$ cd /usr/src/gtest
$ sudo cmake CMakeLists.txt
$ sudo make
$ sudo cp *.a /usr/lib

ビルド

以下を適当な場所で実行します。私はホームディレクトリで実行しました。

$ git clone https://github.com/AutonomyLab/libcreate.git
$ cd libcreate
$ mkdir build && cd build
$ cmake ..
$ make -j

次にROSのsrcフォルダ(手順書ではcreate_ws/srcフォルダを作成。私の場合はインストール済みのROSの環境 catkin_ws/src)へ移動し、以下を実行します。

$ cd ~/catkin_ws/src
$ git clone https://github.com/AutonomyLab/libcreate.git
$ catkin build

ビルドエラー2:-std=c++11がない

libcreate以外にも-std=c++11オプションがないというエラーも出ます。

Errors     << ca_driver:make /home/kosukematsui/catkin_ws/logs/ca_driver/build.make.003.log
In file included from /usr/include/c++/5/chrono:35:0,
                 from /home/kosukematsui/catkin_ws/devel/include/create/create.h:37,
                 from /home/kosukematsui/catkin_ws/src/create_autonomy/ca_driver/include/create_driver/create_driver.h:36,
                 from /home/kosukematsui/catkin_ws/src/create_autonomy/ca_driver/src/create_driver.cpp:28:
/usr/include/c++/5/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
 #error This file requires compiler and library support \

ca_driverのCMakeLists.txtにオプションを追加します。

$ vi ~/catkin_ws/src/create_autonomy/ca_driver/CMakeLists.txt

CMakeLists.txtに以下を追加してください。

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

(参照)
https://github.com/openalpr/openalpr/issues/528
https://answers.ros.org/question/216842/ros-using-c-11-how-to-use-with-catkin/

USB接続

付属のUSBケーブルを接続し、PCがUSBを認識しているか確認します。

$ ls -l /dev/ttyUSB0
crw-rw---- 1 root dialout 188, 0 10月 30 11:56 /dev/ttyUSB0

問題がなければ、以下のコマンドを実行します

$ sudo usermod -a -G dialout $USER

コマンドが正常に実行されれば、/etc/groupファイルにdialoutにユーザー名が追加されています。
コマンドがうまく行かない場合は、このファイルを直接編集してユーザー名を追加しても問題ありません。

dialout:x:20:kosukematsui

ここで一度ログアウトしてから、再ログインします。
私の場合、これをしていなかったため、後述するroslaunchコマンド実行時にPCがirobot create 2を認識せずに"open: Permission denied"のエラーが出てしまいました。

ドライバ実行

まずsource workspaceのコマンドを実行します。

$ source ~/catkin_ws/devel/setup.bash

次に付属のUSBケーブルをiRobot Create 2に接続します。
緑色のカバーが接続口を塞いでいるので外してください。(カバーが意外と鋭く、手でカバーを外そうとするとケガをする恐れがあるので、ドライバーなどを差し込んで外したほうがいいと思います、私は手で外して指を切りました)

IMG_1795.jpg

接続後、中央のCLEANボタンを押下して緑色に点灯するのを確認します。
緑色点灯中にroslaunchコマンドを実行します。

$ roslaunch ca_driver create_2.launch

正常に動作すれば、バッテリーの残量が表示されます。

kosukematsui@kosukematsui-FMVNA3BE:~$ roslaunch ca_driver create_2.launch
... logging to /home/kosukematsui/.ros/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.

xacro: Traditional processing is deprecated. Switch to --inorder processing!
To check for compatibility of your document, use option --check-order.
For more infos, see http://wiki.ros.org/xacro#Processing_Order
xacro.py is deprecated; please use xacro instead
started roslaunch server http://

SUMMARY
========

PARAMETERS
 * /ca_driver/base_frame: base_footprint
 * /ca_driver/dev: /dev/ttyUSB0
 * /ca_driver/latch_cmd_duration: 0.2
 * /ca_driver/loop_hz: 10.0
 * /ca_driver/odom_frame: odom
 * /ca_driver/publish_tf: True
 * /ca_driver/robot_model: CREATE_2
 * /robot_description: <?xml version="1....
 * /rosdistro: kinetic
 * /rosversion: 1.12.14

NODES
  /
    ca_driver (ca_driver/ca_driver)
    robot_state_publisher (robot_state_publisher/robot_state_publisher)

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

setting /run_id to 
process[rosout-1]: started with pid [13147]
started core service [/rosout]
process[ca_driver-2]: started with pid [13158]
process[robot_state_publisher-3]: started with pid [13161]
[ INFO] [1572320303.002640947]: [CREATE] "CREATE_2" selected
[ INFO] [1572320304.153650521]: [CREATE] Connection established.
[ INFO] [1572320304.153824499]: [CREATE] Battery level 48.81 %
[ INFO] [1572320304.231794764]: [CREATE] Ready.

終了したい時は、Ctrl+C で終了できます。

次にすること

これでROSを使う準備が完了したので、次は送受信トピックのメッセージ通信を試してみたいと思います

関連する記事

(2)roslaunch
(3)rostopic

12
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
11