How to make the ign tool work with custom messages
I'm wondering what would be involved to make the ign
tool and subtools like ign topic
work with messages outside of ignition msgs. It seems like the ignition messages get some extra generated code, such as calls to IGN_REGISTER_STATIC_MSG
, which make them discoverable by the ign tool. Can I get a brief explanation of how this works, and how I can get it to work with custom messages? I realize this may not be easy, but I'm willing to put in some work.
Asked by Peter Mitrano on 2017-08-31 18:43:51 UTC
Answers
I'm assuming that you're referring to ign topic --pub
or ign service --req
. The rest of the topic/service options should work with custom messages (info, list, echo).
I think this problem can be reduced as: Given a string representation of a Protobuf message (e.g.: example.msgs.StringMsg
), can you write a function that creates one of your custom messages and returns a pointer to a google::protobuf::message
?
google::protobuf::Message* CreateMsg(const std::string &_type)
This should be possible to implement if you generate your messages with descriptor information, and then, use the DynamicMessage
class from Protobuf. If you can solve this problem first, I'll help you to integrate it with ign
.
The way this is solved in Ignition Messages is different. We essentially maintain a map with types and a Protobuf message for each Ignition Message Type. The IGN_REGISTER_STATIC_MSG
macro is injected in each message because we use our own message generator to add that code. I don't know exactly where, but the maps is populated inside the Ignition Message shared library.
Asked by Carlos Agüero on 2017-09-02 05:11:04 UTC
Comments
I haven't put any work into this yet, but I will just note the echo command also does not work. It simply prints nothing (doesn't crash or print errors) when listening to a topic with custom message type
Asked by Peter Mitrano on 2017-09-09 19:27:19 UTC
@carlos-aguero I confirm it in Gazebo 9, which supposedly is using ignition Transport 4.0. I have a publisher in a plugin, a subscriber in another, on publishing a custom protobuf message and the other subscribing to that same message. I can confirm we have data exchange between the two, but using ign topic --echo </topic/path>
results on the same as @peter-mitrano described.
Asked by Nuno Marques on 2018-12-16 11:19:37 UTC
Comments