Skip to content

Commit 059ff96

Browse files
committed
working elevation map in the new workframe with a new kernels, the old workflow embedded in the elevation map is still inside but commented and I started to document the functions and I integrated the first tests
1 parent 069e69e commit 059ff96

File tree

10 files changed

+787
-33
lines changed

10 files changed

+787
-33
lines changed

elevation_mapping_cupy/config/parameters.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ publishers:
8181
basic_layers: ['elevation', 'traversability']
8282
fps: 2.0
8383
elevation_map_filter:
84-
layers: ['min_filter', 'smooth', 'inpaint', 'upper_bound']
84+
layers: ['min_filter', 'smooth', 'inpaint', 'upper_bound','rgb']
8585
basic_layers: ['min_filter']
8686
fps: 3.0
8787

elevation_mapping_cupy/config/sensor_parameter.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ subscribers:
44
# fusion: ['average','average']
55
# topic_name: '/elevation_mapping/pointcloud_semantic'
66
front_cam:
7-
channels: ['feat_0','feat_1']
8-
fusion: ['average','average']
7+
channels: ['rgb','feat_0','feat_1']
8+
fusion: ['color','average','average']
99
topic_name: '/elvation_mapping/pointcloud_semantic'
10+

elevation_mapping_cupy/rviz/lonomy_single.rviz

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ Panels:
44
Name: Displays
55
Property Tree Widget:
66
Expanded:
7-
- /ElevationMapFilter1
87
- /Image1
98
Splitter Ratio: 0.5768463015556335
10-
Tree Height: 410
9+
Tree Height: 428
1110
- Class: rviz/Selection
1211
Name: Selection
1312
- Class: rviz/Tool Properties
@@ -55,10 +54,10 @@ Visualization Manager:
5554
Autocompute Intensity Bounds: true
5655
Class: grid_map_rviz_plugin/GridMap
5756
Color: 200; 200; 200
58-
Color Layer: smooth
59-
Color Transformer: IntensityLayer
57+
Color Layer: rgb
58+
Color Transformer: ColorLayer
6059
Enabled: true
61-
Height Layer: min_filter
60+
Height Layer: smooth
6261
Height Transformer: GridMapLayer
6362
History Length: 1
6463
Invert Rainbow: false
@@ -221,7 +220,7 @@ Visualization Manager:
221220
Size (Pixels): 3
222221
Size (m): 0.009999999776482582
223222
Style: Flat Squares
224-
Topic: /elvation_mapping/pointcloud_semantic_left
223+
Topic: /elvation_mapping/pointcloud_semantic
225224
Unreliable: false
226225
Use Fixed Frame: true
227226
Use rainbow: true
@@ -433,7 +432,7 @@ Visualization Manager:
433432
Views:
434433
Current:
435434
Class: rviz/Orbit
436-
Distance: 8.01580810546875
435+
Distance: 7.847433090209961
437436
Enable Stereo Rendering:
438437
Stereo Eye Separation: 0.05999999865889549
439438
Stereo Focal Distance: 1
@@ -449,19 +448,19 @@ Visualization Manager:
449448
Invert Z Axis: false
450449
Name: Current View
451450
Near Clip Distance: 0.009999999776482582
452-
Pitch: 0.34979793429374695
451+
Pitch: 0.12979847192764282
453452
Target Frame: base_footprint
454-
Yaw: 5.212028980255127
453+
Yaw: 0.9738447666168213
455454
Saved: ~
456455
Window Geometry:
457456
Displays:
458457
collapsed: false
459-
Height: 1016
458+
Height: 1043
460459
Hide Left Dock: false
461460
Hide Right Dock: true
462461
Image:
463462
collapsed: false
464-
QMainWindow State: 000000ff00000000fd0000000400000000000001f50000039efc0200000009fb0000001200530065006c0065006300740069006f006e00000001e10000009b0000005c00fffffffb0000001e0054006f006f006c002000500072006f007000650072007400690065007302000001ed000001df00000185000000a3fb000000120056006900650077007300200054006f006f02000001df000002110000018500000122fb000000200054006f006f006c002000500072006f0070006500720074006900650073003203000002880000011d000002210000017afb000000100044006900730070006c006100790073010000003d00000261000000c900fffffffb0000000a0049006d00610067006501000002a4000001370000001600fffffffb0000002000730065006c0065006300740069006f006e00200062007500660066006500720200000138000000aa0000023a00000294fb00000014005700690064006500530074006500720065006f02000000e6000000d2000003ee0000030bfb0000000c004b0069006e0065006300740200000186000001060000030c00000261000000010000015f0000053bfc0200000003fb0000001e0054006f006f006c002000500072006f00700065007200740069006500730100000041000000780000000000000000fb0000000a0056006900650077007300000000560000053b000000a400fffffffb0000001200530065006c0065006300740069006f006e010000025a000000b200000000000000000000000200000490000000a9fc0100000001fb0000000a00560069006500770073030000004e00000080000002e100000197000000030000073800000131fc0100000003fb0000000a0049006d0061006700650000000394000003a40000005e00fffffffb0000000800540069006d00650000000000000007380000041800fffffffb0000000800540069006d006501000000000000045000000000000000000000053d0000039e00000004000000040000000800000008fc0000000100000002000000010000000a0054006f006f006c00730100000000ffffffff0000000000000000
463+
QMainWindow State: 000000ff00000000fd0000000400000000000001f5000003b9fc0200000009fb0000001200530065006c0065006300740069006f006e00000001e10000009b0000005c00fffffffb0000001e0054006f006f006c002000500072006f007000650072007400690065007302000001ed000001df00000185000000a3fb000000120056006900650077007300200054006f006f02000001df000002110000018500000122fb000000200054006f006f006c002000500072006f0070006500720074006900650073003203000002880000011d000002210000017afb000000100044006900730070006c006100790073010000003d00000273000000c900fffffffb0000000a0049006d00610067006501000002b6000001400000001600fffffffb0000002000730065006c0065006300740069006f006e00200062007500660066006500720200000138000000aa0000023a00000294fb00000014005700690064006500530074006500720065006f02000000e6000000d2000003ee0000030bfb0000000c004b0069006e0065006300740200000186000001060000030c00000261000000010000015f0000053bfc0200000003fb0000001e0054006f006f006c002000500072006f00700065007200740069006500730100000041000000780000000000000000fb0000000a0056006900650077007300000000560000053b000000a400fffffffb0000001200530065006c0065006300740069006f006e010000025a000000b200000000000000000000000200000490000000a9fc0100000001fb0000000a00560069006500770073030000004e00000080000002e100000197000000030000073800000131fc0100000003fb0000000a0049006d0061006700650000000394000003a40000005e00fffffffb0000000800540069006d00650000000000000007380000041800fffffffb0000000800540069006d0065010000000000000450000000000000000000000585000003b900000004000000040000000800000008fc0000000100000002000000010000000a0054006f006f006c00730100000000ffffffff0000000000000000
465464
Selection:
466465
collapsed: false
467466
Time:
@@ -470,6 +469,6 @@ Window Geometry:
470469
collapsed: false
471470
Views:
472471
collapsed: true
473-
Width: 1848
474-
X: 1992
475-
Y: 27
472+
Width: 1920
473+
X: 0
474+
Y: 0

