I am developing a Lidar sensor on a simulation using Ray-trace. simulation is configurable to run at desired frame per second (in my case 30 fps. i.e 1 frame runs in 33.34ms).
Currently 300000 ray-tracing are done per second (including horizontal and vertical). at 30 fps, 10000 ray-tracing is done per frame. The code looks like below
//call back at the start of frame (just for understanding - not the actual code, data type conversions and some other basics are ignored)
uint32 channels = 16;
float vert_angle[] = {15, 13, 11, 9, 7, 5, 3, 1, -1, -3, -5, -7, -9, -11, -13, -15};
float hor_angle_ref = 0;
uint32 points_per_second = 300000;
float rotation_frequency = 10;
/* 300000 points per second is divided into points per frame.
These points are distributed horizontally and vertically*/
void callback_scan(){
uint32 poits_to_scan_with_one_laser = points_per_second/ (fps * channels);
auto hor_angle_covered_this_frame = points_per_second* rotation_frequency * (1/fps);
auto hor_angle_resolution = hor_angle_covered_this_frame / poits_to_scan_with_one_laser ;
auto hor_angle = hor_angle_ref ;
for(auto i= 0u; i< poits_to_scan_with_one_laser ; ++i){
for(auto ch= 0u; ch< channels; ++ch){
auto hitPoint = raytrace(hor_angle, vert_angle[ch]);
// process_data(); -> distance, time and energy are calculated
/* distance -> Euclidean distance calculation and addition of noise
time -> c=d/t
energy -> Pr = Pt*pow(D,2)*nsys*natm*row/ pow(dist,2);*/
}
hor_angle += hor_angle_resolution ;
}
hor_angle_ref = hor_angle;
}
Above piece of code runs pretty good. Everything completes within expected time of 33.33ms. Now it is required to introduce effect divergence https://en.wikipedia.org/wiki/Beam_divergence.
Solution used: 8 samples are taken for each point. i.e 8 more ray-tracing inside the nested for loops. In total (8+1)*300000
ray-trace. This solution is eating up a lot of time and not possible to complete within 33ms. Could any one suggest any other alternative on structuring the architecture of the code/ algorithm / a different approach that I can use to implement this with less computational complexity.
Additional info:
Unreal Engine 4.22, Running on a GPU