Пример #1
0
    def start_timelapse(
            self, settings, octoprint_printer_profile, ffmpeg_path, g90_influences_extruder):
        # we must supply the settings first!  Else reset won't work properly.
        self._reset()
        # in case the settings have been destroyed and recreated
        self.Settings = settings
        # time tracking - how much time did we add to the print?
        self.SnapshotCount = 0
        self.SecondsAddedByOctolapse = 0
        self.HasSentInitialStatus = False
        self.RequiresLocationDetectionAfterHome = False
        self.OctoprintPrinterProfile = octoprint_printer_profile
        self.FfMpegPath = ffmpeg_path
        self.PrintStartTime = time.time()
        self.Snapshot = Snapshot(self.Settings.current_snapshot())
        self.Gcode = SnapshotGcodeGenerator(
            self.Settings, octoprint_printer_profile)
        self.Printer = Printer(self.Settings.current_printer())
        self.Rendering = Rendering(self.Settings.current_rendering())
        self.CaptureSnapshot = CaptureSnapshot(
            self.Settings, self.DataFolder, print_start_time=self.PrintStartTime)
        self.Position = Position(
            self.Settings, octoprint_printer_profile, g90_influences_extruder)
        self.State = TimelapseState.WaitingForTrigger
        self.IsTestMode = self.Settings.current_debug_profile().is_test_mode
        self.Triggers = Triggers(self.Settings)
        self.Triggers.create()

        # take a snapshot of the current settings for use in the Octolapse Tab
        self.CurrentProfiles = self.Settings.get_profiles_dict()

        # send an initial state message
        self._on_timelapse_start()
Пример #2
0
    def test_GetSnapshotGcode_ReturnCommands(self):
        # test with relative paths, absolute extruder coordinates, retract and z hop
        # use relative coordinates for stabilizations
        self.Settings.current_stabilization().x_type = "fixed_path"
        self.Settings.current_stabilization().x_fixed_path = "50,100"  # 125,250
        self.Settings.current_stabilization().x_fixed_path_loop = False
        self.Settings.current_stabilization().x_fixed_path_invert_loop = False
        self.Settings.current_stabilization().y_type = "fixed_path"
        self.Settings.current_stabilization().y_fixed_path = "50,100"  # 100,200
        self.Settings.current_stabilization().y_fixed_path_loop = False
        self.Settings.current_stabilization().y_fixed_path_invert_loop = False
        self.Settings.current_snapshot().retract_before_move = True
        snapshot_gcode_generator = SnapshotGcodeGenerator(
            self.Settings, self.create_octoprint_printer_profile())
        self.Extruder.is_retracted = lambda: True
        snapshot_gcode = snapshot_gcode_generator.create_snapshot_gcode(
            100, 50, 0, 3600, True, False, self.Extruder, 0.5, "SavedCommand")

        # verify the return commands
        self.assertEqual(snapshot_gcode.get_return_commands()[0], "G1 X100.000 Y50.000")
        self.assertEqual(snapshot_gcode.get_return_commands()[1], "G91")
        self.assertEqual(snapshot_gcode.get_return_commands()[2], "G1 F6000")
        self.assertEqual(snapshot_gcode.get_return_commands()[3], "G1 Z-0.500")
        self.assertEqual(snapshot_gcode.get_return_commands()[4], "G1 F3600")
        self.assertEqual(snapshot_gcode.get_return_commands()[5], "SAVEDCOMMAND")
        self.assertEqual(snapshot_gcode.get_return_commands()[6], "M400")
        self.assertEqual(snapshot_gcode.get_return_commands()[7], "M114")
Пример #3
0
    def StartTimelapse(self, octoprintPrinter, octoprintPrinterProfile,
                       ffmpegPath, g90InfluencesExtruder):
        self.Reset()

        self.OctoprintPrinter = octoprintPrinter
        self.OctoprintPrinterProfile = octoprintPrinterProfile
        self.FfMpegPath = ffmpegPath
        self.PrintStartTime = time.time()
        self.Snapshot = Snapshot(self.Settings.CurrentSnapshot())
        self.Gcode = SnapshotGcodeGenerator(self.Settings,
                                            octoprintPrinterProfile)
        self.Printer = Printer(self.Settings.CurrentPrinter())
        self.Rendering = Rendering(self.Settings.CurrentRendering())
        self.CaptureSnapshot = CaptureSnapshot(
            self.Settings, self.DataFolder, printStartTime=self.PrintStartTime)
        self.Position = Position(self.Settings, octoprintPrinterProfile,
                                 g90InfluencesExtruder)
        self.State = TimelapseState.WaitingForTrigger

        self.IsTestMode = self.Settings.CurrentDebugProfile().is_test_mode
        # create the triggers
        # If the gcode trigger is enabled, add it
        if (self.Snapshot.gcode_trigger_enabled):
            #Add the trigger to the list
            self.Triggers.append(GcodeTrigger(self.Settings))
        # If the layer trigger is enabled, add it
        if (self.Snapshot.layer_trigger_enabled):
            self.Triggers.append(LayerTrigger(self.Settings))
        # If the layer trigger is enabled, add it
        if (self.Snapshot.timer_trigger_enabled):
            self.Triggers.append(TimerTrigger(self.Settings))
