Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature custom snapshot_cmd implemented #154

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

boecko
Copy link

@boecko boecko commented Feb 24, 2024

This PR introduces 4 new timelapse-options .
It allows making timelapses via invocation of a custom shellscript.
In my case i'm using gphoto2 to control a Canon EOS70D camara.
It use_snapshot_cmd is False or snapshot_cmd_check fails, the normal configuration is used.

[timelapse]
    use_snapshot_cmd: True
    snapshot_cmd: /home/pi/bin/gphoto2_capture.sh
    snapshot_cmd_check: /home/pi/bin/gphoto2_check.sh
    snapshot_cmd_waittime: 10.0

example:
[webcam canon]
location: printer
icon:
enabled: False
stream_url: /webcam/stream
snapshot_url: cmd:/home/pi/bin/canoncaptureframe

--- canoncaptureframe ---
BASEFILE=${1%%.jpg}
gphoto2 --quiet --capture-image-and-download --filename="$BASEFILE.%C"
--force-overwrite
rm -f "$BASEFILE.cr3"
---
example for DSLR via gphoto
[timelapse]
park_time: 0.6
snapshot_cmd: /home/pi/bin/gphoto2_capture.sh
snapshot_cmd_check: /home/pi/bin/gphoto2_check.sh #optional
use_snapshot_cmd: True
@AYA-123
Copy link

AYA-123 commented Dec 23, 2024

Hi, how would you go about combining this with the gcode shell command?

@AYA-123
Copy link

AYA-123 commented Dec 23, 2024

I have these macros:

[gcode_macro TAKE_SNAPSHOT]
description: Saves current location, moves toolhead to rear of bed, and takes a snapshot before returning.
gcode:
  {% set delayMS = 2000 %} ; Delay after moving and before taking the snapshot, deals with buffering so we don't get the print head in motion
  {% set snapshotPositionX = printer.toolhead.axis_maximum.x / 2 %} ; Middle of bed
  {% set snapshotPositionY = printer.toolhead.axis_maximum.y - 5 %} ; rear of bed w/ some buffer
  {% 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
  {% set snapshotPositionZ = printer.gcode_move.gcode_position.z + 5 %}
  
  SAVE_GCODE_STATE NAME=take_snapshot_state

  {% if printer.extruder.can_extrude|lower == 'true' %}
    G10 ; retract
  {% endif %}

  G90

  G0 X{snapshotPositionX} Y{snapshotPositionY} Z{snapshotPositionZ} 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} Z {currentZ} F5000.0 ;Return to original position

  {% if printer.extruder.can_extrude|lower == 'true' %}
    G11 ; unretract
  {% endif %}

  RESTORE_GCODE_STATE NAME=take_snapshot_state



[gcode_macro GPHOTO_SNAPSHOT_TEST]
gcode:
  RUN_SHELL_COMMAND CMD=gphoto_trigger

Along with this shell command cfg file:

#=====================================================
# SET CAMERA SAVE LOCATION
#=====================================================
[gcode_shell_command gphoto2_set_config]
command: gphoto2 --set-config capturetarget=1
timeout: 1. ; make sure this is long enough to account for focus time
verbose: False

#=====================================================
# DSLR CAPTURE IMAGE
#=====================================================
[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: False

And I'm using TAKE_SNAPSHOT in my slicer after every line. I saw in #155 to do:

[timelapse]
use_gphoto2=True

But you have to download the .sh files to your pi for that - it would be much simpler to use the cfg files, so is this possible?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants