Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/roboticstoolbox/mobile/PRMPlanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ def __init__(self, occgrid=None, npoints=100, dist_thresh=None, **kwargs):
super().__init__(occgrid, ndims=2, **kwargs)

if dist_thresh is None:
self._dist_thresh = 0.3 * self.occgrid.maxdim
dist_thresh = 0.3 * self.occgrid.maxdim
self._dist_thresh = dist_thresh

self._npoints = npoints
# self._npoints0 = npoints
Expand Down
36 changes: 36 additions & 0 deletions tests/test_prm_constructor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""Regression tests for PRM constructor distance thresholds."""

import unittest
from unittest.mock import patch

import numpy as np

from roboticstoolbox.mobile import PRMPlanner


class TestPRMConstructor(unittest.TestCase):
def test_default_distance_threshold(self):
"""The default threshold is derived from the occupancy grid size."""
planner = PRMPlanner(np.zeros((10, 20)), progress=False)

expected = 0.3 * planner.occgrid.maxdim
self.assertEqual(planner.dist_thresh, expected)
self.assertEqual(planner._dist_thresh0, expected)

def test_explicit_distance_threshold_reaches_planner(self):
"""Explicit thresholds, including zero, remain available during planning."""
grid = np.zeros((10, 20))
for threshold in (0.0, 2.5):
with self.subTest(threshold=threshold):
planner = PRMPlanner(grid, dist_thresh=threshold, progress=False)
self.assertEqual(planner.dist_thresh, threshold)
self.assertEqual(planner._dist_thresh0, threshold)

with patch.object(planner, "_create_roadmap") as create_roadmap:
planner.plan(npoints=1)
create_roadmap.assert_called_once_with(1, threshold, None)

with patch.object(planner, "_create_roadmap") as create_roadmap:
planner.plan(npoints=1, dist_thresh=3.0)
create_roadmap.assert_called_once_with(1, 3.0, None)
self.assertEqual(planner.dist_thresh, threshold)
Loading