-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_image.cfg
80 lines (59 loc) · 2.89 KB
/
check_image.cfg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# Include the timelapse.cfg file
[include timelapse.cfg]
[extended_template]
# This section defines the path to the configuration file for a 3D print error detector using a camera
path: ~/klipper-camera-watchdog/config.yaml
# Move Back Macro - This macro helps the printer head return to its previous position
[extended_macro MOVE_BACK]
# This macro stores the current position of the head and then uses Gcode commands to move back to that position.
# These variables will store the X, Y, and Z coordinates of the printer head when the macro is called
variable_saved_x: 0.0
variable_saved_y: 0.0
variable_saved_z: 0.0
gcode:
# Set absolute positioning mode (G90) - This tells the printer to use absolute coordinates instead of relative ones
G90
G1 Z{saved_z} F300 # Move to saved Z position at 5 mm/s
G1 X{saved_x} Y{saved_y} F6000 # Move to saved X and Y position at 100 mm/s
# Check Print Macro - This macro checks for movement during printing
[extended_macro CHECK_PRINT]
gcode:
{% set cancel_print = check_image() %} # This line calls a function to check the camera image for movement
{% if cancel_print == "Movement detected" %}
G90
CANCEL_PRINT # This command likely triggers a print cancellation
{% endif %}
# Check Image Macro - This macro sets up the printer to capture the image, runs the macro to take the picture and the macro to check if movement is detected
# and then sets up the printer to continue printing
[extended_macro CHECK_IMAGE]
gcode:
{% set position = printer.gcode_move.gcode_position %} # This line gets the current printer head position
# Save the current position for the MOVE_BACK macro to use later
SET_GCODE_VARIABLE MACRO=MOVE_BACK VARIABLE=saved_x VALUE="{position.x}"
SET_GCODE_VARIABLE MACRO=MOVE_BACK VARIABLE=saved_y VALUE="{position.y}"
SET_GCODE_VARIABLE MACRO=MOVE_BACK VARIABLE=saved_z VALUE="{position.z}"
# Save the current printer state
SAVE_GCODE_STATE NAME=saved_state1
# Prime the extruder a bit (-10mm)
M83 # Set relative extrusion for the extruder
G1 E-10 F300 # Retract 10mm
# Move to a specific position (X0 Y220 Z20) for camera capture
G90
G1 X0 Y220 F6000 # Move to X0 Y220 at 100 mm/s
G1 Z20 F300 # Move to Z20 at 5 mm/s
# Restore the printer state to what it was before moving for camera capture
RESTORE_GCODE_STATE NAME=saved_state1
# Capture a timelapse frame
TIMELAPSE_TAKE_FRAME
# Move the head back to the previously saved position using the MOVE_BACK macro
MOVE_BACK
# Call the CHECK_PRINT macro to cancel the print if movement is detected
CHECK_PRINT
# Save the current printer state
SAVE_GCODE_STATE NAME=saved_state2
# Retract the filament a bit (10mm)
M83 # Set relative extrusion for the extruder
G1 E10 F300 # Extrude 10mm to prime the extruder
# Restore the printer state to what it was before priming the extruder
G90
RESTORE_GCODE_STATE NAME=saved_state2