lua script to prepare fixed focus and then shoot heaps of photos - Script Writing - CHDK Forum
supplierdeeply

lua script to prepare fixed focus and then shoot heaps of photos

  • 8 Replies
  • 5872 Views
*

Offline qtmlr

  • *
  • 11
Advertisements
Hello,

for a scanner application i'd like to:

- set my SD1100 to a fixed focus
- fixed zoom
- turn off flash

After that initialisation i'd like to:
- shoot a photo by USB command
- then  download that photo
- then delete the photo on the camera
- and then repeat the procedure...

For this i wrote a simple script:

--[[
@title qwe
]]

function qwe_init()
  switch_mode_usb(1)
  set_prop(16, 2) -- flash off
  set_prop(6, 4) -- manual focus
  set_focus(1000)
  set_aflock(1)
   sleep(500)
end

function qwe()
   press("shoot")
   sleep(500)
   release("shoot")
end

qwe_init()

When i run that script using:
chdkptp
connect
upload qwe.lua
luar loadfile('A/qwe.lua')

Then the camera goes to record mode, but the screen turns black and i get an error:
unexpected return code 0x2ff
ERROR: ptp error


I'm not sure what i do wrong, can anybody give me a hint on that error and how to proceed best with what i want to do?


Best regards,
Torsten.

*

Offline dc3

  • *
  • 6
Re: lua script to prepare fixed focus and then shoot heaps of photos
« Reply #1 on: 13 / August / 2012, 16:41:14 »
I don't think press ("shoot") is valid ?

*

Offline reyalp

  • ******
  • 14080
Re: lua script to prepare fixed focus and then shoot heaps of photos
« Reply #2 on: 13 / August / 2012, 16:57:44 »
I don't think press ("shoot") is valid ?
Correct. The keys are "shoot_half", "shoot_full" or "shoot_full_only"

shoot() is a function, which usually does the correct sequence of these, waiting appropriately.

This shouldn't crash the camera though. It also looks like qwe() would not be called, only qwe_init()

@qtmlr
I would put a sleep after switch_mode_usb(1) to give the camera time to finish switching modes.
If you are using manual focus, then you don't need to use aflock. I'm not sure if you can set manual focus by setting the prop though, you might have to do it with key presses.

Since you are using chdkptp already, narrow down where it is failing by entering each command interactively.
Don't forget what the H stands for.

*

Offline msl

  • *****
  • 1280
  • A720 IS, SX220 HS 1.01a
    • CHDK-DE links
Re: lua script to prepare fixed focus and then shoot heaps of photos
« Reply #3 on: 13 / August / 2012, 17:24:18 »
 set_prop(6, 4) -- manual focus will not work.

1. This propertycase is only readable.
2. The SD1100/ixus80 has no MF mode.

msl
CHDK-DE:  CHDK-DE links


*

Offline qtmlr

  • *
  • 11
Re: lua script to prepare fixed focus and then shoot heaps of photos
« Reply #4 on: 14 / August / 2012, 16:54:56 »
Hello,

thanks a lot for your hints.

Ok, i tried executing the commands in qwe_init() and when executing them line by line then the camera does not switch off or crash.  Hmm, strange.  I'll try to remove some commands and try to track it down.

You mention that the SD1100 has prop(6) only as read-only, is there a list where i can get such informations?

Another issue, whenever i use "shoot()" then the camera uses the flash.  I tried to switch off the flash in the camera menu (non-CHDK) and also by set_prop(16, 2).  Whatever i do, the camera uses the flash.  Is there a way to disable it?

Also, thanks for the hint that press("shoot") will not work.  I'm not sure about the sequence but from reading the scripts of other people i thought:

press("shoot_half")
... wait...
press("shoot_full")
... wait
release("shoot_full")
... wait
release("shoot_half")

But that did not take a photo, not sure why?


Best regards,
Torsten.

*

Offline reyalp

  • ******
  • 14080
Re: lua script to prepare fixed focus and then shoot heaps of photos
« Reply #5 on: 14 / August / 2012, 17:21:26 »
Ok, i tried executing the commands in qwe_init() and when executing them line by line then the camera does not switch off or crash.  Hmm, strange.  I'll try to remove some commands and try to track it down.
As I said earlier, doing some things without any delay might cause a problem. You can test this in chdkptp by sending more than one command in a line, e.g.

lua  switch_mode_usb(1); set_focus(1000) ; set_aflock(1)

Quote
You mention that the SD1100 has prop(6) only as read-only, is there a list where i can get such informations?
You can find some information here: http://chdk.wikia.com/wiki/PropertyCase
If what you are looking for isn't there, then you might need to experiment.
Quote
Another issue, whenever i use "shoot()" then the camera uses the flash.  I tried to switch off the flash in the camera menu (non-CHDK) and also by set_prop(16, 2).  Whatever i do, the camera uses the flash.  Is there a way to disable it?
If there is a Canon setting that turns it off, that should work for CHDK too. CHDK shoot() doesn't do anything special to turn the flash on/off.
Quote
Also, thanks for the hint that press("shoot") will not work.
 I'm not sure about the sequence but from reading the scripts of other people i thought:
