Improvements to press, click, release for shooting keys - page 4 - General Discussion and Assistance - CHDK Forum

Improvements to press, click, release for shooting keys

  • 48 Replies
  • 23059 Views
*

Offline lapser

  • *****
  • 1093
Re: Improvements to press, click, release for shooting keys
« Reply #30 on: 29 / December / 2012, 18:28:58 »
Advertisements
lapser claims that script is too slow and inefficient, but I don't see actual evidence of this. Even if it is true, the most likely cause is the overhead on action stack items (the fact that processing each item on the action stack takes one kbd_task iteration) which is something that could be solved by allowing kbd_task to process more than one action stack item per iteration in some cases.
Code: [Select]
Thu Dec 27 16:17:56 2012
Continuous Drive Mode
Focus 0, Result 3851, Mode 0
tv0=692
Interval=750 Multi=0
shot#  exp# || inter1  delay script raw-so  histo inter0  shutter
 4699  4699 ||      0      0      0    240    100      0  1/836
 4700  4700 ||    750    380      0    250     30    750  1/848
 4701  4701 ||    750     90    350    230     30    750  1/867
 4702  4702 ||    750    390     80    240     30    750  1/867
 4703  4703 ||    910   -160    610    220     30    910  1/848
 4704  4704 ||    750    470      0    240     30    750  1/848
 4705  4705 ||    750    450      0    220     30    750  1/848
 4706  4706 ||    750    470      0    240     30    750  1/854
 4707  4707 ||    750    440     10    220     30    750  1/848
 4708  4708 ||   1910  -1160   1640    240     30   1910  1/848
 4709  4709 ||    750    440     20    220     30    750  1/842
 4710  4710 ||    980   -230    710    240     30    980  1/842
 4711  4711 ||    750    440     20    220     30    750  1/836
 4712  4712 ||    750    300    170    240     30    750  1/836
 4713  4713 ||    910   -160    620    220     30    910  1/836
 4714  4714 ||    750    220    250    240     30    750  1/836
 4715  4715 ||    750    450      0    220     30    750  1/836
 4716  4716 ||    750    460     20    240     30    750  1/830
 4717  4717 ||    750    440     20    220     30    750  1/830
 4718  4718 ||    750    470      0    240     30    750  1/836
 4719  4719 ||   1440   -690   1150    230     30   1440  1/842
 4720  4720 ||    750    450     20    250     30    750  1/842
 4721  4721 ||    750    440      0    230     30    750  1/836
 4722  4722 ||    750    460      0    250     30    750  1/836
 4723  4723 ||    750    440      0    230     30    750  1/836
 4724  4724 ||   1060   -310    770    220     30   1060  1/836
 4725  4725 ||    750    420     50    240     30    750  1/836
 4726  4726 ||    750    440     10    220     30    750  1/836
 4727  4727 ||    750    350    130    250     30    750  1/836
 4728  4728 ||    750    440      0    230     30    750  1/830
 4729  4729 ||    750    460      0    230     30    750  1/830
 4730  4730 ||    750    410     60    210     30    750  1/830
 4731  4731 ||    750    430     60    230     30    750  1/830
 4732  4732 ||    750    450     10    210     30    750  1/824
 4733  4733 ||    750    460     30    230     30    750  1/824
 4734  4734 ||   1050   -300    770    240     30   1050  1/824
 4735  4735 ||    750    430     30    220     30    750  1/824
 4736  4736 ||    750    470      0    240     30    750  1/824
 4737  4737 ||   1310   -560   1020    240     30   1310  1/818
 4738  4738 ||    750    450      0    250     30    750  1/818
 4739  4739 ||    750    430     20    230     30    750  1/818
 4740  4740 ||    750    460      0    250     30    750  1/824
 4741  4741 ||   2080  -1330   1770    240     30   2080  1/830
 4742  4742 ||    750    450      0    240     30    750  1/818
 4743  4743 ||    750    440     20    220     30    750  1/806
 4744  4744 ||    750    460     20    240     30    750  1/806
 4745  4745 ||    750    430     30    220     30    750  1/806
 4746  4746 ||    750    160    310    240     30    750  1/806
 4747  4747 ||    750    450      0    220     30    750  1/812
 4748  4748 ||   1930  -1180   1650    220     30   1930  1/818
 4749  4749 ||    750    460     10    240     30    750  1/818
 4750  4750 ||    750    450      0    220     30    750  1/812
 4751  4751 ||   1720   -970   1450    230     30   1720  1/806
 4752  4752 ||    750    450     20    250     30    750  1/801
 4753  4753 ||    750    260    190    220     30    750  1/801
 4754  4754 ||    750    470      0    240     30    750  1/806
 4755  4755 ||   1690   -940   1390    220     30   1690  1/806
 4756  4756 ||    750    470      0    240     30    750  1/806
 4757  4757 ||    750    440     20    220     30    750  1/806
 4758  4758 ||    750    460     20    240     30    750  1/806
 4759  4759 ||   1960  -1210   1670    230     30   1960  1/806
 4760  4760 ||    750    440     30    210     30    750  1/801
 4761  4761 ||    750    480      0    230     30    750  1/801
 4762  4762 ||   1170   -420    890    230     30   1170  1/801
 4763  4763 ||    750    460      0    250     30    750  1/801
