@@ -72,6 +72,7 @@ def __init__(self, config: dict) -> None:
72
72
self .plan_loop ()
73
73
74
74
def map_callback (self , grid_map : GridMap ) -> None :
75
+ """Update the map from the GridMap message."""
75
76
self .grid_map = grid_map
76
77
if self .height_index is None or self .layers is None :
77
78
self .layers = self .grid_map .layers
@@ -83,6 +84,8 @@ def map_callback(self, grid_map: GridMap) -> None:
83
84
if np .any (np .isnan (self .heightmap )):
84
85
self .map_init = False
85
86
else :
87
+ # this function creates the bitmap (costmap, heightmap)
88
+ # and gets the offset of the map
86
89
self .bitmap , self .offset = process_grid_map (
87
90
self .heightmap ,
88
91
lethalmap = None ,
@@ -95,9 +98,12 @@ def map_callback(self, grid_map: GridMap) -> None:
95
98
def plan (
96
99
self , start_state : np .ndarray , goal_ : np .ndarray , stop : bool = False
97
100
) -> Tuple [Optional [np .ndarray ], bool , int , float , np .ndarray ]:
101
+ """Plan a path from the current state to the goal."""
98
102
if self .bitmap is None :
99
103
return None , False , 0 , 0.0 , goal_
100
104
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
101
107
start , goal = start_goal_logic (
102
108
bitmap ,
103
109
self .map_res ,
@@ -108,10 +114,18 @@ def plan(
108
114
stop = stop ,
109
115
)
110
116
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.
111
124
success = self .planner .search (
112
125
start , goal , bitmap , self .expansion_limit , self .hysteresis , True
113
126
)
114
127
time_taken = time .perf_counter () - now
128
+ # this function gets the profiler info from the planner
115
129
(
116
130
avg_successor_time ,
117
131
avg_goal_check_time ,
@@ -138,6 +152,7 @@ def odom_callback(self, msg: Odometry) -> None:
138
152
self .state = obtain_state (msg , self .state )
139
153
140
154
def global_pos_callback (self , msg : Any ) -> None :
155
+ """Update global position from NavSatFix message."""
141
156
self .global_pos = msg
142
157
143
158
def waypoint_callback (self , msg : WaypointList ) -> None :
@@ -155,6 +170,7 @@ def waypoint_callback(self, msg: WaypointList) -> None:
155
170
self .local_waypoints = get_local_frame_waypoints (self .waypoint_list , gps_origin )
156
171
157
172
def plan_loop (self ) -> None :
173
+ """Main loop for planning."""
158
174
rate = rospy .Rate (20 )
159
175
while not rospy .is_shutdown ():
160
176
rate .sleep ()
0 commit comments