LoginSignup
6
1

More than 3 years have passed since last update.

[ROS] トピックを一度だけ購読する

Posted at

はじめに

  • topicを購読する方法
    1. Subscriber: 一般的, コールバック関数を読んで処理
    2. wait_for_message: ノード不要. コールバック関数も不要なので複雑なことをする時は便利. 書籍で見かけたことがない.

rospy.wait_for_message

  • 書き方
rospy.wait_for_message('<トピック名>', 型, timeout=<>)
test.py
import rospy
from std_msgs.msg import String

def listen():
    while not rospy.is_shutdown():
        m = rospy.wait_for_message('/chatter', String, timeout=None
        rospy.loginfo(m.data)

if __name__ == '__main__':
    listen()
6
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
1