TimeLapse.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. last_x = 0
  75. last_y = 0
  76. if park_print_head:
  77. gcode_to_append += self.putValue(G=1, F=feed_rate,
  78. X=x_park, Y=y_park) + " ;Park print head\n"
  79. gcode_to_append += self.putValue(M=400) + " ;Wait for moves to finish\n"
  80. gcode_to_append += trigger_command + " ;Snap Photo\n"
  81. gcode_to_append += self.putValue(G=4, P=pause_length) + " ;Wait for camera\n"
  82. for idx, layer in enumerate(data):
  83. for line in layer.split("\n"):
  84. if self.getValue(line, "G") in {0, 1}: # Track X,Y location.
  85. last_x = self.getValue(line, "X", last_x)
  86. last_y = self.getValue(line, "Y", last_y)
  87. # Check that a layer is being printed
  88. lines = layer.split("\n")
  89. for line in lines:
  90. if ";LAYER:" in line:
  91. layer += gcode_to_append
  92. layer += "G0 X%s Y%s\n" % (last_x, last_y)
  93. data[idx] = layer
  94. break
  95. return data