brian.sensors.Sensor
Sensor class objects
Base Sensor class
__init__
Initialize a EV3 sensor class at the given port.
Arguments:
port
: Sensor port to which the sensor is attached (sensors.SensorPort.S1-sensors.SensorPort.S4).sensor_type
: Type of the sensor which is attached. sensor_port_probe.AutoDetect.ANALOG_P1 corresponds to LightSensorNXT and TouchSensorNXT sensor_port_probe.AutoDetect.ANALOG_P6 corresponds to TouchSensor sensor_port_probe.AutoDetect.PROTOCOL_UART_EV3 corresponds to ColorSensor, GyroSensor and UltrasonicSensor
Raises:
SensorPortAlreadyInUse
: When trying to create new sensor on port that is already in use.
__del__
close_sensor
is_connected
Returns:
True iff sensor is connected and not in the process of rebooting, False otherwise
is_ready
Ready-state indicates that the attempt to read values will give valid results.
Example reasons for invalid results:
- Sensor is rebooting or not initiated yet
- Sensor is changing modes and the change is not finished yet
- Connected sensor is incompatible with this handler (e.g. wrong type of sensor is connected)
Returns:
True iff values are ready for the next read, False otherwise
wait_until_ready
Waits until the sensor is ready. This function is blocking.
When changing modes, the sensor enters a "not ready" state for a short period (until the mode change is propagated). Therefore, it is recommended to first set the correct mode using set_mode() before the calling this function. This only applies to sensors with modes.
Arguments:
timeout_ms
: Maximum number of milliseconds to wait. If the timeout is negative, the function will wait indefinitely.
Returns:
success
: - True: If the desired button event was caught.
- False: If the timeout ran out.