Dark Frames in Continuous Mode - LUA Scripting - CHDK Forum

Dark Frames in Continuous Mode

  • 8 Replies
  • 7625 Views
Dark Frames in Continuous Mode
« on: 06 / September / 2016, 03:35:56 »
Advertisements
I just want to quickly shoot a sequence of dark frames, but it stops after two shots and exp count is wrong (known bug).  What am I doing wrong here?

Edit: latest code, still doesn't work

Code: [Select]
function dark_shot(tv_direct)
    --enable or disable dark frame subtraction, which doubles time over 2/3sec
    set_raw_nr(RAW_NR_OFF)
   
    --set the time as a tv direct value, where 0=1sec, for the first shot
    --must be in 'P' mode
    set_tv96_direct(tv_direct)
   
    --do preshot
    press('shoot_half')
   
    --and wait until shooting settings are ready
    repeat sleep(10) until get_shooting() == true

    press('shoot_full_only')
           
    for n=1,4 do
        hook_shoot.wait_ready()
        --close mecha shutter for dark frame
        closeshutter()
        logline()
        print(n,'starting')
       
        --exposure starts here
        hook_shoot.continue()
    end
    release('shoot_full')
   
    -- allow final shot to end before restore + possible shutdown
    repeat sleep(10) until not get_shooting()
    sleep(1000)
end

Edit: it might be because shooting and script run in parallel and I need to be careful of where they get in sync.
« Last Edit: 06 / September / 2016, 06:38:13 by jmac698 »

*

Offline reyalp

  • ******
  • 14126
Re: Dark Frames in Continuous Mode
« Reply #1 on: 06 / September / 2016, 13:25:09 »
I just want to quickly shoot a sequence of dark frames, but it stops after two shots and exp count is wrong (known bug).  What am I doing wrong here?
What camera?

My fixedint.lua script http://chdk.wikia.com/wiki/Lua/Scripts:_Fixed_Exposure_Intervalometer does this correctly on the cameras I have. From a quick look it seems like your script ought to work, but without the full script it's hard to be sure.

Quote
Edit: it might be because shooting and script run in parallel and I need to be careful of where they get in sync.
I'm not sure what you mean here. hook_shoot should become ready once per exposure, and wait_ready should wait until it does.

Since you mention the exposure count being wrong, you should verify whether it is taking 4 exposures and only saving two raw files, or just taking two shots.
Don't forget what the H stands for.

Re: Dark Frames in Continuous Mode
« Reply #2 on: 06 / September / 2016, 17:48:59 »
Code: [Select]
--[[
@title dark by temp
]]
 
--log dark frames
--by jmac698

--all initialization and error checking is in this part--
 
RAW_NR_AUTO=0
RAW_NR_OFF=1
RAW_NR_ON=2

RAW_OFF=0
RAW_ON=1
 
propcase=require("propcase")
 
  -- check for native call interface:
if (type(call_event_proc) ~= "function" ) then
    error("your CHDK does not support native calls")
end   
 
local bi=get_buildinfo()
 
if bi.os=="vxworks" then
    closeproc="CloseMShutter"
    openproc="OpenMShutter"
    if (call_event_proc("InitializeAdjustmentFunction") == -1) then
        error("InitAdjFunc failed")
    end
elseif bi.os=="dryos" then
    closeproc="CloseMechaShutter"
    openproc="OpenMechaShutter"
    if (call_event_proc("Mecha.Create") == -1) then
        if (call_event_proc("MechaRegisterEventProcedure") == -1) then
        error("Mecha.Create failed")
    end
end     
else
    error("Unknown OS:" .. bi.os)
end
 
-- close mechanical shutter
function closeshutter()
    if (call_event_proc(closeproc) == -1) then
        print("closeshutter failed")
    end
end

-- open mechanical shutter
function openshutter()
    if (call_event_proc(openproc) == -1) then
        print("openshutter failed")
    end
end


  -- switch to record mode if necessary
if ( get_mode() == false ) then
    print("switching to record mode")
    sleep(1000)
    set_record(1)
    while ( get_mode() == false) do
        sleep(100)
    end
end

-- make sure we are in P mode
capmode=require("capmode")
if ( capmode.get_name() ~= "P") then
    print("Not in Program mode!")
end

-- check that flash is disabled
if ( get_flash_mode() ~= 2) then
    error("Flash not disabled!")
end
 
function logline()
   local fname='A/log.csv'
   local st=os.stat(fname)
   local f=io.open(fname,'ab')
   local CCD=1
   local OPTICAL=0
   if not st then
      f:write('date,exp,ccd temp,opt temp,vbatt\n')
   end
   f:write(string.format('%s,%d,%d,%d,%d\n',os.date('%m/%d/%Y %H:%M:%S'),get_exp_count(),get_temperature(CCD),get_temperature(OPTICAL),get_vbatt()))
   f:close()
end
 
function init()
    require("hookutil")--import hook utils
    hook_shoot.set(10000)--enable hook
end