Пример #4
0
 def test_GetSnapshotGcode_Fixed_AbsoluteCoordintes_ExtruderRelative(self):
     """Test snapshot gcode in absolute coordinate system with relative extruder and fixed coordinate stabilization"""
     # adjust the settings for absolute position and create the snapshot gcode generator
     self.Settings.CurrentStabilization().x_type = "fixed_coordinate"
     self.Settings.CurrentStabilization().x_fixed_coordinate = 10
     self.Settings.CurrentStabilization().y_type = "fixed_coordinate"
     self.Settings.CurrentStabilization().y_fixed_coordinate = 20
     snapshotGcodeGenerator = SnapshotGcodeGenerator(
         self.Settings, self.CreateOctoprintPrinterProfile())
     self.Extruder.IsRetracted = True
     snapshotGcode = snapshotGcodeGenerator.CreateSnapshotGcode(
         0, 0, 0, False, True, self.Extruder, "SavedCommand")
     # verify the created gcode
     # this line should switch from absolute to relative for the ZHop
     self.assertTrue(snapshotGcode.GcodeCommands[0] == "G91")
     # this line should zhop by 0.500 mm
     self.assertTrue(snapshotGcode.GcodeCommands[1] == "G1 Z0.500 F7200")
     # this line should switch to absolute coordinates in prep for move
     self.assertTrue(snapshotGcode.GcodeCommands[2] == "G90")
     # this line should switch back to absolute coordinates
     self.assertTrue(
         snapshotGcode.GcodeCommands[3] == "G1 X10.000 Y20.000 F7200")
     # move back to the return position
     self.assertTrue(
         snapshotGcode.GcodeCommands[4] == "G1 X0.000 Y0.000 F7200")
     # change to relative coordinates
     self.assertTrue(snapshotGcode.GcodeCommands[5] == "G91")
     # this line should zhop by -0.500 mm
     self.assertTrue(snapshotGcode.GcodeCommands[6] == "G1 Z-0.500 F7200")
     # change back to the original coordinate system (absolute)
     self.assertTrue(snapshotGcode.GcodeCommands[7] == "G90")
     # the saved command
     self.assertTrue(snapshotGcode.GcodeCommands[8] == "SavedCommand")
     # verify the return commands
     self.assertTrue(
         snapshotGcode.ReturnCommands()[0] == "G1 X0.000 Y0.000 F7200")
     self.assertTrue(snapshotGcode.ReturnCommands()[1] == "G91")
     self.assertTrue(
         snapshotGcode.ReturnCommands()[2] == "G1 Z-0.500 F7200")
     self.assertTrue(snapshotGcode.ReturnCommands()[3] == "G90")
     self.assertTrue(snapshotGcode.ReturnCommands()[4] == "SavedCommand")
     # verify the snapshot commands
     self.assertTrue(snapshotGcode.SnapshotCommands()[0] == "G91")
     self.assertTrue(
         snapshotGcode.SnapshotCommands()[1] == "G1 Z0.500 F7200")
     self.assertTrue(snapshotGcode.SnapshotCommands()[2] == "G90")
     self.assertTrue(
         snapshotGcode.SnapshotCommands()[3] == "G1 X10.000 Y20.000 F7200")
     # verify the indexes of the generated gcode
     self.assertTrue(snapshotGcode.SnapshotIndex == 3)
     self.assertTrue(snapshotGcode.EndIndex() == 8)
     # verify the return coordinates
     self.assertTrue(snapshotGcode.ReturnX == 0)
     self.assertTrue(snapshotGcode.ReturnY == 0)
     self.assertTrue(snapshotGcode.ReturnZ == 0)
Пример #5
0
    def test_GetSnapshotGcode_RelativePath_RelativeCoordinates_ExtruderAbsolute_ZHop_Retraction(
            self):
        # test with relative paths, absolute extruder coordinates, retract and z hop
        # use relative coordinates for stabilizations
        self.Settings.current_stabilization().x_type = "relative_path"
        self.Settings.current_stabilization(
        ).x_relative_path = "50,100"  # 125,250
        self.Settings.current_stabilization().x_relative_path_loop = False
        self.Settings.current_stabilization(
        ).x_relative_path_invert_loop = False
        self.Settings.current_stabilization().y_type = "relative_path"
        self.Settings.current_stabilization(
        ).y_relative_path = "50,100"  # 100,200
        self.Settings.current_stabilization().y_relative_path_loop = False
        self.Settings.current_stabilization(
        ).y_relative_path_invert_loop = False
        self.Settings.current_snapshot().retract_before_move = True
        snapshot_gcode_generator = SnapshotGcodeGenerator(
            self.Settings, self.create_octoprint_printer_profile())

        snapshot_gcode = snapshot_gcode_generator.create_snapshot_gcode(
            10, 10, 10, 3600, True, False, self.Extruder, 0.5, "SavedCommand")
        # verify the created gcode
        self.assertEqual(snapshot_gcode.GcodeCommands[0], "M83")
        self.assertEqual(snapshot_gcode.GcodeCommands[1], "G1 F4000")
        self.assertEqual(snapshot_gcode.GcodeCommands[2], "G1 E-2.000")
        self.assertEqual(snapshot_gcode.GcodeCommands[3], "G1 F6000")
        self.assertEqual(snapshot_gcode.GcodeCommands[4], "G1 Z0.500")
        self.assertEqual(snapshot_gcode.GcodeCommands[5], "G90")
        self.assertEqual(snapshot_gcode.GcodeCommands[6], "G1 F6000")
        self.assertEqual(snapshot_gcode.GcodeCommands[7],
                         "G1 X125.000 Y100.000")
        self.assertEqual(snapshot_gcode.GcodeCommands[8], "M400")
        self.assertEqual(snapshot_gcode.GcodeCommands[9], "M114")
        self.assertEqual(snapshot_gcode.GcodeCommands[10],
                         "G1 X10.000 Y10.000")
        self.assertEqual(snapshot_gcode.GcodeCommands[11], "G91")
        self.assertEqual(snapshot_gcode.GcodeCommands[12], "G1 F6000")
        self.assertEqual(snapshot_gcode.GcodeCommands[13], "G1 Z-0.500")
        self.assertEqual(snapshot_gcode.GcodeCommands[14], "G1 F3000")
        self.assertEqual(snapshot_gcode.GcodeCommands[15], "G1 E2.000")
        self.assertEqual(snapshot_gcode.GcodeCommands[16], "M82")
        self.assertEqual(snapshot_gcode.GcodeCommands[17], "G1 F3600")
        self.assertEqual(snapshot_gcode.GcodeCommands[18], "SAVEDCOMMAND")
        self.assertEqual(snapshot_gcode.GcodeCommands[19], "M400")
        self.assertEqual(snapshot_gcode.GcodeCommands[20], "M114")

        # verify the indexes of the generated gcode
        self.assertTrue(snapshot_gcode.SnapshotIndex == 9)
        self.assertTrue(snapshot_gcode.end_index() == 20)
        # verify the return coordinates
        self.assertTrue(snapshot_gcode.ReturnX == 10)
        self.assertTrue(snapshot_gcode.ReturnY == 10)
        self.assertTrue(snapshot_gcode.ReturnZ == 10)
