User Tools

Site Tools


Sidebar

Translations of this page:

====== Menu ====== ===== Introductions ===== * [[concept]] * [[about]] * [[laws]] * [[license]] ===== Documents ===== * [[tutorials/index.html]] * [[specifications/index.html]] * [[api_guides/index.html]] * [[faq/index.html]] * [[https://github.com/plenprojectcompany|Resources on the GitHub]] ===== Social Accounts ===== * [[https://ja-jp.facebook.com/PlenProjectCommittee|Facebook Page]] * [[https://twitter.com/plen_project|Twitter]] * [[https://www.instagram.com/plenproject/|Instagram]] * [[https://www.youtube.com/channel/UCoKNQe4Vb5Fa0D00bYLEFJQ|Youtube Channel]] ===== Etc ===== * [[sitepolicy]] * [[editing]] * [[https://www.dokuwiki.org/wiki:syntax|Syntax]]

tutorials:advanced:ros_tutorial

This is an old revision of the document!


FIXME This page is not fully translated, yet. Please help completing the translation.
(remove this paragraph once the translation is finished)

ROS Tutorial

開発環境

  • Ubuntu
  • ROS indigo
  • python 2.7

ROSのインストール

公式の日本語のROSページであるこちらを参考にROSの開発環境をUbuntuのパソコンに構築します。

ワークスペースの作成

ROSを利用して開発を行うために、作業用ディレクトリを作成し、catkinコマンドで作業用ディレクトリを初期化します。

$ mkdir -p ~/catkin_ws/src
$ cd ~/catkin_ws/src
$ catkin_init_workspace
$ cd ~/catkin_ws
$ catkin_make

ROSを利用できる環境にするためsetup.bashを読み込みます。

$ source ~/catkin_ws/devel/setup.bash

この作業は毎回必要となるため、「~/.bashrc」の以下の部分をエディタなどで

#source /opt/ros/indigo/setup.bash
source ~/catkin_ws/devel/setup.bash

を修正し、追加することでその作業を省略できます。

パッケージの作成

ディレクトリを移動して、パッケージを作成します。

$ cd ~/catkin_ws/src
$ catkin_create_pkg <自作のパッケージ名> rospy roscpp std_msgs

ここでもう一度catkin_makeを行います。

$ cd ~/catkin_ws
$ catkin_make
$ source ~/catkin_ws/devel/setup.bash

これで自作のパッケージを利用することができます。 確認のため

catkin_ws$ roscd <自作のパッケージ名>

をすると

catkin_ws/src/<自作のパッケージ名>$

と移動できれば成功です。

PLEN2に接続する

PLEN2はアクセスポイントになっています。PLEN2にはそれぞれ異なるアクセスポイントの名前と同じパスワードが設定されています。

ssid:PLEN2dev<MACアドレス>
password:plenproject

ROSの環境変数の設定

PLEN2に接続できたらifconfigコマンドを利用してPCに割り振られたIPアドレスを調べ、以下の様にROSの環境変数の設定を行います。

export ROS_IP=<割り振られたIPアドレス>
export ROS_HOSTNAME=<割り振られたIPアドレス>
export ROS_MASTER_URI=http://192.168.42.1:11311

この設定を行うことで異なるパソコン間でROSを利用することが可能となります。

PLEN2の目を点滅させる

それでは簡単にPLEN2の目を点滅させてみます。言語はPythonを利用します。まずPythonのプログラムを保存するためにscriptsディレクトリを作成します。

$ mkdir scripts
$ cd scripts

以下のプログラムをpythonファイルとして保存します。

#!/usr/bin/env python

import rospy
from std_msgs.msg import String


def talker():
    rospy.init_node('PCnode', anonymous=True)
    pub = rospy.Publisher('PcToControl', String, queue_size=10)
    rate = rospy.Rate(1)
    hello_str = String()
    hello_str.data ="gpio,w,off"
    while not rospy.is_shutdown():

        if ("on" in hello_str.data):
            hello_str.data = "gpio,w,off"
        elif ("off" in hello_str.data):
            hello_str.data = "gpio,w,on"

        rospy.loginfo("%s",hello_str.data)
        pub.publish(hello_str)
        rate.sleep()

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

このプログラムはPLEN2の目を一秒ごとに点滅させるものです。「PcToControl」という名前で「Topic」に「Publish」するとPLEN2はそのTopicを読んでくれます。 最後に

$ chmod 755 <保存したpythonファイル>
$ python <保存したpythonファイル>

で実行することができます。

他にもPublishする内容を変更することでPLEN2を動かしたりすることが可能です。例えば、スロット4のモーションを再生したい場合は

serial,w,$PM04

としてPublishすることでPLEN2を動かすことができます。

tutorials/advanced/ros_tutorial.1466153872.txt.gz · Last modified: 2021/04/01 13:52 (external edit)