FormerLurker / Octolapse

Stabilized timelapses for Octoprint
GNU Affero General Public License v3.0
633 stars 99 forks source link

[Request] DSLR/External Camera Triggering #187

Closed SrgntBallistic closed 4 years ago

SrgntBallistic commented 6 years ago

If this is a feature request describe it here

Allow configuration for sending triggers to a DSLR via GPIO instead of or in addition to taking a snap with an onboard camera. And/Or launching an external script which can trigger an external camera by other means.

I would like to make some super high resolution and quality timelapses with Octolapse. In the past I've triggered my DSLR via arduino and think my method/circuit can work with the Raspberry Pi GPIO as well.

Alternatively allowing a python script to be run when a snap is taken could be beneficial as some DSLRs can be hooked up to a Raspberry Pi or PC via USB.

This would be really helpful as the only way I've seen to have a DSLR show up as a webcam on a raspberry pi is with a $100+ UVC USB to HDMI converter

Cheers, Brian

Version of Octolapse

Octolapse Version: Octolapse 0.3.1

Version of OctoPrint

OctoPrint Version: OctoPrint 1.3.8 running on OctoPi 0.15.1

When you ran into the problem, did you have diagnostic logging enabled?

Diagnostic Logging was Enabled: YES_OR_NO

What were you doing when the problem occurred

  1. STEP_ONE_GOES_HERE
  2. STEP_TWO_GOES_HERE
  3. STEP_...

What should have happened?

PUT_YOUR_DESCRIPTION_HERE

What happened instead?

PUT_YOUR_DESCRIPTION_HERE

Operating System running OctoPrint and Octolapse

OS Name: OS_NAME_GOES_HERE Os Version: OS_VERSION_GOES_HERE

Printer model & used firmware incl. version

Printer Model: PRINTER_MODEL_GOES_HERE Printer Firmware Version: PRINTER_FIRMWARE_VERSION_GOES_HERE

Browser and version of browser, operating system running browser

Browser: BROWSER_VERSION_GOES_HERE Browser OS: BROWSER_OS_GOES_HERE

Link to the gcode file you were printing when the problem occurred

Link to Gcode File: GCODE_FILE_LINK_GOES_HERE

Link to settings.json

Link to settings.json with all passwords removed: SETTINGS_JSON_LINK_GOES_HERE

Link to plugin_octolapse.log

Link to plugin_octolapse.log: LINK_GOES_HERE

Link to octoprint.log

Link to octoprint.log: LINK_GOES_HERE

Link to contents of Javascript console in the browser

Link to javascript console output: LINK_GOES_HERE

Screenshots and/or videos of the problem:

Screenshot/Video Links: LINKs_GO_HERE

Please consider becoming a patron

If you like this project, please support my work by becoming a patron, and consider adding a 'star' to the repository. It takes a lot of time and effort to maintain the project and respond to issues. The cost of test prints, software, cameras, printer parts, etc. can quickly add up, so every bit helps. I'm currently saving for some additional test cameras in preparation for develiping multi-camera support.

FormerLurker commented 6 years ago

@jetsloth, I added a custom pre-render script option to the camera settings that should let us defer snapshot downloading until AFTER the print is complete, which should reduce the delay caused by camera saving to SD, then copying via usb to the pi. I have NOT had a chance to write a script that actually does the download yet, but I will try that as soon as I have time.

I also added a camera specific initialization script we could use to send settings to the camera at the beginning of each print, but I haven't written a script for that either :) One thing at a time.

FormerLurker commented 6 years ago

@jetsloth, I forgot to mention, but I also added a new camera type that could be used to do what you suggested here:

More of an idea really. In addition to the DLSR I wonder if you could send another gCode which triggers the rotation of another stepper motor E1 or E2 for example. On the sending of M240 to trigger camera, send the stepper a signal to rotate X revolutions (user defined). The idea behind this is that the camera is mounted to the stepper, and the stepper is pushing along a track. Thus, introducing 180,360 timelapse or paning timlapse - examples here and here Somthing to ponder nontheless!

