Skip to Content
Learn Robotics Programming
book

Learn Robotics Programming

by Danny Staple
November 2018
Beginner
472 pages
13h 5m
English
Packt Publishing
Content preview from Learn Robotics Programming

Making our distance sensor object

To integrate this into our robot, we will start by creating a DistanceSensor object. It will have a simple get_distance method. This is a simple interface which we could swap out for implementations of other distance sensors. We will construct it with the two pin numbers. This code will look quite familiar to the code we tested. Put this into distance_sensor_hcsr04.py.

Start again with some imports, and this time, a docstring for the module. Module docstrings usually state why a module exists or what it is for:

"""Object for the HC-SR04 distance sensor type."""import time # import the whole thing, we need more than just sleepfrom gpiozero import DigitalInputDevice, DigitalOutputDevice...

As we saw in the ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learn Robotics Programming - Second Edition

Learn Robotics Programming - Second Edition

Danny Staple

Publisher Resources

ISBN: 9781789340747Supplemental Content