--main loop in this function
function dark_shot(tv_direct)
    --enable or disable dark frame subtraction, which doubles time over 2/3sec
    set_raw_nr(RAW_NR_OFF)
   
    --set the time as a tv direct value, where 0=1sec, for the first shot
    --must be in 'P' mode
    set_tv96_direct(tv_direct)
   
    --do preshot
    press('shoot_half')
   
    --and wait until shooting settings are ready
    repeat sleep(10) until get_shooting() == true

    press('shoot_full_only')
           
    for n=1,4 do
        hook_shoot.wait_ready()
        --close mecha shutter for dark frame
        closeshutter()
        logline()
        print(n,'starting')
       
        --exposure starts here
        hook_shoot.continue()
    end
    release('shoot_full')
   
    -- allow final shot to end before restore + possible shutdown
    repeat sleep(10) until not get_shooting()
    sleep(1000)
end

--main control
init()
--delay
sleep(2000)

tv_sec_tot=1--total time in seconds
tv96_tot=usec_to_tv96(tv_sec_tot*1000000)
dark_shot(tv96_tot)
--record last temp
logline()
--cleanup
hook_shoot.set(0)


 

 

It's loosely based on your fixedint script, which btw crashed on my SX50 when using long intervals.
Anyhow, this one is running on SD1200.
« Last Edit: 06 / September / 2016, 17:55:52 by jmac698 »

Re: Dark Frames in Continuous Mode
« Reply #3 on: 07 / September / 2016, 06:09:35 »
Well I know why it doesn't work now.  It seems to be my port.  Your fixedint doesn't work either, it only took one pic.   Here's the log:

Quote
date,tick,exp,exp_start,sleep,vbatt,tsensor,topt,free_mem,lua_mem,desc
09/06/2016 15:57:20,107980,1905,103260,,4037,32,32,800464,106,fixedint v:1.2 / platform:ixus95_sd1200-100c-1.4.1-4634 May 27 2016 22:28:02 / interval:0 / taking darks / cont_mode / sd:494 af_ok:true fl:6200 efl:35000 zoom_pos:0 / sv96:371 tv96:-192 av96:292

I can update the firmware and try again.  All I know so far is that darks seem to work, but it doesn't take enough pictures.

Edit:
updated with ixus95_sd1200-100c-1.5.0-4682-full, set #shots to 4, it stopped at just one.  However, I set it to unlimited, now it's working. 
« Last Edit: 07 / September / 2016, 07:21:11 by jmac698 »

*

Offline reyalp

  • ******
  • 14126
Re: Dark Frames in Continuous Mode
« Reply #4 on: 07 / September / 2016, 12:57:41 »
I can update the firmware and try again.  All I know so far is that darks seem to work, but it doesn't take enough pictures.

updated with ixus95_sd1200-100c-1.5.0-4682-full, set #shots to 4, it stopped at just one.  However, I set it to unlimited, now it's working.
Nothing much has changed since May, so I wouldn't expect the build change to be significant.

To debug this, I would suggest trying to narrow down what part of the script is not behaving as expected. Make a minimal test case and log every point significant point.

As a wild guess, the script could behave in unexpected ways if the remote hook (wait_until_remote_button_is_released in capt_seq / hook_shoot in lua) is not being executed, or is in the wrong place.
Don't forget what the H stands for.

Re: Dark Frames in Continuous Mode
« Reply #5 on: 07 / September / 2016, 17:48:14 »
What would be helpful, is if I knew the code worked to begin with.  Could you test it on one of your cameras?

*

Offline reyalp

  • ******
  • 14126
Re: Dark Frames in Continuous Mode
« Reply #6 on: 08 / September / 2016, 01:33:57 »
What would be helpful, is if I knew the code worked to begin with.  Could you test it on one of your cameras?
It appears to work on my D10. Takes 4 shots.

Initially, I didn't think to put the camera in continuous mode. This made the script fail after the first shot with a "wait_ready timeout" error. If you want to add a check,  fixedint has an example.

Also note that since your log is immediately after the hook shoot hook becomes ready, there's a good chance the exposure count won't be incremented yet. Putting it after hook_raw should be more reliable.
Don't forget what the H stands for.

Re: Dark Frames in Continuous Mode
« Reply #7 on: 18 / September / 2016, 14:03:36 »
Thanks for testing this, that code was based on theory from learning from your fixint and the answers you gave me about it, very helpful!  I'm glad I now know how to do the continuous mode loop, just wish my camera was reliable with it. 

Btw, my idea for double exposures failed on this camera.  It still might work on another camera.  No wonder I couldn't troubleshoot that one either.

It would be useful to take temps during a long exposure to integrate them as well.

I wish I could read part of the sensor while letting the rest keep exposing. I'd use that to gather some stats which are more accurate than temp.  It would be good for an HDR mode also, of course this has been done in magic lantern.

*

Offline reyalp

  • ******
  • 14126
Re: Dark Frames in Continuous Mode
« Reply #8 on: 18 / September / 2016, 14:33:44 »
Thanks for testing this, that code was based on theory from learning from your fixint and the answers you gave me about it, very helpful!  I'm glad I now know how to do the continuous mode loop, just wish my camera was reliable with it. 
Try hooktest.lua in the test directory and post the log.
Don't forget what the H stands for.

 

Related Topics


SimplePortal © 2008-2014, SimplePortal