Пример #6
0
    def test_GetSnapshotGcode_Relative_RelativeCoordinates_AbsoluteExtruder_ZhopTooHigh(
            self):
        """Test snapshot gcode with relative stabilization, relative coordinates, absolute extruder, z is too high to hop, no retraction"""

        # test with relative coordinates, absolute extruder coordinates, z hop impossible (current z height will not allow this since it puts things outside of the bounds)
        # use relative coordinates for stabilizations
        self.Settings.CurrentStabilization().x_type = "relative"
        self.Settings.CurrentStabilization().x_relative = 50  #125
        self.Settings.CurrentStabilization().y_type = "relative"
        self.Settings.CurrentStabilization().y_relative = 100  #200
        self.Settings.CurrentSnapshot().retract_before_move = False
        snapshotGcodeGenerator = SnapshotGcodeGenerator(
            self.Settings, self.CreateOctoprintPrinterProfile())
        # create
        snapshotGcode = snapshotGcodeGenerator.CreateSnapshotGcode(
            10, 10, 200, True, False, self.Extruder, "SavedCommand")
        # verify the created gcode
        # this line should switch to absolute coordinates in prep for move
        self.assertTrue(snapshotGcode.GcodeCommands[0] == "G90")
        # this line should switch back to absolute coordinates
        self.assertTrue(
            snapshotGcode.GcodeCommands[1] == "G1 X125.000 Y200.000 F7200")
        # move back to the return position
        self.assertTrue(
            snapshotGcode.GcodeCommands[2] == "G1 X10.000 Y10.000 F7200")
        # change to relative coordinates
        self.assertTrue(snapshotGcode.GcodeCommands[3] == "G91")
        # the saved command
        self.assertTrue(snapshotGcode.GcodeCommands[4] == "SavedCommand")
        # verify the return commands
        self.assertTrue(
            snapshotGcode.ReturnCommands()[0] == "G1 X10.000 Y10.000 F7200")
        self.assertTrue(snapshotGcode.ReturnCommands()[1] == "G91")
        self.assertTrue(snapshotGcode.ReturnCommands()[2] == "SavedCommand")
        # verify the snapshot commands
        self.assertTrue(snapshotGcode.SnapshotCommands()[0] == "G90")
        self.assertTrue(snapshotGcode.SnapshotCommands()[1] ==
                        "G1 X125.000 Y200.000 F7200")
        # verify the indexes of the generated gcode
        self.assertTrue(snapshotGcode.SnapshotIndex == 1)
        self.assertTrue(snapshotGcode.EndIndex() == 4)
        # verify the return coordinates
        self.assertTrue(snapshotGcode.ReturnX == 10)
        self.assertTrue(snapshotGcode.ReturnY == 10)
        self.assertTrue(snapshotGcode.ReturnZ == 200)
Пример #7
0
    def test_GetSnapshotPosition_Absolute(self):
        """Test getting absolute snapshot positions for x and y"""
        # adjust the settings for absolute position and create the snapshot gcode generator
        self.Settings.CurrentStabilization().x_type = "fixed_coordinate"
        self.Settings.CurrentStabilization().x_fixed_coordinate = 10
        self.Settings.CurrentStabilization().y_type = "fixed_coordinate"
        self.Settings.CurrentStabilization().y_fixed_coordinate = 20
        snapshotGcodeGenerator = SnapshotGcodeGenerator(
            self.Settings, self.CreateOctoprintPrinterProfile())

        # get the coordinates and test
        coords = snapshotGcodeGenerator.GetSnapshotPosition(0, 0)
        self.assertTrue(coords["X"] == 10 and coords["Y"] == 20)
        # get the coordinates and test
        coords = snapshotGcodeGenerator.GetSnapshotPosition(1, 1)
        self.assertTrue(coords["X"] == 10 and coords["Y"] == 20)
        # get the coordinates and test
        coords = snapshotGcodeGenerator.GetSnapshotPosition(100, 100)
        self.assertTrue(coords["X"] == 10 and coords["Y"] == 20)
Пример #8
0
    def test_GetSnapshotPosition_BedRelative(self):
        """Test getting bed relative snapshot positions for x and y"""
        # adjust the settings for absolute position and create the snapshot gcode generator
        self.Settings.current_stabilization().x_type = "relative"
        self.Settings.current_stabilization().x_relative = 0
        self.Settings.current_stabilization().y_type = "relative"
        self.Settings.current_stabilization().y_relative = 100
        snapshot_gcode_generator = SnapshotGcodeGenerator(
            self.Settings, self.create_octoprint_printer_profile())

        # get the coordinates and test
        coords = snapshot_gcode_generator.get_snapshot_position(0, 0)
        self.assertTrue(coords["X"] == 0 and coords["Y"] == 200)
        # get the coordinates and test
        coords = snapshot_gcode_generator.get_snapshot_position(1, 1)
        self.assertTrue(coords["X"] == 0 and coords["Y"] == 200)
        # get the coordinates and test
        coords = snapshot_gcode_generator.get_snapshot_position(100, 100)
        self.assertTrue(coords["X"] == 0 and coords["Y"] == 200)
Пример #9
0
 def StartTimelapse(self, octoprintPrinter, octoprintPrinterProfile,
                    ffmpegPath, g90InfluencesExtruder):
     self._reset()
     self.HasSentInitialStatus = False
     self.OctoprintPrinter = octoprintPrinter
     self.OctoprintPrinterProfile = octoprintPrinterProfile
     self.FfMpegPath = ffmpegPath
     self.PrintStartTime = time.time()
     self.Snapshot = Snapshot(self.Settings.CurrentSnapshot())
     self.Gcode = SnapshotGcodeGenerator(self.Settings,
                                         octoprintPrinterProfile)
     self.Printer = Printer(self.Settings.CurrentPrinter())
     self.Rendering = Rendering(self.Settings.CurrentRendering())
     self.CaptureSnapshot = CaptureSnapshot(
         self.Settings, self.DataFolder, printStartTime=self.PrintStartTime)
     self.Position = Position(self.Settings, octoprintPrinterProfile,
                              g90InfluencesExtruder)
     self.State = TimelapseState.WaitingForTrigger
     self.IsTestMode = self.Settings.CurrentDebugProfile().is_test_mode
     self.Triggers.Create()
     # send an initial state message
     self._onTimelapseStart()
