0
$\begingroup$

Rosanswers logo

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();
    }
}

Originally posted by ajain on ROS Answers with karma: 281 on 2014-10-21

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by ahendrix with karma: 47576 on 2014-10-21

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by ajain on 2014-10-21:
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?

Comment by ahendrix on 2014-10-21:
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.

Comment by ahendrix on 2014-10-21:
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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.