Skip to content

Commit 8635861

Browse files
committed
working python wrapper but wrong orientation of the elevation map
1 parent da9ca6e commit 8635861

File tree

1 file changed

+33
-16
lines changed

1 file changed

+33
-16
lines changed

Diff for: elevation_mapping_cupy/script/elevation_mapping_cupy/elevation_mapping_ros.py

+33-16
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,21 @@ class ElevationMapWrapper():
2222
def __init__(self):
2323
rospack = rospkg.RosPack()
2424
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 )
2628
self.node_name = "elevation_mapping"
2729
# ROS
2830
self.initalize_ros()
2931
self.register_subscribers()
32+
self.initalize_elevation_mapping()
3033
self.register_publishers()
3134
self.register_timers()
3235

3336
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()
3838
self._pointcloud_process_counter = 0
39-
self._map = ElevationMap(param)
39+
self._map = ElevationMap(self.param)
4040
self._map_data = np.zeros((self._map.cell_n - 2, self._map.cell_n - 2), dtype=np.float32)
4141
self._map_q = None
4242
self._map_t = None
@@ -49,10 +49,24 @@ def initalize_ros(self):
4949

5050
def register_subscribers(self):
5151
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+
5670
def register_publishers(self):
5771
# TODO publishers
5872
self._publishers = {}
@@ -88,7 +102,7 @@ def publish_map(self, t, k):
88102

89103
for i, layer in enumerate(gm.layers):
90104
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)
92106
data = self._map_data.copy()
93107
arr = Float32MultiArray()
94108
arr.layout = MAL()
@@ -107,10 +121,13 @@ def register_timers(self):
107121

108122
def pointcloud_callback(self, msg, config):
109123
# convert pcd into numpy array
110-
channels = config[0]
124+
channels = ['x','y','z']+config[0]
111125
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+
114131
# get pose of pointcloud
115132
t = rospy.Time(secs=msg.header.stamp.secs, nsecs=msg.header.stamp.nsecs)
116133
try:
@@ -123,9 +140,9 @@ def pointcloud_callback(self, msg, config):
123140
t = np.array( [t.x, t.y, t.z] )
124141
q = transform.transform.rotation
125142
R = quaternion_matrix([q.w, q.x, q.y, q.z])[:3,:3]
126-
143+
127144
# 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)
129146
self._pointcloud_process_counter += 1
130147
print(self._pointcloud_process_counter)
131148

0 commit comments

Comments
 (0)