Пример #10
0
    def test_GetSnapshotGcode_Fixed_AbsoluteCoordintes_ExtruderRelative(self):
        """Test snapshot gcode in absolute coordinate system with relative extruder and fixed coordinate
        stabilization """
        # adjust the settings for absolute position and create the snapshot gcode generator
        self.Settings.current_stabilization().x_type = "fixed_coordinate"
        self.Settings.current_stabilization().x_fixed_coordinate = 10
        self.Settings.current_stabilization().y_type = "fixed_coordinate"
        self.Settings.current_stabilization().y_fixed_coordinate = 20
        snapshot_gcode_generator = SnapshotGcodeGenerator(
            self.Settings, self.create_octoprint_printer_profile())
        self.Extruder.is_retracted = lambda: True

        self.Position.update(Commands.parse("G90"))
        self.Position.update(Commands.parse("M83"))
        self.Position.update(Commands.parse("G28"))
        self.Position.update(Commands.parse("G0 X95 Y95 Z0.2 F3600"))
        parsed_command = Commands.parse("G0 X100 Y100")
        self.Position.update(parsed_command)
        snapshot_gcode = snapshot_gcode_generator.create_snapshot_gcode(
            self.Position, None, parsed_command)
        gcode_commands = snapshot_gcode.snapshot_gcode()

        # verify the created gcodegcode_commands
        self.assertEqual(gcode_commands[0], "G1 E-4.00000 F4800")
        self.assertEqual(gcode_commands[1], "G1 X10.000 Y20.000 F10800")
        self.assertEqual(gcode_commands[2], "G1 X100.000 Y100.000")
        self.assertEqual(gcode_commands[3], "G1 E4.00000 F3000")
        self.assertEqual(gcode_commands[4], "G1 F3600")
        self.assertEqual(gcode_commands[5], parsed_command.gcode)

        # verify the return coordinates
        self.assertEqual(snapshot_gcode.ReturnX, 100)
        self.assertEqual(snapshot_gcode.ReturnY, 100)
        self.assertEqual(snapshot_gcode.ReturnZ, 0.2)

        self.assertEqual(snapshot_gcode.X, 10)
        self.assertEqual(snapshot_gcode.Y, 20)
        self.assertEqual(snapshot_gcode.Z, None)
Пример #11
0
 def test_GetSnapshotGcode_Fixed_AbsoluteCoordintes_ExtruderRelative(self):
     """Test snapshot gcode in absolute coordinate system with relative extruder and fixed coordinate
     stabilization """
     # adjust the settings for absolute position and create the snapshot gcode generator
     self.Settings.current_stabilization().x_type = "fixed_coordinate"
     self.Settings.current_stabilization().x_fixed_coordinate = 10
     self.Settings.current_stabilization().y_type = "fixed_coordinate"
     self.Settings.current_stabilization().y_fixed_coordinate = 20
     snapshot_gcode_generator = SnapshotGcodeGenerator(
         self.Settings, self.create_octoprint_printer_profile())
     self.Extruder.is_retracted = lambda: True
     snapshot_gcode = snapshot_gcode_generator.create_snapshot_gcode(
         0, 0, 0, 3600, False, True, self.Extruder, 0.5, "SavedCommand")
     # verify the created gcode
     self.assertEqual(snapshot_gcode.GcodeCommands[0], "G91")
     self.assertEqual(snapshot_gcode.GcodeCommands[1], "G1 F6000")
     self.assertEqual(snapshot_gcode.GcodeCommands[2], "G1 Z0.500")
     self.assertEqual(snapshot_gcode.GcodeCommands[3], "G90")
     self.assertEqual(snapshot_gcode.GcodeCommands[4], "G1 F6000")
     self.assertEqual(snapshot_gcode.GcodeCommands[5], "G1 X10.000 Y20.000")
     self.assertEqual(snapshot_gcode.GcodeCommands[6], "M400")
     self.assertEqual(snapshot_gcode.GcodeCommands[7], "M114")
     self.assertEqual(snapshot_gcode.GcodeCommands[8], "G1 X0.000 Y0.000")
     self.assertEqual(snapshot_gcode.GcodeCommands[9], "G91")
     self.assertEqual(snapshot_gcode.GcodeCommands[10], "G1 F6000")
     self.assertEqual(snapshot_gcode.GcodeCommands[11], "G1 Z-0.500")
     self.assertEqual(snapshot_gcode.GcodeCommands[12], "G90")
     self.assertEqual(snapshot_gcode.GcodeCommands[13], "G1 F3600")
     self.assertEqual(snapshot_gcode.GcodeCommands[14], "SAVEDCOMMAND")
     self.assertEqual(snapshot_gcode.GcodeCommands[15], "M400")
     self.assertEqual(snapshot_gcode.GcodeCommands[16], "M114")
     # verify the indexes of the generated gcode
     self.assertEqual(snapshot_gcode.SnapshotIndex, 7)
     self.assertEqual(snapshot_gcode.end_index(), 16)
     # verify the return coordinates
     self.assertEqual(snapshot_gcode.ReturnX, 0)
     self.assertEqual(snapshot_gcode.ReturnY, 0)
     self.assertEqual(snapshot_gcode.ReturnZ, 0)
