Problem w/ hyperfocal distance in lua script on SX30. How to focus to infinity? - Script Writing - CHDK Forum  

Problem w/ hyperfocal distance in lua script on SX30. How to focus to infinity?

  • 4 Replies
  • 2209 Views
Advertisements
I am having problems when I set hyperfocal distance on the SX30. I am using almost identical scripts on SX30 and SX220HS, and I only have this issue on the SX30. I set focus to the hyperfocal distance at zoom step 0, and after maybe one in 5 power cycles (autocycles every 4 hrs) the focus sets to minimum instead. I had this problem at other zoom steps too.

For example images you can see here (timelapse on a river):

http://www.flickr.com/photos/usgs_elwhacams/sets/72157631807258313/

(power cycle triggers uploads from the eye-fi card over a mifi 2200).

I think the problem is here:

Code: [Select]
function pre_focus()
  local p = get_prop(props.FOCUS_MODE)
  if p == 1 then
    print "Manual focus (MF) found"
  else
    while p ~= 1  do
      sleep(500)
      click("left")
      click("right")
      click("set")
      sleep(500)
      p = get_prop(props.FOCUS_MODE)
    end
    print "Focus set to manual (MF)"
  end

  local focused = false
  hyFo = get_dofinfo().hyp_dist
  print("focusing to hyperfocal distance")
  set_focus(hyFo)
  focused = true
  return focused
But I attached the whole script in case anyone is curious. CAUTION. THIS SCRIPT WILL DELETE IMAGE FILES IF MEMORY CARD HAS < 512 MB FREE SPACE.

I am heading to the site to try to add a sleep(1000) between hyFo = get_dofinfo().hyp_dist
and set_focus(hyFo) but I would love to know how/if I can just focus to infinity instead.

I think infinity on the SX30 needs to be set to a large value. According to  (this post) by Philmoz, Infinity = 4294967295 (0xFFFFFFFF), and CHDK treats the value as a signed int so displays it as -1.

Does that mean that I would say set_focus(4294967295) or set_focus(-1) or set_focus(0xFFFFFFFF)?
A720 1.00c | D10 1.00b |SX220 1.01a | SX230 ? | SX30 1.00p CHDK ver. 1.1.0-r1727

*

Offline philmoz

  • *****
  • 3107
    • Photos
I've done some testing on this with my SX30 and there seems to be a problem with setting focus after first turning the camera on.

While the set_focus call works, the shoot command then sometimes sets the focus distance back to what it was before running the script. This happens even though the camera is in manual focus and set_aflock(1) is called.

It doesn't happen if you use the manual overrides - only when running a script.

I'll do some more testing when I have time and let you know what I find.

Note: using set_focus(-1) to set infinity focus has the same issue.

Phil.


« Last Edit: 03 / November / 2012, 18:50:12 by philmoz »
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)

*

Offline philmoz

  • *****
  • 3107
    • Photos
This version of your pre_focus function seems to work better on my SX30.

Code: [Select]
function pre_focus()
  local p = get_prop(props.FOCUS_MODE)
  if p == 1 then
    print "Manual focus (MF) found"
  else
    while p ~= 1  do
  sleep(500)
      click("left")
      click("right")
      click("set")
  sleep(500)
      p = get_prop(props.FOCUS_MODE)
    end
    print "Focus set to manual (MF)"
  end
 
  press("shoot_half")
  repeat sleep(50) until get_shooting() == true
  set_aflock(1)
  release("shoot_half")
 
  local focused = false
  hyFo = get_dofinfo().hyp_dist
  print("focusing to hyperfocal",hyFo)
  set_focus(hyFo)
  sleep(1000)
  print("focused to",get_focus())
  focused = true
  return focused
end

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)

I haven't noticed any issues yet running the script with that modification. Also FYI for anyone contemplating using the auto-delete function on the script - the free space needs to be more than 500MB (out of memory error with that setting). I ramped it up to 2GB on a 4GB card. will try to update if it freezes again.
A720 1.00c | D10 1.00b |SX220 1.01a | SX230 ? | SX30 1.00p CHDK ver. 1.1.0-r1727


*

Offline lapser

  • *****
  • 1093
Code: (lua) [Select]
--[[
@title Hyperfocal
--]]

press("shoot_half")
repeat sleep(50) until get_shooting()
if(get_focus_mode()~=1)then click("left") end --enters manual mode
set_aflock(1)
release("shoot_half")
while(get_shooting())do sleep(50) end

hyFo = get_dofinfo().hyp_dist
print("focusing to hyperfocal",hyFo)
set_focus(hyFo)
press("shoot_half")
repeat sleep(50) until get_shooting()
release("shoot_half")
while(get_shooting())do sleep(50) end
print("focused to",get_focus())
shoot()
set_aflock(0)
Thanks for the ideas on how to set the focus. This is what I came up with. It seems to work on the G1X and SX270.

Both cameras will toggle manual mode on/off when you press the "left" key with the shutter half way down (without CHDK). It also works in a script, I discovered. This simplifies the method to enter manual mode.

I've had a lot of camera crashes when using set_focus on the sx270. The press/release "half_shoot" after set_focus (in manual mode with aflock) seems to prevent the crashes, so far.
====
I did some more testing with the sx270 and it works great with no crashes. The call to set_aflock(1) is necessary because manual focus isn't always manual focus. There's an option in the record menu for "Safety Manual Focus." set_aflock disables it.
« Last Edit: 15 / November / 2012, 02:05:55 by lapser »
EOS-M3_120f / SX50_100b / SX260_101a / G1X_100g / D20_100b
https://www.youtube.com/user/DrLapser/videos

 

Related Topics