Strange problem with intervals. - LUA Scripting - CHDK Forum

Strange problem with intervals.

  • 3 Replies
  • 4305 Views
Strange problem with intervals.
« on: 05 / July / 2009, 11:40:36 »
Advertisements
Hi,

I'm working on a time lapse script for the total solar eclipse 22nd July in China. The script consits of two separate loops with different settings for partial and total phases of the eclipse (so I can change the interval for totality and maybe alter bracketing settings). I switch between the loops by pressing the "set" key. The shoot-functions in the script are still bare-boned and I start to think about them after I get everything else working.

As a bonus I also log luminance values and temperatures to a file.  At this time the script takes two different input parameters for the interval of the luminance + temp sampling in the two loops, and two more parameters that define how often a pic should be taken (e.g. every third sampling, take a picture).

I have a strange problem with the current code. The script starts with the first loop for the partial phase. When I press SET and change the loop, the interval doesn't  change! Everything else does, for example the pic-taking step (totstep). But the totloop() still uses exactly the same interval as partloop(). Can anyone spot the problem?

Code: [Select]
--[[
@title Solar Eclipse lapse + lum-log.
@param a Part. sampl. intv. min
@param b Part. sampl. intv. sec
@default b 5
@param c Part. shoot step
@default c 2
@param d Tot. sampl. intv. min
@param e Tot. sampl. intv. sec
@default e 2
@param f Tot. shoot step
@default f 10
]]

partintv = a*60000+b*1000
partstep = c
totintv = d*60000+b*1000
totstep = f

start = get_tick_count()

x = 0

function partshoot()
shoot()

repeat
sleep(50)
until get_shooting() == false
end

function totshoot()
shoot()

repeat
sleep(50)
until get_shooting() == false
end


function partloop()
repeat
parttick = get_tick_count()
x = x+1
press("shoot_half")
sleep(1000)
print("part" .. x .. "," .. (get_tick_count()-start) .. "," .. get_bv96() .. "," .. get_temperature(0))
if (x%partstep==0) then
partshoot()
end
release("shoot_half")

wait_click(partintv - (get_tick_count()-parttick))
if is_pressed "set" then
print("switch to totality")
totloop()
end
until false
end

function totloop()
repeat
tottick = get_tick_count()
x = x+1
press("shoot_half")
sleep(1000)
print("tot" .. x .. "," .. (get_tick_count()-start) .. "," .. get_bv96() .. "," .. get_temperature(0))
if (x%totstep==0) then
totshoot()
end
release("shoot_half")

wait_click(totintv - (get_tick_count()-tottick))
if is_pressed "set" then
print("switch to partial")
partloop()
end
until false
end

partloop()


Furthermore, can anyone confirm this being a smart way to switch between loops? Would something like "exit this function and start running the other one" be better? How is it done?

Re: Strange problem with intervals.
« Reply #1 on: 05 / July / 2009, 12:00:30 »
Good thing that I posted. When reading the post I read it like it's not written by me in the first place and immediately spot the error on the line
Code: [Select]
totintv = d*60000+b*1000 :D

So anyway, ideas on proper switching of the loops? Or any other comments on the eclipse stuff?

*

Offline reyalp

  • ******
  • 14128
Re: Strange problem with intervals.
« Reply #2 on: 05 / July / 2009, 18:38:07 »
I haven't looked at the code too closely, but you really don't want to be recursively calling the loop functions from each other. I would suggest making one loop, and changing it's behavior on set eg (pseudocode)

do
  if partial mode
    do partial mode stuff
    interval = partial mode interval
  else
    do full mode stuff
    interval = partial full mode interval
  end
  wait_key (interval - elapsed time)
  if key then change mode
forever
Don't forget what the H stands for.

Re: Strange problem with intervals.
« Reply #3 on: 10 / July / 2009, 15:41:30 »
The recursive thing isn't that big of a deal since the mode is only going to get changed twice. But you're right, your way seems more sophisticated and I think I'll head for that.

 

Related Topics


SimplePortal © 2008-2014, SimplePortal