0
$\begingroup$

I came across this function get_topic_names_and_types in rclcpp recently and I have a basic question about it.

Output type is std::map<std::string, std::vector<std::string>>. In simple term, it is as following

{
"topic_1": ["topic_type"],
"topic_2": ["topic_type"],
}

Here is one of the answers I found that explains the structure of the output by printing it for c++.

My question is, for the topic type, why we need vector of string instead of simple string?

I tried to create topic with the same name but different types. But it has thrown the exception what(): could not create publisher: create_publisher() called for existing topic name.

So I don't understand why vector of strings as topic types?

$\endgroup$

1 Answer 1

0
$\begingroup$

I didn't know that you can publish multiple topic with the same name but different types.

It is why the function's second parameter's type is std::vector<std::string>. It can return multiple types of the same topic name.

I think your problem is related to this link: the link

It is seem so your problem is related to DDS. Can you change your DDS to FastDDS and try again to create a new publisher with the same name but different type.

$\endgroup$
3
  • $\begingroup$ Hello, Yes, apparently it is possible to publish multiple types on same topic name. FastDDS is default DDS in ROS 2 (humble) installation, check here. I also verified it with wireshark, DDS vendor is eProsima Fast RTPS. I am kind of doing the same thins as mentioned in the issue. $\endgroup$
    – aarsht7
    Commented Aug 9 at 14:57
  • $\begingroup$ So did you try it, could you publish it with FastDDS? $\endgroup$ Commented Aug 9 at 16:33
  • $\begingroup$ No, when I tried it for the first time, I was already using FastDDS. So it doesn't work but it should be working according to the issue on github $\endgroup$
    – aarsht7
    Commented Aug 10 at 12:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.