need to detect when the camera is done taking the picture - page 2 - Script Writing - CHDK Forum supplierdeeply

need to detect when the camera is done taking the picture

  • 20 Replies
  • 8052 Views
Re: need to detect when the camera is done taking the picture
« Reply #10 on: 21 / January / 2015, 10:28:38 »
Advertisements
sory..  i guess that makes sense to add....

im using the AF Led 

function blink_led()
status = poke(0xC0220164, 0x46, 1)  --Turn LED ON
status = poke(0xC022C028, 0x46, 1)  --Turn LED ON
sleep((b*100))
status = poke(0xC0220164, 0x44, 1)  --Turn LED OFF
status = poke(0xC022C028, 0x44, 1)  --Turn LED OFF
end




/Kyndal


« Last Edit: 21 / January / 2015, 10:31:15 by kyndal »
SD1100IS 101a,  homebuilt 0.9.9-866

*

Offline reyalp

  • ******
  • 13435
Re: need to detect when the camera is done taking the picture
« Reply #11 on: 21 / January / 2015, 13:02:04 »
Thanks.
Looking at this a little closer, I think I see the problem:

Code: [Select]
repeat
hook_raw.wait_ready()      --  when raw ready
blink_led()              --  blink led

--wait for robot to trigger

if ((is_pressed("remote")) or (is_pressed("video")))  then 
hook_raw.continue()
end

until ( false )
wait_ready() returns true when the shooting code is inside the hook. So once the raw hook is reached, your code will repeatedly run through the loop checking the keys, checking the hook (which will be ready until) and blinking the LED.

What you probably want instead is something more like
Code: [Select]
hook_raw.wait_ready()
blink()
repeat sleep(10) until is_pressed(...) --- or something with wait_click
hook_raw.continue()

A couple other notes:
1) The raw hook is after the picture is taken but before the jpeg is saved, so the next exposure will start at some undetermined time after you do hook_raw.continue(). If you want to start the exposure as soon as the robot is in position, you'll probably want to do something with the shutter hook.
2) The timeout you pass to set() determines how long the hook will wait for you to call continue(). So in your code, if no key / remote signal is received, the next shot would start after 10 seconds.
Don't forget what the H stands for.

Re: need to detect when the camera is done taking the picture
« Reply #12 on: 22 / December / 2015, 14:30:08 »
This is another interesting thread.

I'm thinking of the following test to integrate multicam.lua and a turntable controlled by a Windows client sending tcp commands to an Arduino ethernet shield based server.

With raw enabled, at 30 degree (or so) rotations I will stop the turntable then multicam (i) preshoot (ii) shoot_hook_sync.

get_shooting going false seems a reasonable event to restart the turntable rotation...although it also seems the hook_raw may speed that up a bit? (i.e. at start of buffer writing rather than end?)

I'd like to implement a download (jpg&dng) from sd (and delete) to pc asap after rotation restarts however a test (using shoot in chdkptp GUI) shows that get_exp_count() increments by 1 only (I assume that is related to jpg save and this thread makes me aware the counter is updated before the file is completely saved anyway).

Is there anything other than a large wait that I might rely on to ensure both jpg&dng have finished saving to sd before download jpg&dng to pc is initiated - if nothing has changed since the last post in this thread I assume not?
« Last Edit: 22 / December / 2015, 14:33:11 by andrew.stephens.754365 »

*

Offline reyalp

  • ******
  • 13435
Re: need to detect when the camera is done taking the picture
« Reply #13 on: 22 / December / 2015, 15:08:44 »
get_shooting going false seems a reasonable event to restart the turntable rotation...although it also seems the hook_raw may speed that up a bit? (i.e. at start of buffer writing rather than end?)
Yes, hook_raw should be the start of the raw hook, which is definitively after the exposure is complete, but before saving raw/DNG. If you aren't shooting raw, the difference is marginal
Quote
I'd like to implement a download (jpg&dng) from sd (and delete) to pc asap after rotation restarts however a test (using shoot in chdkptp GUI) shows that get_exp_count() increments by 1 only (I assume that is related to jpg save and this thread makes me aware the counter is updated before the file is completely saved anyway).
The counter behavior varies between cameras and is somewhat unreliable. In general, on most cameras it should increment before the raw hook is entered, if raw is enabled. However, there are probably ports that are broken, and some that are usually correct but occasionally increment late.

On some old cameras (Digic II, maybe early Digic III era) it doesn't increment until after raw saving is complete.

