Shot Histogram Request - page 14 - CHDK Releases - CHDK Forum

Shot Histogram Request

  • 467 Replies
  • 150580 Views
*

Offline lapser

  • *****
  • 1093
Success!
« Reply #130 on: 10 / March / 2013, 00:14:38 »
Advertisements
I got all 3 cameras to take around 5,000 pictures each through an entire sunset, without a script interrupt. Hurrah!

This is with wait_shot_ready() and set_yield(-1,-1). The script actually works better with the yield hook disabled. I haven't found the cause of the bug, but at least I have a way to work around it now, and make sure I get a complete time lapse.

The next step is to see if the bug happens with the yield hook enabled. For a good test, I'll try set_yield(1,10), for a yield every 200 lua operations. My guess is that the yield hook won't trigger the bug, and that it comes from the transition from Lua to a C subroutine getting the stack wrong or something. My wait_shot_ready() has no parameters. Maybe I'll try it with a dummy parameter and see if that causes trouble.

I would like to have an escape option for wait_shot_ready() when you press a key, so a parameter might be useful. One thing I'm wondering is how I can return a value from wait_shot_ready?

Could I end wait_shot_ready() with:
return lua_yield( L, 1 );  ??

Then, I would use lua_pushnumber() from the action stack routine when it finishes?

Speaking of action stacks, maybe that could be causing this lua problem. There's a lot of pushing and popping going on with a function like sleep(10).  I haven't gone through all the action stack logic, but it might be worth it to follow the code for a sleep(10) call from start to finish.
EOS-M3_120f / SX50_100b / SX260_101a / G1X_100g / D20_100b
https://www.youtube.com/user/DrLapser/videos

*

Offline reyalp

  • ******
  • 14128
Re: Shot Histogram Request
« Reply #131 on: 10 / March / 2013, 00:45:08 »
The next step is to see if the bug happens with the yield hook enabled. For a good test, I'll try set_yield(1,10), for a yield every 200 lua operations.
You could also lower the multiplier in the code, YIELD_CHECK_COUNT in luascript.c

Quote
Could I end wait_shot_ready() with:
return lua_yield( L, 1 );  ??
I have no idea where wait_shot_ready is or what it does.
Quote
Then, I would use lua_pushnumber() from the action stack routine when it finishes?
I think you are supposed to be able to do this, but if you haven't already you should take a look at the lua documentation for yield and resume.  http://www.lua.org/manual/5.1/manual.html#lua_yield

edit:
You might want to look at read_usb_msg() which does something similar.

You don't want to use lua_yield( L, 1 );, that would be returning something to lua_resume.

Quote
Speaking of action stacks, maybe that could be causing this lua problem. There's a lot of pushing and popping going on with a function like sleep(10).  I haven't gone through all the action stack logic, but it might be worth it to follow the code for a sleep(10) call from start to finish.
I don't understand how this could be connected.
« Last Edit: 10 / March / 2013, 01:13:30 by reyalp »
Don't forget what the H stands for.

*

Offline lapser

  • *****
  • 1093
Re: Shot Histogram Request
« Reply #132 on: 10 / March / 2013, 01:56:16 »
You might want to look at read_usb_msg() which does something similar.
That's exactly what I was looking for. Thanks!

wait_shot_ready() is like wait_click(), only it waits for get_shot_ready(), which returns 1 right after build_shot_histogram finishes. wait_shot_ready() is equivalent to:

repeat sleep(10) until get_shot_ready()

The sleep(10) loop triggered the bug, but wait_shot_ready didn't.

I'd like to add an escape key to wait_shot_ready(), so if you press "menu", for example, it would exit immediately. It would return true if the shot was ready, and false if the escape key was pressed.

while(wait_shot_ready("menu"))do
  --process shot
end
EOS-M3_120f / SX50_100b / SX260_101a / G1X_100g / D20_100b
https://www.youtube.com/user/DrLapser/videos

*

Offline philmoz

  • *****
  • 3450
    • Photos
Re: Shot Histogram Request
« Reply #133 on: 10 / March / 2013, 05:00:24 »
I got all 3 cameras to take around 5,000 pictures each through an entire sunset, without a script interrupt. Hurrah!

This is with wait_shot_ready() and set_yield(-1,-1). The script actually works better with the yield hook disabled. I haven't found the cause of the bug, but at least I have a way to work around it now, and make sure I get a complete time lapse.

