Full Manual Exposure control - LUA Scripting - CHDK Forum

Full Manual Exposure control

  • 11 Replies
  • 2637 Views
Full Manual Exposure control
« on: 16 / June / 2022, 13:03:20 »
Advertisements
Hi guys,

I hope someone can offer me some hints here.

I'm trying to get my LUA script running that allows full manual control of exposure. The camera is a Canon A1300 (Digic IV image processor).

Current status is: in the scritpt's config menu, you can set ISO, Shutter speed, color balance, zoom position, focus position. The camera gets its settings locked, and it then can be triggered via USB. (Aperture is fix for this camera, 2.8 at the wide zoom end, so no setting here for this one)

The problem: the camera always chooses an exposure time that's way too long, and flash control (enable/disable) via script does not work properly, so I need to do that via the normal CHDK menu. What am I doing wrong here? I've spent hours on this and can't seem to get anywhere.

The trimmed down (for brevity) code looks like this:

Code: [Select]
switch_recmode(1) -- switch to shooting mode
sleep(2000)

set_aelock(1) -- disable auto exposure

iso_sv96 = iso_to_sv96(100)
set_sv96(iso_sv96) -- set ISO value
sleep(500)

set_tv96_direct(800) -- set exposure time to 1/320th

set_prop(props.WB_MODE,colorbalance) --  (0,1,2,3,4,5 = Auto, Day Light, Cloudy, Tungsten, Fluorescent, Fluorescent H)
sleep(200)

set_prop(props.IS_MODE, 3)        -- IS_MODE off
set_prop(props.AF_ASSIST_BEAM,0)  -- AF assist off if supported for this camera
set_config_value(121,1)      -- make sure USB remote is enabled       

set_aflock(1) -- stop camera from autofocusing
set_prop(props.AF_LOCK,1) -- ???
--- causes the Canon firmware to stop focusing when shooting
--- does an initial focus measurement and sets focus at that value when called
set_mf(1)

set_focus(focus_cm*100) -- focus in mm
sleep(1000)

press("shoot_half") -- prepare cam

-- ... and here comes the loop that waits for the trigger via USB



The full LUA script file is attached, for more context and in case anyone wants to try it out.

Any help is greatly appreciated.

Cheers, berferd

*

Offline Caefix

  • *****
  • 945
  • Sorry, busy deleting test shots...
Re: Full Manual Exposure control
« Reply #1 on: 16 / June / 2022, 13:12:43 »
https://chdk.fandom.com/wiki/CHDKplus  :-*
https://chdk.fandom.com/wiki/CHDK_Scripting_Cross_Reference_Page

My 1st guess:  :haha
Code: [Select]
-- prepare cam was better @ line 100
press("shoot_half")
« Last Edit: 16 / June / 2022, 14:16:01 by Caefix »
All lifetime is a loan from eternity.

*

Offline reyalp

  • ******
  • 14082
Re: Full Manual Exposure control
« Reply #2 on: 17 / June / 2022, 00:01:06 »
The problem: the camera always chooses an exposure time that's way too long, and flash control (enable/disable) via script does not work properly, so I need to do that via the normal CHDK menu.
If shutter speed override isn't working, I'd generally suggest trying to reduce it to a minimal case to reproduce that. That is, either start with script that just sets shutter speed and see if that works, and if it does, start adding in the other stuff.

A few other comments
Code: [Select]
set_aelock(1) -- disable auto exposure
CHDK overrides are applied after Canon AE, so you should (edit: not) need AE lock if you are overriding all exposure parameters. Using this may be the cause of your unexpected behavior, since overrides in auto exposure mode expect to be applied at a certain point in the AE process.

Code: [Select]
set_aflock(1) -- stop camera from autofocusing
set_prop(props.AF_LOCK,1) -- ???
--- causes the Canon firmware to stop focusing when shooting
--- does an initial focus measurement and sets focus at that value when called
set_mf(1)
Generally speaking, you should use only one of AF Lock or MF: Whichever works on your camera. Setting props.AF_LOCK should not be necessary or helpful.

The A1300 port currently only has SD override enabled in AF and MF (not AF lock), so you probably want MF alone. You can use get_sd_over_modes to find out which modes are supported on a given port.

Note as with the exposure overrides, when SD override is available in AF mode, SD is set after Canon autofocus.
« Last Edit: 21 / June / 2022, 23:45:26 by reyalp »
Don't forget what the H stands for.

Re: Full Manual Exposure control
« Reply #3 on: 21 / June / 2022, 14:50:37 »
Thanks for your help and suggestions!
I removed the set_aflock(1) and  set_prop(props.AF_LOCK,1) calls and only left in set_mf(1). I also moved press("shoot_half") right to the top, after switch_recmode(1).

Code: [Select]
set_aelock(1) -- disable auto exposure
CHDK overrides are applied after Canon AE, so you should need AE lock if you are overriding all exposure parameters. Using this may be the cause of your unexpected behavior, since overrides in auto exposure mode expect to be applied at a certain point in the AE process.
OK, so this is correct as is - right?
set_aelock(1) enables the lock, i.e. disables auto exposure. After that I set the exposure manually in the code.

