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

feat: gcode_shell_command: option to terminate or not subprocess #237

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ruben-podadera
Copy link

Hi @th33xitus,

I'm using gcode_shell_command to take a timelapse (with gphoto and an external camera plugged in usb). I set as many camera settings as possible in manual mode so the photography process is quite fast (less than 1s). But after that, I copy the image file to a network drive. This part takes up to 10 seconds.

I dont want to pause the print job for something that can be made in background. So I just added a config for the gcode_shell_command in order to let the subprocess continue if I want to.

I know that this is far from perfect (could may be add a second "safety" timeout to actually terminate the subprocess) but may be it could help other users.

Anyway, thank you for you work. Regards

default is true (same behavior as now)
@ruben-podadera ruben-podadera marked this pull request as ready for review August 29, 2022 21:32
@ruben-podadera
Copy link
Author

I can update the doc if you want to

@dw-0
Copy link
Owner

dw-0 commented Sep 8, 2022

Hi, thanks for contributing.
Can you give me an example where you make use of that new option?

I haven't tried it yet but is it not possible to call an external shell script and inside there, start subprocesses as you wish?

In any case, if your idea makes sense and we merge it, we definitely need an example in the docs i would say.

@ruben-podadera
Copy link
Author

Hi ! Sorry for the long answer, i'll try to be quicker now.

I use this command to take pictures with gphoto.

macro_timelapse.cfg :

[gcode_shell_command gphoto_take_frame]
command: sh /home/pi/klipper_config/gphoto_take_snapshot.sh
timeout: 2.
verbose: True
terminate: False

gphoto_take_snapshot.sh :

#!/bin/sh

# UUID is generated in start script. Its a unique number for the print (actually is a datetime is seconds)
UUID=`cat /tmp/uuid`
DIR=/mnt/some-network-drive/klipper-timelapses/$UUID
mkdir -p $DIR
COUNT=`ls -l $DIR | egrep -v "^total " | wc -l`
COUNT=$((COUNT+1))
sudo gphoto2 --capture-image-and-download --filename=$DIR/$COUNT.jpg

With the camera model I have, once the picture is taken, it takes a while before gphoto command returns. For what I've measured, the picture is taken around 1s but the command takes around 9s to return. Thats a lot of time for each layer. Thats why I set timeout: 2. and terminate: False

@Creo2005
Copy link

Привіт ! Вибачте за довгу відповідь, зараз я постараюся бути швидким.

Я використовую цю команду для фотографування за допомогою gphoto.

macro_timelapse.cfg :

[gcode_shell_command gphoto_take_frame]
command: sh /home/pi/klipper_config/gphoto_take_snapshot.sh
timeout: 2.
verbose: True
terminate: False

gphoto_take_snapshot.sh :

#!/bin/sh

# UUID is generated in start script. Its a unique number for the print (actually is a datetime is seconds)
UUID=`cat /tmp/uuid`
DIR=/mnt/some-network-drive/klipper-timelapses/$UUID
mkdir -p $DIR
COUNT=`ls -l $DIR | egrep -v "^total " | wc -l`
COUNT=$((COUNT+1))
sudo gphoto2 --capture-image-and-download --filename=$DIR/$COUNT.jpg

З моєї моделі камери після того, як знімок буде зроблено, команда gphoto повернеться через деякий час. Відповідно до моїх вимірювань знімок робиться приблизно за 1 с, але для повернення команди потрібно близько 9 с. Це багато для кожного часу шару. Ось чому я поставив timeout: 2.іterminate: False

Hi ! Sorry for the long answer, i'll try to be quicker now.

I use this command to take pictures with gphoto.

macro_timelapse.cfg :

[gcode_shell_command gphoto_take_frame]
command: sh /home/pi/klipper_config/gphoto_take_snapshot.sh
timeout: 2.
verbose: True
terminate: False

gphoto_take_snapshot.sh :

#!/bin/sh

# UUID is generated in start script. Its a unique number for the print (actually is a datetime is seconds)
UUID=`cat /tmp/uuid`
DIR=/mnt/some-network-drive/klipper-timelapses/$UUID
mkdir -p $DIR
COUNT=`ls -l $DIR | egrep -v "^total " | wc -l`
COUNT=$((COUNT+1))
sudo gphoto2 --capture-image-and-download --filename=$DIR/$COUNT.jpg

With the camera model I have, once the picture is taken, it takes a while before gphoto command returns. For what I've measured, the picture is taken around 1s but the command takes around 9s to return. Thats a lot of time for each layer. Thats why I set timeout: 2. and terminate: False

How does sudo work for you, I want to run a script for updating the firmware of the board, but sudo does not work for me, because it says that a password must be entered. sudo service klipper stop and sudo service klipper start not working.

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.

3 participants