This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
tutorials:advanced:ros_tutorial [2016/06/17 08:57] wingcloud created |
tutorials:advanced:ros_tutorial [2021/04/01 13:52] (current) |
||
---|---|---|---|
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)// | ||
- | |||
< | < | ||
ROS Tutorial | ROS Tutorial | ||
- | ================ | + | =============================================================================== |
- | ##開発環境 | + | ## Build Environment |
- Ubuntu | - Ubuntu | ||
- ROS indigo | - ROS indigo | ||
- python 2.7 | - python 2.7 | ||
- | ## | ||
- | 公式の日本語のROSページである[こちら](http:// | ||
- | ##ワークスペースの作成 | + | ## Install ROS |
- | ROSを利用して開発を行うために、作業用ディレクトリを作成し、catkinコマンドで作業用ディレクトリを初期化します。 | + | Please check [this page](http:// |
+ | |||
+ | ### Create a Workspace | ||
+ | Please create a working directory to develop with ROS. | ||
+ | After that, initialize the working directory environment as follows: | ||
```bash | ```bash | ||
Line 20: | Line 20: | ||
$ cd ~/ | $ cd ~/ | ||
$ catkin_init_workspace | $ catkin_init_workspace | ||
- | ``` | ||
- | |||
- | ```bash | ||
$ cd ~/catkin_ws | $ cd ~/catkin_ws | ||
$ catkin_make | $ catkin_make | ||
``` | ``` | ||
- | ROSを利用できる環境にするためsetup.bashを読み込みます。 | + | There is a setup script to initialize the environment. |
+ | Please enter command below. | ||
```bash | ```bash | ||
$ source ~/ | $ source ~/ | ||
``` | ``` | ||
- | この作業は毎回必要となるため、「~/ | + | |
+ | This process needs at first time whenever use ROS. Thus, I recommend to add script to **.bashrc** file. | ||
```bash | ```bash | ||
Line 38: | Line 37: | ||
source ~/ | source ~/ | ||
``` | ``` | ||
- | を修正し、追加することでその作業を省略できます。 | ||
- | ##パッケージの作成 | + | ### Create a Package |
- | ディレクトリを移動して、パッケージを作成します。 | + | Please change directory and create a package. |
```bash | ```bash | ||
Line 48: | Line 46: | ||
```bash | ```bash | ||
- | $ catkin_create_pkg <自作のパッケージ名> rospy roscpp std_msgs | + | $ catkin_create_pkg <YOUR_PACKAGE_NAME> rospy roscpp std_msgs |
``` | ``` | ||
- | ここでもう一度catkin_makeを行います。 | + | |
+ | And then, run `catkin_make` again. | ||
```bash | ```bash | ||
Line 57: | Line 56: | ||
$ source ~/ | $ source ~/ | ||
``` | ``` | ||
- | これで自作のパッケージを利用することができます。 | ||
- | 確認のため | ||
- | ```bash | + | Now, your package can be available. |
- | catkin_ws$ roscd < | + | Please check it with following command: |
- | ``` | + | |
- | をすると | + | |
```bash | ```bash | ||
- | catkin_ws/ | + | catkin_ws$ roscd < |
+ | catkin_ws/ | ||
``` | ``` | ||
- | と移動できれば成功です。 | ||
- | ##PLEN2に接続する | + | If you can do it, creating a package is succeeded. |
- | PLEN2はアクセスポイントになっています。PLEN2にはそれぞれ異なるアクセスポイントの名前と同じパスワードが設定されています。 | + | |
+ | |||
+ | ## Connect to PLEN2 | ||
+ | Since time of the shipment, | ||
+ | Also PLEN2 has been set different SSID and common password. | ||
- | ```bash | ||
- | ssid: | ||
- | password: | ||
``` | ``` | ||
+ | SSID: PLEN2dev< | ||
+ | Password: plenproject | ||
+ | ``` | ||
+ | |||
- | ##ROSの環境変数の設定 | + | ## Setting Up ROS Environment |
- | PLEN2に接続できたらifconfigコマンドを利用してPCに割り振られたIPアドレスを調べ、以下の様にROSの環境変数の設定を行います。 | + | After connect your PC to PLEN2, please check IP address of your PC with `ifconfig` command. |
+ | Then, change | ||
```bash | ```bash | ||
- | export ROS_IP=<割り振られたIPアドレス> | + | export ROS_IP=<PC_IP_ADDRESS> |
- | export ROS_HOSTNAME=< | + | export ROS_HOSTNAME=< |
export ROS_MASTER_URI=http:// | export ROS_MASTER_URI=http:// | ||
``` | ``` | ||
- | この設定を行うことで異なるパソコン間でROSを利用することが可能となります。 | ||
- | ## | + | Now, your PC can communicate other ROS setuped devices. |
- | それでは簡単にPLEN2の目を点滅させてみます。言語はPythonを利用します。まずPythonのプログラムを保存するためにscriptsディレクトリを作成します。 | + | |
- | ```bash | ||
- | $ mkdir scripts | ||
- | $ cd scripts | ||
- | ``` | + | ## Blink LED of PLEN2' |
- | 以下のプログラムをpythonファイルとして保存します。 | + | Let you blink LED of PLEN2' |
+ | Please create following sample program. | ||
```python | ```python | ||
# | # | ||
+ | # -*- coding: utf-8 -*- | ||
import rospy | import rospy | ||
Line 106: | Line 104: | ||
def talker(): | def talker(): | ||
- | rospy.init_node(' | + | rospy.init_node(' |
- | pub = rospy.Publisher(' | + | |
- | rate = rospy.Rate(1) | + | |
- | hello_str = String() | + | |
- | hello_str.data =" | + | |
- | while not rospy.is_shutdown(): | + | |
- | | + | p = rospy.Publisher(' |
- | | + | r = rospy.Rate(1) |
- | elif ("off" | + | |
- | | + | led_command = String() |
+ | led_command.data = ' | ||
+ | |||
+ | while ( not rospy.is_shutdown() ): | ||
+ | | ||
+ | | ||
+ | |||
+ | elif ( 'off' | ||
+ | | ||
+ | |||
+ | rospy.loginfo(' | ||
+ | |||
+ | p.publish(led_command) | ||
+ | r.sleep() | ||
- | rospy.loginfo(" | ||
- | pub.publish(hello_str) | ||
- | rate.sleep() | ||
if __name__ == ' | if __name__ == ' | ||
try: | try: | ||
talker() | talker() | ||
+ | |||
except rospy.ROSInterruptException: | except rospy.ROSInterruptException: | ||
pass | pass | ||
- | |||
``` | ``` | ||
- | このプログラムはPLEN2の目を一秒ごとに点滅させるものです。「PcToControl」という名前で「Topic」に「Publish」するとPLEN2はそのTopicを読んでくれます。 | + | |
- | 最後に | + | This script blink PLEN2's eye at every seconds. |
+ | PLEN2 subscribe topic which name is **PcToControl**. | ||
+ | |||
+ | You need to run following command to be availabel the python script: | ||
```bash | ```bash | ||
- | $ chmod 755 <保存したpythonファイル> | + | $ chmod 755 <CREATED_SCRIPT_NAME> |
- | $ python <保存したpythonファイル> | + | $ python <CREATED_SCRIPT_NAME> |
``` | ``` | ||
- | で実行することができます。 | ||
- | 他にもPublishする内容を変更することでPLEN2を動かしたりすることが可能です。例えば、スロット4のモーションを再生したい場合は | + | In addition, You could control |
``` | ``` | ||
- | serial,w,$PM04 | + | serial,w,< |
``` | ``` | ||
- | としてPublishすることでPLEN2を動かすことができます。 | ||
+ | For example, if you would like to play the motion that is placed slot 4, send command below: | ||
+ | |||
+ | ``` | ||
+ | serial, | ||
+ | ``` | ||
</ | </ |