def test_given_a_basic_mapping_yields_expected_results_with_scale_change(self):
        height = 1.0
        lower_points = {
                (1.0, 1.0): (1.0, 1.0),
                (0.0, 1.0): (-1.0, 1.0),
                (1.0, 0.0): (1.0, -1.0),
                (0.0, 0.0): (-1.0, -1.0)
                }
        upper_points = {
                (1.0, 1.0): (1.0, 1.0),
                (0.0, 1.0): (-1.0, 1.0),
                (1.0, 0.0): (1.0, -1.0),
                (0.0, 0.0): (-1.0, -1.0)
                }
        scale = 0.5
        transformer = HomogenousTransformer(scale, height, lower_points, upper_points)
        test_points = [[1.0, 1.0, 0.0], [-1.0, -1.0, 0.0], [0.0, 0.0, 0.0], [0.5, 0.5, 0.0]]
        expected_points_pre = [(0.75, 0.75), (0.25, 0.25), (0.5, 0.5), (0.625, 0.625)]
        expected_points_post = [(1.0, 1.0), (0.0, 0.0), (0.5, 0.5), (0.75, 0.75)]

        actual_points_pre = [transformer.transform(point) for point in test_points]
        transformer.set_scale(1.0)
        actual_points_post = [transformer.transform(point) for point in test_points]

        self.assertEquals(expected_points_pre, actual_points_pre)
        self.assertEquals(expected_points_post, actual_points_post)
    def test_given_a_basic_mapping_yields_expected_results(self):
        height = 1.0
        lower_points = {
                (1.0, 1.0): (1.0, 1.0),
                (0.0, 1.0): (-1.0, 1.0),
                (1.0, 0.0): (1.0, -1.0),
                (0.0, 0.0): (-1.0, -1.0)
                }
        upper_points = {
                (1.0, 1.0): (1.0, 1.0),
                (0.0, 1.0): (-1.0, 1.0),
                (1.0, 0.0): (1.0, -1.0),
                (0.0, 0.0): (-1.0, -1.0)
                }
        scale = 1.0
        transformer = HomogenousTransformer(scale, height, lower_points, upper_points)

        test_points = [
            [1.0, 1.0, 0.0], [-1.0, -1.0, 0.0], [0.0, 0.0, 0.0], [0.5, 0.5, 0.0],
            [1.0, 1.0, 2.5], [-1.0, -1.0, 2.5], [0.0, 0.0, 2.5], [0.5, 0.5, 2.5],
            [1.0, 1.0, 5.0], [-1.0, -1.0, 5.0], [0.0, 0.0, 5.0], [0.5, 0.5, 5.0]]

        expected_points = [((x + 1.0) / 2.0, (y + 1.0) / 2.0) for (x, y, z) in test_points]
        actual_points = [transformer.transform(point) for point in test_points]

        self.assertEquals(expected_points, actual_points)
    def test_given_a_basic_mapping_yields_expected_results_with_scale(self):
        height = 1.0
        lower_points = {
            (1.0, 1.0): (1.0, 1.0),
            (0.0, 1.0): (-1.0, 1.0),
            (1.0, 0.0): (1.0, -1.0),
            (0.0, 0.0): (-1.0, -1.0)
        }
        upper_points = {
            (1.0, 1.0): (1.0, 1.0),
            (0.0, 1.0): (-1.0, 1.0),
            (1.0, 0.0): (1.0, -1.0),
            (0.0, 0.0): (-1.0, -1.0)
        }
        scale = 0.5
        transformer = HomogenousTransformer(scale, height, lower_points,
                                            upper_points)
        test_points = [[1.0, 1.0, 0.0], [-1.0, -1.0, 0.0], [0.0, 0.0, 0.0],
                       [0.5, 0.5, 0.0]]
        expected_points = [(0.75, 0.75), (0.25, 0.25), (0.5, 0.5),
                           (0.625, 0.625)]

        actual_points = [transformer.transform(point) for point in test_points]

        self.assertEquals(expected_points, actual_points)
    def test_given_a_basic_mapping_yields_expected_results(self):
        height = 1.0
        lower_points = {
            (1.0, 1.0): (1.0, 1.0),
            (0.0, 1.0): (-1.0, 1.0),
            (1.0, 0.0): (1.0, -1.0),
            (0.0, 0.0): (-1.0, -1.0)
        }
        upper_points = {
            (1.0, 1.0): (1.0, 1.0),
            (0.0, 1.0): (-1.0, 1.0),
            (1.0, 0.0): (1.0, -1.0),
            (0.0, 0.0): (-1.0, -1.0)
        }
        scale = 1.0
        transformer = HomogenousTransformer(scale, height, lower_points,
                                            upper_points)

        test_points = [[1.0, 1.0, 0.0], [-1.0, -1.0, 0.0], [0.0, 0.0, 0.0],
                       [0.5, 0.5, 0.0], [1.0, 1.0, 2.5], [-1.0, -1.0, 2.5],
                       [0.0, 0.0, 2.5], [0.5, 0.5, 2.5], [1.0, 1.0, 5.0],
                       [-1.0, -1.0, 5.0], [0.0, 0.0, 5.0], [0.5, 0.5, 5.0]]

        expected_points = [((x + 1.0) / 2.0, (y + 1.0) / 2.0)
                           for (x, y, z) in test_points]
        actual_points = [transformer.transform(point) for point in test_points]

        self.assertEquals(expected_points, actual_points)
 def _apply_calibration(self):
     self._path_to_points.set_transformer(
         HomogenousTransformer(
             self._configuration.calibration.max_deflection,
             self._configuration.calibration.height,
             self._configuration.calibration.lower_points,
             self._configuration.calibration.upper_points))
    def test_given_a_basic_mapping_yields_expected_results_2(self):
        height = 2.0
        lower_points = {
            (0.75, 0.75): (4.0, 4.0),
            (0.25, 0.75): (-4.0, 4.0),
            (0.75, 0.25): (4.0, -4.0),
            (0.25, 0.25): (-4.0, -4.0)
        }
        upper_points = {
            (1.0, 1.0): (4.0, 4.0),
            (0.0, 1.0): (-4.0, 4.0),
            (1.0, 0.0): (4.0, -4.0),
            (0.0, 0.0): (-4.0, -4.0)
        }
        scale = 1.0
        transformer = HomogenousTransformer(scale, height, lower_points,
                                            upper_points)

        test_points = [
            [4.0, 4.0, 0.0],
            [4.0, 4.0, 2.0],
            # [-1.0, -1.0, 0.0], [0.0, 0.0, 0.0], [0.5, 0.5, 0.0],
            # [1.0, 1.0, 2.5], [-1.0, -1.0,2.5], [0.0, 0.0,2.5], [0.5, 0.5,2.5],
            # [1.0, 1.0, 5.0], [-1.0, -1.0, 5.0], [0.0, 0.0, 5.0], [0.5, 0.5, 5.0]
        ]

        expected_points = [
            (0.75, 0.75),
            (1.0, 1.0),
            # (0.3750, 0.3750), (0.5000, 0.5000), (0.5625, 0.5625),
            # (0.6667, 0.6667), (0.3333, 0.3333), (0.5000, 0.5000), (0.5833, 0.5833),
            # (1.0000, 1.0000), (0.0000, 0.0000), (0.5000, 0.5000), (0.7500, 0.7500)
        ]

        actual_points = [transformer.transform(point) for point in test_points]

        for idx in range(0, len(test_points)):
            self.assertAlmostEquals(expected_points[idx][0],
                                    actual_points[idx][0])
            self.assertAlmostEquals(expected_points[idx][1],
                                    actual_points[idx][1])
    def test_points_outside_range_clip(self):
        height = 1.0
        lower_points = {
                (1.0, 1.0): (1.0, 1.0),
                (0.0, 1.0): (-1.0, 1.0),
                (1.0, 0.0): (1.0, -1.0),
                (0.0, 0.0): (-1.0, -1.0)
                }
        upper_points = {
                (1.0, 1.0): (1.0, 1.0),
                (0.0, 1.0): (-1.0, 1.0),
                (1.0, 0.0): (1.0, -1.0),
                (0.0, 0.0): (-1.0, -1.0)
                }
        scale = 1.0
        transformer = HomogenousTransformer(scale, height, lower_points, upper_points)

        test_points = [[-2.0, -2.0, 0.0], [2.0, 2.0, 0.0]]
        results = []
        for test_point in test_points:
                results.append(transformer.transform(test_point))
        self.assertEquals([(0.0, 0.0), (1.0, 1.0)], results)
    def test_points_outside_range_clip(self):
        height = 1.0
        lower_points = {
            (1.0, 1.0): (1.0, 1.0),
            (0.0, 1.0): (-1.0, 1.0),
            (1.0, 0.0): (1.0, -1.0),
            (0.0, 0.0): (-1.0, -1.0)
        }
        upper_points = {
            (1.0, 1.0): (1.0, 1.0),
            (0.0, 1.0): (-1.0, 1.0),
            (1.0, 0.0): (1.0, -1.0),
            (0.0, 0.0): (-1.0, -1.0)
        }
        scale = 1.0
        transformer = HomogenousTransformer(scale, height, lower_points,
                                            upper_points)

        test_points = [[-2.0, -2.0, 0.0], [2.0, 2.0, 0.0]]
        results = []
        for test_point in test_points:
            results.append(transformer.transform(test_point))
        self.assertEquals([(0.0, 0.0), (1.0, 1.0)], results)
    def test_given_a_basic_mapping_yields_expected_results_2(self):
        height = 2.0
        lower_points = {
                (0.75, 0.75): (4.0, 4.0),
                (0.25, 0.75): (-4.0, 4.0),
                (0.75, 0.25): (4.0, -4.0),
                (0.25, 0.25): (-4.0, -4.0)
                }
        upper_points = {
                (1.0, 1.0): (4.0, 4.0),
                (0.0, 1.0): (-4.0, 4.0),
                (1.0, 0.0): (4.0, -4.0),
                (0.0, 0.0): (-4.0, -4.0)
                }
        scale = 1.0
        transformer = HomogenousTransformer(scale, height, lower_points, upper_points)

        test_points = [
            [4.0, 4.0, 0.0], [4.0, 4.0, 2.0],
            # [-1.0, -1.0, 0.0], [0.0, 0.0, 0.0], [0.5, 0.5, 0.0],
            # [1.0, 1.0, 2.5], [-1.0, -1.0,2.5], [0.0, 0.0,2.5], [0.5, 0.5,2.5],
            # [1.0, 1.0, 5.0], [-1.0, -1.0, 5.0], [0.0, 0.0, 5.0], [0.5, 0.5, 5.0]
            ]

        expected_points = [
            (0.75, 0.75), (1.0, 1.0), 
            # (0.3750, 0.3750), (0.5000, 0.5000), (0.5625, 0.5625),
            # (0.6667, 0.6667), (0.3333, 0.3333), (0.5000, 0.5000), (0.5833, 0.5833),
            # (1.0000, 1.0000), (0.0000, 0.0000), (0.5000, 0.5000), (0.7500, 0.7500)
            ]

        actual_points = [transformer.transform(point) for point in test_points]

        for idx in range(0,len(test_points)):
            self.assertAlmostEquals(expected_points[idx][0], actual_points[idx][0])
            self.assertAlmostEquals(expected_points[idx][1], actual_points[idx][1])
