@@ -22,21 +22,21 @@ class ElevationMapWrapper():
22
22
def __init__ (self ):
23
23
rospack = rospkg .RosPack ()
24
24
self .root = rospack .get_path ("elevation_mapping_cupy" )
25
- self .initalize_elevation_mapping ()
25
+ weight_file = os .path .join (self .root , "config/weights.dat" )
26
+ plugin_config_file = os .path .join (self .root , "config/plugin_config.yaml" )
27
+ self .param = Parameter ( use_chainer = False , weight_file = weight_file , plugin_config_file = plugin_config_file )
26
28
self .node_name = "elevation_mapping"
27
29
# ROS
28
30
self .initalize_ros ()
29
31
self .register_subscribers ()
32
+ self .initalize_elevation_mapping ()
30
33
self .register_publishers ()
31
34
self .register_timers ()
32
35
33
36
def initalize_elevation_mapping (self ):
34
- weight_file = os .path .join (self .root , "config/weights.dat" )
35
- plugin_config_file = os .path .join (self .root , "config/plugin_config.yaml" )
36
- param = Parameter ( use_chainer = False , weight_file = weight_file , plugin_config_file = plugin_config_file )
37
- param .update ()
37
+ self .param .update ()
38
38
self ._pointcloud_process_counter = 0
39
- self ._map = ElevationMap (param )
39
+ self ._map = ElevationMap (self . param )
40
40
self ._map_data = np .zeros ((self ._map .cell_n - 2 , self ._map .cell_n - 2 ), dtype = np .float32 )
41
41
self ._map_q = None
42
42
self ._map_t = None
@@ -49,10 +49,24 @@ def initalize_ros(self):
49
49
50
50
def register_subscribers (self ):
51
51
pointcloud_subs = {}
52
- for config in self .subscribers .values ():
53
- self .subscribers
54
- rospy .Subscriber (config ["topic_name" ], PointCloud2 , self .pointcloud_callback , (config ["channels" ], config ["fusion" ]))
55
-
52
+ additional = []
53
+ fusion = []
54
+ for key , config in self .subscribers .items ():
55
+ pointcloud_subs [key ] = rospy .Subscriber (config ["topic_name" ], PointCloud2 , self .pointcloud_callback , (config ["channels" ], config ["fusion" ]))
56
+ for chan ,fus in zip (config ["channels" ],config ["fusion" ]):
57
+ if chan not in additional :
58
+ additional .append (chan )
59
+ fusion .append (fus )
60
+ self .param .additional_layers = additional
61
+ self .param .fusion_algorithms = fusion
62
+ self .dtype = [
63
+ ("x" , np .float32 ),
64
+ ("y" , np .float32 ),
65
+ ("z" , np .float32 ),
66
+ ]
67
+ for chan in config ["channels" ]:
68
+ self .dtype .append ((chan , np .float32 ))
69
+
56
70
def register_publishers (self ):
57
71
# TODO publishers
58
72
self ._publishers = {}
@@ -88,7 +102,7 @@ def publish_map(self, t, k):
88
102
89
103
for i , layer in enumerate (gm .layers ):
90
104
self ._map .get_map_with_name_ref (layer , self ._map_data )
91
- self ._map_data = np .nan_to_num (self ._map_data , False , 0 )
105
+ # self._map_data = np.nan_to_num(self._map_data, False, 0)
92
106
data = self ._map_data .copy ()
93
107
arr = Float32MultiArray ()
94
108
arr .layout = MAL ()
@@ -107,10 +121,13 @@ def register_timers(self):
107
121
108
122
def pointcloud_callback (self , msg , config ):
109
123
# convert pcd into numpy array
110
- channels = config [0 ]
124
+ channels = [ 'x' , 'y' , 'z' ] + config [0 ]
111
125
fusion = config [1 ]
112
- points = ros_numpy .point_cloud2 .pointcloud2_to_xyz_array (msg )
113
-
126
+ points = ros_numpy .numpify (msg )
127
+ pts = np .empty ((points .shape [0 ],0 ))
128
+ for ch in channels :
129
+ pts = np .append (pts ,np .expand_dims (points [ch ],1 ),axis = 1 )
130
+
114
131
# get pose of pointcloud
115
132
t = rospy .Time (secs = msg .header .stamp .secs , nsecs = msg .header .stamp .nsecs )
116
133
try :
@@ -123,9 +140,9 @@ def pointcloud_callback(self, msg, config):
123
140
t = np .array ( [t .x , t .y , t .z ] )
124
141
q = transform .transform .rotation
125
142
R = quaternion_matrix ([q .w , q .x , q .y , q .z ])[:3 ,:3 ]
126
-
143
+
127
144
# process pointcloud
128
- self ._map .input (points , [ 'x' , 'y' , 'z' ] + channels , R , t , 0 , 0 )
145
+ self ._map .input (pts , channels , R , t , 0 , 0 )
129
146
self ._pointcloud_process_counter += 1
130
147
print (self ._pointcloud_process_counter )
131
148
0 commit comments