This is one of the unedited logs from my time lapse test yesterday. The first number following  || is the actual shutter to shutter open interval (desired interval was 750 msec). The second number is the amount of delay used to get that interval. Negative numbers means the shot was late, and the interval was longer than 750 msec. The 3rd number is the amount of time the delay routine waited for the Lua script to signal it had finished processing the last shot, by calling reset_shot_ready. The next number is the time it took from shutter open, to raw_save_file(). After that is the time spent in build_shot_histogram() with 4 shot meters. The next number is identical to the first (used for the multi shot per interval option). The last number is the shutter time in seconds.

The numbers under the heading "script" show that the script delays needed to process the shot are variable, and frequently take seconds. Remember, this is in continuous mode, so there are no calls to key functions involved, and no action stacks to process. With your knowledge of CHDK, maybe you can figure out the reason for these variable delays.

Unburdened by excess knowledge of the subject  ::) my theory is that the keyboard task is blocked by the camera for extended periods at times. In continuous mode, the camera is pretty busy converting jpgs, displaying them, and saving them to the SD card right after rawsavefile returns. The user is holding down the shutter button, so there's no need to poll the keyboard more than once per shot, to see if he's still holding it down.

One thing I'm planning to try is waiting in raw_save_file for Lua to call reset_shot_ready(), instead of waiting right before the shutter opens for the next shot. Hopefully, the script can finish its tasks in peace, before the camera starts saving the jpg. In continuous mode, these file saves are buffered, so that might not work either. But it's worth a try.

Thanks for your ideas on this problem.
« Last Edit: 29 / December / 2012, 18:32:14 by lapser »
EOS-M3_120f / SX50_100b / SX260_101a / G1X_100g / D20_100b
https://www.youtube.com/user/DrLapser/videos

*

Offline reyalp

  • ******
  • 14126
Re: Improvements to press, click, release for shooting keys
« Reply #31 on: 29 / December / 2012, 18:31:47 »
Is there a way for camera users who don't have the compiler to download a compiled, experimental version of CHDK for their camera that has these changes? I thought that was what the 1.2 branch was for, but if not, is there any other way to do it?
The official autobuild only builds the development trunk and current stable release. The autobuild is maintained by hacki, I don't expect he'd want to have even more branches, but it would be his decision. The trunk is for development of the next stable release. It does contain experimental and unfinished features at times, but only things expected to accepted for eventual inclusion in a release.

You are welcome to create your own fork and maintain your own autobuilds if you want, but coming up with an implementation that is acceptable for inclusion is likely to require less effort in the long run.
Don't forget what the H stands for.

*

Offline reyalp

  • ******
  • 14126
Re: Improvements to press, click, release for shooting keys
« Reply #32 on: 29 / December / 2012, 18:46:48 »
The numbers under the heading "script" show that the script delays needed to process the shot are variable, and frequently take seconds. Remember, this is in continuous mode, so there are no calls to key functions involved, and no action stacks to process. With your knowledge of CHDK, maybe you can figure out the reason for these variable delays.
It's quite possible that kbd_task doesn't run extended periods of time during continuous shooting. This doesn't mean *script* is slow though, it would apply just the same to C code running in kbd_task. If your script is sleeping, it does involve the action stack, because script sleep is an action stack action.