elevation_mapping_cupy/script/elevation_mapping_cupy/custom_kernels.py

Lines changed: 263 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ def add_points_kernel(
143143
):
144144

145145
add_points_kernel = cp.ElementwiseKernel(
146-
in_params="raw U p, raw U center_x, raw U center_y, raw U R, raw U t, raw U norm_map",
147-
out_params="raw U map, raw T newmap",
146+
in_params="raw U center_x, raw U center_y, raw U R, raw U t, raw U norm_map",
147+
out_params="raw U p, raw U map, raw T newmap",
148148
preamble=map_utils(
149149
resolution,
150150
width,
@@ -165,8 +165,8 @@ def add_points_kernel(
165165
U y = transform_p(rx, ry, rz, R[3], R[4], R[5], t[1]);
166166
U z = transform_p(rx, ry, rz, R[6], R[7], R[8], t[2]);
167167
U v = z_noise(rz);
168+
int idx = get_idx(x, y, center_x[0], center_y[0]);
168169
if (is_valid(x, y, z, t[0], t[1], t[2])) {
169-
int idx = get_idx(x, y, center_x[0], center_y[0]);
170170
if (is_inside(idx)) {
171171
U map_h = map[get_map_idx(idx, 0)];
172172
U map_v = map[get_map_idx(idx, 1)];
@@ -258,6 +258,9 @@ def add_points_kernel(
258258
}
259259
}
260260
}
261+
p[i * 3]= idx;
262+
p[i * 3 + 1] = is_valid(x, y, z, t[0], t[1], t[2]);
263+
p[i * 3 + 2] = is_inside(idx);
261264
"""
262265
).substitute(
263266
mahalanobis_thresh=mahalanobis_thresh,
@@ -653,6 +656,263 @@ def polygon_mask_kernel(width, height, resolution):
653656
return polygon_mask_kernel
654657

655658

659+
def sum_kernel(
660+
resolution,
661+
width,
662+
height,
663+
664+
):
665+
# input the list of layers, amount of channels can slo be input through kernel
666+
sum_kernel = cp.ElementwiseKernel(
667+
in_params="raw U p, raw U center_x, raw U center_y, raw U R, raw U t, raw W pcl_chan, raw W map_lay, raw W pcl_channels",
668+
out_params="raw U map, raw T newmap",
669+
preamble=string.Template(
670+
"""
671+
__device__ int get_map_idx(int idx, int layer_n) {
672+
const int layer = ${width} * ${height};
673+
return layer * layer_n + idx;
674+
}
675+
"""
676+
).substitute(resolution=resolution,width=width, height=height),
677+
operation=string.Template(
678+
"""
679+
U idx = p[i * pcl_channels[0]];
680+
U valid = p[i * pcl_channels[0] + 1];
681+
U inside = p[i * pcl_channels[0] + 2];
682+
//U x = transform_p(rx, ry, rz, R[0], R[1], R[2], t[0]);
683+
//U y = transform_p(rx, ry, rz, R[3], R[4], R[5], t[1]);
684+
//U z = transform_p(rx, ry, rz, R[6], R[7], R[8], t[2]);
685+
// U v = z_noise(rz);
686+
//if (valid) {
687+
// int idx = get_idx(x, y, center_x[0], center_y[0]);
688+
U map_h = map[get_map_idx(idx, 0)];
689+
if (inside) {
690+
for ( int it=0;it<pcl_channels[1];it++){
691+
T feat = p[i * pcl_channels[0] + pcl_chan[it]];
692+
atomicAdd(&newmap[get_map_idx(idx, map_lay[it])], feat);
693+
}
694+
}
695+
//}
696+
"""
697+
).substitute(
698+
# pcl_channels=pcl_channels,
699+
# amount_features=amount_features,
700+
),
701+
name="sum_kernel",
702+
)
703+
return sum_kernel
704+
705+
706+
def average_kernel(
707+
width,
708+
height,
709+
max_variance,
710+
initial_variance,
711+
pcl_channels,
712+
amount_features,
713+
amount_class_prob,
714+
sem_class,
715+
rgb,
716+
):
717+
average_kernel = cp.ElementwiseKernel(
718+
in_params="raw U newmap",
719+
out_params="raw U map",
720+
preamble=string.Template(
721+
"""
722+
__device__ int get_map_idx(int idx, int layer_n) {
723+
const int layer = ${width} * ${height};
724+
return layer * layer_n + idx;
725+
}
726+
"""
727+
).substitute(width=width, height=height),
728+
operation=string.Template(
729+
"""
730+
U h = map[get_map_idx(i, 0)];
731+
U v = map[get_map_idx(i, 1)];
732+
U valid = map[get_map_idx(i, 2)];
733+
U new_h = newmap[get_map_idx(i, 0)];
734+
U new_v = newmap[get_map_idx(i, 1)];
735+
U new_cnt = newmap[get_map_idx(i, 2)];
736+
if (new_cnt > 0) {
737+
//U sem_cnt = newmap[get_map_idx(i, 7)];
738+
//for ( int it=0;it<${amount_features};it++){
739+
// U orig_f=map[get_map_idx(i, 7+${rgb}+it)];
740+
// U new_f=newmap[get_map_idx(i, 7+${rgb}+it)];
741+
// if (orig_f==0){
742+
// map[get_map_idx(i, 7+${rgb}+it)]=new_f/sem_cnt;
743+
// }
744+
// else{
745+
// map[get_map_idx(i, 7+${rgb}+it)]=orig_f*0.5+new_f/sem_cnt*0.5;
746+
// }
747+
//}
748+
// int stored_it = 0;
749+
// U highest_probability = 0;
750+
// for ( int it=0;it<${amount_class_prob};it++){
751+
// U orig_p=map[get_map_idx(i, 7+${rgb}+${amount_features}+it)];
752+
// U new_p=newmap[get_map_idx(i, 7+${rgb}+${amount_features}+it)];
753+
// U probability =0;
754+
// if (orig_p==0){
755+
// probability = new_p/sem_cnt;
756+
// map[get_map_idx(i, 7+${rgb}+${amount_features}+it)]=probability;
757+
// }
758+
// else{
759+
// probability = orig_p*0.5+new_p/sem_cnt*0.5;
760+
// map[get_map_idx(i, 7+${rgb}+${amount_features}+it)]=probability;
761+
// }
762+
// if(probability>= highest_probability){
763+
// stored_it = it;
764+
// highest_probability = probability;
765+
// }
766+
// }
767+
// if (${sem_class}){
768+
// // check max classs prob
769+
// map[get_map_idx(i, 7+${rgb}+${amount_features}+${amount_class_prob})] = stored_it;
770+
// }
771+
}
772+
773+
"""
774+
).substitute(
775+
max_variance=max_variance,
776+
initial_variance=initial_variance,
777+
pcl_channels=pcl_channels,
778+
amount_features=amount_features,
779+
amount_class_prob=amount_class_prob,
780+
sem_class=int(sem_class),
781+
rgb=int(rgb),
782+
),
783+
name="average_map_kernel",
784+
)
785+
return average_kernel
786+
787+
788+
def add_color_kernel(
789+
width,
790+
height,
791+
):
792+
add_color_kernel = cp.ElementwiseKernel(
793+
in_params="raw T p, raw U center_x, raw U center_y, raw U R, raw U t, raw W pcl_chan, raw W map_lay, raw W pcl_channels",
794+
out_params="raw U map, raw V color_map",
795+
preamble=string.Template(
796+
"""
797+
__device__ int get_map_idx(int idx, int layer_n) {
798+
const int layer = ${width} * ${height};
799+
return layer * layer_n + idx;
800+
}
801+
__device__ unsigned int get_color(unsigned int color){
802+
unsigned int red = 0xFF0000;
803+
unsigned int green = 0xFF00;
804+
unsigned int blue = 0xFF;
805+
unsigned int reds = (color & red) >> 16;
806+
unsigned int greens = (color & green) >> 8;
807+
unsigned int blues = ( color & blue);
808+
unsigned int rgbValue = (reds<<16 ) + (greens << 8) + blues;
809+
// TODO: at the moment it seems to be working, but if we want
810+
//to average over all points we need to use the color layer
811+
//color_out[get_map_idx(idx, 1)] = color;
812+
//[get_map_idx(idx, 2)] = color;
813+
return rgbValue;
814+
}
815+
__device__ unsigned int get_r(unsigned int color){
816+
unsigned int red = 0xFF0000;
817+
unsigned int reds = (color & red) >> 16;
818+
return reds;
819+
}
820+
__device__ unsigned int get_g(unsigned int color){
821+
unsigned int green = 0xFF00;
822+
unsigned int greens = (color & green) >> 8;
823+
return greens;
824+
}
825+
__device__ unsigned int get_b(unsigned int color){
826+
unsigned int blue = 0xFF;
827+
unsigned int blues = ( color & blue);
828+
return blues;
829+
}
830+
"""
831+
).substitute(width=width, height=height),
832+
operation=string.Template(
833+
"""
834+
U idx = p[i * pcl_channels[0]];
835+
U valid = p[i * pcl_channels[0] + 1];
836+
U inside = p[i * pcl_channels[0] + 2];
837+
if (true){
838+
for ( int it=0;it<pcl_channels[1];it++){
839+
unsigned int color = __float_as_uint(p[i * pcl_channels[0] + pcl_chan[it]]);
840+
// unsigned int rgbValue = get_color(color);
841+
842+
if (! false){
843+
map[get_map_idx(idx, map_lay[it])] = color;
844+
atomicAdd(&color_map[get_map_idx(idx, it*3)], get_r(color));
845+
atomicAdd(&color_map[get_map_idx(idx, it*3+1)], get_g(color));
846+
atomicAdd(&color_map[get_map_idx(idx, it*3 + 2)], get_b(color));
847+
atomicAdd(&color_map[get_map_idx(idx, pcl_channels[1]*3)], 1);}
848+
}
849+
}
850+
"""
851+
).substitute(
852+
width=width
853+
),
854+
name="add_color_kernel",
855+
)
856+
return add_color_kernel
857+
858+
def color_average_kernel(
859+
width,
860+
height,
861+
):
862+
color_average_kernel = cp.ElementwiseKernel(
863+
in_params="raw V color_map, raw W pcl_chan, raw W map_lay, raw W pcl_channels",
864+
out_params="raw U map",
865+
preamble=string.Template(
866+
"""
867+
__device__ int get_map_idx(int idx, int layer_n) {
868+
const int layer = ${width} * ${height};
869+
return layer * layer_n + idx;
870+
}
871+
__device__ unsigned int get_r(unsigned int color){
872+
unsigned int red = 0xFF0000;
873+
unsigned int reds = (color & red) >> 16;
874+
return reds;
875+
}
876+
__device__ unsigned int get_g(unsigned int color){
877+
unsigned int green = 0xFF00;
878+
unsigned int greens = (color & green) >> 8;
879+
return greens;
880+
}
881+
__device__ unsigned int get_b(unsigned int color){
882+
unsigned int blue = 0xFF;
883+
unsigned int blues = ( color & blue);
884+
return blues;
885+
}
886+
"""
887+
).substitute(width=width, height=height),
888+
operation=string.Template(
889+
"""
890+
unsigned int cnt = color_map[get_map_idx(i, pcl_channels[1]*3)];
891+
if (cnt>0){
892+
for ( int it=0;it<pcl_channels[1];it++){
893+
// U prev_color = map[get_map_idx(i, map_lay[it])];
894+
unsigned int r = color_map[get_map_idx(i, it*3)]/(1*cnt);
895+
unsigned int g = color_map[get_map_idx(i, it*3+1)]/(1*cnt);
896+
unsigned int b = color_map[get_map_idx(i, it*3+2)]/(1*cnt);
897+
//if (prev_color>=0){
898+
// unsigned int prev_r = get_r(prev_color);
899+
// unsigned int prev_g = get_g(prev_color);
900+
// unsigned int prev_b = get_b(prev_color);
901+
// unsigned int r = prev_r/2 + color_map[get_map_idx(i, it*3)]/(2*cnt);
902+
// unsigned int g = prev_g/2 + color_map[get_map_idx(i, it*3+1)]/(2*cnt);
903+
// unsigned int b = prev_b/2 + color_map[get_map_idx(i, it*3+2)]/(2*cnt);
904+
//}
905+
//unsigned int rgb = (r<<16) + (g << 8) + b;
906+
// map[get_map_idx(i, map_lay[it])] = __uint_as_float(rgb);
907+
}
908+
}
909+
"""
910+
).substitute(
911+
),
912+
name="color_average_kernel",
913+
)
914+
return color_average_kernel
915+
656916
if __name__ == "__main__":
657917
for i in range(10):
658918
import random

0 commit comments

Comments
 (0)