Пример #12
0
    def test_GetSnapshotGcode_Relative_RelativeCoordinates_AbsoluteExtruder_ZhopTooHigh(
            self):
        """Test snapshot gcode with relative stabilization, relative coordinates, absolute extruder, z is too high to
        hop, no retraction """

        # test with relative coordinates, absolute extruder coordinates, z hop impossible (current z height will not
        # allow this since it puts things outside of the bounds) use relative coordinates for stabilizations
        self.Settings.current_stabilization().x_type = "relative"
        self.Settings.current_stabilization().x_relative = 50  # 125
        self.Settings.current_stabilization().y_type = "relative"
        self.Settings.current_stabilization().y_relative = 100  # 200
        self.Settings.current_snapshot().retract_before_move = False
        snapshot_gcode_generator = SnapshotGcodeGenerator(
            self.Settings, self.create_octoprint_printer_profile())
        # create
        snapshot_gcode = snapshot_gcode_generator.create_snapshot_gcode(
            10, 10, 200, 3600, True, False, self.Extruder, 0.5, "SavedCommand")
        # verify the created gcode
        self.assertEqual(snapshot_gcode.GcodeCommands[0], "G90")
        self.assertEqual(snapshot_gcode.GcodeCommands[1], "G1 F6000")
        self.assertEqual(snapshot_gcode.GcodeCommands[2],
                         "G1 X125.000 Y200.000")
        self.assertEqual(snapshot_gcode.GcodeCommands[3], "M400")
        self.assertEqual(snapshot_gcode.GcodeCommands[4], "M114")
        self.assertEqual(snapshot_gcode.GcodeCommands[5], "G1 X10.000 Y10.000")
        self.assertEqual(snapshot_gcode.GcodeCommands[6], "G91")
        self.assertEqual(snapshot_gcode.GcodeCommands[7], "G1 F3600")
        self.assertEqual(snapshot_gcode.GcodeCommands[8], "SAVEDCOMMAND")
        self.assertEqual(snapshot_gcode.GcodeCommands[9], "M400")
        self.assertEqual(snapshot_gcode.GcodeCommands[10], "M114")

        # verify the indexes of the generated gcode
        self.assertTrue(snapshot_gcode.SnapshotIndex == 4)
        self.assertTrue(snapshot_gcode.end_index() == 10)
        # verify the return coordinates
        self.assertTrue(snapshot_gcode.ReturnX == 10)
        self.assertTrue(snapshot_gcode.ReturnY == 10)
        self.assertTrue(snapshot_gcode.ReturnZ == 200)
Пример #13
0
    def test_GetSnapshotPosition_AbsolutePath(self):
        """Test getting absolute path snapshot positions for x and y"""
        # adjust the settings for absolute position and create the snapshot gcode generator
        self.Settings.CurrentStabilization().x_type = "fixed_path"
        self.Settings.CurrentStabilization().x_fixed_path = "0,1,2,3,4,5"
        self.Settings.CurrentStabilization().y_type = "fixed_path"
        self.Settings.CurrentStabilization().y_fixed_path = "5,4,3,2,1,0"

        # test with no loop
        self.Settings.CurrentStabilization().x_fixed_path_loop = False
        self.Settings.CurrentStabilization().x_fixed_path_invert_loop = False
        self.Settings.CurrentStabilization().y_fixed_path_loop = False
        self.Settings.CurrentStabilization().y_fixed_path_invert_loop = False
        snapshotGcodeGenerator = SnapshotGcodeGenerator(
            self.Settings, self.CreateOctoprintPrinterProfile())
        coords = snapshotGcodeGenerator.GetSnapshotPosition(0, 0)
        self.assertTrue(coords["X"] == 0 and coords["Y"] == 5)
        coords = snapshotGcodeGenerator.GetSnapshotPosition(0, 0)
        self.assertTrue(coords["X"] == 1 and coords["Y"] == 4)
        coords = snapshotGcodeGenerator.GetSnapshotPosition(1, 0)
        self.assertTrue(coords["X"] == 2 and coords["Y"] == 3)
        coords = snapshotGcodeGenerator.GetSnapshotPosition(1, 1)
        self.assertTrue(coords["X"] == 3 and coords["Y"] == 2)
        coords = snapshotGcodeGenerator.GetSnapshotPosition(0, 1)
        self.assertTrue(coords["X"] == 4 and coords["Y"] == 1)
        coords = snapshotGcodeGenerator.GetSnapshotPosition(0, 0)
        self.assertTrue(coords["X"] == 5 and coords["Y"] == 0)
        coords = snapshotGcodeGenerator.GetSnapshotPosition(0, 0)
        self.assertTrue(coords["X"] == 5 and coords["Y"] == 0)
        coords = snapshotGcodeGenerator.GetSnapshotPosition(0, 0)
        self.assertTrue(coords["X"] == 5 and coords["Y"] == 0)

        # test with loop, no invert
        self.Settings.CurrentStabilization().x_fixed_path_loop = True
        self.Settings.CurrentStabilization().x_fixed_path_invert_loop = False
        self.Settings.CurrentStabilization().y_fixed_path_loop = True
        self.Settings.CurrentStabilization().y_fixed_path_invert_loop = False
        snapshotGcodeGenerator = SnapshotGcodeGenerator(
            self.Settings, self.CreateOctoprintPrinterProfile())
        coords = snapshotGcodeGenerator.GetSnapshotPosition(0, 0)
        self.assertTrue(coords["X"] == 0 and coords["Y"] == 5)
        coords = snapshotGcodeGenerator.GetSnapshotPosition(0, 0)
        self.assertTrue(coords["X"] == 1 and coords["Y"] == 4)
        coords = snapshotGcodeGenerator.GetSnapshotPosition(1, 0)
        self.assertTrue(coords["X"] == 2 and coords["Y"] == 3)
        coords = snapshotGcodeGenerator.GetSnapshotPosition(1, 1)
        self.assertTrue(coords["X"] == 3 and coords["Y"] == 2)
        coords = snapshotGcodeGenerator.GetSnapshotPosition(0, 1)
        self.assertTrue(coords["X"] == 4 and coords["Y"] == 1)
        coords = snapshotGcodeGenerator.GetSnapshotPosition(0, 0)
        self.assertTrue(coords["X"] == 5 and coords["Y"] == 0)
        coords = snapshotGcodeGenerator.GetSnapshotPosition(0, 0)
        self.assertTrue(coords["X"] == 0 and coords["Y"] == 5)
        coords = snapshotGcodeGenerator.GetSnapshotPosition(0, 0)
        self.assertTrue(coords["X"] == 1 and coords["Y"] == 4)

        # test with loop and invert
        self.Settings.CurrentStabilization().x_fixed_path_loop = True
        self.Settings.CurrentStabilization().x_fixed_path_invert_loop = True
        self.Settings.CurrentStabilization().y_fixed_path_loop = True
        self.Settings.CurrentStabilization().y_fixed_path_invert_loop = True
        snapshotGcodeGenerator = SnapshotGcodeGenerator(
            self.Settings, self.CreateOctoprintPrinterProfile())
        coords = snapshotGcodeGenerator.GetSnapshotPosition(0, 0)
        self.assertTrue(coords["X"] == 0 and coords["Y"] == 5)
        coords = snapshotGcodeGenerator.GetSnapshotPosition(0, 0)
        self.assertTrue(coords["X"] == 1 and coords["Y"] == 4)
        coords = snapshotGcodeGenerator.GetSnapshotPosition(1, 0)
        self.assertTrue(coords["X"] == 2 and coords["Y"] == 3)
        coords = snapshotGcodeGenerator.GetSnapshotPosition(1, 1)
        self.assertTrue(coords["X"] == 3 and coords["Y"] == 2)
        coords = snapshotGcodeGenerator.GetSnapshotPosition(0, 1)
        self.assertTrue(coords["X"] == 4 and coords["Y"] == 1)
        coords = snapshotGcodeGenerator.GetSnapshotPosition(0, 0)
        self.assertTrue(coords["X"] == 5 and coords["Y"] == 0)
        coords = snapshotGcodeGenerator.GetSnapshotPosition(0, 0)
        self.assertTrue(coords["X"] == 4 and coords["Y"] == 1)
        coords = snapshotGcodeGenerator.GetSnapshotPosition(0, 0)
        self.assertTrue(coords["X"] == 3 and coords["Y"] == 2)
        coords = snapshotGcodeGenerator.GetSnapshotPosition(0, 0)
        self.assertTrue(coords["X"] == 2 and coords["Y"] == 3)
        coords = snapshotGcodeGenerator.GetSnapshotPosition(0, 0)
        self.assertTrue(coords["X"] == 1 and coords["Y"] == 4)
        coords = snapshotGcodeGenerator.GetSnapshotPosition(0, 0)
        self.assertTrue(coords["X"] == 0 and coords["Y"] == 5)
        coords = snapshotGcodeGenerator.GetSnapshotPosition(0, 0)
        self.assertTrue(coords["X"] == 1 and coords["Y"] == 4)
