Skip to content

Instantly share code, notes, and snippets.

@wbatty
Last active August 19, 2024 20:52
Show Gist options
  • Save wbatty/a5f1406b28985ed9dd39a5316bcad06c to your computer and use it in GitHub Desktop.
Save wbatty/a5f1406b28985ed9dd39a5316bcad06c to your computer and use it in GitHub Desktop.
Example of how to setup Klipper to use the gocode_shell_command to do timelapse (pre mainsail built in timelapse)
# Requires `gcode_shell_command` extension to Moonraker (installing via KIUAH is the easy way)
# Requires gphoto2 http://www.gphoto.org/
[gcode_shell_command gphoto2_trigger_snapshot]
command: gphoto2 --auto-detect --trigger-capture
timeout: 10. ; make sure this is long enough to account for focus time
verbose: True
[gcode_shell_command gphoto2_init_camera]
command: gphoto2 --auto-detect --set-config capturetarget=1
timeout: 2.
verbose: True
#Invoke this in your start print script
[gcode_macro INIT_CAMERA]
gcode:
{% if printer.save_variables.variables.snapshots_enabled %}
RUN_SHELL_COMMAND CMD=gphoto2_init_camera
{% else %}
{ action_respond_info("Snapshots disabled") }
{% endif %}
# Invoke this after each layer
[gcode_macro TAKE_SNAPSHOT]
description: Saves current location, moves toolhead to rear of bed, and takes a snapshot before returning.
gcode:
{% if printer.save_variables.variables.snapshots_enabled %}
{% set delayMS = 2000 %} ; Delay after moving and before taking the snapshot, so we don't get the print head in motion
{% set snapshotPositionX = printer.toolhead.axis_maximum.x / 2 %}
{% set snapshotPositionY = printer.toolhead.axis_maximum.y - 5 %}
{% set currentX = printer.gcode_move.gcode_position.x %}
{% set currentY = printer.gcode_move.gcode_position.y %}
{% set currentZ = printer.gcode_move.gcode_position.z %} ; could be used for z-hop which we are not doing in this macro, so it's best to run this in AFTER_LAYER_CHANGE
SAVE_GCODE_STATE NAME=take_snapshot_state
{% if printer.extruder.can_extrude|lower == 'true' %}
G10 ; retract
{% endif %}
G90
G0 X{snapshotPositionX} Y{snapshotPositionY} F5000.0 ;Move to snapshot position
G4 P{delayMS} ; Dwell for delayMS seconds
RUN_SHELL_COMMAND CMD=gphoto2_trigger_snapshot
G0 X{currentX} Y{currentY} F5000.0 ;Return to original position
{% if printer.extruder.can_extrude|lower == 'true' %}
G11 ; unretract
{% endif %}
RESTORE_GCODE_STATE NAME=take_snapshot_state
{% else %}
{ action_respond_info("Snapshots are DISABLED. Run ENABLE_SNAPSHOTS or TOGGLE_SNAPSHOTS to ENABLE.") }
{% endif %}
[gcode_macro ENABLE_SNAPSHOTS]
gcode:
SAVE_VARIABLE VARIABLE=snapshots_enabled VALUE=True
INIT_CAMERA
{ action_respond_info("Snapshots enabled") }
[gcode_macro DISABLE_SNAPSHOTS]
gcode:
SAVE_VARIABLE VARIABLE=snapshots_enabled VALUE=False
{ action_respond_info("Snapshots disabled") }
[gcode_macro TOGGLE_SNAPSHOTS]
gcode:
{% if printer.save_variables.variables.snapshots_enabled %}
DISABLE_SNAPSHOTS
{% else %}
ENABLE_SNAPSHOTS
{% endif %}
[gcode_macro QUERY_SNAP_SHOTS]
gcode:
{% if printer.save_variables.variables.snapshots_enabled %}
{ action_respond_info("Snapshots enabled") }
{% else %}
{ action_respond_info("Snapshots disabled") }
{% endif %}
@larschri15
Copy link

hello I would also like to connect my dslr camera to clipper I just got clipper how can I get started I already have gphoto2 installed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment