-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathktamv_automation_example.cfg
85 lines (77 loc) · 3.94 KB
/
ktamv_automation_example.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
81
82
83
84
85
[gcode_macro tool_align_macro]
description = Aligns all tools
# This macro will align all tools using the KTAMV plugin
gcode:
# Constants to be customized:
{% set VAR_CAMERA_CENTER_COORDINATES = [ 10.0, 10.0] %}# Where you have your camera, X,Y
{% set VAR_TOOL_TO_USE_FOR_CALIBRATION = 0 %}# Tool to use for calibrating the camera
{% set VAR_TOOL_TO_USE_AS_REFERENCE = 0 %}# Tool to use as reference for the offsets
{% set VAR_TOOLS_TO_ALIGN = [ 1, 2, 3] %}# Tools to align and get offset to the reference tool
# Check if printer is homed, mm/px is calculated and we have set a origin for our tools
{% if 'xy' not in printer.toolhead.homed_axes%}
RESPOND PREFIX="info" MSG="Printer not homed."
# If camera is not calibrated or origin position not set, do both.
{% elif printer.ktamv.camera_center_coordinates[0]|default("none")|lower =="none" or printer.ktamv.mm_per_pixels|default("none")|lower == "none"%}
# Set up the server
KTAMV_SEND_SERVER_CFG
# Chose the tool to calibrate with.
T{VAR_TOOL_TO_USE_FOR_CALIBRATION}
# Move to the camera center
G0 X{VAR_CAMERA_CENTER_COORDINATES[0]} Y{VAR_CAMERA_CENTER_COORDINATES[1]} F{printer.ktamv.travel_speed}
# Wait for tool to finish moving
M400
# Calibrate the camera
KTAMV_CALIB_CAMERA
# Load the tool to use as reference for our offsets
T{VAR_TOOL_TO_USE_AS_REFERENCE}
# Move to the camera center
G0 X{VAR_CAMERA_CENTER_COORDINATES[0]} Y{VAR_CAMERA_CENTER_COORDINATES[1]} F{printer.ktamv.travel_speed}
# Find the nozzle center
KTAMV_FIND_NOZZLE_CENTER
# Set the origin to calibrate from if the above calibration was successful
_tool_align_macro_set_origin_if_successful
{% endif %}
# Align all tools, checking everything is ok now inside the next macro because in this the variables have not updated yet.
{% for tool in VAR_TOOLS_TO_ALIGN %}
RESPOND PREFIX="info" MSG="-Aligning tool T{tool}"
_tool_align_macro_align_tool TOOL={tool}
{% endfor %}
# Set Origin if last nozzle center was successful.
# Needs to be in separate macro to be calculated after the previous command is finished.
[gcode_macro _tool_align_macro_set_origin_if_successful]
gcode:
{% if printer.ktamv.last_nozzle_center_successful|default("false")|lower =="true" %}
KTAMV_SET_ORIGIN
{% endif %}
# Align tool macro
[gcode_macro _tool_align_macro_align_tool]
gcode:
# Get tool from params
{% set TOOL = params.TOOL %}
# Check if printer is homed, mm/px is calculated and we have set a origin for our tools
# If everything above is true, we can start the tool alignment
{% if printer.ktamv.camera_center_coordinates[0]|default("none")|lower !="none" and printer.ktamv.mm_per_pixels|default("none")|lower != "none" and 'xy' in printer.toolhead.homed_axes%}
RESPOND PREFIX="info" MSG="Aligning tool T{TOOL}"
# Load tool
T{TOOL}
# Move to camera center
G0 X{printer.ktamv.camera_center_coordinates[0]} Y{printer.ktamv.camera_center_coordinates[1]} F{printer.ktamv.travel_speed}
# Get nozzle center
KTAMV_FIND_NOZZLE_CENTER
# Get offset
KTAMV_GET_OFFSET
# Save offset using the next macro
_tool_align_macro_save_offset TOOL={TOOL}
{% else %}
RESPOND PREFIX="info" MSG="Camera not calibrated or origin not set. Please run the macro again."
{% endif %}
# Macro to save offset
[gcode_macro _tool_align_macro_save_offset]
gcode:
# Get tool from params
{% set TOOL = params.TOOL %}
# If offset is calculated, we can save it
{% if printer.ktamv.last_nozzle_center_successful|default("false")|lower =="true" %}
# Add your code here to save the offset
{action_respond_info("Macro example saving offset X:"~printer.ktamv.last_calculated_offset[0]~" Y:"~printer.ktamv.last_calculated_offset[1]~" for tool T"~TOOL)}
{% endif %}