Shutter Speed script - Completed and Working Scripts - CHDK Forum supplierdeeply

Shutter Speed script

  • 7 Replies
  • 9729 Views
Shutter Speed script
« on: 12 / December / 2007, 14:39:33 »
Advertisements
I have put together a script for stacking shutter speeds.  It also attempts to calculate the actual shutter speed (was actually quite difficult to do 1. with no power function 2. working in integers 3. integer size limit).
This script is built for the AllBest build, however it may be adjusted to suit other builds.

*edit* slight modification, forgot the hundredth seconds in one of the print statements, Also moved to code tags from quote tags

There are 7 parameters that can be set:
a - EV fraction (1/x EV) - specify the EV fraction, used for both Start/End and stepping (e.g. 3 = 1/3EV, 6 = 1/6EV, etc.)
b - Start Tv (1EV) - specify the starting EV in whole EVs (relates directly to shutter speed), 0=1sec, +slower speeds, higher exposure, -higher shutter speeds
c - Start Tv (1/xEV) - specify starting EV fraction (is appended to b to allow partial EV, must be from 0 to a)
d - No.Shots - Number of shots to be taken (>0, can be set to take one shot only)
e - Step Size (y/x EV) - how much to step up/down each exposure for each shot (can be 0 to lock shutter speed)
f  - Start Delay (s) - delay to start shooting
g - Delay between shots (s) - delay between consecutive shots

When starting the script, the start and end shutter speeds will be calculated and presented on-screen (only start if 1 shot), the user then hits <set> to accept or any other key to cancel.
The script will then take the shots required.  For each shot, the shutter speed will be displayed, as well as the shutter value.

EG:

a = 3
b = -11
c = 2
d = 2
e = -1

2 shots to be taken, step size = -1/3EV (e/a)
start EV = -11 2/3
end EV = -12

Tv Start ~1/3243 s
Tv End ~1/4096 s


The shutter speeds should be fairly accurate
compare:
-11 2/3 (Tv = 1120) 1/3243 vs 1/3251 (+0.25%)
-12     (Tv = 1152) 1/4096 vs 1/4096 (+0.00%)

It hasn't been fully tested under all possible conditions, but should work fairly well from between +6 (64.00s) to -20 (1/1,048,576s) with an EV resolution of up to 1/96.

Code: [Select]
rem Author: barberofcivil
rem Tested on S2
rem Requires AllBest build

@title Shutter Speed - AllBest
@param a EV fraction (1/x EV)
@default a 3
@param b Start Tv (1EV)
@default b -11
@param c Start Tv (1/xEV)
@default c 0
@param d No.Shots
@default d 1
@param e Step Size (y/x EV)
@default e 1
@param f Start Delay (s)
@default f 0
@param g Delay between shots (s)
@default g 0

cls
if f<0 then f=0
if g<0 then g=0
if d<1 then d=1
if a<1 then a=1
if c>=a then c=a-1
if c<0 then c=0
if b<0 then c=-c

if d=1 then print "One shot to be taken" else print d,"shots to be taken"
if d=1 or e=0 then gosub "Single" else gosub "Multiple"

print "Click <set> to proceed"
print "Any button to cancel"

wait_click
is_key z "set"
if z=1 then print "Proceeding..." else gosub "Cancel"

while f>0
  print "Starting in",f,"s..."
  sleep 1000
  f=f-1
wend

print "Starting shots now..."

for i=1 to d
  cls
  print "Shot",i,"of",d
  gosub "ShutterCalc"
  if k>=6 then print "Shutter ~1/"o,"s" else print "Shutter ~"r"."st,"s"
  print "Shutter value:",p
  set_tv96_direct p
  shoot
  sleep 1000*g
next i

end