示例#10
0
    def test_given_a_basic_mapping_yields_expected_results_with_scale_change(
            self):
        height = 1.0
        lower_points = {
            (1.0, 1.0): (1.0, 1.0),
            (0.0, 1.0): (-1.0, 1.0),
            (1.0, 0.0): (1.0, -1.0),
            (0.0, 0.0): (-1.0, -1.0)
        }
        upper_points = {
            (1.0, 1.0): (1.0, 1.0),
            (0.0, 1.0): (-1.0, 1.0),
            (1.0, 0.0): (1.0, -1.0),
            (0.0, 0.0): (-1.0, -1.0)
        }
        scale = 0.5
        transformer = HomogenousTransformer(scale, height, lower_points,
                                            upper_points)
        test_points = [[1.0, 1.0, 0.0], [-1.0, -1.0, 0.0], [0.0, 0.0, 0.0],
                       [0.5, 0.5, 0.0]]
        expected_points_pre = [(0.75, 0.75), (0.25, 0.25), (0.5, 0.5),
                               (0.625, 0.625)]
        expected_points_post = [(1.0, 1.0), (0.0, 0.0), (0.5, 0.5),
                                (0.75, 0.75)]

        actual_points_pre = [
            transformer.transform(point) for point in test_points
        ]
        transformer.set_scale(1.0)
        actual_points_post = [
            transformer.transform(point) for point in test_points
        ]

        for idx in range(0, len(expected_points_pre)):
            self.assertAlmostEquals(expected_points_pre[idx][0],
                                    actual_points_pre[idx][0])
            self.assertAlmostEquals(expected_points_pre[idx][1],
                                    actual_points_pre[idx][1])
            self.assertAlmostEquals(expected_points_post[idx][0],
                                    actual_points_post[idx][0])
            self.assertAlmostEquals(expected_points_post[idx][1],
                                    actual_points_post[idx][1])
