def __init__(self, port="I2C", led_state=False, use_mutex=False):
        """
        Constructor for initializing a link to the `Light Color Sensor`_.
        :param str port = "I2C": The port to which the distance sensor is connected to. Can also be connected to ports ``"AD1"`` or ``"AD2"`` of the `GoPiGo3`_. If you're passing an **invalid port**, then the sensor resorts to an ``"I2C"`` connection. Check the :ref:`hardware specs <hardware-interface-section>` for more information about the ports.
        :param bool led_state = False: The LED state. If it's set to ``True``, then the LED will turn on, otherwise the LED will stay off. By default, the LED is turned off.
        :param bool use_mutex = False: When using multiple threads/processes that access the same resource/device, mutexes should be enabled.
        :raises ~exceptions.OSError: When the `Light Color Sensor`_ is not reachable.
        :raises ~exceptions.RuntimeError: When the chip ID is incorrect. This happens when we have a device pointing to the same address, but it's not a `Light Color Sensor`_.
        """

        self.use_mutex = use_mutex

        try:
            bus = ports[port]
        except KeyError:
            bus = "RPI_1SW"

        # in case there's a distance sensor that hasn't been instanciated yet
        # attempt to move it to another address
        ifMutexAcquire(self.use_mutex)
        try:
            VL53L0X.VL53L0X(bus=bus)
        except:
            pass
        ifMutexRelease(self.use_mutex)

        ifMutexAcquire(self.use_mutex)
        try:
            super(self.__class__, self).__init__(led_state=led_state, bus=bus)
        except Exception as e:
            raise
        finally:
            ifMutexRelease(self.use_mutex)

        self.led_state = led_state
Пример #2
0
    def __init__(self, bus="RPI_1"):
        """Initialize the sensor
        
        Keyword arguments:
        bus (default "RPI_1") -- The I2C bus"""
        self.VL53L0X = VL53L0X.VL53L0X(bus=bus)

        # set to long range (about 2 meters)
        self.VL53L0X.set_signal_rate_limit(0.1)
        self.VL53L0X.set_vcsel_pulse_period(self.VL53L0X.VcselPeriodPreRange,
                                            18)
        self.VL53L0X.set_vcsel_pulse_period(self.VL53L0X.VcselPeriodFinalRange,
                                            14)
Пример #3
0
    def __init__(self, bus="RPI_1SW"):
        """
        Constructor for initializing a :py:class:`~di_sensors.distance_sensor.DistanceSensor` class.

        :param str bus = "RPI_1SW": The bus to which the distance sensor is connected to. By default, it's set to bus ``"RPI_1SW"``. Check the :ref:`hardware specs <hardware-interface-section>` for more information about the ports.
        :raises ~exceptions.OSError: When the distance sensor is not connected to the designated bus/port. Most probably, this means the distance sensor is not connected at all.

        """
        self.VL53L0X = VL53L0X.VL53L0X(bus=bus)

        # set to long range (about 2.3 meters)
        self.VL53L0X.set_signal_rate_limit(0.1)
        self.VL53L0X.set_vcsel_pulse_period(self.VL53L0X.VcselPeriodPreRange,
                                            18)
        self.VL53L0X.set_vcsel_pulse_period(self.VL53L0X.VcselPeriodFinalRange,
                                            14)