Need help with zoom script - LUA Scripting - CHDK Forum supplierdeeply

Need help with zoom script

  • 15 Replies
  • 13822 Views
*

Offline c_joerg

  • *****
  • 1248
Need help with zoom script
« on: 14 / April / 2018, 12:14:37 »
Advertisements
I wanted to write my own script based on this script here https://chdk.setepontos.com/index.php?topic=12453.20
Unfortunately, the SX50 crashes when using Refocus Mode 'OnZoom'. The SX50 crashes with ASSERT!! FocusLensController.c Line 708.

My idea was to keep the camera in 'Half Press' as long the zoom is not change (to lock focus and exposure).
When I run the script without zoom changes it’s works very well.
If I run the script with zoom changes the script crashes on SX50. The Error is ASSERT!! ComputerZoom.c Line 1968.
Same Script on G1x works very well.

I found out that a delay after release("shoot_half") helps that the camera does not crash any more. The second sleep after set_zoom comes from original script.
Code: [Select]
release("shoot_half")
sleep(1000)
set_zoom(zoom_position)
sleep(1000)

The problem of the solution is that I now only a minimum interval of 4s. I want to go at least to 3s. Of course, I could optimize the delay.
Are there any function which helps to avoid the fixed delay like set_zoom_ready or release_ready?

I have found different versions of how to wait for a recording to be made. Which is the preferred method?
If is a disadvantage if sleep is 1 instead of 10?

Code: [Select]
local count = get_exp_count()
press("shoot_full_only")
repeat sleep(10) until get_exp_count() ~= count
release("shoot_full_only")
« Last Edit: 14 / April / 2018, 13:26:42 by c_joerg »
M100 100a, M3 121a, G9x II (1.00c), 2*G1x (101a,100e), S110 (103a), SX50 (100c), SX230 (101a), S45,
Flickr https://www.flickr.com/photos/136329431@N06/albums
YouTube https://www.youtube.com/channel/UCrTH0tHy9OYTVDzWIvXEMlw/videos?shelf_id=0&view=0&sort=dd

*

Offline reyalp

  • ******
  • 14079
Re: Need help with zoom script
« Reply #1 on: 14 / April / 2018, 17:12:29 »
I have found different versions of how to wait for a recording to be made. Which is the preferred method?
If is a disadvantage if sleep is 1 instead of 10?
Sleep probably only works in 10ms increments. I don't remember exactly what happens in script if you specify less, but using 10 (or larger multiples of 10) is the best practice.
Quote
Code: [Select]
local count = get_exp_count()
press("shoot_full_only")
repeat sleep(10) until get_exp_count() ~= count
release("shoot_full_only")
This this roughly detects when picture has been taken, before the file has been saved. Waiting for the raw shooting hook is roughly equivalent.

There isn't really a reliable way to find out when a shot is completely finished (in theory, we might be able to detect it in filewrite hook, but some ports don't implement it or have issues in some shooting modes).

You can wait for get_shooting() to go false, but this requires that you have already released half press, and it's not guaranteed the shot will be finished at that point. This would looks something like
Code: [Select]
release("shoot_half")
repeat sleep(10) until not get_shooting()
Additional sleep might or might not be required, and might depend on the camera. If want to runs as fast as possible, you'll probably need to experiment.

set_zoom() should wait for the zoom to complete, but it's possible a small additional delay is needed.
Don't forget what the H stands for.

*

Offline c_joerg

  • *****
  • 1248
Re: Need help with zoom script
« Reply #2 on: 15 / April / 2018, 02:34:51 »
Thank you, you have been a great help to me…
You can wait for get_shooting() to go false, but this requires that you have already released half press, and it's not guaranteed the shot will be finished at that point.
That helped. I could set the delay to 0
set_zoom() should wait for the zoom to complete, but it's possible a small additional delay is needed.
If I set delay after zoom to 0, the cam sometimes crashes. I set it now to 100 and this is OK. So I come with my interval nearly to 3s.

Code: [Select]
buffer_mode='sync'And this helps to get a log file even when the cam is crashing…

Now I will test the script in practice first. If all goes well, then I'll turn to the exposure control with rawoplib.
M100 100a, M3 121a, G9x II (1.00c), 2*G1x (101a,100e), S110 (103a), SX50 (100c), SX230 (101a), S45,
Flickr https://www.flickr.com/photos/136329431@N06/albums
YouTube https://www.youtube.com/channel/UCrTH0tHy9OYTVDzWIvXEMlw/videos?shelf_id=0&view=0&sort=dd

*

Offline c_joerg

  • *****
  • 1248
Re: Need help with zoom script
« Reply #3 on: 18 / April / 2018, 04:45:16 »
I still have to deal with delays after half press and set zoom. I still have sometimes crashes. But 500ms delay looks ok.

Attached are a first version of my script and a plot of my first run. The plot shows focus state, focus and focal length.

