From 8c3132913b8e4f942bc98b9b82268ff4e5765820 Mon Sep 17 00:00:00 2001 From: Hao-Xuan Song <44140526+Cryst4L9527@users.noreply.github.com> Date: Wed, 9 Nov 2022 12:03:48 +0800 Subject: [PATCH 1/3] Update amcl_node.cpp --- nav2_amcl/src/amcl_node.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/nav2_amcl/src/amcl_node.cpp b/nav2_amcl/src/amcl_node.cpp index 2e9730ae56..3738848ef5 100644 --- a/nav2_amcl/src/amcl_node.cpp +++ b/nav2_amcl/src/amcl_node.cpp @@ -807,7 +807,16 @@ bool AmclNode::updateFilter( RCLCPP_DEBUG( get_logger(), "Laser %d angles in base frame: min: %.3f inc: %.3f", laser_index, angle_min, angle_increment); - + + // Check the validity of range_max, must > 0.0 + if (laser_scan->range_max <= 0.0){ + RCLCPP_WARN( + get_logger(), "wrong range_max of laser_scan data: %f. The message could be malformed." + " Ignore this message and stop updating.", + laser_scan->range_max); + return false; + } + // Apply range min/max thresholds, if the user supplied them if (laser_max_range_ > 0.0) { ldata.range_max = std::min(laser_scan->range_max, static_cast(laser_max_range_)); From dfaf4e3e1cf78346830fe6a3de1b38f85b36196b Mon Sep 17 00:00:00 2001 From: Hao-Xuan Song <44140526+Cryst4L9527@users.noreply.github.com> Date: Thu, 10 Nov 2022 10:51:41 +0800 Subject: [PATCH 2/3] fit the code style --- nav2_amcl/src/amcl_node.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nav2_amcl/src/amcl_node.cpp b/nav2_amcl/src/amcl_node.cpp index 3738848ef5..edc8ea0b7e 100644 --- a/nav2_amcl/src/amcl_node.cpp +++ b/nav2_amcl/src/amcl_node.cpp @@ -809,7 +809,7 @@ bool AmclNode::updateFilter( angle_increment); // Check the validity of range_max, must > 0.0 - if (laser_scan->range_max <= 0.0){ + if (laser_scan->range_max <= 0.0) { RCLCPP_WARN( get_logger(), "wrong range_max of laser_scan data: %f. The message could be malformed." " Ignore this message and stop updating.", From 0f1c613bd5c3c68f32ad546a26b53df887d0d0ed Mon Sep 17 00:00:00 2001 From: Hao-Xuan Song <44140526+Cryst4L9527@users.noreply.github.com> Date: Thu, 10 Nov 2022 16:29:18 +0800 Subject: [PATCH 3/3] fit code style --- nav2_amcl/src/amcl_node.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nav2_amcl/src/amcl_node.cpp b/nav2_amcl/src/amcl_node.cpp index edc8ea0b7e..303a753b73 100644 --- a/nav2_amcl/src/amcl_node.cpp +++ b/nav2_amcl/src/amcl_node.cpp @@ -807,7 +807,7 @@ bool AmclNode::updateFilter( RCLCPP_DEBUG( get_logger(), "Laser %d angles in base frame: min: %.3f inc: %.3f", laser_index, angle_min, angle_increment); - + // Check the validity of range_max, must > 0.0 if (laser_scan->range_max <= 0.0) { RCLCPP_WARN( @@ -816,7 +816,7 @@ bool AmclNode::updateFilter( laser_scan->range_max); return false; } - + // Apply range min/max thresholds, if the user supplied them if (laser_max_range_ > 0.0) { ldata.range_max = std::min(laser_scan->range_max, static_cast(laser_max_range_));