Simulating LIDAR driving with Rust and OpenAI

One of the reasons that I created the Rust OpenAI framework was so that I could code general algorithms into bots with high performance. Now that the framework is becoming more stable, I thought that I should test it out with a competitive bot.

I don’t really want to start deep-learning or neural networks right now, mostly because it can obscure what really is happening. So instead I challenged one of the many flash racing games in OpenAI with a LIDAR sensing bot.

The basic idea is that I would simulate LIDAR using edge detection. Then the bot would determine whether to turn left or right depending on the area with the most open space. This is made much more complicated by the stripes on roads and obstacles, not to mention other cars. Due to those factors, the bot often decides to turn off the road entirely, leading to poor performance and negative rewards. Despite that dangerous tendency, the bot often performs well, and has passed many game AIs without issue.

First I built the LIDAR beam concept. LIDAR is a real world technology that sends a light beam out, and catches the scatter to determine how far away the nearest solid object is. In flash world, this means sending out a directional beam and measuring the distance to any “edge”. There are a few parameters that matter for this calculation: starting position, directionality of beam, and density threshold to determine a scatter.

I first planned to put two LIDAR sensors at the bottom middle and point them at the 10' and 2' directions. The end result looks like this (LIDAR rays are pink)

The game has a dashboard, which caught both beams, so I decided to move the sensors to behind either rear wheel:

And the same concept in original colour:

This arrangement was fairly competitive and allowed the car to pass several competitors. However, the car did not handle turns well, due to the poor starting placement of beams. To fix this I decided to add two more sensors at the front left and right tires:

This time, throughout several tests, the car often passes competitors in the beginning, though it still has issues of running off road when a sensors starting position is outside the roadway. Further work will be needed to correct this. Code for the bot is available on GitHub and some of the tests are recorded below.