You can now send any arbitrary gcode via a custom camera gcode script (multiline should work too). If you can get it to work by sending gcode to the printer, I think this should cover it.

jetsloth commented 6 years ago

@FormerLurker sweet awesome thanks.

You can now send any arbitrary gcode via a custom camera gcode script (multiline should work too). If you can get it to work by sending gcode to the printer, I think this should cover it.

Is there a dev version I need to update to?

Lavarus commented 6 years ago

I've got a question. I have a Nikon 5300, I'm trying to setup via USB to pi 3b.

I have the latest Octoprint and lapse running; I've installed gphoto2 and the script. However, my camera will not display in Control webcam streaming or in Octoprint, so I'm not sure what I'm doing wrong. I do have the green gear in Octoprint, but no display of video. 2018-08-14 08_41_13-octoprint

In the script do we leave the parameters as $1, $2, etc, or change them?

FormerLurker commented 6 years ago

@Lavarus,

However, my camera will not display in Control webcam streaming or in Octoprint

You won't get any streaming from your DSLR. Also, the 'Welcome to Octolapse' image is a placeholder until a snapshot is taken. Have you tried running a print with Octolapse enabled? Once your camera takes a picture the 'Welcome to Octolapse' image should change to the latest DSLR capture thumbnail. I'm planning on changing that placeholder to something a bit more reasonable so as not to confuse anyone.

Also, have you gotten your webcam to work with Octolapse at all? If not I suggest starting there and running a few test prints. Let me know if you need any help with that.

If you HAVE gotten your webcam working and know how to run a test print, please use the Test Mode Full Diagnostic profile, run a very small print (smaller the better else the log file will be huge), and if you don't get any snapshots send me your log file.

Thanks for posting your issue!

FormerLurker commented 6 years ago

@Lavarus, oh, and you won't need to change the $1, $2 etc.. those are arguments passed into the script by octolapse (argument 1, argument 2, etc) copied into a variable for convenience and legibility.

Lavarus commented 6 years ago

I don't have a webcam unfortunately.

I tried a test print, with no luck. Octoprint says waiting to take a photo, and fails to render. 2018-08-14 09_44_44-octoprint

Does this look right? 2018-08-14 09_52_45-configuring an external camera formerlurker_octolapse wiki

FormerLurker commented 6 years ago

@Lavarus , Can you post your plugin_octolapse.log file for me? You can download it from the 'Log' settings page within the Octoprint settings. Also, it looks like your nikon is setup to deliver raw (.nef) images. Switch to jpeg within your camera, since that's the only source image format Octolapse currently supports. Start out with a lower resolution and quality since you have to do some special things to get huge image files to work in a reasonable amount of time.

Also, you are running the script without any parameters, so it won't know where to put the resulting image or what to name it. You don't really need to do that anyway.

Also, while a print is running (test mode is fine) and after a few layers, take a snapshot of the 'Position State' info panel (I see you have it enabled). There could be other reasons (start gcode) that Octolapse is not triggering a snapshot.

Lavarus commented 6 years ago

Newb mistake by not switching camera to Jpeg. Done and lowered the resolution. Still not working.

2018-08-14 10_11_10-

octoprint.log

FormerLurker commented 6 years ago

Sorry, I need plugin_octolapse.log not octoprint.log. It looks like your start gcode is correct though, so that's great!

Lavarus commented 6 years ago

Okay plugin_octolapse.log

FormerLurker commented 6 years ago

That's the right file, but it doesn't look like you were using the 'Full Diagnostic - Test Mode' debug profile in Octolapse, so the log is mostly empty. Go ahead and change your debug profile, print a few layers, then cancel and send me the result (it will be MUCH MUCH bigger). Be sure to switch back to 'Test Mode' when you are finished. No reason to create more logs than necessary!

I wish the debug process wasn't as tedious for everybody. I'm investigating ways of delivering better error messages, but I suspect your problem is within the .sh file, and I'm still working on proper logging here.

