(訳注:最新の情報は[[ROS/Tutorials/UnderstandingTopics|原文]]を参照してください.) #################################### ##FILL ME IN #################################### ## links to any required tutorials ## note.0= [[ja/ROS/Tutorials/UnderstandingNodes|ROSノードの理解]] ## descriptive title for the tutorial ## title = ROSトピックの理解 ## multi-line description to be displayed in search ## description = このチュートリアルは[[rostopic]] や [[rqt_plot]]などのコマンドとともに,ROSのtopicについて学びます. ## the next tutorial description ## next = ## links to next tutorial ## next.0.link= [[ja/ROS/Tutorials/UnderstandingServicesParams|ROS サービスとパラメータについて理解する]] ## what level user is this tutorial for ## level= BeginnerCategory #################################### <> <> === セットアップ === ==== roscore ==== roscore が起動していることを,'''新しいターミナルで'''確認しましょう: {{{ $ roscore }}} もし先ほどのチュートリアルで起動している roscore を残していたら,次のエラーメッセージが出ます: {{{ roscore cannot run as another roscore/master is already running. Please kill other roscore/zenmaster processes before relaunching }}} これは正しい挙動です.roscore はただ1つしか起動できません. ==== turtlesim ==== このチュートリアルでも,turtlesim を使います.'''新しいターミナルで'''起動してください: {{{ $ rosrun turtlesim turtlesim_node }}} ==== キーボードによる亀(turtle)の操作 ==== 亀の動きを操作するものが必要です.'''新しいターミナルで'''以下を起動してください. {{{ $ rosrun turtlesim turtle_teleop_key }}} ##[ INFO] 1254264546.878445000: Started node [/teleop_turtle], pid [5528], bound on [aqy], xmlrpc port [43918], tcpros port [55936], logging to [~/ros/ros/log/teleop_turtle_5528.log], using [real] time ## updated for version Hydro {{{ [ INFO] [1412519294.247868693]: Starting turtlesim with node name /turtlesim [ INFO] [1412519294.251346604]: Spawning turtle [turtle1] at x=[5.544445], y=[5.544445], theta=[0.000000] Reading from keyboard --------------------------- Use arrow keys to move the turtle. }}} これで亀の動きをキーボードの矢印キーで操作することができるようになりました.もし亀を操作できなければ,'''turtle_teleop_key のウィンドウを選択して'''押したキーが認識されていることを確認してください. {{attachment:ROS/Tutorials/UnderstandingTopics/turtle_key.png}} 亀の動きが操作できるようになったところで,この舞台裏で行われていることを見ていきましょう. ## === Ros Topics === === ROS トピック === ## The `turtlesim_node` and the `turtle_teleop_key` node are communicating with each other over a ROS '''Topic'''. `turtle_teleop_key` is '''publishing''' the key strokes on a topic, while `turtlesim` '''subscribes''' to the same topic to receive the key strokes. Let's use [[rqt_graph]] which shows the nodes and topics currently running. `turtlesim_node` と `turtle_teleop_key` のノードはお互い ROS '''トピック'''を介して通信しています.`turtle_teleop_key` は押されたキーをトピックに配信しています.そのとき,`turtle_sim` は同じトピックを'''購読'''することで,押されたキーを受け取っています.起動中のノードとトピックを表示する新しいツール, `rqt_graph` を使ってみましょう. ## Note: If you're using `electric` or earlier, `rqt` is not available. Use `rxgraph` instead. Note:`electric`, もしくはさらに古いバージョンを使用している場合, `rqt`は提供されていません. 代わりに, `rxgraph`を使用してください. ## ==== Using rqt_graph ==== ## `rqt_graph` creates a dynamic graph of what's going on in the system. rqt_graph is part of the `rqt` package. Unless you already have it installed, run: ==== rqt_graphを使う ==== `rqt_graph` はシステム進行状況・挙動を示す,動的なグラフを生成します.rqt_graph は `rqt_tools` パッケージの一部です.ただし, インストールしていない場合, 下記のコマンドを実行してインストールしてください: {{{ $ sudo apt-get install ros--rqt $ sudo apt-get install ros--rqt-common-plugins }}} ## replacing with the name of your rosdistribution (fuerte, groovy, etc.) の部分を使用しているディストリビューションの名前(hydroやindigoなど)に置換します. ## '''In a new terminal''': '''新しい端末を開いて''': {{{ $ rosrun rqt_graph rqt_graph }}} ## You will see something similar to: …とすると, このように表示されます: ## 和訳版のページでオリジナルのページに添付された画像を流用する場合, 画像は絶対パスで指定する ##{{attachment:ROS/Tutorials/UnderstandingTopics/rqt_graph_turtle_key.png||width=100%}} {{attachment:rqt_graph_turtle_key_hydro.png||width=100%}} ## If you place your mouse over `/turtle1/command_velocity` it will highlight the ROS nodes (here blue and green) and topics (here red). As you can see, the `turtlesim_node` and the `turtle_teleop_key` nodes are communicating on the topic named `/turtle1/cmd_vel`. `/turtle1/cmd_vel`にマウスカーソルを重ねると, ROSのノードやトピックがハイライトされます(ここでは, ノードが青と緑, トピックが赤). 見てわかるように, `turtlesim_node`と`turtle_teleop_key`のノードが`/turtle1/cmd_vel`と命名されたトピック上で通信しています. ##{{attachment:ROS/Tutorials/UnderstandingTopics/rqt_graph_turtle_key2.png||width=100%}} {{attachment:rqt_graph_turtle_key2_hydro.png||width=100%}} ## ==== Introducing rostopic ==== ==== rostopicについて ==== `rostopic` ツールで ROS '''トピック'''についての情報を得ることができます. {{{rostopic}}} のヘルプのオプションで、{{{rostopic}}}に存在するサブコマンドを調べることができます. {{{ $ rostopic -h }}} {{{ rostopic bw トピックで使用されている帯域を表示する rostopic echo スクリーンにメッセージを出力する rostopic find メッセージの型からトピックを探す rostopic hz トピックの配信頻度を表示する rostopic info アクティブなトピックについての情報を出力する rostopic list アクティブなトピックをリスト表示する rostopic pub トピックへデータを配信する rostopic type トピックの型を出力する }}} turtlesimについて調べるために,これらのトピックのサブコマンドを使ってみましょう. ==== rostopic echo を使う ==== `rostopic echo` はトピックから配信されているデータを表示します. 使い方: {{{ rostopic echo [topic] }}} `turtle_teleop_key` ノードが配信している `/turtle1/cmd_vel` トピックのデータを見てみましょう.'''新しいターミナルで'''以下を実行してください: {{{ $ rostopic echo /turtle1/cmd_vel }}} もしかしたら,何も見えないかもしれません.それはトピックにデータが配信されていないからです.矢印キーを押して,`turtle_teleop_key` にデータを配信させてみましょう.もう一度 `turtle_teleop_key` のターミナルを選択しないと,亀は動かないことを忘れないでください. 上矢印キーを押すと,次のように表示されるでしょう: {{{ --- linear: 2.0 angular: 0.0 --- linear: 2.0 angular: 0.0 --- linear: 2.0 angular: 0.0 --- linear: 2.0 angular: 0.0 --- linear: 2.0 angular: 0.0 }}} ## Or in hydro: もしくは, hydroでは: {{{ linear: x: 2.0 y: 0.0 z: 0.0 angular: x: 0.0 y: 0.0 z: 0.0 --- linear: x: 2.0 y: 0.0 z: 0.0 angular: x: 0.0 y: 0.0 z: 0.0 --- }}} ## Now let's look at `rqt_graph` again (you might need to refresh the ROS graph). As you can see `rostopic echo`, shown here in red, is now also '''subscribed''' to the `turtle1/command_velocity` topic. `rostopic echo` が `turtle1/cmd_vel` トピックを'''購読'''していることを確認するために,もう一度 `rqt_graph` を見てみましょう. `rostopic echo`で確認できるように, ここでは赤で`turtle1/cmd_vel`トピックが購読されていることが示されています. ##{{attachment:ROS/Tutorials/UnderstandingTopics/rqt_graph_echo.png||width=100%}} {{attachment:rqt_graph_echo_hydro.png||width=100%}} ## ==== Using rostopic list ==== ==== rostopic list を使う ==== ## `rostopic list` returns a list of all topics currently subscribed to and published. `rostopic list` は現在購読・配信されている全トピックのリストを返します. ## Lets figure out what argument the `list` sub-command needs. In a '''new terminal''' run: `list` サブ-コマンドに必要な引数を確かめましょう.'''新しいターミナルで'''こちらを実行します: {{{ $ rostopic list -h }}} {{{ Usage: rostopic list [/topic] Options: -h, --help show this help message and exit -b BAGFILE, --bag=BAGFILE list topics in .bag file -v, --verbose list full details about each topic -p list only publishers -s list only subscribers }}} ## For {{{rostopic list}}} use the '''verbose''' option: {{{rostopic list}}} は '''verbose''' オプションを使用します: {{{ $ rostopic list -v }}} ## This displays a verbose list of topics to publish to and subscribe to and their type. これは配信・購読されている,トピックとその型についての詳細なリストを表示します. {{{ Published topics: * /turtle1/color_sensor [turtlesim/Color] 1 publisher * /turtle1/cmd_vel [geometry_msgs/Twist] 1 publisher * /rosout [rosgraph_msgs/Log] 2 publishers * /rosout_agg [rosgraph_msgs/Log] 1 publisher * /turtle1/pose [turtlesim/Pose] 1 publisher Subscribed topics: * /turtle1/cmd_vel [geometry_msgs/Twist] 1 subscriber * /rosout [rosgraph_msgs/Log] 1 subscriber }}} ## === ROS Messages === === ROS メッセージ === ## Communication on topics happens by sending ROS '''messages''' between nodes. For the publisher (`turtle_teleop_key`) and subscriber (`turtlesim_node`) to communicate, the publisher and subscriber must send and receive the same '''type''' of message. This means that a topic '''type''' is defined by the message '''type''' published on it. The '''type''' of the message sent on a topic can be determined using `rostopic type`. ノード間でのROS '''メッセージ'''の送信により, トピック上での通信が生じます.配信者(`turtle_teleop_key`)と購読者(`turtlesim_node`)が通信するためには,配信者と購読者は同じ'''型'''のメッセージを送受信する必要があります.これは, トピックの'''型'''がそのトピック上に配信されるメッセージの'''型'''により定義されるということを意味します. トピック上で送信されるメッセージの'''型'''は`rostopic type`で確認することができます. ## ==== Using rostopic type ==== ==== rostopic type の使い方 ==== ## {{{rostopic type}}} returns the message type of any topic being published. {{{rostopic type}}} は配信されているあらゆるトピックのメッセージ型を返します. ## Usage: 使い方: {{{ rostopic type [topic] }}} ## Try (not for hydro): 試してみましょう(非hydro): {{{ $ rostopic type /turtle1/command_velocity }}} ## You should get: 以下のように表示されます: {{{ turtlesim/Velocity }}} ## In hydro, try: hydroでは, こちらを試します: {{{ $ rostopic type /turtle1/cmd_vel }}} ## You should get: 以下のように表示されます: {{{ geometry_msgs/Twist }}} ## We can look at the details of the message using `rosmsg` (not for hydro): `rosmsg` を使用してメッセージの詳細を見ることができます(非hydro): {{{ $ rosmsg show turtlesim/Velocity }}} {{{ float32 linear float32 angular }}} ## In hydro: hydroでは: {{{ $ rosmsg show geometry_msgs/Twist }}} {{{ geometry_msgs/Vector3 linear float64 x float64 y float64 z geometry_msgs/Vector3 angular float64 x float64 y float64 z }}} ## Now that we know what type of message turtlesim expects, we can publish commands to our turtle: これでturtlesimが要求するメッセージの型が分かり, turtleにコマンドを配信できるようになります: ## === rostopic continued === === その他のrostopic サブコマンド === ## Now that we have learned about ROS '''messages''' let's use rostopic with messages. 前項でROS の'''メッセージ'''について学んだので、メッセージを使った rostopicのサブコマンド を使用してみましょう. ## ==== Using rostopic pub ==== ==== rostopic pub を使う ==== ## `rostopic pub` publishes data on to a topic currently advertised. `rostopic pub` は現在立ちあがっているトピックへデータを配信します. 使い方: {{{ rostopic pub [topic] [msg_type] [args] }}} 例(非hydro): {{{ $ rostopic pub -1 /turtle1/command_velocity turtlesim/Velocity -- 2.0 1.8 }}} ## Example for hydro: hydroの例: {{{ $ rostopic pub -1 /turtle1/cmd_vel geometry_msgs/Twist -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, 1.8]' }}} ## The previous command will send a single message to turtlesim telling it to move with an linear velocity of 2.0, and an angular velocity of 1.8 . 上記のコマンドでは turtlesim に直線速度 2.0 角速度 1.8 で移動するように指令する単一のメッセージを送信します. {{attachment:ROS/Tutorials/UnderstandingTopics/turtle(rostopicpub).png}} ## This is a pretty complicated example, so lets look at each argument in detail. これはやや複雑な例なので, それぞれの引数の詳細を見てみましょう. * {{{ rostopic pub}}} このコマンドは与えられたトピックへメッセージを配信します. * {{{ -1 }}} (dash-one) このオプションで rostopic は1つのメッセージを配信した後に終了させます. * {{{ /turtle1/cmd_vel}}} これは配信するトピックの名前です. * {{{ geometry_msgs/Twist}}} これはトピックで配信する際に使用されるメッセージの型です. * {{{ --}}} (double-dash) これは後の引数を'''表示させなくする'''ためのオプションです.これは,例えばどれかの引数がダッシュ `-` (負数のような)に続いている場合に使用します. * {{{ 2.0 1.8 }}} 前述の通り,geometry_msgs/Twistメッセージは {{{linear}}} と {{{angular}}} という2つの浮動小数点要素を持っています.この場合は,{{{2.0}}} が{{{linear}}}(並進速度)で,{{{1.8}}} が {{{angular}}}(角速度) になります.これらの引数の実際はYAML構文となっており, 詳細は[[ROS/YAMLCommandLine|YAML command line documentation]]に記述されています. ## As noted before, a turtlesim/Velocity msg has two floating point elements : {{{linear}}} and {{{angular}}}. In this case, {{{2.0}}} becomes the linear value, and {{{1.8}}} is the {{{angular}}} value. These arguments are actually in YAML syntax, which is described more in the [[ROS/YAMLCommandLine|YAML command line documentation]]. ## You may have noticed that the turtle has stopped moving; this is because the turtle requires a steady stream of commands at 1 Hz to keep moving. We can publish a steady stream of commands using `rostopic pub -r` command (not for hydro): 亀の動きが止まったのは,亀は動き続けるために定期的な 1 Hz のコマンドを必要とするからです.定期的なコマンドは `rostopic pub -r` コマンドを使用して配信することができます(非hydro): {{{ $ rostopic pub /turtle1/command_velocity turtlesim/Velocity -r 1 -- 2.0 -1.8 }}} ## For hydro: hydroでは: {{{ $ rostopic pub /turtle1/cmd_vel geometry_msgs/Twist -r 1 -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, -1.8]' }}} ## This publishes the velocity commands at a rate of 1 Hz on the velocity topic. これは速度トピックに 1 Hz で速度のコマンドを配信します. {{attachment:ROS/Tutorials/UnderstandingTopics/turtle(rostopicpub)2.png}} ## We can also look at what is happening in `rqt_graph`, The rostopic pub node (here in red) is communicating with the rostopic echo node (here in green): 何が起こっているかは,`rqt_graph` でも見ることができます. rostopic pub node (ここでは赤色) が rostopic echo node (ここでは緑色) と通信しています: ##{{attachment:ROS/Tutorials/UnderstandingTopics/rqt_graph_pub.png||width=100%}} {{attachment:rqt_graph_pub_hydro.png||width=100%}} ## As you can see the turtle is running in a continuous circle. In a '''new terminal''', we can use `rostopic echo` to see the data published by our turtlesim: 亀を等速円運動させるためには,'''新しいターミナル'''で,turtlesim に配信されているデータを `rostopic echo` で見ることができます. ## ==== Using rostopic hz ==== ==== rostopic hz の使い方 ==== ## `rostopic hz` reports the rate at which data is published. `rostopic hz` は配信されたデータの更新頻度を調べます. 使い方: {{{ rostopic hz [topic] }}} ## Let's see how fast the `turtlesim_node` is publishing `/turtle1/pose`: `/turtle1/pose` を配信して,`turtlesim_node` の速さがどれくらいか見てみましょう: {{{ $ rostopic hz /turtle1/pose }}} ## You will see: 以下のように表示されます: {{{ subscribed to [/turtle1/pose] average rate: 59.354 min: 0.005s max: 0.027s std dev: 0.00284s window: 58 average rate: 59.459 min: 0.005s max: 0.027s std dev: 0.00271s window: 118 average rate: 59.539 min: 0.004s max: 0.030s std dev: 0.00339s window: 177 average rate: 59.492 min: 0.004s max: 0.030s std dev: 0.00380s window: 237 average rate: 59.463 min: 0.004s max: 0.030s std dev: 0.00380s window: 290 }}} ## Now we can tell that the turtlesim is publishing data about our turtle at the rate of 60 Hz. We can also use `rostopic type` in conjunction with `rosmsg show` to get in depth information about a topic (not for hydro): turtlesim が turtle に配信するデータの更新頻度はおよそ 60 Hz だと言えます.トピックについての深い情報を得るために, `rostopic type` と `rosmsg show` を結合して使うことができます(非hydro). {{{ $ rostopic type /turtle1/command_velocity | rosmsg show }}} hydroでは: {{{ rostopic type /turtle1/cmd_vel | rosmsg show }}} ## Now that we've examined the topics using `rostopic` let's use another tool to look at the data published by our turtlesim: ここでは `rostopic` を使用してトピックを調査しました.他のツールも使用して,turtlesim が配信しているデータを見てみましょう: ## === Using rqt_plot === === rqt_plot の使い方 === ## Note: If you're using `electric` or earlier, `rqt` is not available. Use [[rxplot]] instead. 注意: `electric`, もしくは, それ以前のディストリビューションを使用している場合, `rqt`が提供されていません. 代わりに, [[rxplot]]を使用しましょう. ## `rqt_plot` displays a scrolling time plot of the data published on topics. Here we'll use `rqt_plot` to plot the data being published on the `/turtle1/pose` topic. First, start rqt_plot by typing `rqt_plot` はトピックで配信されているデータの時間図を表示します.ここでは `rqt_plot` を `/turtle1/pose` トピックで配信されているデータに対して使ってみましょう. まず, このように入力して新しいターミナルでrqt_plotを起動します: {{{ $ rosrun rqt_plot rqt_plot }}} ## in a new terminal. In the new window that should pop up, a text box in the upper left corner gives you the ability to add any topic to the plot. Typing `/turtle1/pose/x` will highlight the plus button, previously disabled. Press it and repeat the same procedure with the topic `/turtle1/pose/y`. You will now see the turtle's x-y location plotted in the graph. 新しいウインドウが立ちあがり, 左上隅のテキストボックスで図に任意のトピックを追加する機能が提供されます. `/turtle1/pose/x`と入力すると, 無効化されていた+ボタンがハイライトされます. そのボタンを押して, `/turtle1/pose/y`のトピックにも同じ手順を繰り返し行います. そうすると, 亀のxy座標位置がグラフ上に表示されます. {{attachment:ROS/Tutorials/UnderstandingTopics/rqt_plot.png||width=100%}} ## Pressing the minus button shows a menu that allows you to hide the specified topic from the plot. Hiding both the topics you just added and adding `/turtle1/pose/theta` will result in the plot shown in the next figure. -ボタンを押すと, グラフから特定のトピックを非表示にするメニューが表示されます. 今追加した両方のトピックを非表示にして, `/turtle1/pose/theta`を追加すると, 次に図示するような結果が得られます. {{attachment:ROS/Tutorials/UnderstandingTopics/rqt_plot2.png||width=100%}} ## That's it for this section, use `Ctrl-C` to kill the `rostopic` terminals but keep your turtlesim running. これでこのセクションは終わりです.`Ctrl-C` を使って `rostopic` を kill しましょう.ただし,turtlesim は起動したままにしておいてください. ## Now that you understand how ROS topics work, let's look at how [[ROS/Tutorials/UnderstandingServicesParams |services and parameters work]]. ここでは ROS トピックがどのように働くかを理解しました.次は[[ja/ROS/Tutorials/UnderstandingServicesParams |サービスとパラメータを理解する]]を見てみましょう. ## AUTOGENERATED DO NOT DELETE ## TutorialCategory ## ROSTutorialCategory ## TutorialTurtlesim