3636pool = cp .cuda .MemoryPool (cp .cuda .malloc_managed )
3737cp .cuda .set_allocator (pool .malloc )
3838
39-
4039class ElevationMap :
4140 """
4241 Core elevation mapping class.
@@ -49,16 +48,16 @@ def __init__(self, param: Parameter):
4948 param (elevation_mapping_cupy.parameter.Parameter):
5049 """
5150 self .param = param
52-
51+ self . data_type = self . param . data_type
5352 self .resolution = param .resolution
54- self .center = xp .array ([0 , 0 , 0 ], dtype = float )
53+ self .center = xp .array ([0 , 0 , 0 ], dtype = self . data_type )
5554 self .map_length = param .map_length
5655 self .cell_n = param .cell_n
5756
5857 self .map_lock = threading .Lock ()
5958 self .additional_layers = dict (zip (self .param .additional_layers , self .param .fusion_algorithms ))
6059 self .semantic_map = SemanticMap (self .param , self .additional_layers )
61- self .elevation_map = xp .zeros ((7 , self .cell_n , self .cell_n ))
60+ self .elevation_map = xp .zeros ((7 , self .cell_n , self .cell_n ), dtype = self . data_type )
6261 self .layer_names = [
6362 "elevation" ,
6463 "variance" ,
@@ -71,7 +70,7 @@ def __init__(self, param: Parameter):
7170
7271 # buffers
7372 self .traversability_buffer = xp .full ((self .cell_n , self .cell_n ), xp .nan )
74- self .normal_map = xp .zeros ((3 , self .cell_n , self .cell_n ))
73+ self .normal_map = xp .zeros ((3 , self .cell_n , self .cell_n ), dtype = self . data_type )
7574 # Initial variance
7675 self .initial_variance = param .initial_variance
7776 self .elevation_map [1 ] += self .initial_variance
@@ -223,12 +222,12 @@ def compile_kernels(self):
223222
224223 """
225224 # Compile custom cuda kernels.
226- self .new_map = cp .zeros ((self .elevation_map .shape [0 ], self .cell_n , self .cell_n ))
227- self .traversability_input = cp .zeros ((self .cell_n , self .cell_n ))
228- self .traversability_mask_dummy = cp .zeros ((self .cell_n , self .cell_n ))
229- self .min_filtered = cp .zeros ((self .cell_n , self .cell_n ))
230- self .min_filtered_mask = cp .zeros ((self .cell_n , self .cell_n ))
231- self .mask = cp .zeros ((self .cell_n , self .cell_n ))
225+ self .new_map = cp .zeros ((self .elevation_map .shape [0 ], self .cell_n , self .cell_n ), dtype = self . data_type )
226+ self .traversability_input = cp .zeros ((self .cell_n , self .cell_n ), dtype = self . data_type )
227+ self .traversability_mask_dummy = cp .zeros ((self .cell_n , self .cell_n ), dtype = self . data_type )
228+ self .min_filtered = cp .zeros ((self .cell_n , self .cell_n ), dtype = self . data_type )
229+ self .min_filtered_mask = cp .zeros ((self .cell_n , self .cell_n ), dtype = self . data_type )
230+ self .mask = cp .zeros ((self .cell_n , self .cell_n ), dtype = self . data_type )
232231 self .add_points_kernel = add_points_kernel (
233232 self .resolution ,
234233 self .cell_n ,
@@ -302,8 +301,8 @@ def update_map_with_kernel(self, points_all, channels, R, t, position_noise, ori
302301 self .error_counting_kernel (
303302 self .elevation_map ,
304303 points ,
305- cp .array ([0.0 ]),
306- cp .array ([0.0 ]),
304+ cp .array ([0.0 ], dtype = self . data_type ),
305+ cp .array ([0.0 ], dtype = self . data_type ),
307306 R ,
308307 t ,
309308 self .new_map ,
@@ -324,8 +323,8 @@ def update_map_with_kernel(self, points_all, channels, R, t, position_noise, ori
324323 if np .abs (self .mean_error ) < self .param .max_drift :
325324 self .elevation_map [0 ] += self .mean_error * self .param .drift_compensation_alpha
326325 self .add_points_kernel (
327- cp .array ([0.0 ]),
328- cp .array ([0.0 ]),
326+ cp .array ([0.0 ], dtype = self . data_type ),
327+ cp .array ([0.0 ], dtype = self . data_type ),
329328 R ,
330329 t ,
331330 self .normal_map ,
@@ -337,7 +336,7 @@ def update_map_with_kernel(self, points_all, channels, R, t, position_noise, ori
337336 self .average_map_kernel (self .new_map , self .elevation_map , size = (self .cell_n * self .cell_n ))
338337
339338 # self.update_additional_layers(additional_fusion, points_all, channels, R, t)
340- self .semantic_map .update_layers (points_all , channels , R , t ,self .new_map )
339+ self .semantic_map .update_layers (points_all , channels , R , t , self .new_map )
341340
342341 if self .param .enable_overlap_clearance :
343342 self .clear_overlap_map (t )
@@ -405,10 +404,10 @@ def input(self, raw_points: cp._core.core.ndarray, channels: List[str], R: cp._c
405404 None:
406405 """
407406 # Update elevation map using point cloud input.
408- raw_points = cp .asarray (raw_points )
407+ raw_points = cp .asarray (raw_points , dtype = self . data_type )
409408 additional_channels = channels [3 :]
410409 raw_points = raw_points [~ cp .isnan (raw_points ).any (axis = 1 )]
411- self .update_map_with_kernel (raw_points , additional_channels , cp .asarray (R ), cp .asarray (t ), position_noise , orientation_noise )
410+ self .update_map_with_kernel (raw_points , additional_channels , cp .asarray (R , dtype = self . data_type ), cp .asarray (t , dtype = self . data_type ), position_noise , orientation_noise )
412411
413412 def update_normal (self , dilated_map ):
414413 """ Clear the normal map and then apply the normal kernel with dilated map as input.
@@ -561,7 +560,7 @@ def get_map_with_name_ref(self, name, data):
561560 elif name in self .additional_layers .keys ():
562561 m = self .semantic_map .get_map_with_name (name )
563562 elif name in self .plugin_manager .layer_names :
564- self .plugin_manager .update_with_name (name , self .elevation_map , self .layer_names )
563+ self .plugin_manager .update_with_name (name , self .elevation_map , self .layer_names , self . semantic_map )
565564 m = self .plugin_manager .get_map_with_name (name )
566565 p = self .plugin_manager .get_param_with_name (name )
567566 xp = self .xp_of_array (m )
@@ -607,7 +606,7 @@ def get_polygon_traversability(self, polygon, result):
607606 """
608607 polygon = xp .asarray (polygon )
609608 area = calculate_area (polygon )
610- polygon = polygon .astype (np . float64 )
609+ polygon = polygon .astype (self . data_type )
611610 pmin = self .center [:2 ] - self .map_length / 2 + self .resolution
612611 pmax = self .center [:2 ] + self .map_length / 2 - self .resolution
613612 polygon [:, 0 ] = polygon [:, 0 ].clip (pmin [0 ], pmax [0 ])
@@ -630,7 +629,7 @@ def get_polygon_traversability(self, polygon, result):
630629 if masked_isvalid .sum () > 0 :
631630 t = masked .sum () / masked_isvalid .sum ()
632631 else :
633- t = cp .asarray (0.0 )
632+ t = cp .asarray (0.0 , dtype = self . data_type )
634633 is_safe , un_polygon = is_traversable (
635634 masked , self .param .safe_thresh , self .param .safe_min_thresh , self .param .max_unsafe_n
636635 )
@@ -662,7 +661,7 @@ def initialize_map(self, points, method="cubic"):
662661 """
663662 self .clear ()
664663 with self .map_lock :
665- points = cp .asarray (points )
664+ points = cp .asarray (points , dtype = self . data_type )
666665 indices = transform_to_map_index (points [:, :2 ], self .center [:2 ], self .cell_n , self .resolution )
667666 points [:, :2 ] = indices .astype (points .dtype )
668667 points [:, 2 ] -= self .center [2 ]
@@ -708,7 +707,7 @@ def initialize_map(self, points, method="cubic"):
708707 for layer in layers :
709708 elevation .get_map_with_name_ref (layer , data )
710709 print (i )
711- polygon = cp .array ([[0 , 0 ], [2 , 0 ], [0 , 2 ]], dtype = np . float64 )
710+ polygon = cp .array ([[0 , 0 ], [2 , 0 ], [0 , 2 ]], dtype = param . data_type )
712711 result = np .array ([0 , 0 , 0 ])
713712 elevation .get_polygon_traversability (polygon , result )
714713 print (result )
0 commit comments