Also, can you let me know when you installed the plugin and from what URL? This could be helpful info.

Lavarus commented 6 years ago

I just got the Pi, and Octoprint yesterday; Octoprint plugin from the repository. I got the Octolapse plugin from the zip you linked far above.

Here is full diagnostic: plugin_octolapse (1).log

FormerLurker commented 6 years ago

Can you try installing from this URL and trying again: https://github.com/FormerLurker/Octolapse/archive/eae5c49afe88ed2c3a4d490a92746b0f6b761e45.zip

It looks like the snapshot worked by looking at the logs, but there were some problems with error logging that (I think) have been fixed in the above build. You should see camera errors display in a popup window if they occur. Let me know the results of your next test, and post your log after it's complete.

I think we're getting close!

FormerLurker commented 6 years ago

@Lavarus, I forgot to mention that you need to reboot and clear your browser cache (usually ctrl+f5) before the new version is completely installed and ready to use. Otherwise the javascript may be stale, and we don't want that!

Lavarus commented 6 years ago

2018-08-14 14_07_03-octoprint

Can't install without pip?

SrgntBallistic commented 6 years ago

@FormerLurker Wondering if you had a chance to check out my last post? https://github.com/FormerLurker/Octolapse/issues/187#issuecomment-412121794

Thanks

Lavarus commented 6 years ago

Yes, I rebooted and Ctrl +F5. Did it twice, same thing.

Lavarus commented 6 years ago

Uninstalling, and installing new worked.

FormerLurker commented 6 years ago

@SrgntBallistic, sorry it's getting crowded in here, lol! I saw your original comment but forgot to reply.

gphoto2 --set-config capturetarget=1

Sets the capture target to SD for your camera apparently. The default is 'RAM' for mine, so no image ever gets put on the camera. This shouldn't matter for the 'download and capture' command since it will be downloaded either from RAM or from SD memory (but ram is faster).

Are you sure your password is correct and that it is surrounded in double quotes?

Try running this command (assuming your script is at /home/pi/scripts/ and is called take-snapshot.sh):

/home/pi/scripts/take-snapshot.sh 0 0.0 /home/pi/.octoprint/data/octolapse /home/pi/.octoprint/data/octolapse/snapshots/test test_image.jpg /home/pi/.octoprint/data/octolapse/snapshots/test/test_image.jpg

That should capture and download an image to /home/pi/.octorpint/data/octolapse/snapshots/test

Let me know if that works. You might also want to try installing from the link I sent to @Lavarus just a few minutes ago and check the 'Timeout' setting in the camera profile. Turn this up to like 10000 (10 seconds). There is no error message for a timeout yet in the logs (whoops...)

@Lavarus, you could try running that command too to double check your script.

Lavarus commented 6 years ago

It still isn't working in Octolapse. The camera does not take a single shot.

All the tests in the SSH console work fine, The script test above works and the camera takes a photo. Maybe it's my camera profile? 2018-08-15 01_13_57-octoprint

Lavarus commented 6 years ago

I found this cool way of taking snap shots: https://www.youtube.com/watch?v=SvZjNSLXAJc

But then I got this error: 2018-08-15 01_39_54-octoprint

FormerLurker commented 6 years ago

@Lavarus, is this line at the top of your script: #!/bin/sh

if so, delete it (press backspace several times, there might be a hidden character) and re-add the line, being extra sure that you are ONLY adding the text above.

If this doesn't fix your issue, maybe please post it your sh file somewhere (Please replace your sudo password with nonsense characters, but leave the surrounding quotes please). It's best that you upload the file itself and do not copy/paste so as not to accidentally exclude hidden characters, though that works in a pinch.

Regarding the video, I've seen it and love it! However, using the pause gcode is totally not necessary since camera delay is built in, and the command will be suppressed by Octolapse anyway (if all is working as it should). If you want to use the gcode trigger just use the regular 'snap' command. You shouldn't need any camera delay for a DSLR unless you are using the trigger-capture command in gphoto2 (which I think you are not).

