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

Multiple nodes providing same service, which one will get through (many to one services) [closed]

asked 2014-10-21 14:49:46 -0500

ajain gravatar image

updated 2014-10-21 14:52:04 -0500

I am trying a very simple task. I have a 2D laser scanner and 3D velodyne laser on my robot and I want to create an assembled point cloud which includes data from both lasers in one point cloud. I am trying to have laser_assembler package do all the work with laser_scan_assembler and point_cloud2_assembler nodes, which both provide services of same name /assembled_point_cloud which is of the same type sensor_msgs::PointCloud.

The problem I'm facing is that my temp_service_call_node only subscribes to one service (the one provided by point_cloud2_assembler), and gets no data from laser_scan_assembler. Also, if I kill the velodyne node, so that no point cloud2 data is published for point_cloud2_assembler, it doesn't change anything. /assembled_point_cloud which instead of showing only 2D laser scan data when no point cloud2 data is available, keeps subscribing to the point_cloud2_assembler which doesn't give any data.

Is there anything I'm missing or a different approach that I can try?

Please see code for reference-

Here's my launch file:

<launch>
    <node type="laser_scan_assembler" pkg="laser_assembler" name="laser_scan_assembler">
        <remap from="scan" to="/laser/scan"/>
        <remap from="assemble_scans" to="assembled_point_cloud"/>
        <param name="max_scans" type="int" value="1" />
        <param name="fixed_frame" type="string" value="base_link" />
    </node>

    <node type="point_cloud_assembler" pkg="laser_assembler" name="point_cloud_assembler">
        <remap from="cloud" to="/laser/point_cloud"/>
        <remap from="assemble_scans" to="assembled_point_cloud"/>
        <param name="max_clouds" type="int" value="1" />
        <param name="fixed_frame" type="string" value="base_link" />
    </node>

     <node type="point_cloud2_assembler" pkg="laser_assembler" name="point_cloud2_assembler">
        <remap from="cloud" to="/laser/point_cloud2"/>
        <remap from="assemble_scans" to="assembled_point_cloud"/>
        <param name="max_clouds" type="int" value="1" />
        <param name="fixed_frame" type="string" value="base_link" />
    </node>
</launch>

temp_service_call.cpp file:

void publishPointCloud2()
{
    //Wait for service to start
    ros::service::waitForService("/assembled_point_cloud");

    ros::Rate r(updateRate);

    while(ros::ok())
    {
        assemblerService.request.begin = assemblerService.request.end;
        assemblerService.request.end   = ros::Time::now();
        if (assemblerClient.call(assemblerService))
        {
            pointCloud = assemblerService.response.cloud;
                    sensor_msgs::convertPointCloudToPointCloud2(pointCloud, pointCloud2);

            ROS_INFO("Got cloud with %u points\n", assemblerService.response.cloud.points.size());
        }
        else
        {
            ROS_ERROR("Service call for getting assembled laser scan failed\n");
        }

        if (pointCloud2.data.size() > 0)
            pointCloud2Publisher.publish(pointCloud2);

        ros::spinOnce();
        r.sleep();
    }
}
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by ajain
close date 2015-01-05 12:40:55.072510

1 Answer

Sort by ยป oldest newest most voted
2

answered 2014-10-21 15:03:03 -0500

ahendrix gravatar image

ROS does not allow two nodes to provide the same service.

You should instead remap one or both services to a different name, and call them separately.

edit flag offensive delete link more

Comments

Okay. So if I subscribe to two different services for point_cloud2 from each assembler and then use pcl::concatenatePointCloud() to merge them, will it take care of assembling point clouds with closest timestamps and returning the merged point cloud with latest timestamp?

ajain gravatar image ajain  ( 2014-10-21 15:21:53 -0500 )edit

It looks like you're trying to assemble only the most recent scan from each sensor into a composite cloud. Since the primary purpose of the laser assembler is to buffer and assemble multiple scans, it isn't really helping you here.

ahendrix gravatar image ahendrix  ( 2014-10-21 16:32:26 -0500 )edit

It may be simpler to subscribe to the topics in question and assemble the scans yourself, using the source code for the laser scan assembler as inspiration.

ahendrix gravatar image ahendrix  ( 2014-10-21 16:33:08 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2014-10-21 14:49:46 -0500

Seen: 2,063 times

Last updated: Oct 21 '14