I think I have to do something with the focus. Sometimes the focus distance has big variations (around 200). Not sure if I try to smooth it.

I still have some question and I’m not sure if I can damage the cam if I do this:
1) What happens if I set focus manually on beginning and the zoom changes?
2) What happens if I change zoom in ‘half shoot’?

Update:
-   Changing zoom on half press crashes the cam on zoom changing
-   Running on Canon UI manual Focus crashes the cam on zoom changing
« Last Edit: 18 / April / 2018, 14:58:45 by c_joerg »
M100 100a, M3 121a, G9x II (1.00c), 2*G1x (101a,100e), S110 (103a), SX50 (100c), SX230 (101a), S45,
Flickr https://www.flickr.com/photos/136329431@N06/albums
YouTube https://www.youtube.com/channel/UCrTH0tHy9OYTVDzWIvXEMlw/videos?shelf_id=0&view=0&sort=dd


*

Offline reyalp

  • ******
  • 14079
Re: Need help with zoom script
« Reply #4 on: 18 / April / 2018, 15:01:15 »
I think I have to do something with the focus. Sometimes the focus distance has big variations (around 200)
CHDK set_zoom tries to reset the focus to the previous distance after the zoom change, so it isn't a surprise that it's a factor.
Quote
I still have some question and I’m not sure if I can damage the cam if I do this:
1) What happens if I set focus manually on beginning and the zoom changes?
I'm not sure what you mean? Setting MF and focus distance before setting zoom should fine, as much as these functions are ever fine in CHDK.
Quote
2) What happens if I change zoom in ‘half shoot’?
The Canon firmware doesn't let you do this using normal controls, so I would proceed with caution, or a camera you don't care much about  ;)
Don't forget what the H stands for.

*

Offline c_joerg

  • *****
  • 1248
Re: Need help with zoom script
« Reply #5 on: 18 / April / 2018, 15:43:44 »
I'm not sure what you mean? Setting MF and focus distance before setting zoom should fine, as much as these functions are ever fine in CHDK.
No, I want to set focus manual on Canon UI before starting the script. But this crashes the cam when I set the zoom in script.  If I set focus manually on Canon UI and change zoom without a script, the cam didn’t crash. But this didn’t works very well because the focus changes a bit.

The Canon firmware doesn't let you do this using normal controls, so I would proceed with caution, or a camera you don't care much about  ;)
The camera crashes but is not destroyed…

Even if you set the focus by script to infinity or hyperfocal distance, there are no particularly sharp images with large focal lengths. The best results are when you focus the camera on a high-contrast fixed point.
M100 100a, M3 121a, G9x II (1.00c), 2*G1x (101a,100e), S110 (103a), SX50 (100c), SX230 (101a), S45,
Flickr https://www.flickr.com/photos/136329431@N06/albums
YouTube https://www.youtube.com/channel/UCrTH0tHy9OYTVDzWIvXEMlw/videos?shelf_id=0&view=0&sort=dd

*

Offline c_joerg

  • *****
  • 1248
Re: Need help with zoom script
« Reply #6 on: 23 / April / 2018, 12:06:15 »
@reyalp

My script is working very well. Only the exposure control is missing. Now maybe I thought too easy. I have integrated the following code in rawopint (before exp: run ()). As soon as the camera went into ‘Half Press Release’ and ‘Half Press’ again I get the error message in rawop.meter:

Quote
raw data not available
Is this a timing problem because of the delay’s?


Code: [Select]
-- if warning LED specified, make sure it's turned off here
if ui_interval_warn_led then
set_led(ui_interval_warn_led,0)
end

    ----------------------------------------------------------------------------------
    -- Begin My Code
    shot_count = i
    if shot_count >= pre_shots then
      -- change the zoom position after user defined shot interval  - reset focus and exposure if necessary
      zoom_pass = ((shot_count-pre_shots)%shots_per_step == 0)
      if zoom_pass then
        if (  (( zoom_direction >0) and (zoom_position>zoom_position_stop ))
           or (( zoom_direction <0) and (zoom_position<zoom_position_stop ))) then
              zoom_pass = false
        else
          if (half_shoot == true) then             
            release("shoot_half")
            repeat sleep(10) until not get_shooting()
            sleep(Delay_after_Half)
            half_shoot = false
            print('Release Half')
          end
          print("setting zoom step:",zoom_position)   
          set_zoom(zoom_position)
          sleep(Delay_after_Zoom)
          zoom_position = zoom_position + zoom_direction
        end
      end
    else
      print("Pre shoot") 
    end

    -- Half shoot -------------------------------
    if (half_shoot == false) then
      local fault = false
      local timeout = get_tick_count()+5000

      press("shoot_half")
      print('Press Half')
      repeat
        sleep(10)
        fault = (get_tick_count() > timeout)
      until (get_shooting() == true) or fault
      if fault then
        print("Error Timeout Half")
        logdesc("Error Timeout Half");
      end
      half_shoot = true
    end

    local dof=get_dofinfo()
