How many message types can be published to a topic?
I have seen that messages can be transfered to topics. Can we send only one type of msg type? or any number of message types?
ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
I have seen that messages can be transfered to topics. Can we send only one type of msg type? or any number of message types?
Topics are (in a way) strongly typed, so theoretically you can only send messages of a single type to them (namely, the type that was NodeHandle::advertise(..)
d.
Edit: just tested this with three rostopic
instances:
pub /chatter std_msgs/String "data: 'piet'" -r1
pub /chatter std_msgs/Int16 "data: 345" -r1
echo /chatter
Result: the last publisher "wins", so the topic type registered appears to be std_msgs/int16
. rostopic echo
also prints 345
.
The std_msgs/String
publisher prints this:
[/rostopic_15588_1537948069134] [WARN] [1537948151.558332]: Could not process inbound connection: topic types do not match: [std_msgs/Int16] vs. [std_msgs/String]{'message_definition': 'int16 data\n', 'callerid': '/rostopic_17009_1537948151282', 'tcp_nodelay': '0', 'md5sum': '8524586e34fbd7cb1c08c5f5f1ca0e57', 'topic': '/chatter', 'type': 'std_msgs/Int16'}
Summarising: you can advertise(..)
any type on a single topic, but the "last one" will "win" and connections between publishers and subscribers will error out as they expect a certain type but during handshaking they see another.
Note: rostopic
is Python, I've not tested C++ but the behaviour should be similar.
How many message types can be published to a topic? 1.
Asked: 2018-09-26 02:43:40 -0500
Seen: 3,126 times
Last updated: Sep 26 '18
basic question in understanding publishing and subscribing
Can I "overload" topic names in ROS? (Different versions by datatype)
Subscribing to the odometry topic
Problem using subscribed motor position topic
publish arrays to a topic on the command line
How to create a global listener for any ROS topic and extract all data from any message?
Diagnostic aggregator not reading messages from new publishers on /diagnostics topic [closed]