LoginSignup
12
7

More than 5 years have passed since last update.

RaspberryPi3とZumoとROSで半永久自走式充放電ロボを作成したい_002日目_用語・TOPIC

Last updated at Posted at 2018-04-07

◆ 前回記事

RaspberryPi3とZumoとROSで半永久自走式充放電ロボを作成したい_001日目_はじめに の続き

◆ はじめに

実は、思い立ちのトリガーを明確に引いたブログがあって、実作業に移る前に少し紹介させていただきたい。
下記、karaageさん と言う方のブログ。
karaage.[からあげ] http://karaage.hatenadiary.jp/
素直に直感的に、むちゃくちゃ面白いし分かり易く丁寧だ、と感じた。
真似はできないが、節々に読み手への配慮を感じる。
これといった趣味も無く、無駄金を使いまくっていた自分を救済してくれた、と言っても過言ではない気がする。

話は変わるが、WEB上で綺麗に作図できるツールが無いか探していたたころ、 draw.io というものを見つけた。
インストール不用、無料、機能がやたら豊富、日本語対応、保存先にクラウド上のドライブ指定可能。
Visioの無料Web版のようなイメージ。
個人的には Visio より猛烈に使い勝手が良い。

なんなんだ、これは…。
GOD降臨。
初代4号機なら 5,000枚確定 だ。
0000_Tool01a.png
0000_Tool02a.png
0000_Tool03a.png
0000_Tool04a.png
0000_Tool05a.png
0000_Tool06a.png
0000_Tool07a.png
0000_Tool08a.png

・WEB作図ツールで参考にさせていただいた記事
https://www.google.co.jp/amp/s/nelog.jp/draw-io%3famp=1

慣れてきたら、おいおいハードウェア構成図も描こうと思う。

◆ ROSはじめ

さて本題。
大半の方はこの記事を読むまでも無いと思う。
それほどに、初歩的な話題と実装に終始することからのスタートとなる。
ひとつずつ着実に理解するため、自分なりに腹落ちした内容をそのままアウトプットすることにする。

* 基本用語などなど

  • ROSとは
    • Robot Operating System (ロボットオペレーティングシステム) の略称
    • オペレーティング・システムと言いながら Windows/Linux などのそれとは別義
    • OSの上で動くロボット制御のための通信用ライブラリ集 ≒ フレームワーク
    • オープンソース
  • ROSが使用されている有名なロボット
    • Pepper
    • 良く知っているロボ以外にもたくさん出回っているらしい→ http://robots.ros.org/
  • NODE
    • 日本語で "節" OS上でプロセス1個に該当、こじんまりとした処理をする
  • MESSAGE
    • 日本語で "伝言" NODE間で伝達対象となるデータそのもの 構造体・クラスのように型付けされている
  • MASTER
    • 日本語で "親方" NODEを統べる指揮者的な振る舞いをする DNSのようにNODE間の名前解決をする
  • TOPIC
    • 日本語で "話題" 非同期処理方式 バラバラなタイミングで飛び交うデータを一時的にストックし、NODE間で情報を共有するタイプの通信形式
  • SERVICE
    • 日本語で "サービス" 同期処理方式 NODE間で親子関係を持たせる通信方式
  • PARAMETER
    • 日本語で "パラメータ" 起動パラメータのようなものかな?
  • PUBLISH
    • 日本語で "発行する" TOPICへデータを書き込むこと
  • SUBSCRIBE
    • 日本語で "定期購読する" TOPICからデータを読み出すこと
  • PUBLISHER
    • 日本語で "発行者" データをTOPICへ書き込む人
  • SUBSCRIBER
    • 日本語で "購読者" データをTOPICから読み出す人

英語を日本語に翻訳して少し注釈を足しただけだけど、なんとなく登場人物の役割が見え隠れしてきた。

* シンプルな構成の場合(Pub/Sub型)

  • NODE間の処理順序は非同期
  • NODE間はすべて対等な関係
  • NODEたちは自分が欲しい情報(MESSAGE)に狙いを定めてTOPICからピンポイントに取り出し可能
  • 逆に、それぞれのNODEは自分の好き勝手なタイミングでTOPICへ情報(MESSAGE)を保存可能
Pub/Sub型
0001_Pub-SUb.png

なるほど、ROSは小さな役割(処理)を複数のNODE(プロセス)に分散処理させる、というコンセプトで、役割の数だけNODEを起動させるのがセオリーなのかな。
Pepperの具体的な仕組みは知らないけれど、腕を動かす役割のNODE、カメラ画像から顔を認識するNODE、車輪を動かすNODE、のように役割分担をして動いていると予想。
各部品はバラバラに動いていても、全体としてはうまく統制がとれているように見える、ということかな。感心感心。

* 少しトリッキーな構成の場合(Service型)

  • NODE間の処理順序は同期
  • 任意のNODE間が親子関係になる
  • 子側の処理が終わるまでは、呼び出し元にあたる親側は子側の処理完了を待機する
Service型
0002_Service.png

ふむ、非同期前提のフレームワークだけれど、ちゃんと同期処理も可能ということ。
ただ、むやみやたらにサービス化すると、お互いのNODE間で処理終了待ちが発生してデッドロックのような状況になってしまうかもしれないな。気をつけよう。

◆ RaspberryPi へ ROS 開発環境の導入

座学は飽きてきたので早速手を動かしたい。
基本的な作業は Raspbian Stretch+NCS(Neural Compute Stick)+YoloV2+Webカメラ+ROSによるリアルタイム複数動体検知環境の構築 に記載の、
 ◆ ROS [kinetic]のインストール
 ◆ 環境変数の追加
に基づいて実施。
基本構想ではRaspberryPi上でROS環境の全てを完結させたいため、
RaspberryPi側でマスターを起動する場合 のほうを採用する。

◆ ROS のワークスペース作成

作業用エリアを確保する作業、かな。

ワークスペースの作成
$ mkdir -p ~/catkin_ws/src
$ cd ~/catkin_ws/src
$ catkin_init_workspace

下記のように src フォルダの中身を確認すると、

$ ls
CMakeLists.txt

CMakeLists.txt というファイルが自動生成されている。
catkin_init_workspace コマンドは最初に1回だけ実行する『オマジナイ』のようなものなのかな。
試しに、Smaba越しに ~/catkin_ws/src の中身を覗いてみると、何故か何も表示されない。不思議。
0002.png

続いて次の『オマジナイ』を実行する。

catkin_make
$ cd ..
$ catkin_make

何やら、C と C++ のコンパイラみたいなものが動いて、どこにあるのか分からないプログラムのコンパイルがスタートした、ように見える。

実行ログ
Base path: /home/pi/catkin_ws
Source space: /home/pi/catkin_ws/src
Build space: /home/pi/catkin_ws/build
Devel space: /home/pi/catkin_ws/devel
Install space: /home/pi/catkin_ws/install
####
#### Running command: "cmake /home/pi/catkin_ws/src -DCATKIN_DEVEL_PREFIX=/home/pi/catkin_ws/devel -DCMAKE_INSTALL_PREFIX=/home/pi/catkin_ws/install -G Unix Makefiles" in "/home/pi/catkin_ws/build"
####
-- The C compiler identification is GNU 6.3.0
-- The CXX compiler identification is GNU 6.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Using CATKIN_DEVEL_PREFIX: /home/pi/catkin_ws/devel
-- Using CMAKE_PREFIX_PATH: /opt/ros/kinetic
-- This workspace overlays: /opt/ros/kinetic
-- Found PythonInterp: /usr/bin/python (found version "2.7.13") 
-- Using PYTHON_EXECUTABLE: /usr/bin/python
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/pi/catkin_ws/build/test_results
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Found gtest sources under '/usr/src/gtest': gtests will be built
-- Using Python nosetests: /usr/bin/nosetests-2.7
-- catkin 0.7.8
-- BUILD_SHARED_LIBS is on
-- Configuring done
-- Generating done
-- Build files have been written to: /home/pi/catkin_ws/build
####
#### Running command: "make -j4 -l4" in "/home/pi/catkin_ws/build"
####

