scripts, taking pics, and stability (hhhhhelp!) - Script Writing - CHDK Forum supplierdeeply

scripts, taking pics, and stability (hhhhhelp!)

  • 8 Replies
  • 7299 Views
scripts, taking pics, and stability (hhhhhelp!)
« on: 24 / March / 2009, 23:57:50 »
Advertisements
I'm curious if there are others that have pushed the limits of chdk scripting, picture taking, and software stability.

I've been working for some time on a script with simple goals. take a pic, evaluate the exposure, delete the oldest image on the card, repeat forever. unfortunately i'm finding that the combination of scripting and taking pics is far less stable than i had hoped.

my script runs forever (or at least 1000x iterations) if i simply remove the press("shoot_full") commands. if i create a simple script that takes pics, it will exit at far less than 1000x iterations. this means that taking pics is a necessary component of the stability problems.

i've been working with lua because it appears to better support complex scripts but perhaps this is a lua only problem.

i've spent several months trying to isolate the bugs in my code but have failed to get closer to my goal. now i'm fieldng ideas that i may have overlooked. at this point my only option is frequent camera resets via a arduino micro controller.

*

Offline reyalp

  • ******
  • 14118
Re: scripts, taking pics, and stability (hhhhhelp!)
« Reply #1 on: 25 / March / 2009, 02:47:01 »
It's probably a bug. If you can give a reproducible test case, there is a much greater chance someone will be able to fix it.

edit:
and if it's a problem with your script, rather than a chdk bug, there's very little chance anyone can tell you the problem without seeing the script.

lua is relatively new, and only a few people have written complicated scripts with it.
« Last Edit: 25 / March / 2009, 02:50:03 by reyalp »
Don't forget what the H stands for.

Re: scripts, taking pics, and stability (hhhhhelp!)
« Reply #2 on: 25 / March / 2009, 07:22:51 »
part of the problem is that since its an intermittent bug its difficult to provide a solid test case. however, my simplified script should reveal the bug after many iterations.

it may be necessary to run this code a couple of times to see the crash. i've had the same code run 800 iterations and then on the next run crash after 40.

oh, and i should explain what i mean by crash. the script is exited without an error. my logging has shown that this almost always happens on press or release of shoot_half. however, if i remove the shoot_full lines this no longer occurs.

i've also tried calling press("shoot_half") through the pcall method which calls functions and catches errors. it doesn't work.

Code: [Select]

--[[
  Log file handling. Uses io functions if they are available, otherwise print().

  Usage:
 
    require "f-log"
    log.open("my_log.txt")
    log.print("A quick brown fox etc.\n")
    log.close()
 
  Author: fudgey 2008/10/27
  Licence: GPL v3 or higher
--]]


log={}

-- If io.* are available, open log CHDK/LOGS/name for append. If name==nil, use lua_0000.log
function log.open(name)
log.filename = name
    -- yes, use write() for logging
    if name==nil then name="lua_0000.log" end
    log.file,msg=io.open("A/CHDK/LOGS/"..name,"a")
    if not log.file then
      log.type=0 
      print_screen(1)
      print("Error opening log, using print() from now on: "..tostring(msg))
    else
    log.type=1
      log.isopen=true
    end
  bi=get_buildinfo()
  log.print("\n--- Log opened at ",date.datetimestamp()," ---\n")
  log.print("platform: ",bi.platform," ",bi.platsub,"\n")
  log.print("version: ",bi.version," ",bi.build_number," built on ",bi.build_date," ",bi.build_time,"\n")
end

function log.close()
  if log.type==1 then
    log.print("\n--- Log closed at ",date.datetimestamp()," ---\n")
    io.close(log.file)
    log.isopen=false
  end
end

function log.print(...)
  if log.type==1 and log.isopen==true then
    log.file:write(...)
    log.file:flush()
  else
    print(...)
  end
end