Пример #14
0
    def test_GetSnapshotGcode_FixedPath_RelativeCoordinates_ExtruderAbsolute_ZHop_AlreadyRetracted(
            self):
        # test with relative paths, absolute extruder coordinates, retract and z hop
        # use relative coordinates for stabilizations
        self.Settings.CurrentStabilization().x_type = "fixed_path"
        self.Settings.CurrentStabilization().x_fixed_path = "50,100"  #125,250
        self.Settings.CurrentStabilization().x_fixed_path_loop = False
        self.Settings.CurrentStabilization().x_fixed_path_invert_loop = False
        self.Settings.CurrentStabilization().y_type = "fixed_path"
        self.Settings.CurrentStabilization().y_fixed_path = "50,100"  #100,200
        self.Settings.CurrentStabilization().y_fixed_path_loop = False
        self.Settings.CurrentStabilization().y_fixed_path_invert_loop = False
        self.Settings.CurrentSnapshot().retract_before_move = True
        snapshotGcodeGenerator = SnapshotGcodeGenerator(
            self.Settings, self.CreateOctoprintPrinterProfile())
        self.Extruder.IsRetracted = True
        snapshotGcode = snapshotGcodeGenerator.CreateSnapshotGcode(
            100, 50, 0, True, False, self.Extruder, "SavedCommand")
        # verify the created gcode
        # this line should switch to absolute coordinates in prep for move
        self.assertTrue(snapshotGcode.GcodeCommands[0] == "G1 Z0.500 F7200")
        self.assertTrue(snapshotGcode.GcodeCommands[1] == "G90")
        self.assertTrue(
            snapshotGcode.GcodeCommands[2] == "G1 X50.000 Y50.000 F7200")
        # move back to the return position
        self.assertTrue(
            snapshotGcode.GcodeCommands[3] == "G1 X100.000 Y50.000 F7200")
        # change to relative coordinates
        self.assertTrue(snapshotGcode.GcodeCommands[4] == "G91")
        self.assertTrue(snapshotGcode.GcodeCommands[5] == "G1 Z-0.500 F7200")
        # the saved command
        self.assertTrue(snapshotGcode.GcodeCommands[6] == "SavedCommand")
        # verify the return commands
        self.assertTrue(
            snapshotGcode.ReturnCommands()[0] == "G1 X100.000 Y50.000 F7200")
        self.assertTrue(snapshotGcode.ReturnCommands()[1] == "G91")
        self.assertTrue(
            snapshotGcode.ReturnCommands()[2] == "G1 Z-0.500 F7200")
        self.assertTrue(snapshotGcode.ReturnCommands()[3] == "SavedCommand")
        # verify the snapshot commands
        self.assertTrue(
            snapshotGcode.SnapshotCommands()[0] == "G1 Z0.500 F7200")
        self.assertTrue(snapshotGcode.SnapshotCommands()[1] == "G90")
        self.assertTrue(
            snapshotGcode.SnapshotCommands()[2] == "G1 X50.000 Y50.000 F7200")

        # verify the indexes of the generated gcode
        self.assertTrue(snapshotGcode.SnapshotIndex == 2)
        self.assertTrue(snapshotGcode.EndIndex() == 6)
        # verify the return coordinates
        self.assertTrue(snapshotGcode.ReturnX == 100)
        self.assertTrue(snapshotGcode.ReturnY == 50)
        self.assertTrue(snapshotGcode.ReturnZ == 0)

        # Get the next coordinate in the path
        snapshotGcode = snapshotGcodeGenerator.CreateSnapshotGcode(
            101, 51, 0, True, False, self.Extruder, "SavedCommand")
        # verify the created gcode
        # this line should switch to absolute coordinates in prep for move
        self.assertTrue(snapshotGcode.GcodeCommands[0] == "G1 Z0.500 F7200")
        self.assertTrue(snapshotGcode.GcodeCommands[1] == "G90")
        self.assertTrue(
            snapshotGcode.GcodeCommands[2] == "G1 X100.000 Y100.000 F7200")
        # move back to the return position
        self.assertTrue(
            snapshotGcode.GcodeCommands[3] == "G1 X101.000 Y51.000 F7200")
        # change to relative coordinates
        self.assertTrue(snapshotGcode.GcodeCommands[4] == "G91")
        self.assertTrue(snapshotGcode.GcodeCommands[5] == "G1 Z-0.500 F7200")
        # the saved command
        self.assertTrue(snapshotGcode.GcodeCommands[6] == "SavedCommand")
        # verify the return commands
        self.assertTrue(
            snapshotGcode.ReturnCommands()[0] == "G1 X101.000 Y51.000 F7200")
        self.assertTrue(snapshotGcode.ReturnCommands()[1] == "G91")
        self.assertTrue(
            snapshotGcode.ReturnCommands()[2] == "G1 Z-0.500 F7200")
        self.assertTrue(snapshotGcode.ReturnCommands()[3] == "SavedCommand")
        # verify the snapshot commands
        self.assertTrue(
            snapshotGcode.SnapshotCommands()[0] == "G1 Z0.500 F7200")
        self.assertTrue(snapshotGcode.SnapshotCommands()[1] == "G90")
        self.assertTrue(snapshotGcode.SnapshotCommands()[2] ==
                        "G1 X100.000 Y100.000 F7200")
        # verify the indexes of the generated gcode
        self.assertTrue(snapshotGcode.SnapshotIndex == 2)
        self.assertTrue(snapshotGcode.EndIndex() == 6)
        # verify the return coordinates
        self.assertTrue(snapshotGcode.ReturnX == 101)
        self.assertTrue(snapshotGcode.ReturnY == 51)
        self.assertTrue(snapshotGcode.ReturnZ == 0)
        # test the second coordinate in the path
        snapshotGcode = snapshotGcodeGenerator.CreateSnapshotGcode(
            10, 10, 10, True, False, self.Extruder, "SavedCommand")