「-- Build files have been written to: /home/pi/catkin_ws/build」 ということなので、Samba越しに ~/catkin_ws を覗いてみる。

0003.png

勝手に build フォルダと devel フォルダが生成されている。
ん〜? 何者だ、このフォルダ?
build = ビルド
devel = development(開発) か何かの略称か?

とりあえず細かいことはさておいて、チュートリアルどおりに進めるなら、次は
$ source devel/setup.bash
を実行せよ。とのことなのでおもむろに実行。

「環境変数 ROS_PACKAGE_PATH にワークスペースのディレクトリが含まれる」 ということらしいが、国語力が無いのでチュートリアルにうたわれている内容、読者に説明しようとしている本質的なこと、がこの時点ではまったく理解不能。
とりあえず、環境変数 ROS_PACKAGE_PATH の内容を確認してみる。

devel/setup.bash実行前
$ echo $ROS_PACKAGE_PATH
/opt/ros/kinetic/share
devel/setup.bash実行後
$ echo $ROS_PACKAGE_PATH
/home/pi/catkin_ws/src:/opt/ros/kinetic/share

「/home/pi/catkin_ws/src:」 が先頭に足されていることが確認できる。
環境変数に書き込むぐらいだから、自分の作業領域上で作成したプログラムの実行時検索先PATHか何かだろうか。

次は 「パッケージの作成」 らしいが、いったん、立ち止まって単語の意味を整理してみる。

  • ワークスペース パッケージをビルドするためのユーザーディレクトリ配下のトップディレクトリを指す
  • パッケージ プログラムを格納するための最小単位 ROSでは全てのプログラムはどこかのパッケージに属する必要があり、プログラムのビルドはパッケージ単位で行われる パッケージにはソースコード、実行ファイル、及び関連するファイルが集められる
  • CMakeLists.txt パッケージのビルドに関する情報が CMakeLists.txt に記述され、パッケージの定義(基本情報)は package.xml というマニフェストファイルに記述される
  • マニフェストファイル package.xml そのアプリの基本的な設定が記述される たとえばアプリの名前、アプリのバージョン、対象OSバージョン、必要とする権限、ライセンス情報、著作者の情報などなど 初心者が軽くチュートリアルレベルで触る程度ならどうでも良さげな内容

「パッケージの作成」を行うと、こういう構成イメージが出来上がるらしい。
最初の準備段階ではコマンドを数回実行するだけで必要な立て付けを整えてくれるようだ。
今の段階では階層が複雑過ぎて、正直言うといまいちピンと来ない。

ROSのフォルダ階層イメージ
0003_Workspace.png

◆ パッケージの作成

ここまででワークスペースは生成されているため、今度はパッケージを作成する。
パッケージを作成するための基本スクリプトは下記のとおりらしい。

パッケージ作成スクリプト
$ cd ~/catkin_ws/src
$ catkin_create_pkg パッケージ名 [ビルドに必要なパッケージ名]

では、「パッケージA」 に該当する部分に 「tutorials」 という名前で初めてのパッケージを作ってみる。
std_msgs と rospy と roscpp というのがチュートリアルレベルでインクルードが必要となる基本的なパッケージらしい。
自前で作ったパッケージをインクルードさせる場合は 「自前作成のパッケージ名」 を追加で指定することになる、と予想。
名前から勝手に推察するに、

  • std_msgs = std_msg だから スタンダードなメッセージを扱うパッケージかな?
  • rospy = py だから Python のラッパーか何かかな?
  • roscpp = cpp だから C++ のラッパーか何かかな?

早速実行してみる。

パッケージ作成スクリプト
$ cd ~/catkin_ws/src
$ catkin_create_pkg tutorials std_msgs rospy roscpp
実行ログ
Created file tutorials/CMakeLists.txt
Created file tutorials/package.xml
Created folder tutorials/include/tutorials
Created folder tutorials/src
Successfully created files in /home/pi/catkin_ws/src/tutorials. Please adjust the values in package.xml.

