supplierdeeply

Is the 'sleep' statement sometimes advised for stability of scripted behaviour ?

  • 3 Replies
  • 856 Views
*

Offline fx

  • *
  • 15
Advertisements
Hello,

I have the following question:

When writing a script, and issuing a command such as "set_focus", or "set_zoom", or whatever else,
should one be carefull about timing, in other word should one put some *delay* before issuing the *next* command ?, possibly using a 'sleep' statement, or polling the appropriate variable (e.g. for focus until the requested focus-value has been effectively achieved ) ?

The question boils down to the way commands are executed: the command start the process; when the script then get to the next command, is it granted -or not- that the last command is fully completed, icluding mechanical stabilization ?


Thanks for your advices  :) !

*

Offline zeno

  • *****
  • 884
The last command is not necessarily complete since it typically happens on a separate thread. You can use a sleep to wait a bit - many scripts do this. You can also use on of the "get_..." script functions that tell you the status of certain commands. For example "get_movie_status" will tell you if the movie file has been written to the card.

See http://chdk.wikia.com/wiki/CHDK_Scripting_Cross_Reference_Page for more information.
A570, S100, Ixus 127
Author of ASSIST, STICK, WASP, ACID, SDMInst, LICKS, WICKS, MacBoot, UBDB, CFGEdit

*

Online reyalp

  • ******
  • 11491
The question boils down to the way commands are executed: the command start the process; when the script then get to the next command, is it granted -or not- that the last command is fully completed, icluding mechanical stabilization ?
It depends on the specific function and sometimes on the specific port. Because CHDK is hacked into an undocumented and poorly understood system, these things are often not well specified.

AFAIK set_zoom generally wait for the action to complete before returning. On some cameras, set_capture_mode can return before the mode changes is complete.

set_focus is more complicated. If the camera is in an auto-focus mode, calling set_focus from script should just tell the camera what focus you want to use for the next shot. The actual focus isn't updated until half shoot. If the camera is in MF mode (or AF lock in chdk 1.3) the focus should update immediately, and (AFAIK) set_focus generally won't return until the actual lens movement is done. In CHDK 1.2 and earlier, many ports didn't implement this correctly, so the behavior was even more random.
Don't forget what the H stands for.

*

Offline fx

  • *
  • 15
Hi Reyalp and Zeno,

thanks for those answers.

I will continue experimenting,

a)  taking the advice of using chdk 1.3 for better defined behaviour for set_focus

b) will start first using long sleep after set_zoom or set_focus, and when proper result is achieved, will then only tweek the sleep delays back to lower value, while preserving proper expected result.

Thanks  :) !


 

Related Topics