Пример #15
0
    def test_GetSnapshotPosition_BedRelativePath(self):
        """Test getting bed relative path snapshot positions for x and y"""
        # adjust the settings for absolute position and create the snapshot gcode generator
        self.Settings.CurrentStabilization().x_type = "relative_path"
        self.Settings.CurrentStabilization().x_relative_path = "0,25,50,75,100"
        self.Settings.CurrentStabilization().y_type = "relative_path"
        self.Settings.CurrentStabilization().y_relative_path = "100,75,50,25,0"

        # test with no loop
        self.Settings.CurrentStabilization().x_relative_path_loop = False
        self.Settings.CurrentStabilization(
        ).x_relative_path_invert_loop = False
        self.Settings.CurrentStabilization().y_relative_path_loop = False
        self.Settings.CurrentStabilization(
        ).y_relative_path_invert_loop = False
        snapshotGcodeGenerator = SnapshotGcodeGenerator(
            self.Settings, self.CreateOctoprintPrinterProfile())
        coords = snapshotGcodeGenerator.GetSnapshotPosition(0, 0)
        self.assertTrue(coords["X"] == 0 and coords["Y"] == 200)
        coords = snapshotGcodeGenerator.GetSnapshotPosition(0, 0)
        self.assertTrue(coords["X"] == 62.5 and coords["Y"] == 150)
        coords = snapshotGcodeGenerator.GetSnapshotPosition(1, 0)
        self.assertTrue(coords["X"] == 125 and coords["Y"] == 100)
        coords = snapshotGcodeGenerator.GetSnapshotPosition(1, 1)
        self.assertTrue(coords["X"] == 187.5 and coords["Y"] == 50)
        coords = snapshotGcodeGenerator.GetSnapshotPosition(0, 1)
        self.assertTrue(coords["X"] == 250 and coords["Y"] == 0)
        coords = snapshotGcodeGenerator.GetSnapshotPosition(0, 0)
        self.assertTrue(coords["X"] == 250 and coords["Y"] == 0)
        coords = snapshotGcodeGenerator.GetSnapshotPosition(0, 0)
        self.assertTrue(coords["X"] == 250 and coords["Y"] == 0)

        # test with loop, no invert
        self.Settings.CurrentStabilization().x_relative_path_loop = True
        self.Settings.CurrentStabilization(
        ).x_relative_path_invert_loop = False
        self.Settings.CurrentStabilization().y_relative_path_loop = True
        self.Settings.CurrentStabilization(
        ).y_relative_path_invert_loop = False
        snapshotGcodeGenerator = SnapshotGcodeGenerator(
            self.Settings, self.CreateOctoprintPrinterProfile())
        coords = snapshotGcodeGenerator.GetSnapshotPosition(0, 0)
        self.assertTrue(coords["X"] == 0 and coords["Y"] == 200)
        coords = snapshotGcodeGenerator.GetSnapshotPosition(0, 0)
        self.assertTrue(coords["X"] == 62.5 and coords["Y"] == 150)
        coords = snapshotGcodeGenerator.GetSnapshotPosition(1, 0)
        self.assertTrue(coords["X"] == 125 and coords["Y"] == 100)
        coords = snapshotGcodeGenerator.GetSnapshotPosition(1, 1)
        self.assertTrue(coords["X"] == 187.5 and coords["Y"] == 50)
        coords = snapshotGcodeGenerator.GetSnapshotPosition(0, 1)
        self.assertTrue(coords["X"] == 250 and coords["Y"] == 0)
        coords = snapshotGcodeGenerator.GetSnapshotPosition(0, 0)
        self.assertTrue(coords["X"] == 0 and coords["Y"] == 200)
        coords = snapshotGcodeGenerator.GetSnapshotPosition(0, 0)
        self.assertTrue(coords["X"] == 62.5 and coords["Y"] == 150)

        # test with loop and invert
        self.Settings.CurrentStabilization().x_relative_path_loop = True
        self.Settings.CurrentStabilization().x_relative_path_invert_loop = True
        self.Settings.CurrentStabilization().y_relative_path_loop = True
        self.Settings.CurrentStabilization().y_relative_path_invert_loop = True
        snapshotGcodeGenerator = SnapshotGcodeGenerator(
            self.Settings, self.CreateOctoprintPrinterProfile())
        coords = snapshotGcodeGenerator.GetSnapshotPosition(0, 0)
        self.assertTrue(coords["X"] == 0 and coords["Y"] == 200)
        coords = snapshotGcodeGenerator.GetSnapshotPosition(0, 0)
        self.assertTrue(coords["X"] == 62.5 and coords["Y"] == 150)
        coords = snapshotGcodeGenerator.GetSnapshotPosition(1, 0)
        self.assertTrue(coords["X"] == 125 and coords["Y"] == 100)
        coords = snapshotGcodeGenerator.GetSnapshotPosition(1, 1)
        self.assertTrue(coords["X"] == 187.5 and coords["Y"] == 50)
        coords = snapshotGcodeGenerator.GetSnapshotPosition(0, 1)
        self.assertTrue(coords["X"] == 250 and coords["Y"] == 0)
        coords = snapshotGcodeGenerator.GetSnapshotPosition(0, 0)
        self.assertTrue(coords["X"] == 187.5 and coords["Y"] == 50)
        coords = snapshotGcodeGenerator.GetSnapshotPosition(0, 0)
        self.assertTrue(coords["X"] == 125 and coords["Y"] == 100)
