Checks whether the `Grove Ultrasonic Sensor`_ measures a distance that's too close to a target than what we consider a *safe distance*. :returns: Whether the `Grove Ultrasonic Sensor`_ is too close from a target. :rtype: bool :raises gopigo3.SensorError: If
(self)
| 784 | |
| 785 | |
| 786 | def is_too_close(self): |
| 787 | """ |
| 788 | Checks whether the `Grove Ultrasonic Sensor`_ measures a distance that's too close to a target than |
| 789 | what we consider a *safe distance*. |
| 790 | |
| 791 | :returns: Whether the `Grove Ultrasonic Sensor`_ is too close from a target. |
| 792 | :rtype: bool |
| 793 | :raises gopigo3.SensorError: If a sensor is not yet configured when trying to read it. |
| 794 | |
| 795 | A *safe distance* can be set with the :py:meth:`~easysensors.UltraSonicSensor.set_safe_distance` method. |
| 796 | |
| 797 | .. note:: |
| 798 | |
| 799 | The default *safe distance* is set at 50 cm. |
| 800 | |
| 801 | |
| 802 | """ |
| 803 | try: |
| 804 | val = self.gpg.get_grove_value(self.get_port_ID()) |
| 805 | except gopigo3.SensorError as e: |
| 806 | print("Invalid Reading") |
| 807 | print(e) |
| 808 | return False |
| 809 | |
| 810 | if val < self.get_safe_distance(): |
| 811 | return True |
| 812 | return False |
| 813 | |
| 814 | def set_safe_distance(self, dist): |
| 815 | """ |
nothing calls this directly
no test coverage detected