示例#11
0
    def print_layers(self,
                     layer_generator,
                     print_sub_layers=True,
                     dry_run=False,
                     force_source_speed=False):
        logger.info("Shuffled: %s" %
                    self._configuration.options.use_shufflelayers)
        logger.info("Sublayered: %s" %
                    self._configuration.options.use_sublayers)
        logger.info("Overlapped: %s" % self._configuration.options.use_overlap)

        if self._configuration.options.use_sublayers and print_sub_layers:
            layer_generator = SubLayerGenerator(
                layer_generator,
                self._configuration.options.sublayer_height_mm)
        if self._configuration.options.use_shufflelayers:
            layer_generator = ShuffleGenerator(
                layer_generator,
                self._configuration.options.shuffle_layers_amount)
        if self._configuration.options.use_overlap:
            layer_generator = OverLapGenerator(
                layer_generator, self._configuration.options.overlap_amount)

        if self._configuration.serial.on:
            self._commander = SerialCommander(self._configuration.serial.port)
        else:
            self._commander = NullCommander()

        self.laser_control = LaserControl(
            self._configuration.cure_rate.override_laser_power_amount)

        transformer = HomogenousTransformer(
            self._configuration.calibration.max_deflection,
            self._configuration.calibration.height,
            self._configuration.calibration.lower_points,
            self._configuration.calibration.upper_points,
        )

        state = MachineState()
        self._status = MachineStatus()

        if dry_run:
            abort_on_error = False
        else:
            abort_on_error = True

        self._zaxis = self._get_zaxis(dry_run)

        disseminator = self._get_digital_disseminator(dry_run)

        path_to_points = PathToPoints(
            disseminator.samples_per_second, transformer,
            self._configuration.options.laser_thickness_mm)

        if force_source_speed:
            override_draw_speed = None
            override_move_speed = None
        else:
            override_draw_speed = self._configuration.cure_rate.draw_speed if self._configuration.cure_rate.use_draw_speed else None
            override_move_speed = self._configuration.cure_rate.move_speed if self._configuration.cure_rate.use_draw_speed else None

        pre_layer_delay = self._configuration.options.pre_layer_delay if self._configuration.options.pre_layer_delay else 0.0
        post_fire_delay_speed = None
        slew_delay_speed = None
        if self._configuration.options.post_fire_delay:
            post_fire_delay_speed = self._configuration.options.laser_thickness_mm / (
                float(self._configuration.options.post_fire_delay) / 1000.0)
        if self._configuration.options.slew_delay:
            slew_delay_speed = self._configuration.options.laser_thickness_mm / (
                float(self._configuration.options.slew_delay) / 1000.0)

        if self._configuration.options.wait_after_move_milliseconds > 0:
            wait_speed = self._configuration.options.laser_thickness_mm / (
                float(self._configuration.options.wait_after_move_milliseconds)
                / 1000.0)
        else:
            wait_speed = None

        self._writer = LayerWriter(disseminator,
                                   path_to_points,
                                   self.laser_control,
                                   state,
                                   move_distance_to_ignore=self._configuration.
                                   options.laser_thickness_mm,
                                   override_draw_speed=override_draw_speed,
                                   override_move_speed=override_move_speed,
                                   wait_speed=wait_speed,
                                   post_fire_delay_speed=post_fire_delay_speed,
                                   slew_delay_speed=slew_delay_speed)

        self._layer_processing = LayerProcessing(
            self._writer,
            state,
            self._status,
            self._zaxis,
            self._configuration.dripper.max_lead_distance_mm,
            self._commander,
            pre_layer_delay,
            self._configuration.serial.layer_started,
            self._configuration.serial.layer_ended,
            self._configuration.serial.print_ended,
            self._configuration.serial.on_command,
            self._configuration.serial.off_command,
        )

        if self._zaxis:
            self._zaxis.set_call_back(self._status.drip_call_back)
            self._zaxis.start()

        self._controller = Controller(
            self._writer,
            self._layer_processing,
            layer_generator,
            self._status,
            abort_on_error=abort_on_error,
        )

        self._controller.start()