Simulating Lidar for AI Pathfinding
To feed meaningful input into our RNN, we simulate lidar-like distance readings across 360 degrees, using 2-degree resolution. This results in 180 values per position.
Each angle is computed using trigonometric ray tracing against map obstacles, with edge cases handled for vertical and horizontal detection. The function lidarValues
integrates these calculations and returns the range data.
def lidarValues(Position, mapArray):
lidarRange = 360
distanceMatrix = []
for theeta in range(0, lidarRange, 2):
angle = theeta
distanceMatrix.append(distance(Position, angle, mapArray))
return distanceMatrix
Combining this with the robot's current position forms the complete input vector used for training and inference. It allows the network to "sense" its environment similar to a real-world robot.