Shadowen commented 6 years ago

Remember to check that the sudo password doesn't contain any escape characters :) That would be... awkward.

On Wed, Aug 15, 2018 at 6:19 AM FormerLurker notifications@github.com wrote:

@Lavarus https://github.com/Lavarus, is this line at the top of your script:

!/bin/sh

if so, delete it (press backspace several times, there might be a hidden character) and re-add the line, being extra sure that you are ONLY adding the text above.

If this doesn't fix your issue, maybe please post it your sh file somewhere (Please replace your sudo password with nonsense characters, but leave the surrounding quotes please). It's best that you upload the file itself and do not copy/paste so as not to accidentally exclude hidden characters, though that works in a pinch.

Regarding the video, I've seen it and love it! However, using the pause gcode is totally not necessary since camera delay is built in, and the command will be suppressed by Octolapse anyway (if all is working as it should). If you want to use the gcode trigger just use the regular 'snap' command. You shouldn't need any camera delay for a DSLR unless you are using the trigger-capture command in gphoto2 (which I think you are not).

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/FormerLurker/Octolapse/issues/187#issuecomment-413194391, or mute the thread https://github.com/notifications/unsubscribe-auth/AIJ8N9L2QfjP9Ayl_Jw2IvG9GnVsd7SXks5uRB_fgaJpZM4VGzJ3 .

Lavarus commented 6 years ago

Yes! That was it, somehow I was missing the # char. It's working!

One more problem though. The printer pauses for about 3 seconds while the camera is taking a shot. This seems excessive. I tried to change to custom image preferences and use manual focus, but I get an error: 2018-08-15 11_14_11-octoprint

FormerLurker commented 6 years ago

Yeah, you won't be able to use the custom image settings with your DLSR. They interface with mjpegstreamer's control.htm page, which doesn't exist on your camera. I think I need to disable that for DSLRs right away (I thought I had actually, thanks for posting it). I am working on some auto-detection that would also have taken care of it, but it will be a bit before that is working properly.

You'll need to configure your camera manually, or you can create an initialization script (there is an option for that in the camera settings) and use gphoto2 to change the settings. I'm in the process of creating a guide for just this, and will post it to the wiki when complete (along with a few other guides).

Regarding the delay, it's probably due to gphoto2 taking a while. If you think it is slow now try cranking the resolution to the max. Download over slow USB definitely doesn't help.

However, there IS a way to defer downloading and to leave the images on the camera until right before rendering. There is a 'trigger-capture' command that returns as soon as the shutter closes and before the image is written to internal RAM/SD (I think...) I've created a script to download all of the images at the end of the print to the proper location and rename them to work with ffmpeg, which saves a ton of time and made capturing 6000x4000 images actually work for my slow camera. It still takes way longer than my webcam (just a few 100MS), but is MUCH faster than the capture-image-and-download method. Once you get your camera working well let me know and I'll walk you through the process of deferring download until right before rendering. You'll lose the snapshot preview, but it's worth it in my opinion for faster snapshots/prints.

FormerLurker commented 6 years ago

@Shadowen, good thinking. I need to add this to the guide because 100% someone will do this. I'm trying to figure out a way to make gphoto2 --capture-image-and-download work without sudo so I can just package the scripts with Octolapse (though I guess I would need to run chmod on them) without requiring any user edits. I'm thinking maybe I could create a script that adds gphoto2 to the NOPASSWORD list somehow. I'm really paying for not learning Linux like I should have way back in the day.... Better late than never!

jetsloth commented 6 years ago

@FormerLurker Another successful test https://youtu.be/jhvMrc7CyOs (bar the camera battery running out right at the end - as usual)

Also tried the gCode sender script - worked perfectly. Just tested on existing extruder motor as I haven't done any custom work yet, but worked a charm.

I'll post more results of the 360 project as I progress.

FormerLurker commented 6 years ago