:ShutterCalc
  k=(1-i)*e-b*a-c
  l=(k/a/4)*4*a
  if k<0 then l=l-4*a
  m=1
  for j = 1 to (l/a/4+2)
    m=m*16
  next j
  h=(k-l)
  j=(((((((((30*h*h*h)/(4*a))*h)/(4*a))*h)/(4*a))*243)/(4*a))*7)
  j=j-(((((((30*h*h*h)/(4*a))*h)/(4*a))*254)/(4*a))*4)
  j=j+(((((30*h*h*h)/(4*a))*227)/(4*a))*9)
  j=j+(((30*h*h*307)/(4*a))*3)
  j=j+(30*h*850)
  o=(((((((j/(18000)+1)/2)+a)*m)/(128*a)+1))/2)
  p=(k*96)/a
  q=(((51200*a)/(((((j/18000)+1)/2)+a)*m)+1)/2)
  r=q/100
  s=(q-r*100)/10
  t=q-r*100-s*10
return

:Cancel
  print "Shots cancelled"
  end

:Single
  if e=0 and d>1 then print "Tv locked (step=0)"
  i=1
    gosub "ShutterCalc"
    if k>=6 then print "Tv: ~1/"o,"s" else print "Tv: ~"r"."st,"s"
return

:Multiple
  i=1
    gosub "ShutterCalc"
    if k>=6 then print "Tv Start: ~1/"o,"s" else print "Tv Start: ~"r"."st,"s"
  i=d
    gosub "ShutterCalc"
    if k>=6 then print "Tv End:   ~1/"o,"s" else print "Tv End:   ~"r"."st,"s"
return


(moderated edit: Added "Lamp" message icon for easier finding later of useful working scripts.)
« Last Edit: 12 / December / 2007, 16:51:48 by Woodsman »

Re: Shutter Speed script
« Reply #1 on: 12 / December / 2007, 15:36:27 »
What a nice and well-written script! Will you be adding this to the Wikia User-Written Scripts archive? (if you have trouble doing that and would rather someone else add it, it could eventually be done, when someone has time)

Thanks for the work involved, and sharing it. I'm sure this will come in handy for many.

Yes I will add it it.  Wasn't sure of the procedure for getting it added, but I guess I just do it myself if the script runs fine.

Re: Shutter Speed script
« Reply #2 on: 12 / December / 2007, 15:59:57 »
What a nice and well-written script! Will you be adding this to the Wikia User-Written Scripts archive? (if you have trouble doing that and would rather someone else add it, it could eventually be done, when someone has time)

Thanks for the work involved, and sharing it. I'm sure this will come in handy for many.

It has been submitted to the wiki now.

Re: Shutter Speed script
« Reply #3 on: 16 / January / 2009, 11:56:55 »
I have modified this script based on some bug reports:

- minor display issue with cutoff transition displaying fractional vs decimal shutter speeds
       cutoff number was hardcoded based on 1/3EV, now relative to user 1/xEV

- script wasn't working properly for shutter speeds 32s and up.
       for loop running from 1 to 0 runs one iteration rather than bypassing as it would in other languages

I have recieved reports of it working incorrectly with certain parameters on Ixus cameras (possibly others).  It works fine on the models I have available for testing (A570 & S2). I can't duplicate the error as I don't have access to an Ixus at present.  Anyone with further input on this, please let me know.  The error happens when the tv96 is set to 0.  I am thinking it may be a conflict with internally coded shutter speed index numbers.

Code: [Select]
rem Author: barberofcivil
rem Tested on S2/A570

@title Shutter Speed
@param a EV fraction (1/x EV)
@default a 3
@param b Start Tv (1EV)
@default b -11
@param c Start Tv (1/xEV)
@default c 0
@param d No.Shots
@default d 1
@param e Step Size (y/x EV)
@default e 1
@param f Start Delay (s)
@default f 0
@param g Delay between shots (s)
@default g 0

cls
if f<0 then f=0
if g<0 then g=0
if d<1 then d=1
if a<1 then a=1
if c>=a then c=a-1
if c<0 then c=0
if b<0 then c=-c