log:set{
      focus_state=bool_to_number[get_focus_ok()],
      focus=dof.focus,
      focal_length=dof.focal_length,
      eff_focal_length=dof.eff_focal_length,
      zoom_step=get_zoom(),
}

    -- End My Code
    ----------------------------------------------------------------------------------
   
exp:run()
M100 100a, M3 121a, G9x II (1.00c), 2*G1x (101a,100e), S110 (103a), SX50 (100c), SX230 (101a), S45,
Flickr https://www.flickr.com/photos/136329431@N06/albums
YouTube https://www.youtube.com/channel/UCrTH0tHy9OYTVDzWIvXEMlw/videos?shelf_id=0&view=0&sort=dd

*

Offline reyalp

  • ******
  • 14079
Re: Need help with zoom script
« Reply #7 on: 23 / April / 2018, 13:10:58 »
My script is working very well. Only the exposure control is missing. Now maybe I thought too easy. I have integrated the following code in rawopint (before exp: run ()). As soon as the camera went into ‘Half Press Release’ and ‘Half Press’ again I get the error message in rawop.meter:
Maybe I'm missing something, but rawop.meter is only valid in the raw hook, after a shot has been taken but before the image has been processed. See http://chdk.wikia.com/wiki/Lua/Raw_Hook_Operations

exp:run assumes it will be run inside the raw hook, it does the meter, calculates all the exposure parameters, and sets the exposure values for the next shot. This won't work if you  release the shutter between shots, but you might be able to use some of the lower level functions without too much work, e.g. call meter in the raw hook, and the rest after half press is released.
I haven't looked at what would be required to do this. One thing you'll need to watch out for is the aperture changing with zoom.

Alternately, you could get scene brightness from BV between shots instead of meter, since you're doing a half press per shot anyway. You could probably feed that into rawpop exp instead of meter96 without too much change.

general outline of what's called from exp:run
init_frame - adjusts some values related to the changing black level on g1x
get_cam_exposure_params - gets the initial exposure parameters if from Canon firmware values if it's the first shot
do_meter - reads the raw buffer, calculates mval96 and histogram values
calc_ev_change - calculates the required exposure change, in ev units, without
calc_exposure_parameters  - distributes the required exposure change among the available parameters (tv, sv, nd)
set_cam_exposure_params - sets the overrides for the next shot.

The above should be relatively independent: If you want to replace one you should just make sure it sets the same self.foo as the existing function.
Don't forget what the H stands for.


*

Offline c_joerg

  • *****
  • 1248
Re: Need help with zoom script
« Reply #8 on: 23 / April / 2018, 13:50:05 »
Maybe I'm missing something, but rawop.meter is only valid in the raw hook, after a shot has been taken but before the image has been processed.
I almost thought something like that…

but you might be able to use some of the lower level functions without too much work, e.g. call meter in the raw hook, and the rest after half press is released.
If I understand you correctly:
I could do the zoom change after calc_exposure_params() and before set_cam_exposure_params()?

One thing you'll need to watch out for is the aperture changing with zoom.
Yes of course. At the moment I always use the aperture of the largest focal length…

Alternately, you could get scene brightness from BV between shots instead of meter, since you're doing a half press per shot anyway.
That was also my first approach. For a few shots per stage, it will probably work. I'm fine even if I only change the shutter speed. I have already programmed something like that. But then I have to do something when I do 50 pre shoots and 50 shoots after zooming.



M100 100a, M3 121a, G9x II (1.00c), 2*G1x (101a,100e), S110 (103a), SX50 (100c), SX230 (101a), S45,
Flickr https://www.flickr.com/photos/136329431@N06/albums
YouTube https://www.youtube.com/channel/UCrTH0tHy9OYTVDzWIvXEMlw/videos?shelf_id=0&view=0&sort=dd

*

Offline reyalp

  • ******
  • 14079
Re: Need help with zoom script
« Reply #9 on: 23 / April / 2018, 16:08:30 »
but you might be able to use some of the lower level functions without too much work, e.g. call meter in the raw hook, and the rest after half press is released.
If I understand you correctly:
I could do the zoom change after calc_exposure_params() and before set_cam_exposure_params()?
I think only do_meter has to happen in the raw hook. I haven't looked in detail at what the effects doing the rest outside the hook would be.

A couple other things to watch out for:
- Exposure overrides (setting Tv, Sv etc) behave differently depending whether the camera is in half press or not. Outside of halfpress, the value is simply saved, and applied (setting the relevant propcases) the next time the camera becomes ready in the next half press. Inside half press, the values are set immediately. The latter applies to rawopint, which normally sets exposure inside the raw hook. I don't know of anything that will specifically break due to this, but I've never tried to run the exp: stuff outside of halfpress.
- Some of these cameras have a LOT of vignetting,  and it changes significantly depending on zoom. This might affect exposure calculation depending how big your meter area is.
Don't forget what the H stands for.

 

Related Topics