From dd895d2afb6f1a56d7485182322ba6e25d6f89ed Mon Sep 17 00:00:00 2001 From: Kai-Tao Xie Date: Mon, 16 Aug 2021 15:33:24 +0800 Subject: [PATCH 1/2] catch runtime_error if the message from laser is malformed --- nav2_costmap_2d/plugins/obstacle_layer.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/nav2_costmap_2d/plugins/obstacle_layer.cpp b/nav2_costmap_2d/plugins/obstacle_layer.cpp index 11a79558ab..87e63a17da 100644 --- a/nav2_costmap_2d/plugins/obstacle_layer.cpp +++ b/nav2_costmap_2d/plugins/obstacle_layer.cpp @@ -291,6 +291,12 @@ ObstacleLayer::laserScanCallback( global_frame_.c_str(), ex.what()); projector_.projectLaser(*message, cloud); + } catch (std::runtime_error &ex) { + RCLCPP_WARN( + logger_, + "transformLaserScanToPointCloud error, it seems the message from laser is malformed. Ignore this message. what(): %s", + ex.what()); + return; //ignore this message } // buffer the point cloud @@ -327,6 +333,12 @@ ObstacleLayer::laserScanValidInfCallback( "High fidelity enabled, but TF returned a transform exception to frame %s: %s", global_frame_.c_str(), ex.what()); projector_.projectLaser(message, cloud); + } catch (std::runtime_error &ex) { + RCLCPP_WARN( + logger_, + "transformLaserScanToPointCloud error, it seems the message from laser is malformed. Ignore this message. what(): %s", + ex.what()); + return; //ignore this message } // buffer the point cloud From c92cd3da2207424df4c4bc62653051235f510d6c Mon Sep 17 00:00:00 2001 From: Kai-Tao Xie Date: Tue, 17 Aug 2021 11:07:51 +0800 Subject: [PATCH 2/2] fix styling --- nav2_costmap_2d/plugins/obstacle_layer.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/nav2_costmap_2d/plugins/obstacle_layer.cpp b/nav2_costmap_2d/plugins/obstacle_layer.cpp index 87e63a17da..164227a21b 100644 --- a/nav2_costmap_2d/plugins/obstacle_layer.cpp +++ b/nav2_costmap_2d/plugins/obstacle_layer.cpp @@ -291,12 +291,13 @@ ObstacleLayer::laserScanCallback( global_frame_.c_str(), ex.what()); projector_.projectLaser(*message, cloud); - } catch (std::runtime_error &ex) { + } catch (std::runtime_error & ex) { RCLCPP_WARN( logger_, - "transformLaserScanToPointCloud error, it seems the message from laser is malformed. Ignore this message. what(): %s", + "transformLaserScanToPointCloud error, it seems the message from laser is malformed." + " Ignore this message. what(): %s", ex.what()); - return; //ignore this message + return; } // buffer the point cloud @@ -333,12 +334,13 @@ ObstacleLayer::laserScanValidInfCallback( "High fidelity enabled, but TF returned a transform exception to frame %s: %s", global_frame_.c_str(), ex.what()); projector_.projectLaser(message, cloud); - } catch (std::runtime_error &ex) { + } catch (std::runtime_error & ex) { RCLCPP_WARN( logger_, - "transformLaserScanToPointCloud error, it seems the message from laser is malformed. Ignore this message. what(): %s", + "transformLaserScanToPointCloud error, it seems the message from laser is malformed." + " Ignore this message. what(): %s", ex.what()); - return; //ignore this message + return; } // buffer the point cloud