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

subscriber pointcloud

asked 2011-06-27 01:55:59 -0600

kang gravatar image

Hi, I am using perception-pcl under ros. I want to get pointcloud from two kinects. Here, I subscribe to both topics. How can I get the data, which is the "cloud_s" and "cloud_t" into my main function and compute it there? I tried to put argument on callback function like cloud_cb1(cloud_s) in:

ros::Subscriber sub_source = nh1.subscribe("camera1/depth/points", 1,cloud_cb1);

but, it did not work. below is part of my code. Thanks in advanced.

...
    void cloud_cb1 (const sensor_msgs::PointCloud2ConstPtr& cloud_s)
    {
      if ((cloud_s->width * cloud_s->height) == 0)
        return; 
}
void cloud_cb2 (const sensor_msgs::PointCloud2ConstPtr& cloud_t)
{
      if ((cloud_t->width * cloud_t->height) == 0)
        return;
}


int main(int argc, char** argv)
{
ros::init (argc, argv, "reg_icp_ros");  //initialize ros  
ros::NodeHandle nh1;
ros::NodeHandle nh2;

while (ros::ok())
  {
//subscribe node
ros::Subscriber sub_source = nh1.subscribe("camera1/depth/points", 1,cloud_cb1);
ros::Subscriber sub_target = nh2.subscribe("camera2/depth/points", 1,cloud_cb2);

...

best,

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2011-06-27 02:24:54 -0600

dornhege gravatar image

You should have the subscribers outside of the main loop. You only need to subscribe once. Also you don't need individual NodeHandles, you can use the same handle to subscribe.

edit flag offensive delete link more

Comments

Thanks, but still how can I get the "cloud_s" and "cloud_t" in my main function? I just use "cloud_s" and "cloud_t" but it seems to be empty. Btw, I don't get it since I think I need two subscriber for two kinect inputs.
kang gravatar image kang  ( 2011-06-27 02:33:36 -0600 )edit
Once the callback is called you can do whatever you want with the cloud_s and cloud_t. You do need two Subscribers, but one NodeHandle is sufficient.
dornhege gravatar image dornhege  ( 2011-06-27 04:29:28 -0600 )edit
I suggest that you look through the tutorials for roscpp http://www.ros.org/wiki/roscpp/Tutorials In particular this tutorial http://www.ros.org/wiki/roscpp_tutorials/Tutorials/WritingPublisherSubscriber on how to subscribe to messages.
tfoote gravatar image tfoote  ( 2011-06-27 17:51:54 -0600 )edit
Thanks ffoote, the links were quite helpful.
kang gravatar image kang  ( 2011-06-28 23:11:36 -0600 )edit

Question Tools

Stats

Asked: 2011-06-27 01:55:59 -0600

Seen: 916 times

Last updated: Jun 27 '11