Skip to content

Commit a18e5df

Browse files
committed
added useful comments to ROS example.py
1 parent 911ee78 commit a18e5df

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

examples/ROS/example.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def __init__(self, config: dict) -> None:
7272
self.plan_loop()
7373

7474
def map_callback(self, grid_map: GridMap) -> None:
75+
"""Update the map from the GridMap message."""
7576
self.grid_map = grid_map
7677
if self.height_index is None or self.layers is None:
7778
self.layers = self.grid_map.layers
@@ -83,6 +84,8 @@ def map_callback(self, grid_map: GridMap) -> None:
8384
if np.any(np.isnan(self.heightmap)):
8485
self.map_init = False
8586
else:
87+
# this function creates the bitmap (costmap, heightmap)
88+
# and gets the offset of the map
8689
self.bitmap, self.offset = process_grid_map(
8790
self.heightmap,
8891
lethalmap=None,
@@ -95,9 +98,12 @@ def map_callback(self, grid_map: GridMap) -> None:
9598
def plan(
9699
self, start_state: np.ndarray, goal_: np.ndarray, stop: bool = False
97100
) -> Tuple[Optional[np.ndarray], bool, int, float, np.ndarray]:
101+
"""Plan a path from the current state to the goal."""
98102
if self.bitmap is None:
99103
return None, False, 0, 0.0, goal_
100104
bitmap = torch.clone(self.bitmap)
105+
# this function effectively projects the start and goal to the
106+
# bitmap if it is not already inside the bitmap bounds
101107
start, goal = start_goal_logic(
102108
bitmap,
103109
self.map_res,
@@ -108,10 +114,18 @@ def plan(
108114
stop=stop,
109115
)
110116
now = time.perf_counter()
117+
# this function does the actual planning
118+
# it takes in the start, goal, bitmap, expansion limit, hysteresis, and ignore goal validity
119+
# it returns a boolean indicating if the goal was reached, the number of expansions, the time taken, and the output goal
120+
# the output goal is the goal projected to the bitmap bounds
121+
# Map convention: x is east, y is north. 0,0 is the bottom left corner of the map.
122+
# if the map was shown using cv2.imshow, the origin would be the top left corner.
123+
# Start and goal are relative to the bottom left corner of the map.
111124
success = self.planner.search(
112125
start, goal, bitmap, self.expansion_limit, self.hysteresis, True
113126
)
114127
time_taken = time.perf_counter() - now
128+
# this function gets the profiler info from the planner
115129
(
116130
avg_successor_time,
117131
avg_goal_check_time,
@@ -138,6 +152,7 @@ def odom_callback(self, msg: Odometry) -> None:
138152
self.state = obtain_state(msg, self.state)
139153

140154
def global_pos_callback(self, msg: Any) -> None:
155+
"""Update global position from NavSatFix message."""
141156
self.global_pos = msg
142157

143158
def waypoint_callback(self, msg: WaypointList) -> None:
@@ -155,6 +170,7 @@ def waypoint_callback(self, msg: WaypointList) -> None:
155170
self.local_waypoints = get_local_frame_waypoints(self.waypoint_list, gps_origin)
156171

157172
def plan_loop(self) -> None:
173+
"""Main loop for planning."""
158174
rate = rospy.Rate(20)
159175
while not rospy.is_shutdown():
160176
rate.sleep()

0 commit comments

Comments
 (0)