This whole theory is testable without too much difficulty, increment a counter in kbd_task, and see how much it increments over a continuous shooting sequence vs idle.
Quote
One thing I'm planning to try is waiting in raw_save_file for Lua to call reset_shot_ready(), instead of waiting right before the shutter opens for the next shot. Hopefully, the script can finish its tasks in peace, before the camera starts saving the jpg. In continuous mode, these file saves are buffered, so that might not work either. But it's worth a try.
raw_savefile runs in spytask, which has lower priority (higher priority number) than kbd_task, so if kbd_task is really getting locked out, spytask would as well (note task priority is in boot.c so it could theoretically vary by platform). Unless there is some other special magic locking out kbd_task.
Don't forget what the H stands for.

*

Offline lapser

  • *****
  • 1093
Re: Improvements to press, click, release for shooting keys
« Reply #33 on: 29 / December / 2012, 20:16:30 »
I moved the wait for script to call reset_shot_ready(), to raw_save_file(), and it did improve things some. The faster the shot rate, the slower the script runs. It makes sense because continuous shooting is as busy as the camera ever gets. Everything has to slow down. It's not a script problem, it's just a very busy camera, which affects script processing more than C code.

The following logs show that the script easily keeps up at 1 shot per second taking only 20 to 40 msec. It kept pace at a 750 msec interval, unlike before, so moving the delay to after the shot worked. Faster than that, and those intermittent long delays start happening. The 2 numbers on the left are the shot counter, incremented in raw_save_file, and get_exp_count(), which reflects the file number of the current file being saved. When buffering, this number would be behind the shot counter. It seems that the longer delays correlate to this. So the cause is probably that the camera is super busy saving a buffered photo.

At a 1 msec interval, as fast as the camera can go, the script delays are frequently >500 msec, which makes the shot rate irregular and unusable for time lapse. So the only solution is to take the script out of the loop and set the camera free to take continuous shots at it's own rate. Exposure adjustments will need to be made in build_shot_histogram(), controlled by guidelines received from Lua scripts.

Code: [Select]

Continuous Drive Mode
Interval=1000 Multi=0
shot#  exp# || inter1  delay script raw-so  histo inter0  shutter
 8473  8473 ||   1000    600     20    230     30   1000  1/46.2
 8474  8474 ||   1000    700     20    250     30   1000  1/45.5
 8475  8475 ||   1000    670     30    240     30   1000  1/48.2
 8476  8476 ||   1000    690     20    260     30   1000  1/46.5
 8477  8477 ||   1000    650     40    240     30   1000  1/46.5
 8478  8478 ||   1000    670     40    260     30   1000  1/46.5
 8479  8479 ||   1000    670     20    260     30   1000  1/48.9

Continuous Drive Mode
Interval=750 Multi=0
shot#  exp# || inter1  delay script raw-so  histo inter0  shutter
 8558  8558 ||    750    350     30    250     30    750  1/46.9
 8559  8559 ||    750    330    120    260     30    750  1/47.9
 8560  8560 ||    750    240    200    250     30    750  1/48.9
 8561  8561 ||    750    110    340    270     30    750  1/48.2
 8562  8561 ||    780    -30    460    260     40    780  1/45.9
 8563  8563 ||    750    310     30    260     30    750  1/46.2
 8564  8564 ||    750    320    120    270     30    750  1/43.9
 8565  8565 ||    750    400     30    270     30    750  1/43.9
 8566  8566 ||    750    360     70    240     30    750  1/44.6
 8567  8567 ||    750    380     80    250     30    750  1/44.6
 8568  8568 ||    750    430     20    240     30    750  1/44.6
 8569  8569 ||    750    440     20    250     30    750  1/43.6
 8570  8570 ||    750    400     50    250     30    750  1/42.7
 8571  8571 ||    750    410     40    260     30    750  1/43.0
 8572  8572 ||    750    400     40    250     30    750  1/43.9

