I am trying publish height but the data out is zero

asked 2020-04-29 15:24:47 -0600

rosbiggener gravatar image

updated 2022-05-23 09:54:56 -0600

lucasw gravatar image

Code:

#include "ros/ros.h"
#include <sensor_msgs/PointCloud2.h>
#include <std_msgs/UInt32.h>

int height =1;

void pointCallback(const sensor_msgs::PointCloud2 msg)
{
  ROS_INFO("Height is: [%i]", msg.height);

}
int main(int argc, char **argv)
{

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


  ros::NodeHandle n;


  ros::Publisher chatter_pub = n.advertise<std_msgs::UInt32>("point_c", 1000);
  ros::Subscriber sub = n.subscribe("/points_raw", 1000, pointCallback);

  ros::Rate loop_rate(10);


  int count = 0;

  while (ros::ok())
  {


      std_msgs::UInt32 msg;

      msg.data = height;

      chatter_pub.publish(msg);

      ros::spinOnce();

      loop_rate.sleep();

      ++count;
  }


  return 0;
}
edit retag flag offensive close merge delete

Comments

Maybe a conversion issue? height is declared as int and msg.data is an unsigned int. Have you tried declaring height as usinged int?

Martin Peris gravatar image Martin Peris  ( 2020-04-29 21:39:01 -0600 )edit

thanks its work now another question , if I am using rosbag play is it right to give the height a value ?

rosbiggener gravatar image rosbiggener  ( 2020-04-30 16:32:06 -0600 )edit