Skip to content

Commit df9cdad

Browse files
committed
Test: Add unit test to verify smoothed path respects robot_radius
1 parent bbe005a commit df9cdad

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import conftest
2+
import math
3+
4+
from PathPlanning.RRT import rrt_with_pathsmoothing as rrt_module
5+
6+
def test_smoothed_path_safety():
7+
# Define test environment
8+
obstacle_list = [
9+
(5, 5, 1.0),
10+
(3, 6, 2.0),
11+
(3, 8, 2.0),
12+
(3, 10, 2.0),
13+
(7, 5, 2.0),
14+
(9, 5, 2.0)
15+
]
16+
robot_radius = 0.5
17+
18+
# Disable animation for testing
19+
rrt_module.show_animation = False
20+
21+
# Create RRT planner
22+
rrt = rrt_module.RRT(
23+
start=[0, 0],
24+
goal=[6, 10],
25+
rand_area=[-2, 15],
26+
obstacle_list=obstacle_list,
27+
robot_radius=robot_radius
28+
)
29+
30+
# Run RRT
31+
path = rrt.planning(animation=False)
32+
33+
# Smooth the path
34+
smoothed = rrt_module.path_smoothing(path, max_iter=1000,
35+
obstacle_list=obstacle_list,
36+
robot_radius=robot_radius)
37+
38+
# Check if all points on the smoothed path are safely distant from obstacles
39+
for x, y in smoothed:
40+
for ox, oy, obs_radius in obstacle_list:
41+
d = math.hypot(x - ox, y - oy)
42+
min_safe_dist = obs_radius + robot_radius
43+
assert d > min_safe_dist, \
44+
f"Point ({x:.2f}, {y:.2f}) too close to obstacle at ({ox}, {oy})"
45+
46+
47+
if __name__ == '__main__':
48+
conftest.run_this_test(__file__)

0 commit comments

Comments
 (0)