If we have the map of an environment (an occupancy grid for instance) and precisely know the pose of the robot within it. How can one reconstruct what the laser scan should look like at a given location ?
2 Answers
You can do it manually with a protractor and straight edge - put the center of your protractor on the scanner center, align your protractor's zero-angle mark to the scanner zero, then mark off ticks at whatever your scanner resolution is.
Then you use the straight edge to connect the dots from the center, through each tick, until either you draw to an object or you reach the max range of the laser scanner.
In software, you can simulate this by "ray casting" from the scanner center along each scan angle.
-
$\begingroup$ would it possible for you to point me to a good resource that covers 'ray casting' in the context of a 2D laserscan and a map? $\endgroup$– skpro19Aug 11, 2021 at 19:18
-
1$\begingroup$ @skpro19 - The Moller-Trumbore ray-triangle intersection algorithm is how I got started with raycasting. There's a 3D file format called "STL" that breaks an object into triangles, so then basically you just define your scanner to be an origin with rays at fixed intervals, then you loop through each ray and check it against each triangle. If a ray gets multiple hits, take the hit with the shortest distance. Then you wind up with a list of "hits" and that's your simulated scan data. $\endgroup$– Chuck ♦Aug 11, 2021 at 21:15
-
1$\begingroup$ @skpro19 - If you mean doing the ray casting on a strictly 2D map, then that should be easier. Same setup - define the scanner to be a point with rays at the inter-beam resolution, then go through each ray and, for each ray, loop through all the wall segments that make up your map. Test if your ray intersects that line segment, collect the shortest distance of any wall segments that do intersect, and again the result is a simulated laser scanner data. $\endgroup$– Chuck ♦Aug 11, 2021 at 21:18
This would depend on how your map is formed in the first place. Is it saved by aggregating several scans into one map? If so, it'd be very hard to extract individual scans since this information is lost in the registration and subsequent aggregation. You can however, use a filter (eg: radius filter, crop box, etc.) to query the map based on your current pose and extract a portion of the map. This wont give you an individual scan but will be close.
The other option would be to skip the aggregation step and save individual scans with their poses. You will have to write a script to merge them at runtime and view/show a complete map, but no information is lost in the process. Extracting a scan would then be easy, as you just find the scan with the lowest distance between the current pose and one saved in the files.