The next step is to see if the bug happens with the yield hook enabled. For a good test, I'll try set_yield(1,10), for a yield every 200 lua operations. My guess is that the yield hook won't trigger the bug, and that it comes from the transition from Lua to a C subroutine getting the stack wrong or something. My wait_shot_ready() has no parameters. Maybe I'll try it with a dummy parameter and see if that causes trouble.

I've create a test branch, philmoz-modulesV2, which has Lua version 5.1.5 (among other things).

It might be worth trying in case the problem is in Lua rather than CHDK.

Phil.
CHDK ports:
  sx30is (1.00c, 1.00h, 1.00l, 1.00n & 1.00p)
  g12 (1.00c, 1.00e, 1.00f & 1.00g)
  sx130is (1.01d & 1.01f)
  ixus310hs (1.00a & 1.01a)
  sx40hs (1.00d, 1.00g & 1.00i)
  g1x (1.00e, 1.00f & 1.00g)
  g5x (1.00c, 1.01a, 1.01b)
  g7x2 (1.01a, 1.01b, 1.10b)

*

Offline lapser

  • *****
  • 1093
coroutine.yield
« Reply #134 on: 10 / March / 2013, 14:03:37 »
This is something exciting that I just discovered after looking at the Lua docs for yield (thanks reyalp). I always assumed that sleep(10) was the only way to yield, but a better way is:

coroutine.yield()

This eliminates the call to a C function from Lua, which yields from C, and may be the cause of the bug. It seems much safer to yield from Lua.

Code: (lua) [Select]
--[[
@title Yield Test
@param y yield hook?
@default y 0
--]]
--set_console_layout(0,0,45,14) -- full screen
if(y==0)then set_yield(-1,-1) end
tick0=get_tick_count()
n=1
repeat
  coroutine.yield()
  tick=get_tick_count()
  print(n,tick-tick0)
  tick0=tick
  n=n+1
until is_pressed("menu")
set_yield()

It looks like coroutine.yield() is the same as sleep(10), but without the overhead and bug risk of a C yield.

I accidentally discovered that setting the console to full screen increases the time between yields from 10 to 40 or 50 msec on my sx260. I'm assuming that's a problem with the console routines.

Anyway, I'll try my time lapse script using coroutine.yield() instead of sleep(10) or wait_shot_ready(). If it works, and I think it will, it will prove that the bug is coming from the lua_yield() call from C.

[EDIT] Here's the new wait loop in my time lapse routine. This way is more flexible than wait_shot_ready() since you can do other tests while waiting:

Code: (lua) [Select]
  repeat
    wait_click(1) -- just checks for key, no delay or yield
    if(is_key("set"))then
      bl=bitxor(bl,1) -- 0 or 1
      set_backlight(bl)
    elseif(is_key("display")) then
      nd=bitxor(nd,3) -- 1 or 2 for nd filter
    end
    done=is_key("menu")
    coroutine.yield() -- same as sleep(10) but without C yield bug (hopefully)
  until get_shot_ready() or done
  if(done) then break end -- script over
« Last Edit: 10 / March / 2013, 15:29:53 by lapser »
EOS-M3_120f / SX50_100b / SX260_101a / G1X_100g / D20_100b
https://www.youtube.com/user/DrLapser/videos

*

Offline reyalp

  • ******
  • 14128
Re: Shot Histogram Request
« Reply #135 on: 10 / March / 2013, 16:16:07 »
This is something exciting that I just discovered after looking at the Lua docs for yield (thanks reyalp). I always assumed that sleep(10) was the only way to yield, but a better way is:

coroutine.yield()

This eliminates the call to a C function from Lua, which yields from C, and may be the cause of the bug. It seems much safer to yield from Lua.
What do you think coroutine.yield does under the hood?
static int luaB_yield (lua_State *L) {
  return lua_yield(L, lua_gettop(L));
}
Don't forget what the H stands for.

*

Offline lapser

  • *****
  • 1093
Re: Shot Histogram Request
« Reply #136 on: 10 / March / 2013, 18:36:44 »
What do you think coroutine.yield does under the hood?
static int luaB_yield (lua_State *L) {
  return lua_yield(L, lua_gettop(L));
}
Well, I guess everything is C under the hood. I meant it yields from code written by Lua programmers instead of us.  At least it doesn't start a new action stack with a delay. It just yields. I think it will work, but we'll C.

Here's the videos from last night, which were uninterrupted, except for the guy who walked in front of the SX260 and created a flash.

http://www.youtube.com/watch?v=I-8i1e8Da_E#ws

