BedLevelMachineAction.py 3.4 KB

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