publisherの基本的な使い方について学ぶ。
- rosのインストール → install_ros_kinetic.sh
- workspaceの作成の方法 → install_catkin_ws.sh
cd catkin_ws/src
git clone https://github.com/KoutaOhishi/publisher_tutorial.git
cd publisher_tutorial/src
chmod 755 *
cd ~/catkin_ws/
catkin_make
すべての端末をすべて切った後、
roslaunch publisher_tutorial dummy_led.launch
を実行する。
別の端末を起動させ、
rostopic list
と打つと、
/publisher_tutorial/led_color
/publisher_tutorial/led_on
/rosout
/rosout_agg
が表示される。
それぞれのトピックの型は、
- /publisher_tutorial/led_on : [std_msgs/Bool]
- /publisher_tutorial/led_color : [std_msgs/String]
-
/publisher_tutorial/led_on (LEDのON/OFFを制御)
rostopic pub /publisher_tutorial/led_on std_msgs/Bool "data: false" #LEDが消える rostopic pub /publisher_tutorial/led_on std_msgs/Bool "data: true" #LEDが付く -
/publisher_tutorial/led_color (LEDの色を制御)
rostopic pub /publisher_tutorial/led_color std_msgs/String "data: 'Blue'" rostopic pub /publisher_tutorial/led_color std_msgs/String "data: 'Yellow'"
pythonやc++でtopicをpublishできるようになろう!
ただpublishするだけだと面白くないので、ちょっとした処理を加えてください。
publisher_tutorial/src/の中にサンプルプログラムがあるので参考にしてください。
c++のファイルを追加する場合は、CMakeList.txtの末尾に以下を加える
# 名前は適宜変更してください。
add_executable({node_name} src/{file_name}.cpp)
target_link_libraries({node_name} ${catkin_LIBRARIES})


