BedLevelMachineAction.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # Copyright (c) 2018 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from typing import List
  4. from cura.MachineAction import MachineAction
  5. from cura.PrinterOutput.PrinterOutputDevice import PrinterOutputDevice
  6. from UM.FlameProfiler import pyqtSlot
  7. from UM.Application import Application
  8. from UM.i18n import i18nCatalog
  9. from UM.Logger import Logger
  10. catalog = i18nCatalog("cura")
  11. ## A simple action to handle manual bed leveling procedure for printers that don't have it on the firmware.
  12. # This is currently only used by the Ultimaker Original+
  13. class BedLevelMachineAction(MachineAction):
  14. def __init__(self):
  15. super().__init__("BedLevel", catalog.i18nc("@action", "Level build plate"))
  16. self._qml_url = "BedLevelMachineAction.qml"
  17. self._bed_level_position = 0
  18. def _execute(self):
  19. pass
  20. def _reset(self):
  21. self._bed_level_position = 0
  22. pass
  23. @pyqtSlot()
  24. def startBedLeveling(self):
  25. self._bed_level_position = 0
  26. printer_output_devices = self._getPrinterOutputDevices()
  27. if not printer_output_devices:
  28. Logger.log("e", "Can't start bed levelling. The printer connection seems to have been lost.")
  29. return
  30. printer = printer_output_devices[0].activePrinter
  31. printer.homeBed()
  32. printer.moveHead(0, 0, 3)
  33. printer.homeHead()
  34. printer.homeBed()
  35. def _getPrinterOutputDevices(self) -> List[PrinterOutputDevice]:
  36. return [printer_output_device for printer_output_device in Application.getInstance().getOutputDeviceManager().getOutputDevices() if isinstance(printer_output_device, PrinterOutputDevice)]
  37. @pyqtSlot()
  38. def moveToNextLevelPosition(self):
  39. output_devices = self._getPrinterOutputDevices()
  40. if not output_devices: #No output devices. Can't move.
  41. Logger.log("e", "Can't move to the next position. The printer connection seems to have been lost.")
  42. return
  43. printer = output_devices[0].activePrinter
  44. if self._bed_level_position == 0:
  45. printer.moveHead(0, 0, 3)
  46. printer.homeHead()
  47. printer.moveHead(0, 0, 3)
  48. printer.moveHead(Application.getInstance().getGlobalContainerStack().getProperty("machine_width", "value") - 10, 0, 0)
  49. printer.moveHead(0, 0, -3)
  50. printer.homeBed()
  51. self._bed_level_position += 1
  52. elif self._bed_level_position == 1:
  53. printer.moveHead(0, 0, 3)
  54. printer.moveHead(-Application.getInstance().getGlobalContainerStack().getProperty("machine_width", "value" ) / 2, Application.getInstance().getGlobalContainerStack().getProperty("machine_depth", "value") - 10, 0)
  55. printer.moveHead(0, 0, -3)
  56. self._bed_level_position += 1
  57. elif self._bed_level_position == 2:
  58. printer.moveHead(0, 0, 3)
  59. printer.moveHead(-Application.getInstance().getGlobalContainerStack().getProperty("machine_width", "value") / 2 + 10, -(Application.getInstance().getGlobalContainerStack().getProperty("machine_depth", "value") + 10), 0)
  60. printer.moveHead(0, 0, -3)
  61. self._bed_level_position += 1
  62. elif self._bed_level_position >= 3:
  63. output_devices[0].sendCommand("M18") # Turn off all motors so the user can move the axes
  64. self.setFinished()