ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

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

This is the code for publisher a string:

std_msgs::String msg;
std::stringstream ss;
ss << "hello world " << count; = ss.str();

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

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; = 17;
edit flag offensive delete link more



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

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

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

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


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

Seen: 17,170 times

Last updated: Sep 02 '21