-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtimelapse.cfg
339 lines (323 loc) · 17.1 KB
/
timelapse.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
# Timelapse klipper macro definition
#
# Copyright (C) 2021 Christoph Frei <[email protected]>
# Copyright (C) 2021 Alex Zellner <[email protected]>
#
# This file may be distributed under the terms of the GNU GPLv3 license
#
# Macro version 1.5
#
##### DO NOT CHANGE ANY MACRO!!! #####
##########################################################################
# #
# GET_TIMELAPSE_SETUP: Print the Timelapse setup to console #
# #
##########################################################################
[gcode_macro GET_TIMELAPSE_SETUP]
description: Print the Timelapse setup
gcode:
{% set tl = printer['gcode_macro TIMELAPSE_TAKE_FRAME'] %}
{action_respond_info("Timelapse Setup:
enable: %s
park: %s
park position: %s
custom cord x:%s y:%s dz:%s
retract: %s mm speed: %s mm/s
extrude: %s mm speed: %s mm/s
travel speed: %s mm/s
verbose: %s "% (tl.enable, tl.park.enable, tl.park.pos, tl.custom.x, tl.custom.y, tl.custom.dz,
tl.extruder.retract, tl.speed.retract, tl.extruder.extrude, tl.speed.extrude, tl.speed.travel, tl.verbose))}
###############################################################################################
# #
# Use SET_TIMELAPSE_SETUP [ENABLE=value] [VERBOSE=value] [PARK_ENABLE=value] [PARK_POS=value] #
# [CUSTOM_POS_X=value] [CUSTOM_POS_Y=value] [CUSTOM_POS_DZ=value] #
# [TRAVEL_SPEED=value] [RETRACT_SPEED=value] [EXTRUDE_SPEED=value] #
# [EXTRUDE_DISTANCE=value] [RETRACT_DISTANCE=value] #
# #
###############################################################################################
[gcode_macro _SET_TIMELAPSE_SETUP]
description: Set user parameters for timelapse
gcode:
##### get dictonaries #####
{% set enable = printer['gcode_macro TIMELAPSE_TAKE_FRAME'].enable %}
{% set verbose = printer['gcode_macro TIMELAPSE_TAKE_FRAME'].verbose %}
{% set park = printer['gcode_macro TIMELAPSE_TAKE_FRAME'].park %}
{% set custom = printer['gcode_macro TIMELAPSE_TAKE_FRAME'].custom %}
{% set speed = printer['gcode_macro TIMELAPSE_TAKE_FRAME'].speed %}
{% set extruder = printer['gcode_macro TIMELAPSE_TAKE_FRAME'].extruder %}
##### get min and max bed size #####
{% set min = printer.toolhead.axis_minimum %}
{% set max = printer.toolhead.axis_maximum %}
##### set new values #####
{% if params.ENABLE is defined %}
{% if params.ENABLE|lower == 'true' or params.ENABLE|lower == 'false' %}
{% set enable = params.ENABLE %}
{% else %}
{action_raise_error("ENABLE=%s not supported. Allowed values are [True, False]" % params.ENABLE)}
{% endif %}
{% endif %}
{% if params.VERBOSE is defined %}
{% if params.VERBOSE|lower == 'true' or params.VERBOSE|lower == 'false' %}
{% set verbose = params.VERBOSE %}
{% else %}
{action_raise_error("VERBOSE=%s not supported. Allowed values are [True, False]" % params.VERBOSE)}
{% endif %}
{% endif %}
{% if params.PARK_ENABLE is defined %}
{% if params.PARK_ENABLE|lower == 'true' or params.PARK_ENABLE|lower == 'false' %}
{% set _dummy = park.update({'enable':params.PARK_ENABLE}) %}
{% else %}
{action_raise_error("PARK_ENABLE=%s not supported. Allowed values are [True, False]" % params.PARK_ENABLE)}
{% endif %}
{% endif %}
{% if params.PARK_POS is defined %}
{% if params.PARK_POS|lower == 'center' or params.PARK_POS|lower == 'front_left' or params.PARK_POS|lower == 'front_right'
or params.PARK_POS|lower == 'back_left' or params.PARK_POS|lower == 'back_right' or params.PARK_POS|lower == 'custom' %}
{% set _dummy = park.update({'pos':params.PARK_POS}) %}
{% else %}
{action_raise_error("PARK_POS=%s not supported. Allowed values are [CENTER, FRONT_LEFT, FRONT_RIGHT, BACK_LEFT, BACK_RIGHT, CUSTOM]"
% params.PARK_POS)}
{% endif %}
{% endif %}
{% if params.CUSTOM_POS_X is defined %}
{% if params.CUSTOM_POS_X|float >= min.x and params.CUSTOM_POS_X|float <= max.x %}
{% set _dummy = custom.update({'x':params.CUSTOM_POS_X}) %}
{% else %}
{action_raise_error("CUSTOM_POS_X=%s must be within [%s - %s]" % (params.CUSTOM_POS_X, min.x, max.x))}
{% endif %}
{% endif %}
{% if params.CUSTOM_POS_Y is defined %}
{% if params.CUSTOM_POS_Y|float >= min.y and params.CUSTOM_POS_Y|float <= max.y %}
{% set _dummy = custom.update({'y':params.CUSTOM_POS_Y}) %}
{% else %}
{action_raise_error("CUSTOM_POS_Y=%s must be within [%s - %s]" % (params.CUSTOM_POS_Y, min.y, max.y))}
{% endif %}
{% endif %}
{% if params.CUSTOM_POS_DZ is defined %}
{% if params.CUSTOM_POS_DZ|float >= min.z and params.CUSTOM_POS_DZ|float <= max.z %}
{% set _dummy = custom.update({'dz':params.CUSTOM_POS_DZ}) %}
{% else %}
{action_raise_error("CUSTOM_POS_DZ=%s must be within [%s - %s]" % (params.CUSTOM_POS_DZ, min.z, max.z))}
{% endif %}
{% endif %}
{% if params.TRAVEL_SPEED is defined %}
{% if params.TRAVEL_SPEED|float > 0 %}
{% set _dummy = speed.update({'travel':params.TRAVEL_SPEED}) %}
{% else %}
{action_raise_error("TRAVEL_SPEED=%s must be larger than 0" % params.TRAVEL_SPEED)}
{% endif %}
{% endif %}
{% if params.RETRACT_SPEED is defined %}
{% if params.RETRACT_SPEED|float > 0 %}
{% set _dummy = speed.update({'retract':params.RETRACT_SPEED}) %}
{% else %}
{action_raise_error("RETRACT_SPEED=%s must be larger than 0" % params.RETRACT_SPEED)}
{% endif %}
{% endif %}
{% if params.EXTRUDE_SPEED is defined %}
{% if params.EXTRUDE_SPEED|float > 0 %}
{% set _dummy = speed.update({'extrude':params.EXTRUDE_SPEED}) %}
{% else %}
{action_raise_error("EXTRUDE_SPEED=%s must be larger than 0" % params.EXTRUDE_SPEED)}
{% endif %}
{% endif %}
{% if params.EXTRUDE_DISTANCE is defined %}
{% if params.EXTRUDE_DISTANCE|float >= 0 %}
{% set _dummy = extruder.update({'extrude':params.EXTRUDE_DISTANCE}) %}
{% else %}
{action_raise_error("EXTRUDE_DISTANCE=%s must be specified as positiv number" % params.EXTRUDE_DISTANCE)}
{% endif %}
{% endif %}
{% if params.RETRACT_DISTANCE is defined %}
{% if params.RETRACT_DISTANCE|float >= 0 %}
{% set _dummy = extruder.update({'retract':params.RETRACT_DISTANCE}) %}
{% else %}
{action_raise_error("RETRACT_DISTANCE=%s must be specified as positiv number" % params.RETRACT_DISTANCE)}
{% endif %}
{% endif %}
##### write values to variables #####
SET_GCODE_VARIABLE MACRO=TIMELAPSE_TAKE_FRAME VARIABLE=enable VALUE='"{enable}"'
SET_GCODE_VARIABLE MACRO=TIMELAPSE_TAKE_FRAME VARIABLE=verbose VALUE='"{verbose}"'
SET_GCODE_VARIABLE MACRO=TIMELAPSE_TAKE_FRAME VARIABLE=park VALUE="{park}"
SET_GCODE_VARIABLE MACRO=TIMELAPSE_TAKE_FRAME VARIABLE=custom VALUE="{custom}"
SET_GCODE_VARIABLE MACRO=TIMELAPSE_TAKE_FRAME VARIABLE=speed VALUE="{speed}"
SET_GCODE_VARIABLE MACRO=TIMELAPSE_TAKE_FRAME VARIABLE=extruder VALUE="{extruder}"
##########################################################################
# #
# TIMELAPSE_TAKE_FRAME: take the next picture #
# #
##########################################################################
######################### definition #########################
## enable: enable or disable the next frame. Valid inputs: [True, False]
## takingframe: internal use. Valid inputs: [True, False]
##
## park.enable: enable or disable to park the head while taking a picture. Valid inputs: [True, False]
## park.pos : used position for parking. Valid inputs: [center, front_left, front_right, back_left, back_right, custom]
##
## custom.x, custom.y: coordinates of the custom parkposition. Unit [mm]
## custom.dz : custom z hop for the picture. Unit [mm]
## extruder.extrude: filament extruded at the end of park. Unit [mm]
## extruder.retract: filament retract at the start of park. Unit [mm]
##
## speed.travel : used speed for travel from and to the park positon. Unit: [mm/min]
## speed.retract: used speed for retract [mm/min]
## speed.extrude: used speed for extrude [mm/min]
##
## verbose: Enable mesage output of TIMELAPSE_TAKE_FRAME
## absolute.coordinates: internal use.
## absolute.extrude: internal use.
###############################################################
[gcode_macro TIMELAPSE_TAKE_FRAME]
description: Take Timelapse shoot
variable_enable: False
variable_takingframe: False
variable_park: {'enable': False,
'pos' : 'center'}
variable_custom: {'x': 0, 'y': 0, 'dz': 0}
variable_extruder: {'retract': 1.0,
'extrude': 1.0}
variable_speed: {'travel': 100,
'retract': 15,
'extrude': 15}
variable_verbose: True
variable_absolute: {'coordinates': True, 'extrude': True}
gcode:
##### get input parameters #####
{% set hyperlapse = params.HYPERLAPSE|default('false')|lower %}
##### define park position #####
{% set min = printer.toolhead.axis_minimum %}
{% set max = printer.toolhead.axis_maximum %}
{% set act = printer.toolhead.position %}
{% set pos_dic = {'center' : {'x': (max.x-(max.x-min.y)/2), 'y': (max.y-(max.y-min.y)/2), 'dz': 1 },
'front_left' : {'x': min.x , 'y': min.y , 'dz': 0 },
'front_right': {'x': max.x , 'y': min.y , 'dz': 0 },
'back_left' : {'x': min.x , 'y': max.y , 'dz': 0 },
'back_right' : {'x': max.x , 'y': max.y , 'dz': 0 },
'custom' : {'x': custom.x , 'y': custom.y , 'dz': custom.dz}} %}
##### check z max #####
{% if (act.z|float + pos_dic[park.pos].dz|float) < max.z|float %}
{% set pos = {'x': pos_dic[park.pos|lower].x, 'y': pos_dic[park.pos].y, 'z': (act.z|float + pos_dic[park.pos].dz|float)} %}
{% else %}
{% set pos = {'x': pos_dic[park.pos|lower].x, 'y': pos_dic[park.pos].y, 'z': max.z} %}
{% endif %}
##### end of definition #####
{% if enable|lower == 'true' %}
{% if (hyperlapse == 'true' and printer['gcode_macro HYPERLAPSE'].run|lower == 'true') or
(hyperlapse == 'false' and printer['gcode_macro HYPERLAPSE'].run|lower == 'false') %}
{% set absolute = {'coordinates': printer.gcode_move.absolute_coordinates,
'extrude' : printer.gcode_move.absolute_extrude} %}
SET_GCODE_VARIABLE MACRO=TIMELAPSE_TAKE_FRAME VARIABLE=absolute VALUE="{absolute}"
{% if park.enable|lower == 'true' %}
M83 ; insure relative extrusion
{% if printer.extruder.can_extrude|lower == 'false' %}
{action_respond_info("Timelapse: Warning, minimum extruder temperature not reached!")}
{% else %}
G0 E-{extruder.retract} F{speed.retract|int * 60}
{% endif %}
{printer.configfile.settings['gcode_macro pause'].rename_existing} ; execute the klipper PAUSE command
G90 ; insure absolute move
{% if "xyz" not in printer.toolhead.homed_axes %}
{action_respond_info("Timelapse: Warning, axis not homed yet!")}
{% else %}
G0 X{pos.x} Y{pos.y} Z{pos.z} F{speed.travel|int * 60}
{% endif %}
SET_GCODE_VARIABLE MACRO=TIMELAPSE_TAKE_FRAME VARIABLE=takingframe VALUE=True
UPDATE_DELAYED_GCODE ID=_WAIT_TIMELAPSE_TAKE_FRAME DURATION=0.5
M400
{% endif %}
_TIMELAPSE_NEW_FRAME HYPERLAPSE={hyperlapse}
{% endif %}
{% else %}
{% if verbose|lower == 'true' %}
{action_respond_info("Timelapse: disabled, take frame ignored")}
{% endif %}
{% endif %}
[gcode_macro _TIMELAPSE_NEW_FRAME]
description: action call for timelapse shoot. must be a seperate macro
gcode:
{action_call_remote_method("timelapse_newframe",
macropark=printer['gcode_macro TIMELAPSE_TAKE_FRAME'].park,
hyperlapse=params.HYPERLAPSE)}
[delayed_gcode _WAIT_TIMELAPSE_TAKE_FRAME]
gcode:
{% set timelapse = printer['gcode_macro TIMELAPSE_TAKE_FRAME'] %}
{% if timelapse.takingframe %}
UPDATE_DELAYED_GCODE ID=_WAIT_TIMELAPSE_TAKE_FRAME DURATION=0.5
{% else %}
{printer.configfile.settings['gcode_macro resume'].rename_existing} VELOCITY={timelapse.speed.travel} ; execute the klipper RESUME command
{% if printer.extruder.can_extrude|lower == 'false' %}
{action_respond_info("Timelapse: Warning minimum extruder temperature not reached!")}
{% else %}
G0 E{timelapse.extruder.extrude} F{timelapse.speed.extrude|int * 60}
{% endif %}
{% if timelapse.absolute.coordinates|lower == 'false' %} G91 {% endif %}
{% if timelapse.absolute.extrude|lower == 'true' %} M82 {% endif %}
{% endif %}
####################################################################################################
# #
# HYPERLAPSE: Starts or stops a Hyperlapse video #
# Usage: HYPERLAPSE ACTION=START [CYCLE=time] starts a hyperlapse with cycle time (default 30 sec) #
# HYPERLAPSE ACTION=STOP stops the hyperlapse recording #
# #
####################################################################################################
######################### definition #########################
## cycle: cycle time in seconds
## run: internal use [True/False]
###############################################################
[gcode_macro HYPERLAPSE]
description: Start/Stop a hyperlapse recording
variable_cycle: 0
variable_run: False
gcode:
{% set cycle = params.CYCLE|default(30)|int %}
{% if params.ACTION is defined and params.ACTION|lower == 'start' %}
{action_respond_info("Hyperlapse: frames started (Cycle %d sec)" % cycle)}
SET_GCODE_VARIABLE MACRO=HYPERLAPSE VARIABLE=run VALUE=True
SET_GCODE_VARIABLE MACRO=HYPERLAPSE VARIABLE=cycle VALUE={cycle}
UPDATE_DELAYED_GCODE ID=_HYPERLAPSE_LOOP DURATION={cycle}
TIMELAPSE_TAKE_FRAME HYPERLAPSE="True"
{% elif params.ACTION is defined and params.ACTION|lower == 'stop' %}
SET_GCODE_VARIABLE MACRO=HYPERLAPSE VARIABLE=run VALUE=False
{action_respond_info("Hyperlapse: frames stopped")}
UPDATE_DELAYED_GCODE ID=_HYPERLAPSE_LOOP DURATION=0
{% else %}
{action_respond_info("Hyperlapse: No valid input parameter
Use:
- HYPERLAPSE ACTION=START [CYCLE=time]
- HYPERLAPSE ACTION=STOP")}
{% endif %}
[delayed_gcode _HYPERLAPSE_LOOP]
gcode:
UPDATE_DELAYED_GCODE ID=_HYPERLAPSE_LOOP DURATION={printer["gcode_macro HYPERLAPSE"].cycle}
TIMELAPSE_TAKE_FRAME HYPERLAPSE="True"
##########################################################################
# #
# TIMELAPSE_RENDER: Render the video at print end #
# #
##########################################################################
######################### definition #########################
## render: internal use. Valid inputs: [True, False]
## run_identifier: internal use. Valid input [0 .. 3]
###############################################################
[gcode_macro TIMELAPSE_RENDER]
description: Render Timelapse video and wait for the result
variable_render: False
variable_run_identifier: 0
gcode:
{action_respond_info("Timelapse: Rendering started")}
{action_call_remote_method("timelapse_render", byrendermacro="True")}
SET_GCODE_VARIABLE MACRO=TIMELAPSE_RENDER VARIABLE=render VALUE=True
{printer.configfile.settings['gcode_macro pause'].rename_existing} ; execute the klipper PAUSE command
UPDATE_DELAYED_GCODE ID=_WAIT_TIMELAPSE_RENDER DURATION=0.5
[delayed_gcode _WAIT_TIMELAPSE_RENDER]
gcode:
{% set ri = printer['gcode_macro TIMELAPSE_RENDER'].run_identifier|int % 4 %}
SET_GCODE_VARIABLE MACRO=TIMELAPSE_RENDER VARIABLE=run_identifier VALUE={ri + 1}
{% if printer['gcode_macro TIMELAPSE_RENDER'].render %}
M117 Rendering {['-','\\','|','/'][ri]}
UPDATE_DELAYED_GCODE ID=_WAIT_TIMELAPSE_RENDER DURATION=0.5
{% else %}
{action_respond_info("Timelapse: Rendering finished")}
M117
{printer.configfile.settings['gcode_macro resume'].rename_existing} ; execute the klipper RESUME command
{% endif %}