CHDKPTP and CHDK motion mode - General Help and Assistance on using CHDK stable releases - CHDK Forum  

CHDKPTP and CHDK motion mode

  • 5 Replies
  • 1858 Views
CHDKPTP and CHDK motion mode
« on: 25 / January / 2021, 06:49:26 »
Advertisements
When operating CHDK in "motion detection mode" will CHDKPTP support transfers simultaneously?
Thank you.


*

Offline reyalp

  • ******
  • 14080
Re: CHDKPTP and CHDK motion mode
« Reply #1 on: 25 / January / 2021, 12:43:45 »
When operating CHDK in "motion detection mode" will CHDKPTP support transfers simultaneously?
You can use motion detection with chdkptp.

If you want to use it with remoteshoot, you'd use the -script option to run your motion detection script, -shotwait set to a large value so it doesn't time out, and -shots for the max number of shots you want to shoot.

If you want to use a normal camera side script like mdfb, you'd also need a glue script like the example in lua/extras/rawopint_rs.lua (that's specific to a different script, but should give you the idea. See also https://chdk.setepontos.com/index.php?topic=13386.0)
Don't forget what the H stands for.

Re: CHDKPTP and CHDK motion mode
« Reply #2 on: 26 / January / 2021, 09:29:36 »
Thank you.

The goal is to operate the CHDK with motion detection and then every minute (or some interval) poll for a new image with CHDKPTP. Ideally there would be some channel/trigger between a creating new image  and CHDKPTP to transfer. My last experience with CHDK was EyeFi days and image transfers took to long over 54MBPS, speculating USB CHDKPTP transfer speed is 1MByte/SEC? maybe better?

*

Offline reyalp

  • ******
  • 14080
Re: CHDKPTP and CHDK motion mode
« Reply #3 on: 26 / January / 2021, 13:45:42 »
The goal is to operate the CHDK with motion detection and then every minute (or some interval) poll for a new image with CHDKPTP. Ideally there would be some channel/trigger between a creating new image  and CHDKPTP to transfer.
You have a few options, all with some complications and some script coding required
1) Use remoteshoot like a I suggested above.
Images will be saved over USB instead of going to the SD.  On many cameras, saving over USB is about as fast as saving to SD, so there would be negligible performance impact. Needs a custom script or glue script, and if anything goes wrong, images aren't backed up on the SD card. A few ports don't support remoteshoot.

2) Periodically run a chdkptp command to check for images.
The complication here is that CHDK can only run one script at a time, and listing files requires a script, so you can't just use the standard imdl or mdl commands while your MD script continues to run.
2a) You could make your MD script include a check for usb messages (read_usb_msg) and respond with a list of files. The chdkptp side script would send a message, get back a list of filenames, and download them.
2b) Alternately, the camera side script could write a list of names to a file at some predictable location, and the chdkptp side could download that, and then download the listed images. There would be some complication avoiding downloading while the list was being updated.
2c) Have the MD script check for a quit message. Similar 2a, you'd use read_usb_msg, but on receiving the message, the MD script would end and then the chdkptp side script could download with normal commands and restart the MD script.

3) chdkptp side script wait for images to be available
3a) Make the camera side script send a message with the filename after each shot. The chdkptp side script would listen, and download each image as it became available. One complication is that there isn't a direct way to know when camera jpeg is finished saving, so you'd some logic like rlib_wait_file used by the shoot command.
3b) Make the camera side script quit when images are available to download. The chdkptp side script would check script_status until the script was not running, download the files, and restart the MD script.

#2c and #3b stop motion detection while the files are downloading. This is a disadvantage if you want to capture every possible shot, but it's possible you could run into stability issues downloading asynchronously with the shooting process as in #2a, #2b and #3a. I've done this a few times without problems, but it's hard say if it's entirely safe. Option #1 avoids this, since it redirects the normal file save.

If you want to delete files after downloading, beware that chdkptp can't delete without running a script, so #2a, #2b and #3a would need additional logic to handle that.

I can provide some code suggestions if you have a preferred approach.

Quote
My last experience with CHDK was EyeFi days and image transfers took to long over 54MBPS, speculating USB CHDKPTP transfer speed is 1MByte/SEC? maybe better?
This depends on the camera, what models(s) are you planning to use? Some very old cameras that only support USB 1 might be 1MByte/s. Modern cameras are more like 20-30.
Don't forget what the H stands for.


Re: CHDKPTP and CHDK motion mode
« Reply #4 on: 26 / January / 2021, 13:50:10 »
2c sounds worthy of a test. How far back does chdkptp support, assume the Canon model must support PTP.
Have SX30 if that supports CHDKPTP, otherwise will need to order a newer camera.
« Last Edit: 26 / January / 2021, 14:01:59 by apimage »

*

Offline reyalp

  • ******
  • 14080
Re: CHDKPTP and CHDK motion mode
« Reply #5 on: 26 / January / 2021, 14:26:32 »
2c sounds worthy of a test. How far back does chdkptp support, assume the Canon model must support PTP.
chdkptp works with virtually every model supported by CHDK https://chdk.fandom.com/wiki/Template:Supported_Cameras

SX30 should work fine.

2c should be pretty simple. In your MD script, you can do something like
Code: [Select]
repeat
 md_detect_motion(... md paramters ...)
until read_usb_msg() == 'quit'
The md_detect_motion timeout parameter will control how often this is checked when no motion is detected. If you're integrating this into an MD script that already has detect motion in a loop, you'll need to arrange for the quit case to exit entirely.

The chdkptp side script will look something like
Code: [Select]
con:write_msg('quit')
con:wait_status{run=false}
cli:execute('play')
cli:execute('imdl -rm')
cli:execute('rec')
con:exec("loadfile('A/CHDK/SCRIPTS/mdscript.lua')()")
You can run this from the command line like
Code: [Select]
chdkptp -c -e"exec dofile('myfile.lua')"

The code above switches to playback before downloading and deleting files, since some cameras crash when you try to shut down or switch to playback after deleting files in rec mode. If you don't want to delete files from the card, you can leave out the -rm on the imdl command, and the play/rec commands.

You can control the download location with the -d= option to imdl. Use help imdl for details.

If your MD script was written to be run from the CHDK menu, you'll need to set the menu options before the loadfile call, like
Code: [Select]
con:exec("a=1 b=2 loadfile('A/CHDK/SCRIPTS/mdscript.lua')()")
or hard code them in the script.

You could also keep the md script on your PC, and run it like
Code: [Select]
cli:execute('.<myscript.lua')
In that case, all parameters would need to be coded in the script itself
Don't forget what the H stands for.

 

Related Topics