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

Revision history [back]

click to hide/show revision 1
initial version

You can first try to check if the message is empty by using LaserScanMsg.ranges.empty(). If this returns a 1, then your message is indeed empty, and any other action you try to do on it will result in a Segmentation Fault.

I would suggest the following:

if( !LaserScanMsg.ranges.empty() ) { return LaserScanMsg.ranges[LaserScanMsg.ranges.size()/2]; }