MCPcopy Create free account
hub / github.com/DexterInd/GoPiGo3 / is_too_close

Method is_too_close

Software/Python/easysensors.py:786–812  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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 """

Callers

nothing calls this directly

Calls 3

get_safe_distanceMethod · 0.95
get_port_IDMethod · 0.80
get_grove_valueMethod · 0.45

Tested by

no test coverage detected