User Tools

Site Tools


tutorials:advanced:ros_tutorial

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

tutorials:advanced:ros_tutorial [2016/06/17 08:57]
wingcloud created
tutorials:advanced:ros_tutorial [2021/04/01 13:52]
Line 1: Line 1:
-FIXME **This page is not fully translated, yet. Please help completing the translation.**\\ //(remove this paragraph once the translation is finished)// 
  
-<markdown> 
-ROS Tutorial 
-================ 
- 
-##開発環境 
-- Ubuntu 
-- ROS indigo 
-- python 2.7 
- 
-##ROSのインストール 
-公式の日本語のROSページである[こちら](http://wiki.ros.org/ja)を参考にROSの開発環境をUbuntuのパソコンに構築します。 
- 
-##ワークスペースの作成 
-ROSを利用して開発を行うために、作業用ディレクトリを作成し、catkinコマンドで作業用ディレクトリを初期化します。 
- 
-```bash 
-$ mkdir -p ~/catkin_ws/src 
-$ cd ~/catkin_ws/src 
-$ catkin_init_workspace 
-``` 
- 
-```bash 
-$ cd ~/catkin_ws 
-$ catkin_make 
-``` 
- 
-ROSを利用できる環境にするためsetup.bashを読み込みます。 
- 
-```bash 
-$ source ~/catkin_ws/devel/setup.bash 
-``` 
-この作業は毎回必要となるため、「~/.bashrc」の以下の部分をエディタなどで 
- 
-```bash 
-#source /opt/ros/indigo/setup.bash 
-source ~/catkin_ws/devel/setup.bash 
-``` 
-を修正し、追加することでその作業を省略できます。 
- 
-##パッケージの作成 
-ディレクトリを移動して、パッケージを作成します。 
- 
-```bash 
-$ cd ~/catkin_ws/src 
-``` 
- 
-```bash 
-$ catkin_create_pkg <自作のパッケージ名> rospy roscpp std_msgs 
-``` 
-ここでもう一度catkin_makeを行います。 
- 
-```bash 
-$ cd ~/catkin_ws 
-$ catkin_make 
-$ source ~/catkin_ws/devel/setup.bash 
-``` 
-これで自作のパッケージを利用することができます。 
-確認のため 
- 
-```bash 
-catkin_ws$ roscd <自作のパッケージ名> 
-``` 
-をすると 
- 
-```bash 
-catkin_ws/src/<自作のパッケージ名>$ 
-``` 
-と移動できれば成功です。 
- 
-##PLEN2に接続する 
-PLEN2はアクセスポイントになっています。PLEN2にはそれぞれ異なるアクセスポイントの名前と同じパスワードが設定されています。 
- 
-```bash 
-ssid:PLEN2dev<MACアドレス> 
-password:plenproject 
-``` 
- 
-##ROSの環境変数の設定 
-PLEN2に接続できたらifconfigコマンドを利用してPCに割り振られたIPアドレスを調べ、以下の様にROSの環境変数の設定を行います。 
- 
-```bash 
-export ROS_IP=<割り振られたIPアドレス> 
-export ROS_HOSTNAME=<割り振られたIPアドレス> 
-export ROS_MASTER_URI=http://192.168.42.1:11311 
-``` 
-この設定を行うことで異なるパソコン間でROSを利用することが可能となります。 
- 
-##PLEN2の目を点滅させる 
-それでは簡単にPLEN2の目を点滅させてみます。言語はPythonを利用します。まずPythonのプログラムを保存するためにscriptsディレクトリを作成します。 
- 
-```bash 
-$ mkdir scripts 
-$ cd scripts 
- 
-``` 
-以下のプログラムをpythonファイルとして保存します。 
- 
-```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を読んでくれます。 
-最後に 
- 
-```bash 
-$ chmod 755 <保存したpythonファイル> 
-$ python <保存したpythonファイル> 
-``` 
-で実行することができます。 
- 
-他にもPublishする内容を変更することでPLEN2を動かしたりすることが可能です。例えば、スロット4のモーションを再生したい場合は 
- 
-``` 
-serial,w,$PM04 
-``` 
-としてPublishすることでPLEN2を動かすことができます。 
- 
-</markdown> 
tutorials/advanced/ros_tutorial.txt · Last modified: 2021/04/01 13:52 (external edit)