Is it possible to switch topic message type with code?
Hi!
In my ros project I will have a constant flow of information from node A to node B. Node A will tell node B to start up / shut down certain modes via service calls and then feed it with data for that specific mode via a topic. Only one mode will be running at a specific time in node B, but they all require different kinds of data. Adapting the custom message type to one mode will therefore not suit the other modes, since they might require e.g. a string instead of two integers. Having one topic for each node with its specific message type will just be a bad idea since there will be only one "actively used" topic at one time, and lots of unused? So I'm wondering if it's possible to change the message type of a topic in the code so that the program can switch message type depending on what mode is running. I also thought about having a message type that fits all of the different modes, sort of finding the least common denominator, but that will just end up with it always being bigger than it needs to be.
Any advice?
Thanks in advance!
Hi, I think you can try to customize your own message type, like
By doing so, you don't need to change the topic message type in the runtime.
@RyanChen.YLC Thanks for the answer! However, I think you missunderstood me. I don't want to use one type of message, since it would have to be able to acommodate every modes' needed variables. That would be fine in your example since each mode only needs one variable each, but my modes will require much more data per message. Adding them all up to one message would make it difficult, since that kind of message would become massive, which isn't preferrable. I would like to have several different message types like:
ModeAmsg:
ModeBmsg:
And then I would like to be able to have one topic that changes its message type between ModeAmsg, ModeBmsg, ModeCmsg etc depending on what mode is running.