5.4 Mapping

As with error correction, the mapping logic should only get invoked after an ADC-to-length conversion. Otherwise, nothing new can possibly be discovered.

Given that, the mapping logic also needs to be guarded by some logic.

Depending on the geometry of a robot, you need to change the parameters slightly. However, the general concept is to look for a parallel wall at a place where sensing such a wall is reliable (when the sensor is looking at the middle section of a partition, at least well past or before a post).

This condition depends on the geometry (sensor placement and angle) of the robot, and it can be translated to a computation based on the remaining distance to the center of the next cell.

Also, it is important to read the same wall more than once, and only register a wall if there are multiple confirmation of the wall. This helps to elimiate bad sensor information due to noise issues. Due to this “debouncing” logic, it is best to put wall mapping into its own thread that gets triggered by the ADC-to-length conversion.

The logic to detect a front wall should also be guarded to make sure the logic does not get triggered until the front sensor has reliable data. In theory, a GP2D12 sensor can detect a wall from 30cm away. However, to do this reliably, you may want to only conclude there is front wall when the distance is:

Because the front-wall mapping and side-wall mapping logic can debounce at the same time, it is best to organize each as its own thread to decouple the independent logic. However, doing so will also require one semaphore per thread. In other words, the ADC-to-length logic will need to “V” the semaphores of both threads. Having the threads to share one semaphore may give one thread an additional chance when denying the other one the necessary trigger.