Пример #16
0
    def test_GetSnapshotGcode_FixedPath_RelativeCoordinates_ExtruderAbsolute_ZHop_AlreadyRetracted(self):
        # test with relative paths, absolute extruder coordinates, retract and z hop
        # use relative coordinates for stabilizations
        self.Settings.current_stabilization().x_type = "fixed_path"
        self.Settings.current_stabilization().x_fixed_path = "50,100"  # 125,250
        self.Settings.current_stabilization().x_fixed_path_loop = False
        self.Settings.current_stabilization().x_fixed_path_invert_loop = False
        self.Settings.current_stabilization().y_type = "fixed_path"
        self.Settings.current_stabilization().y_fixed_path = "50,100"  # 100,200
        self.Settings.current_stabilization().y_fixed_path_loop = False
        self.Settings.current_stabilization().y_fixed_path_invert_loop = False
        self.Settings.current_snapshot().retract_before_move = True
        snapshot_gcode_generator = SnapshotGcodeGenerator(
            self.Settings, self.create_octoprint_printer_profile())
        self.Extruder.is_retracted = lambda: True
        snapshot_gcode = snapshot_gcode_generator.create_snapshot_gcode(
            100, 50, 0, 3600, True, False, self.Extruder, 0.5, "SavedCommand")

        # verify the created gcode
        self.assertEqual(snapshot_gcode.GcodeCommands[0], "G1 F6000")
        self.assertEqual(snapshot_gcode.GcodeCommands[1], "G1 Z0.500")
        self.assertEqual(snapshot_gcode.GcodeCommands[2], "G90")
        self.assertEqual(snapshot_gcode.GcodeCommands[3], "G1 F6000")
        self.assertEqual(snapshot_gcode.GcodeCommands[4], "G1 X50.000 Y50.000")
        self.assertEqual(snapshot_gcode.GcodeCommands[5], "M400")
        self.assertEqual(snapshot_gcode.GcodeCommands[6], "M114")
        self.assertEqual(snapshot_gcode.GcodeCommands[7], "G1 X100.000 Y50.000")
        self.assertEqual(snapshot_gcode.GcodeCommands[8], "G91")
        self.assertEqual(snapshot_gcode.GcodeCommands[9], "G1 F6000")
        self.assertEqual(snapshot_gcode.GcodeCommands[10], "G1 Z-0.500")
        self.assertEqual(snapshot_gcode.GcodeCommands[11], "G1 F3600")
        self.assertEqual(snapshot_gcode.GcodeCommands[12], "SAVEDCOMMAND")
        self.assertEqual(snapshot_gcode.GcodeCommands[13], "M400")
        self.assertEqual(snapshot_gcode.GcodeCommands[14], "M114")

        # verify the indexes of the generated gcode
        self.assertEqual(snapshot_gcode.SnapshotIndex, 6)
        self.assertEqual(snapshot_gcode.end_index(), 14)
        # verify the return coordinates
        self.assertEqual(snapshot_gcode.ReturnX, 100)
        self.assertEqual(snapshot_gcode.ReturnY, 50)
        self.assertEqual(snapshot_gcode.ReturnZ, 0)

        # Get the next coordinate in the path
        snapshot_gcode = snapshot_gcode_generator.create_snapshot_gcode(
            101, 51, 0, 3600, True, False, self.Extruder, 0.5, "SavedCommand")
        # verify the created gcode
        self.assertEqual(snapshot_gcode.GcodeCommands[0], "G1 F6000")
        self.assertEqual(snapshot_gcode.GcodeCommands[1], "G1 Z0.500")
        self.assertEqual(snapshot_gcode.GcodeCommands[2], "G90")
        self.assertEqual(snapshot_gcode.GcodeCommands[3], "G1 F6000")
        self.assertEqual(snapshot_gcode.GcodeCommands[4], "G1 X100.000 Y100.000")
        self.assertEqual(snapshot_gcode.GcodeCommands[5], "M400")
        self.assertEqual(snapshot_gcode.GcodeCommands[6], "M114")
        self.assertEqual(snapshot_gcode.GcodeCommands[7], "G1 X101.000 Y51.000")
        self.assertEqual(snapshot_gcode.GcodeCommands[8], "G91")
        self.assertEqual(snapshot_gcode.GcodeCommands[9], "G1 F6000")
        self.assertEqual(snapshot_gcode.GcodeCommands[10], "G1 Z-0.500")
        self.assertEqual(snapshot_gcode.GcodeCommands[11], "G1 F3600")
        self.assertEqual(snapshot_gcode.GcodeCommands[12], "SAVEDCOMMAND")
        self.assertEqual(snapshot_gcode.GcodeCommands[13], "M400")
        self.assertEqual(snapshot_gcode.GcodeCommands[14], "M114")

        # verify the indexes of the generated gcode
        self.assertEqual(snapshot_gcode.SnapshotIndex, 6)
        self.assertEqual(snapshot_gcode.end_index(), 14)
        # verify the return coordinates
        self.assertEqual(snapshot_gcode.ReturnX, 101)
        self.assertEqual(snapshot_gcode.ReturnY, 51)
        self.assertEqual(snapshot_gcode.ReturnZ, 0)