By doing all of the above, exposure now works much better in general, but the camera still behaves strangely.
Flash behaves opposite of what the manual says: set_prop(props.FLASH_MODE, 1) switches if off (should be on),  set_prop(props.FLASH_MODE, 2) switches it on (should be off).

Sometimes exposure times are reported as 1/10th or 1/8th of a second by the OSD (neither are in the list of exposure times I set).

The camera also sporadically goes into "continuous fire" mode, i.e. after triggering it once via USB, it continues to take pictures (about one frame every 2 seconds) until I power it off. This is not reproducible, happens sporadically.

If this was C and not LUA, I'd say it's uninitalized memory or buffer overflows or race conditions (missing thread locking), and fire up gdb. But what can be the reason here?


*

Offline reyalp

  • ******
  • 14082
Re: Full Manual Exposure control
« Reply #4 on: 22 / June / 2022, 00:10:21 »
Quote
CHDK overrides are applied after Canon AE, so you should need AE lock if you are overriding all exposure parameters. Using this may be the cause of your unexpected behavior, since overrides in auto exposure mode expect to be applied at a certain point in the AE process.
OK, so this is correct as is - right?
Sorry, my post was supposed to say "so you should not need AE lock" which I somehow lost in editing  :-[. Apologies for the confusion.

Quote
set_aelock(1) enables the lock, i.e. disables auto exposure. After that I set the exposure manually in the code.
You should not need set_aelock with what you are doing, indeed, it's likely to cause problems.

Quote
Flash behaves opposite of what the manual says: set_prop(props.FLASH_MODE, 1) switches if off (should be on),  set_prop(props.FLASH_MODE, 2) switches it on (should be off).
Not sure what to say about this, on a very wide range of cameras, it's 0 = Auto, 1 = On, 2 = Off. I would be very surprised if on/off were reversed on your camera. You can check by manually setting the flash mode in the UI and watching the values in the propcase display or reading it from script.

Quote
Sometimes exposure times are reported as 1/10th or 1/8th of a second by the OSD (neither are in the list of exposure times I set).
The display doesn't necessarily reflect CHDK overrides. If in doubt, you can try setting the exposure to two different values (like 1/10th and 1/20th) and verifying that the exposure changes in the expected way (one stop darker in the example here).

Quote
The camera also sporadically goes into "continuous fire" mode, i.e. after triggering it once via USB, it continues to take pictures (about one frame every 2 seconds) until I power it off. This is not reproducible, happens sporadically.
Are you certain that the USB power is actually switching in this case? If you turn on "Show Misc. Values" under Miscellaneous Settings -> Debug, the item labeled USB will show the USB power state.
Don't forget what the H stands for.

Re: Full Manual Exposure control
« Reply #5 on: 22 / June / 2022, 10:48:57 »
Ah, ok... makes more sense now. Thanks for clarifying.

I removed set_aelock(1), it did not make much of a difference. At least it did not make things worse, so I'm leaving it out.

Reading back and printing the status of the flash via get_prop(props.FLASH_MODE) showed: when setting the flash to ON in the camera menu, the flash is also on (value 1) in the property. Setting the flash to OFF in the original camera menu, the flash prop is set to 2 as expected (meaning: off).
Writing to props.FLASH_MODE via set_prop() sets the value as expected (as reading back shows), but it has no effect on camera behavior:

Setting in Camera Menu: OFF
Setting via set_prop: OFF
Flash triggered: NO

Setting in Camera Menu: OFF
Setting via set_prop: ON
Flash triggered: NO

Setting in Camera Menu: ON
Setting via set_prop: ON
Flash triggered: YES

Setting in Camera Menu: ON
Setting via set_prop: OFF
Flash triggered: YES

Are you certain that the USB power is actually switching in this case? If you turn on "Show Misc. Values" under Miscellaneous Settings -> Debug, the item labeled USB will show the USB power state.
There is no way to tell, since the camera goes into an endless picture-taking loop that can only be stopped by powering off. But the USB cable is detached, so physically it should be power state off.



*

Offline Caefix

  • *****
  • 945
  • Sorry, busy deleting test shots...
Re: Full Manual Exposure control
« Reply #6 on: 22 / June / 2022, 11:05:55 »
Writing to props.FLASH_MODE via set_prop() sets the value as expected (as reading back shows), but it has no effect on camera behavior:
An other one is METERING_MODE ...  :(

But You could script the keypresses to flash...  :)
All lifetime is a loan from eternity.

Re: Full Manual Exposure control
« Reply #7 on: 22 / June / 2022, 11:40:31 »
By the way... is there a requirement, when props.FLASH_MODE should be written?
I'm currently doing this after switch_recmode(1) and press("shoot_half").


*

Offline Caefix

  • *****
  • 945
  • Sorry, busy deleting test shots...
Re: Full Manual Exposure control
« Reply #8 on: 22 / June / 2022, 11:43:43 »
Between might be better,  :-[ but some propcases are readonly...
All lifetime is a loan from eternity.

Re: Full Manual Exposure control
« Reply #9 on: 22 / June / 2022, 12:02:14 »
OK, between does not change anything. Still the flash setting from the normal camera menu stays active, regardless of what the property is being set to (or reading back as).
Seems flash only can be set via Menu.

 

Related Topics