0

For a personal learning project I'm making a simple neural network to control a simulated car trough a simple maze.

To provide the network with inputs to work with, I need virtual sensors around the car to indicate how close I am to any obstacles.

How would I go about this? I've seen examples where there are lines pertruding out of the vehicle that can sense how far they overlap with obstacles.

This means that for example if the front sensor line is 40% inside a wall, it will kick back the value 0.40 to the network so it knows how close the obstacle is to the front of the car. The same process would be repeated for the left, right and back sensors.

I really hope I explained myself well, I could post some pictures but I know you guys don't like links from strangers.

Any insight would be appreciated, thanks.

Shai
  • 111,146
  • 38
  • 238
  • 371

1 Answers1

1

I'll sketch a simple outline on how I'd tackle this:

  1. Query objects in the environment of the car with a margin that makes sense for your application. Eg: if you want your car to respond to obstacles closer than 2 meters, make your margin 2 meters.
  2. For these nearby objects you have, calculate intersections with these virtual rays of your sensors. For this, you will most likely want to use the mathematical results of a linesegment-linesegment-intersection, which can be found here on SO: How do you detect where two line segments intersect? This of course requires you to be able to model your environment using line segments. If you have curved objects, then a multiline-piece approximation might suffice. Alternatively, define an interface for your environment objects that will calculate the intersection of a ray with itself. Now you can specialise the mathematics for rectangles, circles, arcs, pedestrians, bikers, horses, etc... Make sure you make a tradeoff between how accurate the distance of the sensor should be, versus how much time you want to spend writing intersection calculation code.
  3. Pick for each sensor ray the object that produced the intersection that is closest.
Martijn Courteaux
  • 67,591
  • 47
  • 198
  • 287
  • 1
    To be able to do 1) the (complex) objects must provide a bounding box allowing a fast test. If you have many objects then you might have to look for an efficient [Space partitioning](https://en.wikipedia.org/wiki/Space_partitioning) algorithm. – Olivier Jacot-Descombes Nov 25 '17 at 15:51