@jetsloth, I'm glad the gcode worked. That's not been tested except through the virtual printer!

Nice quality.. thanks for testing it out!

ssvenn commented 6 years ago

These are some really cool improvements to octolapse! I am planning on using the external script to control the ws2812b LED strip in my printer cabinet, so that it can play colorful animations during printing but flash bright white each time octolapse grabs a frame :)

FormerLurker commented 6 years ago

@ssvenn, I may need to add an 'On Before Snapshot' and 'On After Snapshot' to make this work unless you are using a DSLR. Since the snapshots are threaded and executed in parallel, it's possible that your flash will trigger after all or some of your snapshots are taken unless your delay is just right. Also, you'll want a way to turn the flash off after a snapshot is completed I'm guessing. I'll think about this.

zenomsn commented 6 years ago

Hi @FormerLurker thank you for all the hard work you have been putting in this thread. I am a total newbie, installed Raspberry Pi 3+ and Octoprint with octolapse. But I was following directions like an ikea furniture. I am trying to follow you tips, first question is so in order to work I have to have a beta version of octoprint installed (the one I probably installed is no good)? Second, how do I install the GPhoto2? Do I take the SD card from raspberry and plug in the computer then run my Mac terminal to type the commands you instructed?

I have a Prusa MK3 with raspberry pi 3+ (installed the main available version yesterday), octoprint and octolapse, both also installed yesterday. I am trying to connect a Canon 500D that I have laying around (i checked and it is compatible with GPhoto2).

tellblom commented 5 years ago

I found a script that updates gphoto2 to the latest version for raspberry (That I need for my Canon M50) So if you need a newer version just run follow the instructions on this page: https://github.com/gonzalo/gphoto2-updater

Lavarus commented 5 years ago

Excellent, thank you.