--[[
    Find the smallest three digit zero-padded number which doesn't match any
    existing file in A/CHDK/LOGS/ when used as a part of a file name of the
    form headerNNN.extension. Return complete filename without path.
 
    Example:
    logfilename = log.find_new_filename("log_","txt")
    will return "log_002.txt" if log_000.txt and log_001.txt already exist.
 
    If all files up to log_999.txt are found, log_999.txt is returned.   
--]]
function log.find_new_filename(header,extension)
  local numstr 
  local filename
 
  for i=0,999 do
    -- zero pad
    if i<10 then
      numstr = "00"..tostring(i)
    elseif i<100 then
      numstr = "0"..tostring(i)
    else
      numstr = tostring(i)
    end
 
    filename = tostring(header) .. numstr .. "." .. tostring(extension)
    local filepath="A/CHDK/LOGS/"..filename
    log.filename = "A/CHDK/LOGS/"..filename
    local r,msg = os.stat(filepath)
    if r==nil then
      return filename
    end
    -- note: long for loop without forced sleep!
  end
 
  -- no free names found
  return filename
 
end

function log.segmentAndCopy(filePath)
log.close()
disk.moveFile("A/CHDK/LOGS/"..log.filename,filePath)
log.open(log.filename)
end

--[[
  Functions that return Date/Time strings for use in CHDK Lua scripts.
 
  Authors: 2009/01/27 mattkime: replace get_time with os.date
           2008/10/27 fudgey: datestamp(), datetimestamp()
           2008/08/17 Francesco Bonomi: format_nn(), timestamp()
  Licence: GPL
--]]


date = {}



-- formats a number to two digit string with leading zeroes e.g. 3 to "03"
-- (only works for numbers in range 0 - 99)
function date.format_nn(n)
  local r=tostring(n)
  if n<10 then
    r= "0" .. n
  end
  return r
end


-- return a formatted timestamp (hh:mm:ss)
-- if called without parameters, gets current camera time and formats it
-- if a parameter is passed, formats the passed number
function date.timestamp(t)
  if t==nil then
    return os.date("%X")
  else
    return os.date("%X",t)
  end
end


-- Returns formatted date string from camera clock.
-- Output format example: 2008/09/03
function date.datestamp()
  return os.date("%Y/%m/%d")
end

--[[
-- Returns formatted time string from camera clock.
-- Output format example: 23:05:59
function timestamp2()
  local H=get_time("h")
  local M=get_time("m")
  local S=get_time("s")
  return format_nn(H) .. ":" .. format_nn(M) .. ":" .. format_nn(S)
end
--]]

-- Returns formatted date + time string from camera clock.
-- Output format example: 2008/09/03 23:05:59
function date.datetimestamp()
  return os.date("%Y/%m/%d %X")
end


log.open("F2.log")

counter = 0

repeat
counter = counter + 1
print(counter)
--disk.deleteUntilMbFree100CANON(20,40)
log.print("cam.smartShoot - start\n")
-- Shoot: Half press and wait until camera is ready
  press("shoot_half")
  repeat
    sleep(1)
  until get_shooting() == true
  log.print("cam.smartShoot - confirm shooting\n")
  --not sure what good this does
  local bv=get_bv96()
   log.print("cam.smartShoot - get bv\n")
  local av=get_av96()
  log.print("cam.smartShoot - get av\n")
 
  --init aperture and exposure
  if(tv ~= nil)then set_prop(propcase.TV,tv) end
  if(sv ~= nil)then set_prop(propcase.SV,sv) end
   log.print("cam.smartShoot - init aperture and exposure\n")
 
  --set_focus(subjdist)
  log.print("cam.smartShoot - focus set\n")
  press("shoot_full")
  log.print("cam.smartShoot - press shoot full\n")
  release("shoot_full")
  log.print("cam.smartShoot - release shoot full\n")
  release("shoot_half")
  log.print("cam.smartShoot - release shoot half\n")
  repeat
  --log.print("cam.smartShoot - before sleep\n")
    sleep(1)
    --log.print("cam.smartShoot - after sleep\n")
  until get_shooting() ~= true
  log.print("cam.smartShoot - end shoot\n")
  sleep(500)
until false

