How to create an empty message from the publisher

asked 2021-02-12 03:27:01 -0500

BhanuKiran.Chaluvadi gravatar image

updated 2021-02-12 03:52:43 -0500

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.

edit retag flag offensive close merge delete

Comments

Is this useful?

skpro19 gravatar image skpro19  ( 2021-02-12 15:49:41 -0500 )edit