Skip to content

Commit 570580c

Browse files
committed
annotations
1 parent b6ddfa8 commit 570580c

File tree

25 files changed

+220
-74
lines changed

25 files changed

+220
-74
lines changed

src/python_motion_planning/common/env/map/base_map.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
"""
22
@file: map.py
3-
@breif: Map for Path Planning
43
@author: Wu Maojia
5-
@update: 2025.9.5
4+
@update: 2025.10.3
65
"""
76
from typing import Iterable, Union
87
from abc import ABC, abstractmethod

src/python_motion_planning/common/env/map/grid.py

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
"""
22
@file: grid.py
3-
@breif: Grid Map for Path Planning
43
@author: Wu Maojia
5-
@update: 2025.9.5
4+
@update: 2025.10.3
65
"""
76
from itertools import product
87
from typing import Iterable, Union, Tuple, Callable, List, Dict
@@ -11,7 +10,7 @@
1110
import numpy as np
1211
from scipy import ndimage
1312

14-
from .base_map import BaseMap
13+
from python_motion_planning.common.env.map.base_map import BaseMap
1514
from python_motion_planning.common.env import Node, TYPES
1615
from python_motion_planning.common.utils.geometry import Geometry
1716

@@ -109,18 +108,17 @@ class Grid(BaseMap):
109108
resolution: resolution of the grid map
110109
type_map: initial type map of the grid map (its shape must be the same as the converted grid map shape, and its dtype must be int)
111110
dtype: data type of coordinates (must be int)
111+
inflation_radius: radius of the inflation
112112
113113
Examples:
114-
>>> bounds = [[0, 30], [0, 40]]
115-
>>> type_map = np.zeros((61, 81), dtype=np.int8)
116-
>>> grid_map = Grid(bounds=bounds, resolution=0.5, type_map=type_map)
114+
>>> grid_map = Grid(bounds=[[0, 51], [0, 31]], resolution=0.5)
117115
>>> grid_map
118-
Grid(bounds=[[ 0. 30.]
119-
[ 0. 40.]], resolution=0.5)
116+
Grid(bounds=[[ 0. 51.]
117+
[ 0. 31.]], resolution=0.5)
120118
121119
>>> grid_map.bounds # bounds of the base world
122-
array([[ 0., 30.],
123-
[ 0., 40.]])
120+
array([[ 0., 51.],
121+
[ 0., 31.]])
124122
125123
>>> grid_map.dim
126124
2
@@ -129,7 +127,7 @@ class Grid(BaseMap):
129127
0.5
130128
131129
>>> grid_map.shape # shape of the grid map
132-
(61, 81)
130+
(102, 62)
133131
134132
>>> grid_map.dtype
135133
<class 'numpy.int32'>
@@ -143,13 +141,13 @@ class Grid(BaseMap):
143141
[0 0 0 ... 0 0 0]
144142
[0 0 0 ... 0 0 0]
145143
[0 0 0 ... 0 0 0]]
146-
), shape=(61, 81), dtype=int8)
144+
), shape=(102, 62), dtype=int8)
147145
148146
>>> grid_map.map_to_world((1, 2))
149-
(0.5, 1.0)
147+
(0.75, 1.25)
150148
151149
>>> grid_map.world_to_map((0.5, 1.0))
152-
(1, 2)
150+
(0, 2)
153151
154152
>>> grid_map.get_neighbors(Node((1, 2)))
155153
[Node((0, 1), (1, 2), 0, 0), Node((0, 2), (1, 2), 0, 0), Node((0, 3), (1, 2), 0, 0), Node((1, 1), (1, 2), 0, 0), Node((1, 3), (1, 2), 0, 0), Node((2, 1), (1, 2), 0, 0), Node((2, 2), (1, 2), 0, 0), Node((2, 3), (1, 2), 0, 0)]
@@ -159,10 +157,10 @@ class Grid(BaseMap):
159157
160158
>>> grid_map.type_map[1, 0] = TYPES.OBSTACLE # place an obstacle
161159
>>> grid_map.get_neighbors(Node((0, 0))) # limited within the bounds
162-
[Node((0, 1), (0, 0), 0, 0), Node((1, 1), (0, 0), 0, 0)]
160+
[Node((0, 1), (0, 0), 0, 0), Node((1, 0), (0, 0), 0, 0), Node((1, 1), (0, 0), 0, 0)]
163161
164162
>>> grid_map.get_neighbors(Node((grid_map.shape[0] - 1, grid_map.shape[1] - 1)), diagonal=False) # limited within the boundss
165-
[Node((59, 80), (60, 80), 0, 0), Node((60, 79), (60, 80), 0, 0)]
163+
[Node((100, 61), (101, 61), 0, 0), Node((101, 60), (101, 61), 0, 0)]
166164
167165
>>> grid_map.line_of_sight((1, 2), (3, 6))
168166
[(1, 2), (1, 3), (2, 4), (2, 5), (3, 6)]
@@ -174,6 +172,7 @@ class Grid(BaseMap):
174172
False
175173
176174
>>> grid_map.type_map[1, 3] = TYPES.OBSTACLE
175+
>>> grid_map.update_esdf()
177176
>>> grid_map.in_collision((1, 2), (3, 6))
178177
True
179178
"""
@@ -364,7 +363,7 @@ def get_neighbors(self,
364363

365364
return filtered_neighbors
366365

367-
def line_of_sight(self, p1: Tuple[int, ...], p2: Tuple[int, ...]) -> list:
366+
def line_of_sight(self, p1: Tuple[int, ...], p2: Tuple[int, ...]) -> List[Tuple[int, ...]]:
368367
"""
369368
N-dimensional line of sight (Bresenham's line algorithm)
370369
@@ -396,7 +395,7 @@ def line_of_sight(self, p1: Tuple[int, ...], p2: Tuple[int, ...]) -> list:
396395

397396
# Allocate the result array
398397
result = []
399-
result.append(tuple(current))
398+
result.append(tuple(int(x) for x in current))
400399

401400
for i in range(1, steps + 1):
402401
current[primary_axis] += primary_step
@@ -411,7 +410,7 @@ def line_of_sight(self, p1: Tuple[int, ...], p2: Tuple[int, ...]) -> list:
411410
current[d] += 1 if delta[d] > 0 else -1
412411
error[d] -= delta2[primary_axis]
413412

414-
result.append(tuple(current))
413+
result.append(tuple(int(x) for x in current))
415414

416415
return result
417416

@@ -452,10 +451,6 @@ def in_collision(self, p1: Tuple[int, ...], p2: Tuple[int, ...]) -> bool:
452451
steps = abs_delta[primary_axis]
453452
current = p1
454453

455-
# # Check the start point
456-
# if not self.is_expandable(tuple(current)):
457-
# return True
458-
459454
for _ in range(steps):
460455
last_point = current.copy()
461456
current[primary_axis] += primary_step
@@ -469,7 +464,7 @@ def in_collision(self, p1: Tuple[int, ...], p2: Tuple[int, ...]) -> bool:
469464
if error[d] > abs_delta[primary_axis]:
470465
current[d] += 1 if delta[d] > 0 else -1
471466
error[d] -= delta2[primary_axis]
472-
467+
473468
# Check the current point
474469
if not self.is_expandable(tuple(current), tuple(last_point)):
475470
return True

src/python_motion_planning/common/env/node.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
"""
22
@file: node.py
3-
@breif: map node data stucture
43
@author: Wu Maojia, Yang Haodong
5-
@update: 2025.9.5
4+
@update: 2025.10.3
65
"""
76
from __future__ import annotations
87

src/python_motion_planning/common/env/robot/base_robot.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""
2+
@file: base_robot.py
3+
@author: Wu Maojia
4+
@update: 2025.10.3
5+
"""
16
from typing import List, Dict, Tuple, Optional
27
import numpy as np
38

src/python_motion_planning/common/env/robot/circular_robot.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
"""
22
@file: circular_robot.py
3-
@breif: CircularRobot class for the environment.
43
@author: Wu Maojia
5-
@update: 2025.9.20
4+
@update: 2025.10.3
65
"""
76
from typing import List, Dict, Tuple, Optional
87
import numpy as np

src/python_motion_planning/common/env/robot/diff_drive_robot.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""
2+
@file: diff_drive_robot.py
3+
@author: Wu Maojia
4+
@update: 2025.10.3
5+
"""
16
from typing import List, Dict, Tuple, Optional
27

38
import numpy as np

src/python_motion_planning/common/env/types.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
"""
22
@file: types.py
3-
@breif: macro definition of types of plots in maps
4-
@author: Yang Haodong, Wu Maojia
5-
@update: 2025.3.29
3+
@author: Wu Maojia, Yang Haodong
4+
@update: 2025.10.3
65
"""
76
# from enum import IntEnum
87

src/python_motion_planning/common/env/world/base_world.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""
2+
@file: base_world.py
3+
@author: Wu Maojia
4+
@update: 2025.10.3
5+
"""
16
from typing import List, Dict, Tuple, Optional
27
import numpy as np
38
import gymnasium as gym

src/python_motion_planning/common/env/world/toy_simulator.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""
2+
@file: toy_simulator.py
3+
@author: Wu Maojia
4+
@update: 2025.10.3
5+
"""
16
from typing import List, Dict, Tuple, Optional
27
import numpy as np
38
import gymnasium as gym

src/python_motion_planning/common/utils/frame_transformer.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""
2+
@file: frame_transformer.py
3+
@author: Wu Maojia
4+
@update: 2025.10.3
5+
"""
16
from typing import List, Tuple
27

38
import numpy as np
@@ -111,15 +116,15 @@ def pos_world_to_robot(dim: int, pos_world: np.ndarray, robot_pose: np.ndarray)
111116
if dim != 2:
112117
raise NotImplementedError("Only 2D pos transform is implemented.")
113118

114-
# 机器人在世界坐标系中的位置和姿态
119+
# pose in world frame
115120
rx, ry, theta = robot_pose
116121
c, s = np.cos(theta), np.sin(theta)
117122

118-
# 平移到原点
123+
# translate to the origin
119124
tx = pos_world[0] - rx
120125
ty = pos_world[1] - ry
121126

122-
# 旋转(使用逆旋转矩阵)
127+
# rotate (use inverse rotation matrix)
123128
pos_robot = np.array([
124129
c * tx + s * ty,
125130
-s * tx + c * ty
@@ -143,14 +148,13 @@ def pose_world_to_robot(dim: int, pose_world: np.ndarray, robot_pose: np.ndarray
143148
if dim != 2:
144149
raise NotImplementedError("Only 2D pose transform is implemented.")
145150

146-
# 转换位置
151+
# transform position
147152
position_robot = FrameTransformer.pos_world_to_robot(
148153
dim, pose_world[:2], robot_pose
149154
)
150155

151-
# 转换姿态(角度差)
156+
# transform orientation
152157
orientation_robot = pose_world[2] - robot_pose[2]
153-
# 归一化角度到[-π, π]
154158
orientation_robot = Geometry.regularize_orient(orientation_robot)
155159

156160
return np.concatenate([position_robot, [orientation_robot]])
@@ -171,15 +175,15 @@ def pos_robot_to_world(dim: int, pos_robot: np.ndarray, robot_pose: np.ndarray)
171175
if dim != 2:
172176
raise NotImplementedError("Only 2D pos transform is implemented.")
173177

174-
# 机器人在世界坐标系中的位置和姿态
178+
# pose in world frame
175179
rx, ry, theta = robot_pose
176180
c, s = np.cos(theta), np.sin(theta)
177181

178-
# 旋转
182+
# rotate to the origin
179183
tx = c * pos_robot[0] - s * pos_robot[1]
180184
ty = s * pos_robot[0] + c * pos_robot[1]
181185

182-
# 平移
186+
# translate
183187
pos_world = np.array([
184188
tx + rx,
185189
ty + ry
@@ -202,14 +206,13 @@ def pose_robot_to_world(dim: int, pose_robot: np.ndarray, robot_pose: np.ndarray
202206
if dim != 2:
203207
raise NotImplementedError("Only 2D pose transform is implemented.")
204208

205-
# 转换位置
209+
# transform position
206210
position_world = FrameTransformer.pos_robot_to_world(
207211
dim, pose_robot[:2], robot_pose
208212
)
209213

210-
# 转换姿态(角度和)
214+
# transform orientation
211215
orientation_world = pose_robot[2] + robot_pose[2]
212-
# 归一化角度到[-π, π]
213216
orientation_world = Geometry.regularize_orient(orientation_world)
214217

215218
return np.concatenate([position_world, [orientation_world]])

0 commit comments

Comments
 (0)