Script sleep oddity - page 3 - General Discussion and Assistance - CHDK Forum supplierdeeply

Script sleep oddity

  • 57 Replies
  • 21267 Views
*

Offline lapser

  • *****
  • 1093
Re: Script sleep oddity
« Reply #20 on: 14 / January / 2013, 15:57:03 »
Advertisements
Also, I don't see action_push_func(), etc.,  defiined anywhere in the 1.2 build. Where do they come from?
You need to update your source from SVN.
The trunk version was merged from my reorg branch a week ago which includes a rework of the action stack code.
Phil.
OK, thanks.
[EDIT] Whew, that's a lot of changes! Looks like a big improvement though.

I was able to apply my patches to the new version, once I found out what happened to luascript.c, and figured out how to export my new functions.
« Last Edit: 14 / January / 2013, 20:02:34 by lapser »
EOS-M3_120f / SX50_100b / SX260_101a / G1X_100g / D20_100b
https://www.youtube.com/user/DrLapser/videos

*

Offline philmoz

  • *****
  • 3450
    • Photos
Re: Script sleep oddity
« Reply #21 on: 18 / January / 2013, 05:06:35 »
Ok, here's alternate patch for the action stack / script / sleep processing.

This one changes the action stack so that it will continue to process entries on the stack until one of the functions tells it to stop (e.g. needs to wait on something else to happen).

The sleep functions in Lua and uBasic now use custom functions to do the delay - with these changes the sleep accuracy is as close as it can be.

I've also increased the press/release delay values to take into account the reduced action stack overhead - so far, shoot and the key press/release/click routines all seem to work on my cameras.

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
Re: Script sleep oddity
« Reply #22 on: 18 / January / 2013, 12:23:01 »
Ok, here's alternate patch for the action stack / script / sleep processing.
Good work Phil. I installed it along with my time lapse patches and it works. sleep(10) loops always return with get_tick_count() 10 msec greater.

Did you want to add the 2nd shoot() try when shoot fails, before the error return? It worked in the focus bracketing script with flash, and prevented any failures. I'll write out the code I used if you need it.

One more idea:

    action_push_release(KEY_SHOOT_HALF);
    action_push_release(KEY_SHOOT_FULL);
    action_push_press(KEY_SHOOT_FULL);

The above statements could be replaced with the one statement below, and give you the click delay as well:

    action_push_click(KEY_SHOOT_FULL);
EOS-M3_120f / SX50_100b / SX260_101a / G1X_100g / D20_100b
https://www.youtube.com/user/DrLapser/videos

*

Offline lapser

  • *****
  • 1093
re-shoot code
« Reply #23 on: 18 / January / 2013, 14:58:34 »
Here's the re-shoot code made as simple as I can get it. It worked as expected, including simulated shoot failure by holding the <menu> key down for one or two shots.
Code: [Select]
static int action_stack_AS_WAIT_SAVE()
{
    static int first_shoot=1;
    if (!shooting_in_progress())
    {
        action_pop_func();
        int shoot_ok=(camera_info.state.state_shooting_progress != SHOOTING_PROGRESS_NONE);
if(kbd_is_key_pressed(KEY_MENU))shoot_ok=0;
        if(first_shoot && !shoot_ok)
        {
script_console_add_line((long)"RE-SHOOTING");
            first_shoot=0;
            action_push_func(action_stack_AS_SHOOT);
            return 1;
        }
if(!shoot_ok)script_console_add_line((long)"SHOOT FAILED");
else script_console_add_line((long)"shoot succeeded");
        first_shoot=1;
        if (libscriptapi)
            libscriptapi->set_as_ret(shoot_ok);
        return 1;
    }
    return 0;
}
Tested with this script:
Code: (lua) [Select]
--[[
@title Shoot Test
--]]
repeat print(shoot()) until false;
EOS-M3_120f / SX50_100b / SX260_101a / G1X_100g / D20_100b
https://www.youtube.com/user/DrLapser/videos


*

Offline reyalp

  • ******
  • 14111
Re: Script sleep oddity
« Reply #24 on: 18 / January / 2013, 15:43:21 »
The generic problems with sleep and action stack overhead are not closely related to the failed shoot problems. I strongly suggest not mixing them up.
Don't forget what the H stands for.

*

Offline lapser

  • *****
  • 1093
Re: Script sleep oddity
« Reply #25 on: 18 / January / 2013, 17:05:39 »
The generic problems with sleep and action stack overhead are not closely related to the failed shoot problems. I strongly suggest not mixing them up.
OK. I think it's a useful and completely safe update to the shoot code. I'll leave it to you and philmoz to decide if you want to implement it, and how.

I also think as_shoot should use click instead of press/release shoot_full so you get the click delay. Shortening the release delay 10 msec caused shoot failures, so it would be nice to have a safety delay factor.