Continuous Drive Mode
Interval=600 Multi=0
shot#  exp# || inter1  delay script raw-so  histo inter0  shutter
 8606  8606 ||    600    210     10    230     30    600  1/46.5
 8607  8606 ||    600     30    290    260     30    600  1/45.9
 8608  8608 ||    600    190     40    250     30    600  1/45.9
 8609  8608 ||    750   -150    450    250     40    750  1/47.9
 8610  8610 ||    600    170     30    270     30    600  1/46.5
 8611  8610 ||    600     20    260    250     40    600  1/46.5
 8612  8612 ||    600    190     50    270     30    600  1/46.5
 8613  8612 ||    660    -60    340    260     40    660  1/47.2
 8614  8614 ||    600    160     30    250     30    600  1/45.9
 8615  8614 ||    720   -120    420    250     40    720  1/45.9
 8616  8616 ||    600    170     30    270     30    600  1/47.6
 8617  8616 ||   1440   -840   1120    250     40   1440  1/48.6
 
Continuous Drive Mode
Interval=550 Multi=0
shot#  exp# || inter1  delay script raw-so  histo inter0  shutter
 8644  8644 ||    550    130     20    260     30    550  1/46.2
 8645  8644 ||    650   -100    340    260     40    650  1/47.2
 8646  8646 ||    550    110     30    260     30    550  1/48.6
 8647  8646 ||    740   -190    430    260     40    740  1/47.9
 8648  8647 ||    550    110     20    230     30    550  1/46.5
 8649  8649 ||    550    230     40    230     30    550  1/46.5
 8650  8649 ||    570    -20    290    260     40    570  1/48.2
 8651  8651 ||    550    110     30    260     30    550  1/48.2
 8652  8651 ||    710   -160    400    260     40    710  1/47.9
 8653  8653 ||    550    110     30    260     30    550  1/46.5
 8654  8653 ||    670   -120    360    250     40    670  1/46.5
 8655  8654 ||    550    120     30    240     30    550  1/47.2
 8656  8655 ||    720   -170    430    250     40    720  1/48.9
 8657  8656 ||    550    120     30    240     30    550  1/47.9
 8658  8657 ||    770   -220    480    260     40    770  1/46.5

Continuous Drive Mode
Interval=1 Multi=0
shot#  exp# || inter1  delay script raw-so  histo inter0  shutter
 8483  8482 ||    410   -409     30    260     40    410  1/49.7
 8484  8483 ||    430   -429     20    250     50    430  1/49.3
 8485  8484 ||    430   -429     50    260     40    430  1/45.9
 8486  8485 ||    430   -429     40    260     50    430  1/47.6
 8487  8486 ||    890   -889    560    260     40    890  1/48.9
 8488  8487 ||    430   -429     50    230     50    430  1/48.9
 8489  8488 ||    430   -429     60    260     50    430  1/48.9
 8490  8489 ||    440   -439     50    230     50    440  1/48.2
 8491  8490 ||    430   -429     50    260     50    430  1/45.9
 8492  8491 ||    450   -449     60    270     40    450  1/46.9
 8493  8492 ||    450   -449    110    260     40    450  1/49.7
 8494  8493 ||    860   -859    540    260     40    860  1/48.2
 8495  8494 ||    430   -429     50    250     50    430  1/46.9
 8496  8495 ||    430   -429     40    270     40    430  1/46.9
 8497  8496 ||    910   -909    570    250     40    900  1/48.9
 8498  8497 ||    420   -419     40    250     50    420  1/49.3
 8499  8498 ||    870   -869    550    260     40    870  1/48.9
 8500  8499 ||    440   -439     20    270     40    440  1/46.5
EOS-M3_120f / SX50_100b / SX260_101a / G1X_100g / D20_100b
https://www.youtube.com/user/DrLapser/videos

*

Offline lapser

  • *****
  • 1093
Re: Improvements to press, click, release for shooting keys
« Reply #34 on: 29 / December / 2012, 22:05:00 »
@reyalp,

You're a stubborn cuss, and you're wrong, but you've forced me to think up another solution that I think may work even better. Which I guess is my way of saying you're right. Here's the idea.

I'll add a new Lua function called:

shoot_now(continuous)

Assuming you're in half_shoot, it will immediately call kbd_key_press(KEY_SHOOT_FULL_ONLY);
It then will set a flag called "continuous", and return.

In capt_seq_hook_set_nr(), which is called right before the  shutter opens, I'll add this line:

if(continuous) kbd_key_release(KEY_SHOOT_FULL_ONLY);

Then in raw_save_file()

