Publishing a Char Array
Hi Friends,
I have a ROS Node which is creating a TCP/IP Connection and I am Sending & Receiving the data from the Server.
I am using a Char buff[110]
to read the data and I want to publish this array on a ROS topic.
How do I publish this character array on the topic and how to Subscribe this in another node.
I tried few examples using std_msgs::UInt8MultiArray
& pusb_back()
but it was not publishing the data.
Kindly help.
Thanks.
Asked by Radeshwar on 2021-01-19 06:23:53 UTC
Answers
Have you tried using C++ std::string data type? If that fits the use case, should be straightforward and simple. For example, I'm using this with boost::serialize
Publisher :
Advertise<topic type>("topic name", size)
Std_msgs::string msg;
Msg.data = std::string(char *)
Pub.publish(msg)
Subscriber :
void myCallback(const std:_msgs::string::constptr& msg) //prototype
//in the main :
NodeHandle.subscribe(topic_Name, buffer size, myCallback) //Create a subscriber object
Implement what you need in callback.
Asked by Vic on 2021-01-19 08:18:36 UTC
Comments