Quote
Is there anything other than a large wait that I might rely on to ensure both jpg&dng have finished saving to sd before download jpg&dng to pc is initiated - if nothing has changed since the last post in this thread I assume not?
Unfortunately, there isn't any currently any reliable indication when jpeg is done. This might be something we could hack into the filewrite code (currently used for remoteshoot) but it hasn't been done yet.  It's also possible PT_CompleteFileWrite in http://chdk.setepontos.com/index.php?topic=5690.0 could be used.

If you were only using one camera, I'd suggest using remoteshoot, but it's not a good solution for multiple cameras because at the moment you can only remoteshoot from one camera at a time. It would be theoretically possible make multicam do remoteshoot over multiple cameras, but the code would be really complicated.
Don't forget what the H stands for.


Re: need to detect when the camera is done taking the picture
« Reply #14 on: 22 / December / 2015, 15:40:57 »
Appreciate the comments and a good time of year to say thanks again for all your sophisticated works.

Re: need to detect when the camera is done taking the picture
« Reply #15 on: 24 / December / 2015, 08:38:33 »
Is it possible to pin jpg&dng sd save finish down to a second...

os.time in lua script returns seconds since epoch  [do that just after multicam hook_shoot.continue()]

If it were possible to read the time created attribute of all sd image files and loop until 2 of these files are equal or greater to time at exposure start then loop over these two files until their filesize attribute no longer changed then, I assume, both jpg&dng files have finished saving to sd card.

I think sx150is is Digic IV Dryos.

Could it be possible to read the "file created time" attribute via lua script?
Could it be possible to read the "filesize" attribute via lua script?

(if so, i'm sure ff_imglist would come in handy somewhere)

Edit: is it known if the buffer (or buffers) is/are marked in some way after save to sd is completed?
« Last Edit: 24 / December / 2015, 10:00:20 by andrew.stephens.754365 »

*

Offline reyalp

  • ******
  • 13435
Re: need to detect when the camera is done taking the picture
« Reply #16 on: 24 / December / 2015, 15:20:51 »
Could it be possible to read the "file created time" attribute via lua script?
Could it be possible to read the "filesize" attribute via lua script?
Yes, os.stat() http://chdk.wikia.com/wiki/Lua#Added_features_2

Quote
If it were possible to read the time created attribute of all sd image files and loop until 2 of these files are equal or greater to time at exposure start then loop over these two files until their filesize attribute no longer changed then, I assume, both jpg&dng files have finished saving to sd card.
FWIW, JPEG will always be after the raw, so you should only need to look at that one.

Quote
Edit: is it known if the buffer (or buffers) is/are marked in some way after save to sd is completed?
I don't know what you mean. The raw buffer is generally destroyed at some point after the raw hook (though on cameras with two raw buffers it might sit around), and other things like the live view data may occupy that space between shots.
Don't forget what the H stands for.

Re: need to detect when the camera is done taking the picture
« Reply #17 on: 25 / December / 2015, 05:45:31 »
Super - seems imglist() may already have most/all of what I need.

Thanks.


Re: need to detect when the camera is done taking the picture
« Reply #18 on: 25 / January / 2016, 10:23:39 »
FWIW, JPEG will always be after the raw, so you should only need to look at that one.

Is it known if os.time() rounds or truncates (or something) to the second?


I added the attached function, cmds.sd_write_finish(), to multicam.lua (r692) camera side script - it still needs a tidy-up.

To run, it also needs the commented changes made to both rlibs.lua function "ff_imglist_fn(self,opts)" & multicam.lua function "cmds.shoot_hook_sync()".

I've only completed minimal testing using timestamps of image files pre-existing on the camera (i.e. not after shooting while the jpg file is still being written to) but those tests seem to work ok.   

In case I forget how this hangs together (or if it could be useful for others) also included is a basic "function-flow" diagram of how to work through from pc-side multicam -> camera-side-multicam -> rlibs camera side & back to PC.

*

Offline reyalp

  • ******
  • 13435
Re: need to detect when the camera is done taking the picture
« Reply #19 on: 25 / January / 2016, 13:00:47 »
Is it known if os.time() rounds or truncates (or something) to the second?
The value returned os.time the integer number of seconds since Jan 1, 1970 (in the cameras timezone). It's not really rounded or truncated form anything.

get_tick_count() returns the number of milliseconds since boot, with 10 ms precision. The tick count and time value are not necessarily aligned, i.e. you should not assume that time increments by every time get_tick_count() passes a multiple of 1000.
Don't forget what the H stands for.

 

Related Topics