if d=1 then print "One shot to be taken" else print d,"shots to be taken"
if d=1 or e=0 then gosub "Single" else gosub "Multiple"

print "Click <set> to proceed"
print "Any button to cancel"

wait_click
is_key z "set"
if z=1 then print "Proceeding..." else gosub "Cancel"

while f>0
  print "Starting in",f,"s..."
  sleep 1000
  f=f-1
wend

print "Starting shots now..."

for i=1 to d
  cls
  print "Shot",i,"of",d
  gosub "ShutterCalc"
  if k>=(2*a) then print "Shutter ~1/"o,"s" else print "Shutter ~"r"."st,"s"
  print "Shutter value:",p
  set_tv96_direct p
  shoot
  sleep 1000*g
next i

end

:ShutterCalc
  k=(1-i)*e-b*a-c
  l=(k/a/4)*4*a
  if k<0 then l=l-4*a
  m=1
  for j = 1 to (l/a/4+3)
    m=m*16
  next j
  m=m/16
  h=(k-l)
  j=(((((((((30*h*h*h)/(4*a))*h)/(4*a))*h)/(4*a))*243)/(4*a))*7)
  j=j-(((((((30*h*h*h)/(4*a))*h)/(4*a))*254)/(4*a))*4)
  j=j+(((((30*h*h*h)/(4*a))*227)/(4*a))*9)
  j=j+(((30*h*h*307)/(4*a))*3)
  j=j+(30*h*850)
  o=(((((((j/(18000)+1)/2)+a)*m)/(128*a)+1))/2)
  p=(k*96)/a
  q=(((51200*a)/(((((j/18000)+1)/2)+a)*m)+1)/2)
  r=q/100
  s=(q-r*100)/10
  t=q-r*100-s*10
return

:Cancel
  print "Shots cancelled"
  end

:Single
  if e=0 and d>1 then print "Tv locked (step=0)"
  i=1
    gosub "ShutterCalc"
    if k>=(2*a) then print "Tv: ~1/"o,"s" else print "Tv: ~"r"."st,"s"
return

:Multiple
  i=1
    gosub "ShutterCalc"
    if k>=(2*a) then print "Tv Start: ~1/"o,"s" else print "Tv Start: ~"r"."st,"s"
  i=d
    gosub "ShutterCalc"
    if k>=(2*a) then print "Tv End:   ~1/"o,"s" else print "Tv End:   ~"r"."st,"s"
return


*

Offline fudgey

  • *****
  • 1705
  • a570is
Re: Shutter Speed script
« Reply #4 on: 16 / January / 2009, 12:53:42 »
The error happens when the tv96 is set to 0.

I guess those tv commands are still broken when it comes to 0. It's a bug nobody's bothered to fix because it requires some thinking. Meanwhile, make your script detect it's trying to set it zero and set 1 or -1 instead, in tv96 units the difference is probably not visible, at least not significantly.

Tv96 == 1 second Tv, btw.

Re: Shutter Speed script
« Reply #5 on: 16 / January / 2009, 16:20:24 »
Is the bug only present for 0 or is it for other values as well.  I thought it may be related to the pre-indexed shutter speeds built in to the cameras and software (-12 to 35).

For what range of models is this bug present?  I seem to have no problem with my A570 or S2 models.

*

Offline ewavr

  • ****
  • 1057
  • A710IS
Re: Shutter Speed script
« Reply #6 on: 16 / January / 2009, 16:54:58 »
Here is source of this bug (platform/generic/shooting.c):

Quote
void shooting_set_tv96_direct(short v, short is_now)
{
if ((mode_get()&MODE_MASK) != MODE_PLAY){
      if(is_now) {
      _SetPropertyCase(PROPCASE_TV, &v, sizeof(v));
      }
      else photo_param_put_off.tv96=v;
}
}
if  v=0  (1 sec.) then photo_param_put_off.tv96 also is zero.