特にエラーなど発生せずに終わったようだ。
どれ、 「ROSのフォルダ階層イメージ」 のように仕上がっているかな?

0004.png

うん、出来てる出来てる。
ここでWEB上をサーフィンしていたところ、パッケージを作成しただけでは必要なファイルが生成されないことがある、らしい。
ワークスペースの直下で改めて catkin_make コマンドを実行しておくと良いらしい。
意味不明だがやってみる。

catkin_make
$ cd ~/catkin_ws
$ catkin_make
実行ログ
Base path: /home/pi/catkin_ws
Source space: /home/pi/catkin_ws/src
Build space: /home/pi/catkin_ws/build
Devel space: /home/pi/catkin_ws/devel
Install space: /home/pi/catkin_ws/install
####
#### Running command: "cmake /home/pi/catkin_ws/src -DCATKIN_DEVEL_PREFIX=/home/pi/catkin_ws/devel -DCMAKE_INSTALL_PREFIX=/home/pi/catkin_ws/install -G Unix Makefiles" in "/home/pi/catkin_ws/build"
####
-- Using CATKIN_DEVEL_PREFIX: /home/pi/catkin_ws/devel
-- Using CMAKE_PREFIX_PATH: /home/pi/catkin_ws/devel;/opt/ros/kinetic
-- This workspace overlays: /home/pi/catkin_ws/devel;/opt/ros/kinetic
-- Using PYTHON_EXECUTABLE: /usr/bin/python
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/pi/catkin_ws/build/test_results
-- Found gtest sources under '/usr/src/gtest': gtests will be built
-- Using Python nosetests: /usr/bin/nosetests-2.7
-- catkin 0.7.8
-- BUILD_SHARED_LIBS is on
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ~~  traversing 1 packages in topological order:
-- ~~  - tutorials
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- +++ processing catkin package: 'tutorials'
-- ==> add_subdirectory(tutorials)
-- Configuring done
-- Generating done
-- Build files have been written to: /home/pi/catkin_ws/build
####
#### Running command: "make -j4 -l4" in "/home/pi/catkin_ws/build"
####

build フォルダ配下に tutorials フォルダが追加され、
0005.png
tutorials フォルダ配下に色々とフォルダ/ファイルが追加されたようだ。
0006.png

次に install コマンドを発行する必要があるようだ。

$ catkin_make install

実行ログ
Base path: /home/pi/catkin_ws
Source space: /home/pi/catkin_ws/src
Build space: /home/pi/catkin_ws/build
Devel space: /home/pi/catkin_ws/devel
Install space: /home/pi/catkin_ws/install
####
#### Running command: "make cmake_check_build_system" in "/home/pi/catkin_ws/build"
####
####
#### Running command: "make install -j4 -l4" in "/home/pi/catkin_ws/build"
####
Install the project...
-- Install configuration: ""
-- Installing: /home/pi/catkin_ws/install/_setup_util.py
-- Installing: /home/pi/catkin_ws/install/env.sh
-- Installing: /home/pi/catkin_ws/install/setup.bash
-- Installing: /home/pi/catkin_ws/install/setup.sh
-- Installing: /home/pi/catkin_ws/install/setup.zsh
-- Installing: /home/pi/catkin_ws/install/.rosinstall
-- Installing: /home/pi/catkin_ws/install/lib/pkgconfig/tutorials.pc
-- Installing: /home/pi/catkin_ws/install/share/tutorials/cmake/tutorialsConfig.cmake
-- Installing: /home/pi/catkin_ws/install/share/tutorials/cmake/tutorialsConfig-version.cmake
-- Installing: /home/pi/catkin_ws/install/share/tutorials/package.xml

◆ サンプルプログラムの作成と実行

初心者に恒例の HelloWorld プログラムを TOPIC形式 で構成して実行まで試したいと思う。
下図のような構成になることを想定して作業を進める。

