TimeLapse.py 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. # Created by Wayne Porter
  2. from ..Script import Script
  3. class TimeLapse(Script):
  4. def __init__(self):
  5. super().__init__()
  6. def getSettingDataString(self):
  7. return """{
  8. "name": "Time Lapse",
  9. "key": "TimeLapse",
  10. "metadata": {},
  11. "version": 2,
  12. "settings":
  13. {
  14. "trigger_command":
  15. {
  16. "label": "Trigger camera command",
  17. "description": "Gcode command used to trigger camera.",
  18. "type": "str",
  19. "default_value": "M240"
  20. },
  21. "pause_length":
  22. {
  23. "label": "Pause length",
  24. "description": "How long to wait (in ms) after camera was triggered.",
  25. "type": "int",
  26. "default_value": 700,
  27. "minimum_value": 0,
  28. "unit": "ms"
  29. },
  30. "park_print_head":
  31. {
  32. "label": "Park Print Head",
  33. "description": "Park the print head out of the way. Assumes absolute positioning.",
  34. "type": "bool",
  35. "default_value": true
  36. },
  37. "head_park_x":
  38. {
  39. "label": "Park Print Head X",
  40. "description": "What X location does the head move to for photo.",
  41. "unit": "mm",
  42. "type": "float",
  43. "default_value": 0,
  44. "enabled": "park_print_head"
  45. },
  46. "head_park_y":
  47. {
  48. "label": "Park Print Head Y",
  49. "description": "What Y location does the head move to for photo.",
  50. "unit": "mm",
  51. "type": "float",
  52. "default_value": 190,
  53. "enabled": "park_print_head"
  54. },
  55. "park_feed_rate":
  56. {
  57. "label": "Park Feed Rate",
  58. "description": "How fast does the head move to the park coordinates.",
  59. "unit": "mm/s",
  60. "type": "float",
  61. "default_value": 9000,
  62. "enabled": "park_print_head"
  63. }
  64. }
  65. }"""
  66. def execute(self, data):
  67. feed_rate = self.getSettingValueByKey("park_feed_rate")
  68. park_print_head = self.getSettingValueByKey("park_print_head")
  69. x_park = self.getSettingValueByKey("head_park_x")
  70. y_park = self.getSettingValueByKey("head_park_y")
  71. trigger_command = self.getSettingValueByKey("trigger_command")
  72. pause_length = self.getSettingValueByKey("pause_length")
  73. gcode_to_append = ";TimeLapse Begin\n"
  74. if park_print_head:
  75. gcode_to_append += self.putValue(G = 1, F = feed_rate, X = x_park, Y = y_park) + " ;Park print head\n"
  76. gcode_to_append += self.putValue(M = 400) + " ;Wait for moves to finish\n"
  77. gcode_to_append += trigger_command + " ;Snap Photo\n"
  78. gcode_to_append += self.putValue(G = 4, P = pause_length) + " ;Wait for camera\n"
  79. gcode_to_append += ";TimeLapse End\n"
  80. for layer in data:
  81. # Check that a layer is being printed
  82. lines = layer.split("\n")
  83. for line in lines:
  84. if ";LAYER:" in line:
  85. index = data.index(layer)
  86. layer += gcode_to_append
  87. data[index] = layer
  88. break
  89. return data