@@ -81,6 +81,7 @@ def publish_costmap(self) -> None:
81
81
"""
82
82
Publishes the costmap for rviz
83
83
"""
84
+ assert self .costmap is not None , "Costmap is not initialized"
84
85
# Normalize costmap to match the rviz color scheme in a good way
85
86
normalized_costmap = (
86
87
(255 - ((self .costmap - np .min (self .costmap )) / (np .max (self .costmap ) - np .min (self .costmap ))) * 255 / 2.1 )
@@ -157,6 +158,7 @@ def calc_gradients(self) -> None:
157
158
"""
158
159
Recalculates the gradient map based on the current costmap.
159
160
"""
161
+ assert self .base_costmap is not None , "Base costmap is not initialized"
160
162
gradient = np .gradient (self .base_costmap )
161
163
norms = np .linalg .norm (gradient , axis = 0 )
162
164
@@ -203,8 +205,8 @@ def calc_base_costmap(self) -> None:
203
205
204
206
# Create Grid
205
207
grid_x , grid_y = np .mgrid [
206
- 0 : self .field_length + self .map_margin * 2 : (self .field_length + self .map_margin * 2 ) * 10j ,
207
- 0 : self .field_width + self .map_margin * 2 : (self .field_width + self .map_margin * 2 ) * 10j ,
208
+ 0 : self .field_length + self .map_margin * 2 : (self .field_length + self .map_margin * 2 ) * 10j , # type: ignore[misc]
209
+ 0 : self .field_width + self .map_margin * 2 : (self .field_width + self .map_margin * 2 ) * 10j , # type: ignore[misc]
208
210
]
209
211
210
212
fix_points : List [Tuple [Tuple [float , float ], float ]] = []
@@ -278,7 +280,8 @@ def calc_base_costmap(self) -> None:
278
280
)
279
281
280
282
# Smooth the costmap to get more continuous gradients
281
- self .base_costmap = gaussian_filter (interpolated , self .body_config ["base_costmap_smoothing_sigma" ])
283
+ base_costmap : np .ndarray = gaussian_filter (interpolated , self .body_config ["base_costmap_smoothing_sigma" ])
284
+ self .base_costmap = base_costmap
282
285
self .costmap = self .base_costmap .copy ()
283
286
284
287
def get_gradient_at_field_position (self , x : float , y : float ) -> Tuple [float , float ]:
@@ -287,6 +290,7 @@ def get_gradient_at_field_position(self, x: float, y: float) -> Tuple[float, flo
287
290
:param x: Field coordinate in the x direction
288
291
:param y: Field coordinate in the y direction
289
292
"""
293
+ assert self .gradient_map is not None , "Gradient map is not initialized"
290
294
idx_x , idx_y = self .field_2_costmap_coord (x , y )
291
295
return - self .gradient_map [0 ][idx_x , idx_y ], - self .gradient_map [1 ][idx_x , idx_y ]
292
296
@@ -296,6 +300,7 @@ def get_cost_at_field_position(self, x: float, y: float) -> float:
296
300
:param x: Field coordinate in the x direction
297
301
:param y: Field coordinate in the y direction
298
302
"""
303
+ assert self .costmap is not None , "Costmap is not initialized"
299
304
idx_x , idx_y = self .field_2_costmap_coord (x , y )
300
305
return self .costmap [idx_x , idx_y ]
301
306
@@ -358,6 +363,7 @@ def get_cost_of_kick(self, x: float, y: float, direction: float, kick_length: fl
358
363
:param kick_length: The length of the kick
359
364
:param angular_range: The angular range of the kick
360
365
"""
366
+ assert self .costmap is not None , "Costmap is not initialized"
361
367
362
368
# create a mask in the size of the costmap consisting of 8-bit values initialized as 0
363
369
mask = Image .new ("L" , (self .costmap .shape [1 ], self .costmap .shape [0 ]))
0 commit comments