在實際的開發中,想把不同的消息發佈到一個模塊中,就考慮把不同類型的消息發佈到一個話題上,這樣似乎可以省事甚多
然後通過命令測試了一下:
rostopic pub /helloworld std_msgs/String “this is a test string” -r 1
rostopic pub /helloworld std_msgs/Bool 1 -r 1
rostopic echo “/helloworld”
測試現象
訂閱者只能收到後發佈的數據,先發布者報警告如下:
[WARN] [1581548856.701520]: Could not process inbound connection: topic types do not match: [std_msgs/Bool] vs. [std_msgs/String]{‘message_definition’: ‘bool data’, ‘callerid’: ‘/rostopic_16202_1581548852459’, ‘tcp_nodelay’: ‘0’, ‘md5sum’: ‘8b94c1b53db61fb6aed406028ad6332a’, ‘topic’: ‘/helloworld’, ‘type’: ‘std_msgs/Bool’}[WARN] [1581548856.701520]: Could not process inbound connection: topic types do not match: [std_msgs/Bool] vs. [std_msgs/String]{‘message_definition’: ‘bool data’, ‘callerid’: ‘/rostopic_16202_1581548852459’, ‘tcp_nodelay’: ‘0’, ‘md5sum’: ‘8b94c1b53db61fb6aed406028ad6332a’, ‘topic’: