Ask Your Question
1

publisher an integer

asked 2013-01-31 08:47:40 -0600

mrpiccolo gravatar image

updated 2014-01-28 17:15:03 -0600

ngrennan gravatar image

Hello
This is the code for publisher a string:

std_msgs::String msg;
std::stringstream ss;
ss << "hello world " << count;
msg.data = ss.str();
ROS_INFO("%s", msg.data.c_str());
chatter_pub.publish(msg);

If i want publisher an integer, other to sobstitute string with for example int8 what i can do?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
8

answered 2013-01-31 10:21:34 -0600

joq gravatar image

updated 2013-01-31 16:15:05 -0600

It would be something like this:

#include <std_msgs/Int8.h>

std_msgs::Int8 msg;
msg.data = 17;
ROS_INFO("%d", msg.data);
chatter_pub.publish(msg);
edit flag offensive delete link more

Comments

1

as per above but dont forget to set the variable with: std_msgs::Int8 msg; before you start to use it.

PeterMilani gravatar imagePeterMilani ( 2013-01-31 13:06:42 -0600 )edit

Quite right. Answer updated.

joq gravatar imagejoq ( 2013-01-31 16:15:32 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2013-01-31 08:47:40 -0600

Seen: 11,750 times

Last updated: Jan 31 '13