def test_givenResistanceValueStartingWithFive_whenGettingColors_thenFirstColorIsGreen(
        self, ):
        resistance = Resistance(550)

        first_color, *_ = resistance.get_colors()

        self.assertEqual(first_color, Color.GREEN)
    def test_givenResistanceValueOfOrderThree_whenGettingColors_thenThirdColorIsBrown(
        self, ):
        resistance = Resistance(840)

        *_, third_color = resistance.get_colors()

        self.assertEqual(third_color, Color.BROWN)
    def test_givenResistanceValueWithSixAsSecondDigit_whenGettingColors_thenSecondColorIsBlue(
        self, ):
        resistance = Resistance(160)

        _, second_color, *_ = resistance.get_colors()

        self.assertEqual(second_color, Color.BLUE)
    def test_givenResistanceValueOfOrderFive_whenGettingColors_thenThirdColorIsOrange(
        self, ):
        resistance = Resistance(25000)

        *_, third_color = resistance.get_colors()

        self.assertEqual(third_color, Color.ORANGE)
    def test_givenResistanceValueWithTwoAsSecondDigit_whenGettingColors_thenSecondColorIsRed(
        self, ):
        resistance = Resistance(120)

        _, second_color, *_ = resistance.get_colors()

        self.assertEqual(second_color, Color.RED)
    def test_givenResistanceValueStartingWithFour_whenGettingColors_thenFirstColorIsYellow(
        self, ):
        resistance = Resistance(450)

        first_color, *_ = resistance.get_colors()

        self.assertEqual(first_color, Color.YELLOW)
    def test_givenResistanceValueOf4437_whenRoundToNearestE12Value_thenReturnClosestE12ValueOf4700(
        self, ):
        resistance_read = 4437
        expected_resistance = Resistance(4700)

        actual_resistance = Resistance.round_to_nearest_e12_value(
            resistance_read)

        self.assertEqual(expected_resistance, actual_resistance)
    def test_givenResistanceOf270000_whenGettingColors_thenThirdColorIsYellow(
            self):
        resistance = Resistance.round_to_nearest_e12_value(261468.0)

        *_, third_color = resistance.get_colors()

        self.assertEqual(third_color, Color.YELLOW)
Example #9
0
    def run(self):
        print("Sending start command")
        self.send_command_to_robot(Topic.START_STAGE, Stage.READ_COMMAND_PANEL)
        self.wait_for_robot_confirmation(Topic.START_STAGE)

        print("Send movements to starting zone center")
        self._rotation_service.rotate(CardinalOrientation.SOUTH.value)
        robot_pose = self._find_robot_pose()
        movements_to_starting_zone = self._find_movements_to_starting_zone(robot_pose)
        self._move_robot(movements_to_starting_zone)

        print("Send rotation to robot to face command panel")
        self._rotation_service.rotate(CardinalOrientation.WEST.value)

        print("Send read command panel")
        self.send_command_to_robot(Topic.ANALYZE_COMMAND_PANEL, Resistance(260000))
        first_starting_zone_corner: StartingZoneCorner = (
            self._receive_first_starting_zone_corner()
        )
        print(
            "The first corner received is: {}".format(first_starting_zone_corner.name)
        )

        print("Wrapping up stage")
        self.send_command_to_robot(Topic.STAGE_COMPLETED, None)
        self.wait_for_robot_confirmation(Topic.STAGE_COMPLETED)

        print("Stage complete")
 def take_resistance_measurement(self) -> Resistance:
     resistance_read = self._ohmmeter.read_resistance()
     print()
     print()
     print(resistance_read)
     print()
     print()
     return Resistance.round_to_nearest_e12_value(resistance_read)
    def test_givenAResistanceWithNotCorrectValue_whenCallGetTargetCellIndex_ReturnException(
        self, ):

        a_wrong_resistance = Resistance(0)

        with self.assertRaises(CommandPanelTargetException):
            self._command_panel_target_position.get_target_cell_indix(
                a_wrong_resistance)
    def test_givenAResistanceWithCorrectValue_whenCallGetTargetCellIndex_ReturnTheRithCommandPanel(
        self, ):
        a_valid_resistance = Resistance(730)

        command_panel_position = (self._command_panel_target_position.
                                  get_target_cell_indix(a_valid_resistance))

        self.assertEqual(command_panel_position,
                         CommandPanelPosition.LOWER_LEFT)
Example #13
0
    def test_whenTakeResistanceMeasurement_thenReturnResistanceWithValueRead(
            self):
        self.ohmmeter.read_resistance.return_value = self.RESISTANCE_ABOVE_THRESHOLD
        expected_resistance = Resistance(self.RESISTANCE_ABOVE_THRESHOLD)

        actual_resistance = self.resistance_service.take_resistance_measurement(
        )

        self.assertEqual(expected_resistance, actual_resistance)
    def test_givenResistanceValueOf50_whenRoundToNearestE12Value_thenThrowInvalidResistanceException(
        self, ):
        resistance_read = 50

        rounding_to_nearest_e12_value = (
            lambda resistance: Resistance.round_to_nearest_e12_value(resistance
                                                                     ))

        with self.assertRaises(InvalidResistanceException):
            rounding_to_nearest_e12_value(resistance_read)
    def _read_command_panel(self, resistance: Resistance):
        self._vision_service.make_camera_look_up()
        self._align_horizontally_with_command_panel()
        self._vision_service.take_image()
        current_image = self._vision_service.take_image()
        command_panel_letters = (self._command_panel_letters_extractor.
                                 extract_letters_from_image(current_image))

        letter_position = resistance.find_nth_digit(0) - 1
        return command_panel_letters[letter_position]
Example #16
0
 def get_target_cell_indix(self, resistance: Resistance):
     position = resistance.find_nth_digit(0)
     try:
         return CommandPanelPosition(position - 1)
     except Exception:
         raise CommandPanelTargetException()
Example #17
0
 def _get_resistance_value(self, resistance_value: Resistance) -> int:
     return (
         resistance_value.get_value()
         if resistance_value is not None
         else self.NO_RESISTANCE_VALUE
     )