if(continuous>1)kbd_key_press(KEY_SHOOT_FULL_ONLY);
else continuous=0;

That's all there is to it. I'll let you know if it works.

[RESULT]
Well it kind of works, and takes continuous regular shots, but not as fast as I expected. Plus, the script doesn't recognize any keys, and has to be interrupted with the shutter button. It looks like I need to go through action.stack, but it was worth a try.
[RESULT2]If I start the sequence with press("shoot_full_only"), i.e. through the action stack, the script keeps working, and the camera shoots continuous pictures, but the shot rate is only 1 shot every 3 seconds. I'm not sure why it takes so long. It may be related to doing direct key presses from different threads. It doesn't seem worthwhile to keep testing this angle.

So I'll modify shoot_now() to go through action.stack and try to do the same thing that my key modifications do, like reyalp suggests.

I think I see the proposed changes as a tremendous benefit with minimal risk. reyalp sees it as an unnecessary risk for a moderate benefit. It's understandable because reyalp has to clean up the mess if it blows up. So I'll try implementing it as a new Lua function with a moderate benefit and almost no risk.
« Last Edit: 30 / December / 2012, 01:58:15 by lapser »
EOS-M3_120f / SX50_100b / SX260_101a / G1X_100g / D20_100b
https://www.youtube.com/user/DrLapser/videos

*

Offline lapser

  • *****
  • 1093
Re: Improvements to press, click, release for shooting keys
« Reply #35 on: 30 / December / 2012, 22:56:23 »
Here's what I came up with today that I think should make everyone happy. How about adding an optional timeout parameter to click, press, and release for shoot_full, shoot_half, and shoot_full_only? I'm still working on some timing issues, but I have the basic interface working.

press("shoot_full",0)  press key and hold until shutter opens with no timeout
press("shoot_full",5) press and hold for 5 seconds, or until shutter opens
press("shoot"full") or press("shoot_full,-1) same as old key

.. these 2 functions eliminate the need to write get_shooting() wait loops in lua:
press("shoot_half",0) press and hold until get_shooting()==1 (true)
release("shoot_half",0)release and wait until get_shooting()==0 (false)

.. this should do the same thing as the old shoot() function.
click("shoot_full",0) press key and wait for shutter open, then release key and wait for get_shooting==0

