Skip to content

Fix/path smoothing robot radius #1231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ShiboWork
Copy link

Reference issue

What does this implement/fix?

This PR fixes an issue in the path_smoothing() function, where the collision checking via line_collision_check() did not take robot_radius into account correctly. This caused the smoothed path to pass dangerously close to obstacles.

  • Modified line_collision_check() to check collision along finite-length line segments and incorporate robot_radius.
  • Updated path_smoothing() logic to use this corrected check.
  • Added a new unit test to verify that smoothed paths maintain clearance from obstacles based on robot radius.

Additional information

  • Confirmed original vs smoothed paths via animation and test assertions.

CheckList

  • Did you add an unittest for your new example or defect fix?
  • Did you add documents for your new example? N/A (not a new algorithm)
  • All CIs are green? (You can check it after submitting)

@AtsushiSakai AtsushiSakai requested a review from Copilot June 15, 2025 13:12
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR ensures the path smoothing routine respects the robot’s radius by updating collision checks and adding a safety-focused unit test.

  • Expanded line_collision_check to sample finite-length segments and inflate obstacles by robot_radius.
  • Updated path_smoothing to pass robot_radius into collision checks.
  • Added a new test verifying no smoothed path point encroaches on obstacles.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
tests/test_rrt_with_pathsmoothing_radius.py New test ensuring smoothed path maintains clearance.
PathPlanning/RRT/rrt_with_pathsmoothing.py Modified collision logic and updated function calls.
Comments suppressed due to low confidence (2)

tests/test_rrt_with_pathsmoothing_radius.py:43

  • [nitpick] Using a strict '>' may fail when a point lies exactly at the clearance boundary. Consider using '>=' if touching the safety radius is acceptable or adjust the test to account for floating-point tolerances.
assert d > min_safe_dist, \

PathPlanning/RRT/rrt_with_pathsmoothing.py:76

  • [nitpick] The variable 'size' represents an obstacle radius. Rename it to 'obs_radius' or 'radius' for clearer semantics.
for (ox, oy, size) in obstacle_list:

length = math.hypot(dx, dy)

if length == 0:
return True # Degenerate case
Copy link
Preview

Copilot AI Jun 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The degenerate case returns True even if the single point lies inside an inflated obstacle. Instead, explicitly check collision at (x1, y1) against all obstacles with robot_radius.

Suggested change
return True # Degenerate case
for (ox, oy, size) in obstacle_list:
d = math.hypot(ox - x1, oy - y1)
if d <= size + robot_radius:
return False # Collision
return True # Safe

Copilot uses AI. Check for mistakes.

if length == 0:
return True # Degenerate case

steps = int(length / 0.2) + 1 # Sampling every 0.2m along the segment
Copy link
Preview

Copilot AI Jun 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The magic value 0.2 is hard-coded. Consider extracting it to a named constant (e.g., SAMPLE_STEP) or making it a configurable parameter for easier tuning and clarity.

Suggested change
steps = int(length / 0.2) + 1 # Sampling every 0.2m along the segment
steps = int(length / SAMPLE_STEP) + 1 # Sampling every SAMPLE_STEP meters along the segment

Copilot uses AI. Check for mistakes.

Copy link
Owner

@AtsushiSakai AtsushiSakai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for great PR!!. I have some small comments. PTAL.

if length == 0:
return True # Degenerate case

steps = int(length / 0.2) + 1 # Sampling every 0.2m along the segment
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This 0.2 should be an optional argument also for this function.

@@ -121,12 +151,14 @@ def main():
(9, 5, 2)
] # [x,y,size]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
] # [x,y,size]
] # [x,y,radius]

x = x1 + t * dx
y = y1 + t * dy

for (ox, oy, size) in obstacle_list:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This size should be obstacle_radius.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: path_smoothing() Ignores robot_radius, Causing Smoothed Paths to Violate Obstacle Clearance
2 participants