def makeColorSensor(port): try: s = ev3dev.ColorSensor(port) except (AttributeError, OSError): logger.info('no color sensor connected to port [%s]', port) s = None return s
class ColorSensors: """ The class for the color sensors that are used by the robot to follow lines and identify tags. """ line_clr = ev3.ColorSensor(ev3.INPUT_3); assert line_clr.connected tag_clr = ev3.ColorSensor(ev3.INPUT_1); assert tag_clr.connected line_clr.mode = tag_clr.mode = 'COL-REFLECT' @classmethod def get_values(cls): """ Gets the values from the line color and tag color sensor. Keyword arguments: cls -- The class """ return cls.line_clr.value(), cls.tag_clr.value() @classmethod def get_line_value(cls): """ Gets the value from the line color sensor. Keyword arguments: cls -- The class """ return cls.line_clr.value() @classmethod def get_tag_value(cls): """ Get the color value of the tag color sensor. Keyword arguments: cls -- The class """ return cls.tag_clr.value()