ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

Publishing a Char Array

asked 2021-01-19 05:23:53 -0500

Radeshwar gravatar image

updated 2021-01-19 05:32:22 -0500

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.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-01-19 07:18:36 -0500

Vic gravatar image

updated 2021-01-19 08:29:04 -0500

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.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2021-01-19 05:23:53 -0500

Seen: 742 times

Last updated: Jan 19 '21