Chapter 8: Programming Distance Sensors with Python
In this chapter, we look at distance sensors and how to use them to avoid objects. Avoiding obstacles is a key feature in mobile robots, as bumping into stuff is generally not good. It is also a behavior that starts to make a robot appear smart, as if it is behaving intelligently.
In this chapter, we find out about the different types of sensors and choose a suitable type. We then build a layer in our robot object to access them and, in addition to this, we create a behavior to avoid walls and objects.
You will learn about the following topics in this chapter:
- Choosing between optical and ultrasonic sensors
- Attaching and reading an ultrasonic sensor
- Avoiding walls – writing a script to avoid obstacles