Now that we have tested both sensors, it's time to integrate our new sensors with our robot class, and then create an obstacle avoidance behavior for them. We've seen how to write line sensor code that was event-based. For this sensor, we will use a different style, that is, polling. Our behavior loop will read the sensors, and then choose behavior accordingly. For the most part, the way the code will react to things does not change, and it is a decision about where to put the loop for checking sensor state—in the sensor object, or in your own code.
Avoiding walls – a script to avoid obstacles
Making our distance sensor object
To integrate this into our robot, we will start by creating a DistanceSensor...