Re: scripts, taking pics, and stability (hhhhhelp!)
« Reply #3 on: 25 / March / 2009, 07:27:23 »
below is the full script. see how many iterations it goes through and then disable lines 886 and 888 - the shoot_full commands to see the script run indefinitely.




Re: scripts, taking pics, and stability (hhhhhelp!)
« Reply #4 on: 25 / March / 2009, 09:05:46 »
I should also explain further what i understand about i've experienced with the crashes.

first, it seems that the complexity of the script relates to the frequency of the crashes but thats very difficult to be certain about. this means that my short test script will crash much less frequently than my full script - but it will still crash!

the crashes exits the script without a verbose error and sometimes without an error number. the most common error was 707 but i've also seen a 419 (?) error.

---

anyway, i'm more than willing to do the work if someone can point me in the right direction.

*

Offline reyalp

  • ******
  • 14118
Re: scripts, taking pics, and stability (hhhhhelp!)
« Reply #5 on: 26 / March / 2009, 00:10:04 »
The work will most likely involve debugging the C code. If you can find where lua generates the mysterious error numbers, that would be a big start. I had a quick look a while back and didn't see where they would come from.
Don't forget what the H stands for.

Re: scripts, taking pics, and stability (hhhhhelp!)
« Reply #6 on: 26 / March / 2009, 10:28:32 »
i'm working on producing test cases which use as little code as possible. should be complete in the next couple of days.

so far my ubasic script has run without failure. i find that comforting.
« Last Edit: 26 / March / 2009, 10:30:23 by mattkime »

*

Offline reyalp

  • ******
  • 14118
Re: scripts, taking pics, and stability (hhhhhelp!)
« Reply #7 on: 26 / March / 2009, 19:47:07 »
Note that if "doing lots of stuff" triggers the problem earlier, you could try copy/pasting some simple repetitive operations into your loop.

Including memory usage information (from collectgarbage) in your log might also be useful.
Don't forget what the H stands for.


Re: scripts, taking pics, and stability (hhhhhelp!)
« Reply #8 on: 27 / March / 2009, 01:15:51 »
i have two very similar scripts, one which eventually crashes and one that doesn't. (well, that becomes four if you include the versions with delete code) the script that doesn't crash uses the shoot() function while the script that crashes takes a pic via button press/release. be aware that it make take up to one or two thousand iterations to reveal the flaw.

I looked at implementing this shooting method in ubasic but there doesn't seem to be a get_shooting fn. i'm also considering how the shoot fn could replace the button presses in my script but there are vars being set and retrieved so i currently have no idea if it would work.

failure is a premature exit of the script. no error is reported.

working code -
Code: [Select]
counter = 0

repeat
counter = counter + 1
print(counter)
shoot()
until false

working code with delete functions. should run forever.
Code: [Select]
counter = 0

repeat
counter = counter + 1
print(counter)
shoot()
local imgTable = os.listdir("A/DCIM/100CANON", false)
os.remove("A/DCIM/100CANON/"..imgTable[1])
until false

this code fails. note that it requires a larger memory card since there's no delete code
Code: [Select]
counter = 0

repeat
counter = counter + 1
print(counter)
  press("shoot_half")
  repeat
    sleep(1)
  until get_shooting() == true
 
  press("shoot_full")
  release("shoot_full")
  repeat
    sleep(1)
  until get_shooting() ~= true
  release("shoot_half")
  sleep(500)
until false

above code with delete functions. should run indefinitely.
Code: [Select]
counter = 0

repeat
counter = counter + 1
print(counter)
  press("shoot_half")
  repeat
    sleep(1)
  until get_shooting() == true
 
  press("shoot_full")
  release("shoot_full")
  repeat
    sleep(1)
  until get_shooting() ~= true
  release("shoot_half")
  sleep(500)
    local imgTable = os.listdir("A/DCIM/100CANON", false)
  os.remove("A/DCIM/100CANON/"..imgTable[1])
until false

 

Related Topics


SimplePortal 2.3.6 © 2008-2014, SimplePortal