brian.sensors.EV3.ColorSensorEV3
ColorSensorEV3 class objects
Class for interacting with EV3 color sensor.
Sensor is automatically registered in the constructor of the base class and un-registered in its destructor. It can also be unregistered with the ColorSensorEV3.close_sensor() function.
There can be at most one instance at any given time, of any sensor class per port in the entire program.
__init__
Initialize a EV3 color sensor at the given port.
Arguments:
port
: Sensor port to which the sensor is attached.
Mode class objects
REFLECT
AMBIENT
COLOR_DETECT
REFLECT_RAW
RGB_RAW
RGB class objects
Class used to hold rgb values from ColorSensor.rgb_values_raw() measurement. Each color channel holds values between 0-1023. Attributes can be accessed either directly or using an index (RGB[0] = RGB.red)
red
green
blue
__init__
Arguments:
red
: red color component [0-1023].green
: green color component [0-1023].blue
: blue color component [0-1023].
__sub__
Element wise subscription
If resulting element would be smaller than 0, it is set to 0
__getitem__
Color class objects
Constants for ColorSensor.detected_color(self)
function.
NO_COLOR
BLACK
BLUE
GREEN
YELLOW
RED
WHITE
BROWN
set_mode
This function sets the sensor to the desired mode. While it’s not mandatory, it is recommended to call this
function before accessing values from the sensor in a specific mode to prevent SensorIsNotReady exceptions.
Arguments:
mode
: desired mode to be set
reflected_value
Sets the sensor mode to REFLECT
and returns the last value.
Raises:
brian.sensors.SensorIsNotReadyError
: If the sensor is not ready. REFLECT mode: Measure surface reflectivity for red light. The values are calibrated within the sensor itself. Returns the values in percent, in range 0-100. The measurement is corrected for the ambient light change.
Returns:
reflectivity in % (0-100).
reflected_value_raw
Sets the sensor mode toREFLECT_RAW
and returns the last value.
Raises:
brian.sensors.SensorIsNotReadyError
: If the sensor is not ready. REFLECT_RAW mode: Measure surface reflectivity for red light. The values are uncalibrated. Code using this function must thus perform range scaling/shifting manually. Measuring in this mode should provide more resolution overREFLECT
mode. Returns values in range 0-1023. The measurement is corrected for the ambient light change.
Returns:
reflectivity raw values (0-1023).
ambient_value
Sets the sensor mode to AMBIENT
and returns the last value.
Raises:
brian.sensors.SensorIsNotReadyError
: If the sensor is not ready. AMBIENT mode: Measure ambient light intensity. The values are calibrated within the sensor itself. Returns the values in percent, in range 0-100.
Returns:
ambient in % (0-100).
detected_color
Sets the sensor mode to COLOR_DETECT
and returns the last value.
Raises:
brian.sensors.SensorIsNotReadyError
: If the sensor is not ready. COLOR_DETECT mode: Measure and discriminate the color. The discrimination is provided by the sensor itself. If this works poorly for your use case, you can useRGB_RAW
instead.
Returns:
color constants corresponding to Color.[COLOR].
get_color_name
Arguments:
color
: Color to get the name of.
Returns:
English name of the provided color. This is a convenience function for UI or logging.
rgb_values_raw
Sets the sensor mode to RGB_RAW
and return the last value.
Raises:
brian.sensors.SensorIsNotReadyError
: If the sensor is not ready. RGB_RAW mode: Measure surface reflectivity for red, green and blue light. The values are uncalibrated. Code using this function must thus perform range scaling/shifting manually. The measurement is corrected for the ambient light change. rgb_values_raw
Returns:
RGB raw values (0-1023 each channel). You can access them with RGB.red, RGB.green and RGB.blue, or by using subscription (RGB[0], RGB[1], ...)