set_focus problem - page 2 - Script Writing - CHDK Forum  

set_focus problem

  • 27 Replies
  • 5522 Views
Re: set_focus problem
« Reply #10 on: 19 / June / 2012, 08:51:23 »
Advertisements
You can try to use Lua instead of BASIC. It has much more power and the syntax is much more clear.

Here's your script rewritten in Lua rather than UBasic - as outslider said, Lua generally results in cleaner code, and it also runs a lot faster than UBasic which is why I always use it.

Code: [Select]
--[[

@title Manual Focus
@param h Step size
@default h 5000

]]

print_screen(1)
f = get_focus()

while(1) do

wait_click()
k = is_key("right")
if k == true then
add()
end
k = is_key("left")
if k == true then
neg()
end
k = is_key("set")
if k == true then
click("shoot_full")
end

set_focus(f)

end

function add()

f = get_focus()
print(f)
f = f + h
print(f .. ";")
set_focus(f)

end

function neg()

f = get_focus()
print(f)
f = f - h
print(f .. ";")
set_focus(f)

end

I'm not sure whether this will make a difference either way but it's worth a try - sometimes functions are implemented slightly differently in the two languages. Also, for other scripts you might write Lua has some extra useful functions (such as file management) that UBasic lacks.
« Last Edit: 19 / June / 2012, 08:53:22 by dbldash »

Re: set_focus problem
« Reply #11 on: 19 / June / 2012, 09:16:58 »
Code: [Select]
--[[

@title Manual Focus
@param h Step size
@default h 5000

]]

print_screen(1)
f = get_focus()

function add()

f = get_focus()
print(f)
f = f + h
print(f .. ";")
set_focus(f)

end

function neg()

f = get_focus()
print(f)
f = f - h
print(f .. ";")
set_focus(f)

end

while(1) do

wait_click()
k = is_key("right")
if k == true then
add()
end
k = is_key("left")
if k == true then
neg()
end
k = is_key("set")
if k == true then
click("shoot_full")
end

set_focus(f)

end

Still does not work. I think implementation of set focus in chdk is not valid in my case.

*

Offline srsa_4c

  • ******
  • 4416
Re: set_focus problem
« Reply #12 on: 19 / June / 2012, 09:30:43 »
I haven't seen anyone mentioning AF lock. The command is set_aflock, see here: http://chdk.wikia.com/wiki/Script_commands , and also try to search the forum for scripts using this command/function.
If it has no effect or crashes the camera, please post your camera's firmware version.

Re: set_focus problem
« Reply #13 on: 19 / June / 2012, 10:19:41 »
If i set up set_aflock to 1, when i pushing left button always auto focus makes its mesauremets.
If i set up set_aflock to 0, nothing happens.

fw vers 100D
CHDK 0.9.9


Re: set_focus problem
« Reply #14 on: 19 / June / 2012, 13:03:12 »
OK, so it's nothing to do specifically with the UBasic script if the Lua one does the same... must be either the implementation of the focusing code in the CHDK build for your camera or some other specific camera-related issue.

Are you using the "stable" or "development" build? Often it's worth building and using the latest development one because it contains the latest features and bug-fixes, whereas the stable one could be quite old.

Re: set_focus problem
« Reply #15 on: 19 / June / 2012, 13:29:28 »
RC1 build for 1.00d cameras.

*

Offline srsa_4c

  • ******
  • 4416
Re: set_focus problem
« Reply #16 on: 19 / June / 2012, 13:49:17 »
@retsuz
The set_aflock command should work as advertised (it's using the correct Canon firmware function, I checked it manually). Have you tried to override the subject distance (in CHDK menu) while operating the camera by hand? It should work (in worst case, it will crash the camera when not in AF lock). The Canon AF lock can be activated by pressing the "left" key while half-pressing the shutter button. Also, try to change to another shooting mode, if not already.

Re: set_focus problem
« Reply #17 on: 20 / June / 2012, 16:20:55 »
Still does not working.


Re: set_focus problem
« Reply #18 on: 29 / June / 2012, 18:59:14 »
@retsuz

Not sure if this helps, but, after applying several dents to my head, I finally got set_focus working on my camera (A800).  Specifically:
  • make sure your camera is in Canon's P mode not AUTO mode.
  • set_focus doesn't happen until you shoot.

I've updated: http://chdk.wikia.com/wiki/CHDK_scripting#set_focus_.2F_get_focus
--
Note: if you are having problems using set_focus, try putting your camera into P mode (with no chdk loaded: press camera/movie button, click right to highlight P, press set).

Note that set_focus (on all cameras?) requires the execution of "shoot" before it takes effect:

Code: [Select]
@title focusTest script
print "Focus Test!"
for f=95 to 100
  set_focus f
  sleep 500
  rem need shoot for focus to take effect!
  shoot
  g=get_focus
  print "Set to=",f," Actual =",g
next f
end

If you comment out the "shoot" above, you will see that the focus will not change.

Re: set_focus problem
« Reply #19 on: 29 / June / 2012, 19:10:50 »
Note that set_focus (on all cameras?) requires the execution of "shoot" before it takes effect:
....
If you comment out the "shoot" above, you will see that the focus will not change.

What happens if you do a click "shoot_half" instead of a shoot ?
Ported :   A1200    SD940   G10    Powershot N    G16

 

Related Topics