ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
That looks like it should work. beware that your callback will be called with different messages with different types, so you'll have to check the message type and do something different for each type.
Alternately, you could define a different callback for each topic, have each callback parse the message into a common format, and then pass that to a common method which implements the actual program logic.
2 | No.2 Revision |
EDIT: The original question asked, in short "Can I subscribe and pass the same callback to multiple subscribers". I assumed you wanted to process different messages with different types in the same way, using the same callback.
The original answer was:
That looks like it should work. beware work, bug beware
that your callback will be called with with
different messages with different different
types, so you'll have to check the the
message type and do something something
different for each type.
Alternately, you could define a a
different callback for each topic, topic,
have each callback parse the message message
into a common format, and then pass pass
that to a common method which which
implements the actual program logic.
EDIT:
I'm no longer sure what you're expecting ROS to do for you.
3 | No.3 Revision |
EDIT: The original question asked, in short "Can I subscribe and pass the same callback to multiple subscribers". I assumed you wanted to process different messages with different types in the same way, using the same callback.
The original answer was:
That looks like it should work, bug beware that your callback will be called with different messages with different types, so you'll have to check the message type and do something different for each type.
Alternately, you could define a different callback for each topic, have each callback parse the message into a common format, and then pass that to a common method which implements the actual program logic.
EDIT:
I'm no longer sure what you're expecting ROS to do for you.
EDIT:
You can use message_filters to subscribe to multiple topics and get a callback when all topics have new messages. Unless your publishers are explicitly publishing messages with identical timestamps, you'll probably want to use the ApproximateTimeSynchronizer.