0004_Pub-SUb.png

* プログラム作成先フォルダへの移動

roscd
$ cd ~/catkin_ws
$ roscd tutorials/src

* Publisher サンプルプログラム「talker.py」のダウンロード

ROSの公式サイトに御親切にサンプルプログラムが公開されているようなので、ありがたく利用させていただく。
ROSの公式サイトではプログラム数行ずつを懇切丁寧に説明してくれているので、軽く読めば、???となることは無いのでは、と感じた。若干日本語訳として、ソコどうなん?ってなる部分はあるけども。。。
★ROS公式 プログラムの解説
http://wiki.ros.org/ja/ROS/Tutorials/WritingPublisherSubscriber%28python%29

$ wget https://raw.githubusercontent.com/ros/ros_tutorials/kinetic-devel/rospy_tutorials/001_talker_listener/talker.py
$ chmod +x talker.py

talker.py の内容
talker.py
#!/usr/bin/env python
# Software License Agreement (BSD License)
#
# Copyright (c) 2008, Willow Garage, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
#  * Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#  * Redistributions in binary form must reproduce the above
#    copyright notice, this list of conditions and the following
#    disclaimer in the documentation and/or other materials provided
#    with the distribution.
#  * Neither the name of Willow Garage, Inc. nor the names of its
#    contributors may be used to endorse or promote products derived
#    from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# Revision $Id$

## Simple talker demo that published std_msgs/Strings messages
## to the 'chatter' topic

import rospy
from std_msgs.msg import String

def talker():
    pub = rospy.Publisher('chatter', String, queue_size=10)
    rospy.init_node('talker', anonymous=True)
    rate = rospy.Rate(10) # 10hz、1秒間に10回 Publish
    while not rospy.is_shutdown():
        hello_str = "hello world %s" % rospy.get_time()
        rospy.loginfo(hello_str)
        pub.publish(hello_str)
        rate.sleep()

if __name__ == '__main__':
    try:
        talker()
    except rospy.ROSInterruptException:
        pass

* Subscriber サンプルプログラム「listener.py」のダウンロード

こちらも、ROSの公式サイトに御親切にサンプルプログラムが公開されているようなので、ありがたく利用させていただく。

$ wget https://raw.github.com/ros/ros_tutorials/kinetic-devel/rospy_tutorials/001_talker_listener/listener.py
$ chmod +x listener.py

listener.py の内容
listener.py
#!/usr/bin/env python
# Software License Agreement (BSD License)
#
# Copyright (c) 2008, Willow Garage, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
#  * Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#  * Redistributions in binary form must reproduce the above
#    copyright notice, this list of conditions and the following
#    disclaimer in the documentation and/or other materials provided
#    with the distribution.
#  * Neither the name of Willow Garage, Inc. nor the names of its
#    contributors may be used to endorse or promote products derived
#    from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# Revision $Id$

## Simple talker demo that listens to std_msgs/Strings published 
## to the 'chatter' topic

import rospy
from std_msgs.msg import String

def callback(data):
    rospy.loginfo(rospy.get_caller_id() + 'I heard %s', data.data)

def listener():

    # In ROS, nodes are uniquely named. If two nodes with the same
    # name are launched, the previous one is kicked off. The
    # anonymous=True flag means that rospy will choose a unique
    # name for our 'listener' node so that multiple listeners can
    # run simultaneously.
    rospy.init_node('listener', anonymous=True)

    rospy.Subscriber('chatter', String, callback)

    # spin() simply keeps python from exiting until this node is stopped
    rospy.spin()

if __name__ == '__main__':
    listener()

* Publisher / Subscriber プログラムのビルド

catkin_make
$ cd ~/catkin_ws
$ catkin_make
実行ログ
Base path: /home/pi/catkin_ws
Source space: /home/pi/catkin_ws/src
Build space: /home/pi/catkin_ws/build
Devel space: /home/pi/catkin_ws/devel
Install space: /home/pi/catkin_ws/install
####
#### Running command: "make cmake_check_build_system" in "/home/pi/catkin_ws/build"
####
####
#### Running command: "make -j4 -l4" in "/home/pi/catkin_ws/build"
####

