Skip to content

Commit 018e55b

Browse files
committed
path segment depracation and linting
Signed-off-by: silanus23 <berkantali23@outlook.com>
1 parent a40c759 commit 018e55b

File tree

2 files changed

+16
-35
lines changed

2 files changed

+16
-35
lines changed

nav2_costmap_2d/include/nav2_costmap_2d/bounded_tracking_error_layer.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,6 @@ class BoundedTrackingErrorLayer : public nav2_costmap_2d::Layer
293293
std::string tracking_feedback_topic_;
294294
unsigned char corridor_cost_;
295295
int wall_thickness_;
296-
int path_segment_resolution_;
297296
tf2::Duration transform_tolerance_;
298297
double resolution_;
299298

nav2_costmap_2d/plugins/bounded_tracking_error_layer.cpp

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,6 @@ void BoundedTrackingErrorLayer::onInitialize()
6868

6969
wall_thickness_ = node->declare_or_get_parameter(name_ + "." + "wall_thickness", 1);
7070

71-
path_segment_resolution_ = node->declare_or_get_parameter(
72-
name_ + "." + "path_segment_resolution", 5);
73-
7471
int corridor_cost_param = node->declare_or_get_parameter(name_ + "." + "corridor_cost", 190);
7572
corridor_cost_ = static_cast<unsigned char>(std::clamp(corridor_cost_param, 1, 254));
7673

@@ -94,9 +91,6 @@ void BoundedTrackingErrorLayer::onInitialize()
9491
if (step_ <= 0) {
9592
throw std::runtime_error{"step must be greater than zero"};
9693
}
97-
if (path_segment_resolution_ < 1) {
98-
throw std::runtime_error{"path_segment_resolution must be at least 1"};
99-
}
10094

10195
// Join topics with parent namespace for proper namespacing
10296
std::string path_topic = joinWithParentNamespace(path_topic_);
@@ -255,7 +249,6 @@ void BoundedTrackingErrorLayer::updateBounds(
255249
double robot_x, double robot_y, double /*robot_yaw*/,
256250
double * min_x, double * min_y, double * max_x, double * max_y)
257251
{
258-
259252
if (!enabled_) {
260253
return;
261254
}
@@ -338,16 +331,12 @@ void BoundedTrackingErrorLayer::getPathSegment(
338331
const size_t start_index = path_index;
339332
size_t end_index = start_index;
340333
double dist_traversed = 0.0;
341-
const size_t jump = static_cast<size_t>(path_segment_resolution_);
342334

343-
for (size_t i = start_index; i < path.poses.size() - 1; i += jump) {
344-
const size_t next_i = std::min(i + jump, path.poses.size() - 1);
345-
346-
// Calculate straight line distance between jumped poses
335+
for (size_t i = start_index; i < path.poses.size() - 1; i++) {
347336
dist_traversed += nav2_util::geometry_utils::euclidean_distance(
348-
path.poses[i], path.poses[next_i]);
337+
path.poses[i], path.poses[i + 1]);
349338

350-
end_index = next_i;
339+
end_index = i + 1;
351340
if (dist_traversed >= look_ahead_) {
352341
break;
353342
}
@@ -365,7 +354,6 @@ void BoundedTrackingErrorLayer::getPathSegment(
365354
}
366355
}
367356

368-
369357
void BoundedTrackingErrorLayer::fillCorridorQuad(
370358
unsigned char * costmap,
371359
unsigned int size_x,
@@ -394,6 +382,15 @@ void BoundedTrackingErrorLayer::fillCorridorQuad(
394382

395383
// Span buffer: for each y, track [x_min, x_max]
396384
const int height = clamped_y_max - clamped_y_min + 1;
385+
386+
if (height <= 0 || height > static_cast<int>(size_y)) {
387+
RCLCPP_WARN(
388+
logger_,
389+
"Invalid quad height: %d (size_y: %u). Skipping quad.",
390+
height, size_y);
391+
return;
392+
}
393+
397394
span_x_min_buffer_.assign(height, std::numeric_limits<int>::max());
398395
span_x_max_buffer_.assign(height, std::numeric_limits<int>::min());
399396

@@ -466,14 +463,14 @@ void BoundedTrackingErrorLayer::updateCosts(
466463

467464
getPathSegment(*cached_path_ptr, cached_path_index, segment_buffer_);
468465

469-
// Minimum 10 poses needed to produce at least 2 wall polygon points with default step_size_
470-
if (segment_buffer_.poses.size() < 10) {
466+
const size_t min_poses = (step_size_ * 2) + 1;
467+
if (segment_buffer_.poses.size() < min_poses) {
471468
RCLCPP_INFO_THROTTLE(
472469
logger_,
473470
*clock_,
474471
5000,
475-
"Path segment too small (%zu poses), skipping wall generation",
476-
segment_buffer_.poses.size());
472+
"Path segment too small (%zu poses), need at least %zu poses for step_size=%zu",
473+
segment_buffer_.poses.size(), min_poses, step_size_);
477474
return;
478475
}
479476

@@ -645,16 +642,6 @@ rcl_interfaces::msg::SetParametersResult BoundedTrackingErrorLayer::validatePara
645642
result.successful = false;
646643
result.reason = "wall_thickness must be greater than zero";
647644
}
648-
} else if (param_name == name_ + "." + "path_segment_resolution") {
649-
const int new_value = parameter.as_int();
650-
if (new_value < 1) {
651-
RCLCPP_WARN(
652-
logger_, "The value of parameter '%s' is incorrectly set to %d, "
653-
"it should be >= 1. Rejecting parameter update.",
654-
param_name.c_str(), new_value);
655-
result.successful = false;
656-
result.reason = "path_segment_resolution must be at least 1";
657-
}
658645
}
659646
}
660647
}
@@ -709,11 +696,6 @@ void BoundedTrackingErrorLayer::updateParametersCallback(
709696
{
710697
wall_thickness_ = parameter.as_int();
711698
current_ = false;
712-
} else if (param_name == name_ + "." + "path_segment_resolution" &&
713-
path_segment_resolution_ != parameter.as_int())
714-
{
715-
path_segment_resolution_ = parameter.as_int();
716-
current_ = false;
717699
}
718700
}
719701
}

0 commit comments

Comments
 (0)