Skip to content

brian.sensors.Sensor

brian.sensors

Sensor class objects

class Sensor()

Base Sensor class

__init__

def __init__(port: SensorPort, sensor_type: AutoDetect)

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__

def __del__()

Deinitialize the sensor and free the port for other uses.

close_sensor

def close_sensor()

Deinitialize the sensor and free the port for other uses.

is_connected

def is_connected() -> bool

Returns:

True iff sensor is connected and not in the process of rebooting, False otherwise

is_ready

def is_ready() -> bool

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)
In all of the above cases, this function will return False.

Returns:

True iff values are ready for the next read, False otherwise

reboot

def reboot() -> None

Turn off power to the port and turn it back on. This will forcibly reboot the sensor.

The powered-down state lasts about 100ms. In case of some (mostly digital) sensors, there can be some additional time (~1s or more) to boot up and process connection handshake with Brian.