On another note, do you remember the change I proposed to the exposure functions, set_sv96(), set_tv96_direct(), etc? Would you like me to start a new thread for that? They modify the functions so they use SET_NOW in half shoot, so you can adjust exposure without resorting to propcases (which doesn't work for sv96).
EOS-M3_120f / SX50_100b / SX260_101a / G1X_100g / D20_100b
https://www.youtube.com/user/DrLapser/videos

*

Offline philmoz

  • *****
  • 3450
    • Photos
Re: Script sleep oddity
« Reply #26 on: 18 / January / 2013, 18:11:00 »

One more idea:

    action_push_release(KEY_SHOOT_HALF);
    action_push_release(KEY_SHOOT_FULL);
    action_push_press(KEY_SHOOT_FULL);

The above statements could be replaced with the one statement below, and give you the click delay as well:

    action_push_click(KEY_SHOOT_FULL);


The 'action_push_release(KEY_SHOOT_HALF);' line is redundant since releasing KEY_SHOOT_FULL will also release KEY_SHOOT_HALF. This could probably be safely removed.

CAM_KEY_CLICK_DELAY is mostly for using the 'click' command in scripts to control the Canon menus and non shooting functions.
The 'shoot' command works even for cameras that need CAM_KEY_CLICK_DELAY so using action_push_click is adding an unnecessary delay to those cameras.

My current testing on my cameras that use CAM_KEY_CLICK_DELAY would indicate that this might not really be needed if the CAM_KEY_PRESS_DELAY value is increased to 60. If this turns out to be the case then using action_push_click in the shoot code makes sense.

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
Re: Script sleep oddity
« Reply #27 on: 18 / January / 2013, 19:25:31 »
My current testing on my cameras that use CAM_KEY_CLICK_DELAY would indicate that this might not really be needed if the CAM_KEY_PRESS_DELAY value is increased to 60. If this turns out to be the case then using action_push_click in the shoot code makes sense.
I didn't realize you were using 60. That sounds like enough under most conditions. I tracked my high speed continuous mode script delays down to the fact that I was writing a lot of log data at the same time that the camera was saving photos as fast as it can. I'll try writing only to the screen in high speed mode now.

The new script sleep is working great for my purposes. I have a lua loop waiting for build_shot_histogram to finish:

repeat sleep(10) until get_shot_ready()
--set exposure and loop back

I measure the time from the end of build_shot_histogram, until the script detects it through get_shot_ready(), sets exposure, then loops back and calls get_shot_ready() again. It's almost always 10 msec, with the occasional 20 msec. That's as fast as is possible. There's no need for a wait_shot_ready() function, or press_shoot_half() or any of that. Waits are as fast as possible in Lua now.

I think you really fixed this one, Phil. My hat's off to you. Good job.
EOS-M3_120f / SX50_100b / SX260_101a / G1X_100g / D20_100b
https://www.youtube.com/user/DrLapser/videos


*

Offline philmoz

  • *****
  • 3450
    • Photos
Re: Script sleep oddity
« Reply #28 on: 18 / January / 2013, 21:00:09 »
3rd version of patch (against trunk version 2492).

This includes removal of CAM_KEY_CLICK_DELAY for G1X, SX30 and SX40 (uses CAM_KEY_PRESS_DELAY = 60 instead). I think this will apply to all cameras that currently use CAM_KEY_CLICK_DELAY; but it will need to be tested for each of them.

Having thought about it some more, I think a single retry if 'shoot' fails is worth doing so I've included that as well for lapser to test :)
I've done this differently to lapsers suggestion to avoid having the 'action_push_delay(conf.script_shoot_delay*100)' delay execute twice in the event of a shoot retry.

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
Re: Script sleep oddity
« Reply #29 on: 18 / January / 2013, 21:44:20 »
I've done this differently to lapsers suggestion to avoid having the 'action_push_delay(conf.script_shoot_delay*100)' delay execute twice in the event of a shoot retry.
Good point. Wouldn't it be easier just to pop the delay off the stack before pushing as_shoot again? The delay hasn't started yet, so it doesn't need to be cleared:
Code: (php) [Select]
static int action_stack_AS_WAIT_SAVE()
{
    static int first_shoot=1;
    if (!shooting_in_progress())
    {
        action_pop_func();
        int shoot_ok=(camera_info.state.state_shooting_progress != SHOOTING_PROGRESS_NONE);
if(kbd_is_key_pressed(KEY_MENU))shoot_ok=0;
        if(first_shoot && !shoot_ok)
        {
script_console_add_line((long)"RE-SHOOTING");
            first_shoot=0;
            action_pop_func(); //pop extra delay********************************
            action_pop();      //off the stack
            action_push_func(action_stack_AS_SHOOT);
            return 1;
        }
if(!shoot_ok)script_console_add_line((long)"SHOOT FAILED");
else script_console_add_line((long)"shoot succeeded");
        first_shoot=1;
        if (libscriptapi)
            libscriptapi->set_as_ret(shoot_ok);
        return 1;
    }
    return 0;
}
EOS-M3_120f / SX50_100b / SX260_101a / G1X_100g / D20_100b
https://www.youtube.com/user/DrLapser/videos

 

Related Topics


SimplePortal 2.3.6 © 2008-2014, SimplePortal