http://www.youtube.com/watch?v=ZQMdG8TV7Xg#ws

http://www.youtube.com/watch?v=34nT5m7urOc#ws
EOS-M3_120f / SX50_100b / SX260_101a / G1X_100g / D20_100b
https://www.youtube.com/user/DrLapser/videos

*

Offline reyalp

  • ******
  • 14128
Re: Shot Histogram Request
« Reply #137 on: 10 / March / 2013, 18:57:03 »
Well, I guess everything is C under the hood. I meant it yields from code written by Lua programmers instead of us.
It's a C function just like ours, which calls exactly the same lua API function that sleep() etc call. (luaB_yield is registered in lua as coroutine.yield)
Quote
  At least it doesn't start a new action stack with a delay. It just yields. I think it will work, but we'll C.
Huh?
If it doesn't put something on the action stack, then you will just yield for one iteration of kdb_task, which is what sleep(0) does now in the trunk, because AS_SCRIPT_RUN will still be on top of the stack. Unless you've butchered the script action stack handling in some other way...
Don't forget what the H stands for.

*

Offline lapser

  • *****
  • 1093
coroutine.yield bites the dust
« Reply #138 on: 11 / March / 2013, 02:24:24 »
The SX50 triggered the bug again, this time with coroutine.yield(). I also have wait_click(1) and is_key() calls in the wait loop with coroutine.yield(). It's possible that caused the problem, but it seems to be a bug in lua yield(). I'll see if I can try Phils lua updated branch when I get the time. Here's the log file after the error:

menu
*** TERMINATED ***
Lapser:      7 3209594  3473    -1

I added the last line. "7" shows that is_key() was the last C function called before the error. The next number is the return value from resume(), which appears to be a pointer, probably to "menu". The error occurred after 3473 pictures, and happened during the pre_shot timing delay in capt_seq_hook_nr().


If it doesn't put something on the action stack, then you will just yield for one iteration of kdb_task, which is what sleep(0) does now in the trunk, because AS_SCRIPT_RUN will still be on top of the stack. Unless you've butchered the script action stack handling in some other way...
Shouldn't sleep(<=10) also just yield() without action stacking?

Anyway, I'll go back to wait_shot_ready(), and check for key clicks while waiting. Ii'll see if I can return TRUE if a key is pressed, and FALSE if the shot is ready with no key pressed.

while(wait_shot_ready())do
  if(is_key("menu"))then done=true break end
end

By the way, I consider myself a Kosher butcher, but the action stack code in my builds is still pure, virgin, philmoz beef filet.
« Last Edit: 11 / March / 2013, 02:26:38 by lapser »
EOS-M3_120f / SX50_100b / SX260_101a / G1X_100g / D20_100b
https://www.youtube.com/user/DrLapser/videos

*

Offline lapser

  • *****
  • 1093
Re: Shot Histogram Request
« Reply #139 on: 12 / March / 2013, 12:42:54 »
The new wait_shot_ready() worked perfectly last night, including returning TRUE if a key was clicked. I used all 3 cameras without a script error, so I'm declaring the Lua yield() bug successfully fixed, well, worked around.

I also added some code to keep the backlight off that worked well. It's all in luascript.c, but requires adding a test in all the AS_WAIT functions. A better way would be to put one test in action_stack.c which would also work for ubasic. I'll get out my action_stack filet knife and see if I can butcher it correctly!

Last Sunday night, I went out to the airport and stuck the sx260 lens through the tiny hole in the chain link fence at the start of the runway. I used a Gorillapod hooked into the fence to hold the camera. I set the SX260 at 2 shots per second, which is faster than my other cameras can go. The SX260 uses a 32K Transcend Class 10 SDHC card, which appears to be faster than the 64K Transcend Class 10 in the SX50, maybe because of a larger FAT32 block size. The Transcend cards appear to be faster than the SanDisk 64K Class 10 in the G1X, but I would have to test them in the same camera to see. So here's the airport sunset video:

http://www.youtube.com/watch?v=x8rvMn6fXfQ#ws

And here are the 3 sunset videos from last night:

http://www.youtube.com/watch?v=lVRcbv1yiq8#ws

http://www.youtube.com/watch?v=HbNCs-MrHJc#ws

http://www.youtube.com/watch?v=y9Klroj6V6A#ws
EOS-M3_120f / SX50_100b / SX260_101a / G1X_100g / D20_100b
https://www.youtube.com/user/DrLapser/videos

 

Related Topics


SimplePortal © 2008-2014, SimplePortal