ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
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];
}