* Masterの起動

自前で作成したTOPIC形式プログラムを実行するには、まず全体を統括する Master プログラムを起動する必要がある。

Masterを起動するコマンド
$ roscore

何やらlog出力先フォルダに関して WARNING が表示されたが特に問題なく起動できているようだ。
環境初期構築時にlogフォルダをRAMディスク化したのが影響している可能性があるが、今は気にしないことにする。

起動ログ.
WARNING: Could not change permissions for folder [/home/pi/.ros/log/2aa0a502-3a41-11e8-a989-b827eb3a0927], make sure that the parent folder has correct permissions.
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://raspberrypi.local:42541/
ros_comm version 1.12.12


SUMMARY
========

PARAMETERS
 * /rosdistro: kinetic
 * /rosversion: 1.12.12

NODES

auto-starting new master
process[master]: started with pid [7741]
ROS_MASTER_URI=http://raspberrypi.local:11311/

setting /run_id to 2aa0a502-3a41-11e8-a989-b827eb3a0927
process[rosout-1]: started with pid [7762]
started core service [/rosout]

process[master]: started with pid [7741] とあるので、プロセス番号「7741」番として Master が起動したようだ。
また、Master のURIは 「ROS_MASTER_URI=http://raspberrypi.local:11311/」 だそうだ。

ここで、あまり聞き慣れない単語 「URI」 が出てきたが、Zuishinさんが下記記事にURLとURIの違いについてまとめてくださっているので参考にさせていただいた。 謝辞。
★[Qiita] Zuishinさん記事 「URL と URI の違い」
https://qiita.com/Zuishin/items/3bd56117ab08ec2ec818

* Publisher (talker.py) の起動

Masterを起動したターミナルとは別のターミナルを起動する必要があるようだ。
NODE は全て別のプロセスで実行される、ということを思い出してみると当然のことなのかな。
Ctrl + Alt + t でターミナルをひとつ起動し、下記コマンドで Publisher (talker.py) を実行する。

$ cd ~/catkin_ws
$ source ./devel/setup.bash
$ rosrun tutorials talker.py

実行した瞬間から延々としつこいぐらいに "hello world" が Publish され続ける。
若干やかましいけど我慢我慢。。。

0007.png

* Subscriber (listener.py) の起動

同じく、Master、Publisher を起動したターミナルとは別のターミナルを Ctrl + Alt + t で起動し、下記コマンドで Subscriber (listener.py) を実行する。

$ cd ~/catkin_ws
$ source ./devel/setup.bash
$ rosrun tutorials listener.py

来た来たー!!
Publisher(talker.py) が TOPIC に書き込んだ内容を Subscriber(listener.py) がひたすら延々と読み取っていく様子が見える。

0008.png

◆ 本日のまとめ

  • 環境作成からTOPIC形式のサンプル実行までを実施、成功した
  • 不覚にも率直に 「え? たったこれだけ?」 と感じてしまった
  • おそらくTOPIC形式なら、RaspberryPiに接続されたセンサーから無限に検知される測定値を Publisher側 でバラ撒き、Subscriber側 で必要なタイミングで読み取る構成になる、と予想
  • 動体検知プログラムを絡めて考えるなら、推論(プレディクション)の結果を Publisher でバンバンばら撒くことになるのかな
  • サンプルを動かすまでの手番より、慣れないMarkdown記法で記事を書くことに9割の体力を費やす
  • $ source devel/setup.bash はターミナルを起動するごとに実行しなくてはならない面倒くささがあることが分かった .bashrc か何かに書いておくと楽になるのかな

◆ 次回予告

独自のMessage と Service形式 のサンプルを試行してみようと思う。

◆ 次回記事

RaspberryPi3とZumoとROSで半永久自走式充放電ロボを作成したい_003日目_独自Message・Service へ続く

12
7
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
7