And:
Quote
void __attribute__((naked,noinline)) shooting_expo_param_override(void){
<skip>
 if ((state_kbd_script_run) && (photo_param_put_off.tv96)) {
  shooting_set_tv96_direct(photo_param_put_off.tv96, SET_NOW);   
  photo_param_put_off.tv96=0;
 }
etc

Maybe we need additional flag instead of using photo_param_put_off.tv96 as flag for shooting_expo_param_override().

Re: Shutter Speed script
« Reply #7 on: 19 / January / 2009, 15:23:20 »
I seem to have no problem with my A570 or S2 models.

Revised to avoid this
(when tv96=0, it is reset to 1 which equals ~0.993 seconds, hopefully noone can tell the difference...)

Now that I recheck it, this statement is incorrect, it does appear to have the glitch as well.

Code: [Select]
rem Author: barberofcivil
rem Tested on S2/A570

@title Shutter Speed
@param a EV fraction (1/x EV)
@default a 3
@param b Start Tv (1EV)
@default b -11
@param c Start Tv (1/xEV)
@default c 0
@param d No.Shots
@default d 1
@param e Step Size (y/x EV)
@default e 1
@param f Start Delay (s)
@default f 0
@param g Delay between shots (s)
@default g 0

cls
if f<0 then f=0
if g<0 then g=0
if d<1 then d=1
if a<1 then a=1
if c>=a then c=a-1
if c<0 then c=0
if b<0 then c=-c

if d=1 then print "One shot to be taken" else print d,"shots to be taken"
if d=1 or e=0 then gosub "Single" else gosub "Multiple"

print "Click <set> to proceed"
print "Any button to cancel"

wait_click
is_key z "set"
if z=1 then print "Proceeding..." else gosub "Cancel"

while f>0
  print "Starting in",f,"s..."
  sleep 1000
  f=f-1
wend

print "Starting shots now..."

for i=1 to d
  cls
  print "Shot",i,"of",d
  gosub "ShutterCalc"
  if k>=(2*a) then print "Shutter ~1/"o,"s" else print "Shutter ~"r"."st,"s"
  print "Shutter value:",p
  if p=0 then p=1
  set_tv96_direct p
  shoot
  sleep 1000*g
next i

end

:ShutterCalc
  k=(1-i)*e-b*a-c
  l=(k/a/4)*4*a
  if k<0 then l=l-4*a
  m=1
  for j = 1 to (l/a/4+3)
    m=m*16
  next j
  m=m/16
  h=(k-l)
  j=(((((((((30*h*h*h)/(4*a))*h)/(4*a))*h)/(4*a))*243)/(4*a))*7)
  j=j-(((((((30*h*h*h)/(4*a))*h)/(4*a))*254)/(4*a))*4)
  j=j+(((((30*h*h*h)/(4*a))*227)/(4*a))*9)
  j=j+(((30*h*h*307)/(4*a))*3)
  j=j+(30*h*850)
  o=(((((((j/(18000)+1)/2)+a)*m)/(128*a)+1))/2)
  p=(k*96)/a
  q=(((51200*a)/(((((j/18000)+1)/2)+a)*m)+1)/2)
  r=q/100
  s=(q-r*100)/10
  t=q-r*100-s*10
return

:Cancel
  print "Shots cancelled"
  end

:Single
  if e=0 and d>1 then print "Tv locked (step=0)"
  i=1
    gosub "ShutterCalc"
    if k>=(2*a) then print "Tv: ~1/"o,"s" else print "Tv: ~"r"."st,"s"
return

:Multiple
  i=1
    gosub "ShutterCalc"
    if k>=(2*a) then print "Tv Start: ~1/"o,"s" else print "Tv Start: ~"r"."st,"s"
  i=d
    gosub "ShutterCalc"
    if k>=(2*a) then print "Tv End:   ~1/"o,"s" else print "Tv End:   ~"r"."st,"s"
return


 

Related Topics