How to create an empty message from the publisher
Hi,
Since publisher is tied up to single topic and topic had a fixed message datatype. Other words, given a publisher it is possible to obtain the topic name and message type. Is it possible to obtain the empty message from the publisher ?
// currently
auto chatterPub = node->create_publisher<std_msgs::msg::String>("chatter", 10);
std_msgs::msg::String message;
message.data = "Hello, world! "
// Looking for
auto chatterPub = node->create_publisher<std_msgs::msg::String>("chatter", 10);
chatterMsg = ros2message(chatterPub); // here //
chatterMsg.data = "Hello, world! "
I found this kind of interface in matlab. I am not sure how this is achieved. From publisher, topic name and topic type can be obtained as a string. But not sure hoe to convert into a datatype. Any helpful thoughts is greatly appreciated.
Is this useful?