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

Pointcloud2 vs PointCloud2Ptr

asked 2021-06-20 22:36:23 -0500

gyrados10 gravatar image

Hi, the message i am subscribing to from a topic is PointCloud2, whereas my subscriber callback routine looks like this

void cloud_callback (const sensor_msgs::PointCloud2ConstPtr& cloud_msg){
 ROS_INFO("inside callback");
}

int main (int argc, char** argv) {
 ros::init (argc, argv, "cloud_sub");
 ros::NodeHandle nh;
 ros::Rate loop_rate(10);
 ros::Subscriber sub;
 while (nh.ok()) {
   sub = nh.subscribe ("input_cloud", 1, cloud_callback);
   ros::spinOnce ();
   loop_rate.sleep ();
 }
}

Will the fact that the callback type is a Ptr affect the message? How should i take in a Ptr in my callback with the fact that my message subscribed to is PointCloud2 datatype?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-06-20 23:15:23 -0500

The PointCloud2Ptr is just a pointer to your PointCloud2 datatype. The actual sensor data is held in the PointCloud2 message structure and a pointer is passed to the callback to prevent duplication of data (saving time and memory) and other benefits that CS majors can fill you in.

You can still access your data in your callback using the -> operator. For eg: cloud_msg->size()

edit flag offensive delete link more

Comments

yeah, but do you mean that the callback will automatically convert my subscribed msg from raw data form to a pointer form?

gyrados10 gravatar image gyrados10  ( 2021-06-21 00:27:34 -0500 )edit

There is no need to convert anything. The pointer is just a symbolic reference to the address where the sensor data is stored.

Akhil Kurup gravatar image Akhil Kurup  ( 2021-06-21 00:31:13 -0500 )edit

Question Tools

Stats

Asked: 2021-06-20 22:36:23 -0500

Seen: 310 times

Last updated: Jun 20 '21