In some modes, the camera needs to be ready to shoot (AF, AE done etc) or it will just ignore the press. If it can't find something to focus on it will just beep and not shoot. This is true whether you are sending scripted keys or physically pressing the shutter.

Normally, if you want to shoot using key-presses, it should look something like this
Code: [Select]
press("shoot_half")
repeat sleep(50) until get_shooting() == true

click("shoot_full")
release("shoot_half")
Don't forget what the H stands for.

Re: lua script to prepare fixed focus and then shoot heaps of photos
« Reply #6 on: 02 / December / 2013, 15:46:39 »
Sensible question ?  :blink:

from this thread #2

shoot() is a function, which usually does the correct sequence of these, waiting appropriately.

[I think] i'm trying to think of supplying [pre-determined] particular settings [to multiple cameras] and not then have these settings impacted by subsequent commands / events [until, at least, after image capture].

To that end, from http://chdk.setepontos.com/index.php?topic=9443.msg102538#msg102538

Can you try the following:
Locate shooting_expo_param_override_thumb() in core/shooting.c
Comment out the following part of that function:
Code: [Select]
    if (((camera_info.state.state_kbd_script_run) || (usb_remote_active)) && (photo_param_put_off.subj_dist))
    {
        shooting_set_focus(photo_param_put_off.subj_dist, SET_NOW);
        photo_param_put_off.subj_dist=0;
    }
    else if (is_sd_override_enabled)
        shooting_set_focus(shooting_get_subject_distance_override_value(), SET_NOW);

If the above isn't there, CHDK will not attempt to set the focus right before shooting. This obviously will cripple CHDK, but you'll still be able to use either set_focus() from a script, or the manual SD override options. You'll need to be in AF lock of course, or SD override will be ineffective.


So, if the proposed code is removed from "shooting.c" then it seems [to me] that a shoot() command will not impact any pre-set focus setting.

Are there any other pre-set settings that the "shoot()" command will [/might] impact before the shutter opens ?

[tentatively posted]

*

Offline reyalp

  • ******
  • 14080
Re: lua script to prepare fixed focus and then shoot heaps of photos
« Reply #7 on: 02 / December / 2013, 16:15:16 »
So, if the proposed code is removed from "shooting.c" then it seems [to me] that a shoot() command will not impact any pre-set focus setting.

Are there any other pre-set settings that the "shoot()" command will [/might] impact before the shutter opens ?

[tentatively posted]
You are mixing up several totally different topics. The stuff you quoted from srsa was related to diagnosing a particular problem in a particular port, and has nothing to do with the thread you are posting it or the normal operation of CHDK.

I would suggest your time would be better spent actually experimenting and then asking about whatever issues arise in your particular project, as opposed to trying to read every thread that might be related and figure out the answers in advance.

I don't really understand what the point of your question is, it sounds like you are thinking that removing this code would prevent the camera from changing focus when you shoot. This is not the case at all, because shoot() just sends button presses to the the original firmware, which does all of it's normal shooting stuff.

If you want to have fixed focus, you should use the cameras manual focus, AF lock, or CHDK SD override (if it works on your camera). See http://chdk.wikia.com/wiki/CHDK_Manual_Focus_and_Subject_Distance_Overrides for some useful information.
Don't forget what the H stands for.


Re: lua script to prepare fixed focus and then shoot heaps of photos
« Reply #8 on: 02 / December / 2013, 17:12:07 »
You are mixing up several totally different topics. The stuff you quoted from srsa was related to diagnosing a particular problem in a particular port, and has nothing to do with the thread you are posting it or the normal operation of CHDK.

Appreciate that [please be assured, if it had been obvious to me I would not have posted the query]

I would suggest your time would be better spent actually experimenting and then asking about whatever issues arise in your particular project, as opposed to trying to read every thread that might be related and figure out the answers in advance.

Yours is a perfectly valid perspecitive. I am experimenting [a little]. I've probably always had a propensity for reading though [and honestly don't think that will change now].

I don't really understand what the point of your question is, it sounds like you are thinking that removing this code would prevent the camera from changing focus when you shoot. This is not the case at all, because shoot() just sends button presses to the the original firmware, which does all of it's normal shooting stuff.

Exactly - your further explanation is part of the reason why I posted, thanks.

If you want to have fixed focus, you should use the cameras manual focus, AF lock, or CHDK SD override (if it works on your camera). See http://chdk.wikia.com/wiki/CHDK_Manual_Focus_and_Subject_Distance_Overrides for some useful information.

Precisely the sort of information I was looking for, thanks again !

I can understand if you may be frustrated with this kind of post - but please also remember that your comments [about how this stuff works] is both appreciated [as free information always is] and helps those [like me] who are mostly just confused by a lot of this.




 

Related Topics