click("shoot_full_only,0) press and wait for shutter open, then release and wait until the camera is
            ready for a new click. (I think this is at the end of raw_savefile(), but still testing)

I'm also working on a get_shot_tick_counts(index) function that will return the button pressed, shutter open, raw save_file() enter and exit times, and whatever else we want.
EOS-M3_120f / SX50_100b / SX260_101a / G1X_100g / D20_100b
https://www.youtube.com/user/DrLapser/videos

*

Offline lapser

  • *****
  • 1093
Re: Improvements to press, click, release for shooting keys
« Reply #36 on: 31 / December / 2012, 22:51:15 »
I finally got the new timeout option for click, press, and release working. They work pretty much like I described above. Here's what I did in Luascript to tell the new key actions from the old ones:
Code: [Select]
// for press,release and click
static int luaCB_keyfunc( lua_State* L )
{
  int key=lua_get_key_arg( L, 1 ); //key number
  int tout=luaL_optnumber( L, 2, -1 ); //timeout
  if(tout>=0) //<0 default means use old key functions
  {
    key=-key; //flag new key functions (i.e. wait for shutter open)
  }
  action_stack_timeout(tout); //<=0 no timeout
  void* func = lua_touserdata( L, lua_upvalueindex(1) );
  ((void(*)(long))func)( key );
  return lua_yield( L, 0 );
}
I tested the new key actions in loops like this:
repeat click("shoot_full_only") until is_pressed(menu)

I timed the interval between shutter_opens, and it's about 750 msec per shot, with occasional 300 msec double shots. That's probably when the sx260 picture buffers catch up. I think this is as fast as the camera can go. All the measurable Lua script time is spent in action.stack waiting for the shutter to open for the next shot. Here's the data:
Code: [Select]
Last column is time between shots (starts with 700)
Column to the left of it is time in click(SFO) (starts with 710)
click SFO 9680 9679 710 700
click SFO 9681 9680 720 730
click SFO 9682 9681 310 300
click SFO 9683 9682 850 850
click SFO 9684 9683 300 300
click SFO 9685 9684 850 850
click SFO 9686 9685 310 310
click SFO 9687 9686 840 850
click SFO 9688 9687 730 720
click SFO 9689 9688 300 300
click SFO 9690 9689 850 850
click SFO 9691 9690 730 730
click SFO 9692 9691 720 730
click SFO 9693 9692 310 300
click SFO 9694 9693 840 850
click SFO 9695 9694 310 300
click SFO 9696 9695 850 850
release shoot_half
click SF 9696 9697 2430 1990
click SF 9697 9698 1810 1810
click SF 9698 9699 1980 1980
click SF 9699 9700 1830 1840
click SF 9700 9701 1810 1800
click SF 9701 9702 1830 1840
click SF 9702 9703 2030 2030
shoot() 9703 9704 1860 1880
shoot() 9704 9705 1860 1860
shoot() 9705 9706 1860 1860
shoot() 9706 9707 2020 2010
shoot() 9707 9708 2280 2280
shoot() 9708 9709 2100 2100
shoot() 9709 9710 2110 2120
press/release SFO 9710 9710 1590 2040
press/release SFO 9711 9711 310 300
press/release SFO 9712 9712 850 860
press/release SFO 9713 9713 730 730
press/release SFO 9714 9714 730 730
press/release SFO 9715 9715 730 720
press/release SFO 9716 9716 310 310
press/release SFO 9717 9717 850 850
press/release SFO 9718 9718 310 310
press/release SFO 9719 9719 850 850
press/release SFO 9720 9720 720 730
press/release SFO 9721 9721 310 300
press/release SFO 9722 9722 850 860
press/release SFO 9723 9723 310 300
press/release SFO 9724 9724 850 850
press/release SFO 9725 9725 310 310
*** FINISHED ***

release("shoot_full")currently waits for get_shooting() to go false, but I'm not sure that's necessary. release("shoot_half") can handle that.  It might make click("shoot_full") go a little faster that way, i.e. for shots with metering and focus before the shot.
EOS-M3_120f / SX50_100b / SX260_101a / G1X_100g / D20_100b
https://www.youtube.com/user/DrLapser/videos

*

Offline lapser

  • *****
  • 1093
Re: Improvements to press, click, release for shooting keys
« Reply #37 on: 01 / January / 2013, 13:50:54 »
OK, some new ideas about how to implement this. An optional timeout parameter for each key isn't the best way to do it, although it proves it can be done. For long shutter times, the timeout would need to be over 64 seconds, so you might as well not have one and avoid the confusion.  But here's the best way:

shoot([interval])

shoot() will be the same, but hold the press("shoot_full") until the shutter opens

shoot(interval) will return as soon as the shot starts, but the shutter will wait to open until the time since the last shot >=  interval.

shoot_wait([interval])

shoot_wait() and shoot_wait(interval)  are the same as above, but they will wait until after the raw buffer is ready and build_shot_histogram is finished. That is, the time when my new shot meters are valid. The wait will timeout in 2 seconds, or when shoot_wait() is called again.

If any of the functions are called with get_shooting() true, they will use shoot_full_only, and get_shooting() will remain true. This will work for high speed shooting.

If they are called with get_shooting() false, they will use shoot_full to focus and meter the shot (and wait for flash_ready), and return with get_shooting() false. This is the way the current shoot() works.

I'll also include 2 functions to press and release half_shoot with delays:

press_half()
release_half()

This isn't just to make scripting easier, although it will do that by eliminating the need for sleep..get_shooting() loops. Waiting with an action stack is much more effecient, and the  mechanism is already there to do it. When shooting at maximum speed, I've demonstrated that the script has very little time to set the exposure from the shot meters before the next shot, or it can end up delaying the shot by over a second. Doing it this way will increase the maximum shot rate, and still let LUA compute and set the exposure for each shot in time.

So, setting up a time lapse will go like this:

Code: (lua) [Select]
3 seconds per shot with pre_shot metering between each shot
repeat
  shoot(3000)
until false

4 seconds per shot with pre-shot metering and exposure adjustments
repeat
  press_half()
  set_tv96_direct(get_tv96-96) -- for example, 1 fstop underexposed
  shoot(4000)
  release_half()
until false

1 second per shot using first shot metering for all shots
press_half()
repeat
  shoot(1000)
until false

1 second per shot using post shot metering (with my new functions)
set_shot_meter(1,30,30,70,70) -- sets metering area in the center for meter #1 (4 available)
repeat
  shoot_wait(1000) -- does automatic press_half() for first shot
  tv=get_tv96()+get_shot_meter(1)  --adjust exposure for next shot
  set_tv96_direct(tv) -- I fixed this to work in half_shoot immediately now
until is_pressed("menu")
shoot_wait(-1) aborts current post shot wait and does auto release_half(),
   or you could let it time out 2 seconds later
It's funny, but this is almost exactly what reyalp suggested! I'll never doubt you again reyalp. Well, at least until the next time you're wrong about something.

If this works, I'll be able to get rid of most of my current shot_interval and lua handshaking functions. It simplifies both the C code, and the Lua code, and will work better and be more flexible in the process.

For example, let's say you have a 1 minute interval between shots. Using shot metering as in the example, the exposure for each shot will be determined by what was happening 1 minute ago. But you could set it up to take two quick shots like this:

Code: (lua) [Select]
interval=0 --imediate first shot
repeat
  shoot_wait(interval) -- shoots 1 minute later with auto press_half() first shot
  tv=get_tv96()+get_shot_meter(1)
  set_tv96_direct(tv)
  shoot(0)-- then shoot another shot immediately  with correct exposure
  interval=60000 -- 60 sec interval from no on
until false
EOS-M3_120f / SX50_100b / SX260_101a / G1X_100g / D20_100b
https://www.youtube.com/user/DrLapser/videos

*

Offline lapser

  • *****
  • 1093
Shutter Actions
« Reply #38 on: 01 / January / 2013, 14:52:50 »
To understand this idea, you need to forget what the "H" means in CHDK, and think like like a Canon camera programmer. You're assigned the job of triggering the camera with the shutter button.

Unlike all the other buttons, the shutter button has 3 states. I'll call them UP, DOWN, and HALF.

Based on the shutter button, you are asked to trigger 2 camera actions. I'll call them SHOOT and METER

You have one extra input. I'll call it: IS_METERED. I believe this is the same as the current "get_shooting()," which probably should have been called, "get_metered()".

You have a function that is polled repeatedly that can check the status of the shutter button. You are notified when the camera is ready to shoot again after taking a shot.

This is they way I think the Canon programmer solved this problem:

boolean wasUP -- shutter has been UP since last shot
boolean wasHALF -- shutter button has been HALF since last shot
shutter=UP --starts in up position

1. wait until ready to shoot .. monitor shutter and set wasUP and wasHALF true if the shutter is ever in these states

2. if shutter is DOWN when ready to shoot, and wasUP is TRUE, then METER() & SHOOT()
    if shutter is DOWN when ready to shoot, and wasHALF is TRUE, then wait for IS_METERED and SHOOT()
    if shutter is DOWN when ready to shoot, and both wasUP and wasHALF are false, then do nothing
                     (continuous mode would shoot in some manner)
    if shutter is HALF and  IS_METERED is false, then METER()

3. SHOOT(), taking a picture, resets wasUP and wasHALF to false.

Anyway, I hope you get the idea of how I think the shutter works. Another way to look at it is that while the camera is busy shooting a picture, it is monitoring UP clicks and HALF UP clicks, not DOWN clicks. If you want the camera to shoot a picture immediately when it is ready, the shutter must be DOWN, and must have been either HALF way up, or fully UP since the last shot, for the camera to shoot another picture right away.

The current implementation of the function shoot() does a half press, waits for IS_METERED (get_shooting()), and then does a brief DOWN UP click. For this to work, the camera must be finished with the last shot, and ready to shoot again during this brief DOWN UP click. The camera will only shoot a picture if the shutter is DOWN at the time it becomes ready to shoot.

So the way to get the camera to shoot as soon as it finishes the last shot is to hold the shutter DOWN until the shot starts, which I detect when shutter_open_tick_count changes. Then, you have to release the shutter, to HALF if you want to skip metering, i.e. release("shoot_full_only"), or to UP and wait for IS_METERED to be false,  if you want to meter the next shot.

I think the shoot() bug we've been talking about happens when get_shooting() becomes true, but the camera is still not ready to shoot, i.e. because it is still waiting for the flash to be ready, or a task is a little slow. So if the shutter goes back UP before the camera is ready for the shot, it won't take the shot.  shoot() hangs because it waits for SHOOTING_PROGRESS_PROCESSING, which never happens. philmoz was able to fix the hang part by changing shoot() to wait for !get_shooting(), but it still misses shots. This is the link to the shoot() bug I've been talking about.
http://chdk.setepontos.com/index.php?topic=9118.msg95097#msg95097

So if my theory is correct, this should be fixed by holding the shutter button down until the shutter opens, then letting it up  so the camera will take another shot as soon as possible the next time it goes down, regardless of when that is.
EOS-M3_120f / SX50_100b / SX260_101a / G1X_100g / D20_100b
https://www.youtube.com/user/DrLapser/videos

*

Offline lapser

  • *****
  • 1093
shoot() function bug fix, and high speed shooting enhancement
« Reply #39 on: 02 / January / 2013, 04:03:49 »
Here's a short modification to shoot() that should fix the bug in addition to adding high speed shooting capability.

As I've said above, the key to getting the camera to reliably shoot a picture is press("shoot_full") and wait for the camera to start the shot before release("shoot_full").  This is the cause of shoot() hanging, or with the recent philmoz changes, missing shots.

But you don't need to wait for shutter_open_tick_count to change, which may not work for all cameras. Instead, you can wait for state_shooting_progress to change, which is already in AS_WAIT_SAVE. But instead of waiting for:
        if (state_shooting_progress == SHOOTING_PROGRESS_DONE)
you wait for:
        if (state_shooting_progress != SHOOTING_PROGRESS_NONE)

If you move the AS_WAIT_SAVE to go between the press and release, it should work.

I also added changes that check for shooting_in_progress, and use shoot_full_only if shoot() is called with half_press already down. That way, you can take pictures at about 1 shot per second using a simple shoot() loop, if you start in half press. I've attached a test Lua program to demonstrate.

Code: [Select]
    case AS_WAIT_SAVE:
        if (state_shooting_progress != SHOOTING_PROGRESS_NONE)
            action_pop();
        break;

    case AS_WAIT_NOT_SHOOTING_IN_PROGRESS:
        if (!shooting_in_progress())
        {
            action_pop();
        }
        break;

    case AS_SHOOT:
        // Initiate a shoot. Remember that stack program flow is reversed!
        action_pop();
        //if(MODE_IS_VIDEO(mode_get()))break; //don't shoot in video mode?
        state_shooting_progress = SHOOTING_PROGRESS_NONE;
        int need_half= !shooting_in_progress();
        if(need_half)
        {
          action_push(AS_WAIT_NOT_SHOOTING_IN_PROGRESS);
          action_push_release(KEY_SHOOT_HALF);
        }
        action_push_release(KEY_SHOOT_FULL_ONLY); //for possible high speed shoot()
        action_push(AS_WAIT_SAVE); //holds shutter down until camera shoots
        action_push_press(KEY_SHOOT_FULL_ONLY); //could use shoot_full here
        action_push(AS_WAIT_FLASH);
        if(need_half)
        {
          action_push(AS_WAIT_SHOOTING_IN_PROGRESS);
          action_push_press(KEY_SHOOT_HALF);
        }
        break;
    default:
        return 0;
    }
Code: (lua) [Select]
--[[
@title shoot() test 1
--]]
print_screen(1)
t0=get_tick_count()
i=get_exp_count()
repeat
  shoot()
  t1=get_tick_count()
  print("shoot()",i,get_exp_count(),t1-t0) -- about 2 seconds per shot
  t0=t1
  i=i+1
until is_pressed("set") -- press <set> to move on to next test

press("shoot_half",t) -- start in half shoot
print("press shoot_half")
repeat sleep(10) until get_shooting()

repeat
  shoot()
  t1=get_tick_count()
  print("shoot()",i,get_exp_count(),t1-t0) -- about 1 second per shot this way
  t0=t1
  i=i+1
until is_pressed("menu") -- press <menu> to exit
EOS-M3_120f / SX50_100b / SX260_101a / G1X_100g / D20_100b
https://www.youtube.com/user/DrLapser/videos

 

Related Topics


SimplePortal © 2008-2014, SimplePortal