From: tellblom notifications@github.com Sent: Thursday, October 4, 2018 12:45:17 AM To: FormerLurker/Octolapse Cc: Lavarus; Mention Subject: Re: [FormerLurker/Octolapse] [Request] DSLR/External Camera Triggering (#187)

I found a script that updates gphoto2 to the latest version for raspberry (That I need for my Canon M50) So if you need a newer version just run follow the instructions on this page: https://github.com/gonzalo/gphoto2-updater

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/FormerLurker/Octolapse/issues/187#issuecomment-426903640, or mute the threadhttps://github.com/notifications/unsubscribe-auth/Aoa0GemdwjCBimDMyisqNFdSYD6FBIATks5uha59gaJpZM4VGzJ3.

FormerLurker commented 5 years ago

@tellblom and @Lavarus, if you are running a newer version of Octopi, a change was made to Git that might break the gphoto2-updater script. If you run into an error about git and sudo, edit the script and change

if (git clone $branch_gphoto https://github.com/gphoto/gphoto2.git)

to

if (/usr/bin/git clone $branch_gphoto https://github.com/gphoto/gphoto2.git)
FormerLurker commented 5 years ago

@zenomsn, I seem to have missed your comment! Sometimes I get overwhelmed and miss some, sorry. Check this video out for a detailed walk through, including installation of the latest pre-release.

Let me know if that helps!

tellblom commented 5 years ago

@tellblom and @Lavarus, if you are running a newer version of Octopi, a change was made to Git that might break the gphoto2-updater script. If you run into an error about git and sudo, edit the script and change

if (git clone $branch_gphoto https://github.com/gphoto/gphoto2.git)

to

if (/usr/bin/git clone $branch_gphoto https://github.com/gphoto/gphoto2.git)

It' worked for me :) But I change it anyway

kimpimmel commented 5 years ago

Thank you @FormerLurker for all the time and effort to create this awesome tool, and for supporting the growing community!

Not sure if this thread is the right place, but I wanted to re-share a solution to a problem I encountered while getting OctoLapse + DSLR working. Hopefully it will help someone else.

I had a problem where my interface didn't match what was shown in the tutorials / guides. I couldn't find the 'Camera Dropdown' where you should add the DSLR Camera Profile, nor the Slicer Settings that were described for matching your print settings. The simple solution was that I was running an old version of OctoLapse - which I had installed through the OctoPrint Plugin Manager and assumed was the latest version - and all I had to do to fix the problem was to manually upgrade! I did it through the command line. The correct Camera Profile and Slicer Profile UI showed up right away and I was up and running.

Here's my first OctoLapse after getting DSLR triggering working https://twitter.com/kpimmel/status/1050567112584904704

FormerLurker commented 5 years ago

Hey @kimpimmel, thanks for your post! I've been having a lot of trouble rolling out the new version, but I am making steady progress. Thanks for sharing your video too! That is a difficult print to pull off with no artifacts. You might consider trying the 'high quality' snapshot trigger (I need testers). Here is a video explaining setup if you are interested: https://youtu.be/sDyg9lMqMG8

peterpetiesmith commented 5 years ago

I spent some time a trying to do this myself a while ago and just didn't have the time! Thanks @FormerLurker for EVERYTHING to do with this!!

I've just got this working on a virtual printer whilst I am in the middle of a rebuild, however I would love to hear how to defer the download until the end of the print. Once I get the printer back into a single piece I will give the "high quality" a go as this would also be a real benifit!

Thanks again!!

FormerLurker commented 5 years ago

@peterpetiesmith - I have a partially finished guide available here. Some of the guide is not finished, but it mostly involves testing the scripts. I will be reviewing and tweaking this guide for the next week or so, so let me know if you find any issues or comments. Let me know if it works too, and good luck with your printer rebuild! Also, I think you'll like the high quality mode. With that mode so long as your current slicer settings are entered into Octolapse and are exact, it should be pretty hard to tell which prints were made with Octolapse enabled and which without. Of course your mileage may vary :)

For anyone interested in learning how to use a DSLR with NO image download (best if you want to manually render your video), check out this draft guide. Again, this is a draft so some parts aren't finished, but it should be enough for the technically inclined.

peterpetiesmith commented 5 years ago

@FormerLurker Thanks for the reply!

Funny you should mention the separate processing of the images in "post" as I think this is actually more in line with what I would like to achieve. I know my way around an edit so it probably makes more sense for me. All seems to work fine "your end", my 7D seems to only take every other photo when I CMD line trigger it which causes it to fail on time-lapse after the first photo with:

snapshot_script_error: The snapshot script failed with the following error message: Error PTP I/O Error

Hopefully it isn't too painful a fix for me.

Otherwise I noticed:

I noticed you create a file call initialize_camera_save_to_sd.sh and try to give permissions to initialize-camera-save-to-sd.sh in that no image download instruction.

Once again thanks for your implementation of this!!

FormerLurker commented 5 years ago

@peterpetiesmith, regarding the IO error, my guess would be that your camera is still saving an image to SD, and can't be called to capture another snapshot until the first one is finished saving. Try manually calling gphoto2 --trigger-capture, wait 30 seconds and try again. If that fails, try again after 60 seconds, etc. If it doesn't start working after some period of time there is probably another issue.

Also, thanks for catching that file name error. I believe I have fixed it. I did a lot of copy/paste for that guide and knew I'd miss something :)

Also, if you develop any cool pre/post render scripts (or any others) that are useful, send them my way if you don't mind! Eventually I would like to have a library of pre-written scripts for users to play with. Also, let me know if you need any additional parameters to be sent to the scripts. There's a ton I COULD include, but I'm not sure what else could be useful.

FormerLurker commented 4 years ago

So, this is an old issue that I'm going to close, but I wanted to first mention that the DSLR guides have been updated over the last 9 months, and a lot of the problems you encountered have been fixed. There are, of course, some problems for particular cameras still, but it's working now more and more. I recommend updating GPhoto2 to the latest version if possible, since lots of new cameras are being supported all the time.

If you continue to have issues, please open a new ticket and I will take a look.

Thanks for your participation!!!