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

publisher an integer

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

mrpiccolo gravatar image

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

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

2 Answers

Sort by ยป oldest newest most voted
11

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

joq gravatar image

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

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

2

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

PeterMilani gravatar image PeterMilani  ( 2013-01-31 13:06:42 -0500 )edit
1

Quite right. Answer updated.

joq gravatar image joq  ( 2013-01-31 16:15:32 -0500 )edit

Thanks a lot

MedoSalah97 gravatar image MedoSalah97  ( 2020-08-21 05:26:38 -0500 )edit
0

answered 2021-09-02 00:23:14 -0500

prathamesh gravatar image

when std_msgs::Int are getting passing from the param from launch file upto 127 number it takes the value as it is after that at number 128 it take it as -128 number because 127 8bit binary number is 1111111 and 128 binary number is 10000000 why this happens because it take 8th bit as negative bit.

bit if you use normal Int then it shows the number without any conversions.

edit flag offensive delete link more

Question Tools

1 follower

Stats

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

Seen: 19,589 times

Last updated: Sep 02 '21