Ask Your Question

how to publish int8,float ...and function ? [closed]

asked 2014-09-12 02:13:01 -0600

turtle gravatar image

i can't publish int8 .. can you help me?

  #include "ros/ros.h"
#include "std_msgs/Int8.h"

#include <sstream>

int main(int argc, char **argv)

  ros::init(argc, argv, "talker");

  ros::NodeHandle n;

  ros::Publisher chatter_pub = n.advertise<std_msgs::Int8>("mytopic", 1000);

  ros::Rate loop_rate(10);

    int8_t count = 0;
  while (ros::ok())

    std_msgs::Int8 msg; = count++;






  return 0;

display : NULL

edit retag flag offensive reopen merge delete

Closed for the following reason duplicate question by turtle
close date 2014-09-12 04:43:04.004741

2 Answers

Sort by ยป oldest newest most voted

answered 2014-09-12 02:23:33 -0600

gvdhoorn gravatar image

For std_msgs::Int8, the data field is of the int8 type (see the msg doc). The %s format string is for strings (or char*), so that won't work. Try %d.

PS: are you sure you aren't ignoring some compiler warning?

PPS: the question title says you cannot publish an Int8, but in your actual question it would seem you only have difficulty logging the data field using ROS_INFO(..). Perhaps you should update the title to reflect your actual issue.

edit flag offensive delete link more


Thanhk you ! i done

turtle gravatar imageturtle ( 2014-09-12 04:37:54 -0600 )edit

answered 2014-09-12 02:17:49 -0600

bvbdort gravatar image
ROS_INFO("%d",;  // is int data type so %d
edit flag offensive delete link more

Question Tools

1 follower


Asked: 2014-09-12 02:13:01 -0600

Seen: 4,490 times

Last updated: Sep 12 '14