|
32 | 32 | from utility.threading import Lock # noqa: E402 |
33 | 33 |
|
34 | 34 | class Ros: |
35 | | - INFLATE: int = 3 # radius of agent for extended walls. Note, this currently isn't supported with dynamic maps due to time constraints (parameter is ignored). |
| 35 | + INFLATE: int = 2 # radius of agent for extended walls. |
36 | 36 | INIT_MAP_SIZE: int = 128 # maximum map size for the first received map (this determines the scaling factor for all subsequent map updates). |
37 | 37 | MAP_SIZE: int = 256 # the overall map size, can be as big as you like. Note, the initial map fragment will be located at the center of this 'big' map. |
| 38 | + TRAVERSABLE_THRESHOLD: int = 30 # weight grid values above this value are considered to be obstacles |
38 | 39 |
|
39 | 40 | _sim: Optional[Simulator] # simulator |
40 | 41 | _grid: Optional[NDArray[(MAP_SIZE, MAP_SIZE), np.float32]] # weight grid, shape (width, height), weight bounds: (0, 100), unmapped: -1 |
@@ -104,10 +105,23 @@ def _set_slam(self, msg: OccupancyGrid) -> None: |
104 | 105 | if i >= 0 and j >= 0 and i < raw_grid.shape[1] and j < raw_grid.shape[0]: |
105 | 106 | grid[i - start[0]][j - start[1]] = raw_grid[j][i] |
106 | 107 |
|
| 108 | + # hacky work-around for not having extended walls implemented. Here we manually |
| 109 | + # extend the walls, by placing obstacles (works just as well, but should still |
| 110 | + # ideally implement extended walls). |
| 111 | + INVALID_VALUE = -2 |
| 112 | + grid_walls_extended = np.full(self._size, INVALID_VALUE) |
| 113 | + for idx in np.ndindex(grid_walls_extended.shape): |
| 114 | + if grid_walls_extended[idx] == INVALID_VALUE: |
| 115 | + grid_walls_extended[idx] = grid[idx] |
| 116 | + if grid[idx] > self.TRAVERSABLE_THRESHOLD: |
| 117 | + for i in range(-self.INFLATE, self.INFLATE+1): |
| 118 | + for j in range(-self.INFLATE, self.INFLATE+1): |
| 119 | + grid_walls_extended[(idx[0]+i, idx[1]+j)] = grid[idx] |
| 120 | + |
107 | 121 | # make new grid accessible. |
108 | 122 | # Note, it's up to the user / algorithm to request a map update for thread |
109 | 123 | # safety, e.g. via `self._sim.services.algorithm.map.request_update()`. |
110 | | - self.grid = grid |
| 124 | + self.grid = grid_walls_extended |
111 | 125 |
|
112 | 126 | @property |
113 | 127 | def grid(self) -> str: |
@@ -229,7 +243,7 @@ def _map_update_requested(self) -> None: |
229 | 243 | Map update was requested. |
230 | 244 | """ |
231 | 245 | pass |
232 | | - |
| 246 | + |
233 | 247 | def _world_to_grid(self, world_pos: Point, origin: Optional[Point] = None) -> Point: |
234 | 248 | """ |
235 | 249 | Converts from meters coordinates to PathBench's grid coordinates (`self.grid`). |
@@ -291,7 +305,7 @@ def _setup_sim(self, config: Optional[Configuration] = None, goal: Optional[Poin |
291 | 305 | mp = RosMap(agent, |
292 | 306 | goal, |
293 | 307 | lambda: self.grid, |
294 | | - traversable_threshold=30, |
| 308 | + traversable_threshold=self.TRAVERSABLE_THRESHOLD, |
295 | 309 | unmapped_value=-1, |
296 | 310 | wp_publish=self._send_way_point, |
297 | 311 | update_requested=self._map_update_requested, |
|
0 commit comments