def sense_and_act(self):
        line_sensob = self.sensobs[0]
        if not isinstance(line_sensob, LineSensob):
            raise Exception("Invalid type for line_sensob: "+str(type(line_sensob)))

        found_lines = line_sensob.get_found_lines()
        position = line_sensob.get_line_position()

        self.set_match_degree(1.0 if found_lines else 0.0)

        left_sign, right_sign = 1.0, 1.0        # Negate in if-test to reverse motor

        if position < 0.5:  # Line is left, drive right
            strength = max(0.3, position/0.5)           # Map to [0.3, 1]
            right_sign = -1.0
        else:               # Line is right, drive left
            strength = max(0.3, 0.5-(position-0.5)/0.5)       # Map to [0.3, 1]
            left_sign = -1.0

        # Meh, override strength
        strength = 1.0

        print("AvoidLineBehaviour: Strength: " + str(strength))
        amount = 1.0*strength    # Motor power in range [0, 1.0]

        if not found_lines:
            print("AvoidLineBehaviour: Did not find any lines")
            # If arbitrator chooses this anyways, then don't drive.
            amount = 0.0

        # Recommendation is a list with tuples for each motob.
        recommendation = [make_recommendation(amount*left_sign, amount*right_sign)]
        self.motor_recommendations = [recommendation]
        print(self)
    def sense_and_act(self):
        ultra_sensob = self.sensobs[0]
        if not isinstance(ultra_sensob, UltraSensob):
            raise Exception("Invalid type for line_sensob: "+str(type(ultra_sensob)))

        distance = ultra_sensob.get_value()  # distance cm

        if distance <= 5:
            recommendation = [make_recommendation(-1, -1)]
            self.motor_recommendations = [recommendation]     #recommends the motors to stop
            self.set_match_degree(1.0)                        #sets a high match degree
        else:
            self.set_match_degree(0.0)
        print(self)
    def sense_and_act(self):
        red_detector = self.sensobs[0]

        if not isinstance(red_detector, RedDetector):
            raise Exception("Invalid type red_detector: " + str(type(red_detector)))

        red_position = red_detector.get_red_position()

        red_position = red_detector.get_red_position()

        left = abs(1.0-red_position)/2.0
        right = abs(red_position)/2.0

        left = min(left, 1.0)
        right = min(right, 1.0)

        print("\033[91m Red position: "+str(red_position)+ ", dir:{} {}".format(left, right) +"\033[0m")

        recommendation = [make_recommendation(left, right)]
        self.motor_recommendations = [recommendation]

        confidence = red_detector.get_confidence() * 0.9
        print("RED confidence: {}".format(confidence))
        self.set_match_degree(confidence)