Set zoom problems - Script Writing - CHDK Forum

Set zoom problems

  • 19 Replies
  • 8111 Views
Set zoom problems
« on: 17 / October / 2011, 20:19:34 »
Advertisements
I am new to CHDK and fascinated by its potential.  However, I am trying to do what should be the simplest of operations: turn on camera, zoom out lens to a set point, and take a picture over the past two days and am pulling my hair out.  I used Zoom and Shoot script as my starting point (which seems to mostly work, though not always flawlessly) and tried to whittle it down to something like this:

rem Author ~Keoeeit~
rem For S-series cameras ONLY!
set_zoom_speed 20
set_zoom 0
set_zoom 1
click "shoot_half"
shoot
end

Trying this on both an A480 and a g11 with an autoboot 4GB card in them.  The behavior is flakier than a croisant.  First if I try to start it in Autostart mode - forget it, never executes properly.  Sometimes it will actually get to the shoot command, but the zoom is all wrong.  Othertimes it just freezes, and sometimes it just doesn't execute at all.  Second if I turn off Autostart, start CHDK up via autoboot, press the print key and then shutter to start the script it works some of the time, but not others.  In the "not others" sometimes it doesn't zoom, but snaps the picture anyway/ sometimes the camera just shuts off mid script / sometimes it works for several consecutive executions of the macro flawlessly.  Again the behavior is the same on both the G11 and the A480.

What in the world am I not getting here ?  I thought it might just be timing issues and so I've tried all sorts of sleep 100, sleep 500, sleep 6000 throughout the script to no avail.  I've tried to put together a loop of click "zoom out" commands together with sleep 600 after each click.  Just as flaky in its behavior.

So can someone tell me is a) Autostart just plain an simple flaky and its a flip of the coin whether a script will work b) everything requires exquisite timing and I just haven't found the magical combination c) I'm just not waiting long enough to start or repeat my macro.  And is there any guide as to the "quirks" of CHDK scripting that one has to watch out for ?

I really want to use this for my project, but until I can understand why I am creating all this instability or if its just inherent to CHDK, its difficult to progress further.

*

Offline SkyWalker9

  • ****
  • 301
  • SX20 IS (fw 1.02b)
Re: Set zoom problems
« Reply #1 on: 17 / October / 2011, 21:18:10 »
I am new to CHDK...I am trying to do what should be the simplest of operations: turn on camera, zoom out lens to a set point, and take a picture...something like this:

rem Author ~Keoeeit~
rem For S-series cameras ONLY!
set_zoom_speed 20
set_zoom 0
set_zoom 1
click "shoot_half"
shoot
end

...The behavior is flakier than a croisant...Sometimes it will actually get to the shoot command, but the zoom is all wrong...I've tried all sorts of sleep 100, sleep 500, sleep 6000 throughout the script to no avail...
The set_zoom_speed statement appears to cause odd behavior in some camera models (per the CHDK Users's Guide), so I'd try the script without the statement.

Depending on how much you ask your camera lense to move with the set_zoom statement, you may need to add enough delay with a sleep statement to allow the camera time to settle. The same for the press "shoot_half" statement. As a test, you might try the following to see how your cameras react:

Code: [Select]
rem Author ~Keoeeit~
rem For S-series cameras ONLY!
set_zoom 1
sleep 1000
press "shoot_half"
sleep 1000
shoot
release "shoot_half"
end

Note: The sleep 1000 statements might be able to be shortened or if needed increased depending on the camera. Good Luck!
« Last Edit: 17 / October / 2011, 21:31:16 by SkyWalker9 »

Re: Set zoom problems
« Reply #2 on: 19 / October / 2011, 10:00:48 »
Thanks for the help.  Unfortunately the script changes you proposed do not solve the problem.  And this is regardless of whether I am running it on an A495, A480, or G11. The set_zoom 1 command (or set_zoom anything for that matter) is essentially ignored if one tries to run this Autostart.  It does however reliably take a picture (just at zoom 0)  However,  it will work if you run the script manually.   I even tried putting a wait_click or any other filler in front of the set_zoom command and its a no go.

I guess I'm somewhat perplexed.  Surely someone out there has had a need to completely autoconfigure the camera on an autostart script setting ISO, shutter, aperture and most importantly zoom setting before taking the first photo.

Can anyone point me to an example of such a simple script that works ?

And can someone explain to me why in the middle of a script that the camera can execute successfully sometimes, at other times (say the 3rd time in a row running it) the camera just shuts down ?  Is this just the vagaries of CHDK or is it just bad coding on my part ?  I'm assuming its the latter, but I can't see how with the simple scripts like those below that I'm doing anything wrong.

Re: Set zoom problems
« Reply #3 on: 19 / October / 2011, 16:05:31 »
To add further to my investigation, I can in fact get set_zoom to work in an autostart script, BUT the only way I have found to do so is to have a shoot command somewhere prior to my first set_zoom command.  Further, if I want to keep the camera from shutting off after the set_zoom, then I need to do something like press/release "shutter_half" or shoot or whatever.  If you have set_zoom and then end OR even if you have set_zoom x, sleep y, end, the camera (at least my A480) will always shut down at the end of the autostart script.

I'm ready to call this a bug and not an error on my part.  I think anyone using set_zoom in an autostart script does so at their own peril. Please feel free to correct me if I'm missing something here.


*

Offline msl

  • *****
  • 1280
  • A720 IS, SX220 HS 1.01a
    • CHDK-DE links
Re: Set zoom problems
« Reply #4 on: 21 / October / 2011, 11:50:52 »
What would you do in concrete, set zoom and shooting with a autostart script?

CHDK on A480 or A495 will start normally in playback mode. At first the script must switch to the recording mode. Then you can set and check the zoom position. After this you can make a shooting.

Because there is no problem with CHDK. But you have to check in your script, if all commands were executed really. Only then you can use the next command.

msl
CHDK-DE:  CHDK-DE links

*

Offline SkyWalker9

  • ****
  • 301
  • SX20 IS (fw 1.02b)
Re: Set zoom problems
« Reply #5 on: 21 / October / 2011, 17:13:08 »
To add further to my investigation, I can in fact get set_zoom to work in an autostart script, BUT the only way I have found to do so is to have a shoot command somewhere prior to my first set_zoom command.  Further, if I want to keep the camera from shutting off after the set_zoom, then I need to do something like press/release "shutter_half" or shoot or whatever.  If you have set_zoom and then end OR even if you have set_zoom x, sleep y, end, the camera (at least my A480) will always shut down at the end of the autostart script.

I'm ready to call this a bug and not an error on my part.  I think anyone using set_zoom in an autostart script does so at their own peril. Please feel free to correct me if I'm missing something here.
I don't think this is a bug. I've included this short script that works on my SX20. It worked correctly 10 times in a row whether the script was run autostart or run manually. Give it a test...It prints a short message that it is waiting for you to press the SET button. Next it zooms out to the Zoom Step you specify in the parameter, focuses, and then shoots a photo. Note: Be sure to set the zoom parameter to something appropriate for the camera being used.

Code: [Select]
rem Test

@param a Zoom Step
@default a 50

  cls
  print "Set when ready..."
  print " "

:check_again
  wait_click
  is_key k "set"
  if k=1 then goto "ok"
  goto "check_again"

:ok
  set_zoom a
  sleep 1000

  press "shoot_half"
  sleep 1000

  shoot

  release "shoot_half"

end

*

Offline msl

  • *****
  • 1280
  • A720 IS, SX220 HS 1.01a
    • CHDK-DE links
Re: Set zoom problems
« Reply #6 on: 21 / October / 2011, 17:37:24 »
@SkyWalker9

Why do you use this code?
Code: [Select]
...
press "shoot_half"
  sleep 1000

  shoot

  release "shoot_half"
...
shoot includes shoot_half

Either
Code: [Select]
shootor
Code: [Select]
press "shoot_half"
press "shoot_full"
release "shoot_full"
release "shoot_half"

And you must check the max. zoom steps of a camera. Not all cameras have 50 or more steps. Use get_zoom_steps.

msl
CHDK-DE:  CHDK-DE links

*

Offline SkyWalker9

  • ****
  • 301
  • SX20 IS (fw 1.02b)
Re: Set zoom problems
« Reply #7 on: 21 / October / 2011, 19:42:46 »
@SkyWalker9

Why do you use this code?
Code: [Select]
...
press "shoot_half"
  sleep 1000

  shoot

  release "shoot_half"
...
shoot includes shoot_half

Either
Code: [Select]
shootor
Code: [Select]
press "shoot_half"
press "shoot_full"
release "shoot_full"
release "shoot_half"

And you must check the max. zoom steps of a camera. Not all cameras have 50 or more steps. Use get_zoom_steps.

msl
The reason for using the particular code in the script was twofold: keep most of the original statements @nohair wanted to use and provide a simple script that works using CHDK. It appeared to me that @nohair wanted to test both of the press "shoot_half" and shoot statements. I added the release "shoot_half" at the end as a reminder when using the press "shoot_half".

The reason for not checking the zoom capability of the camera was to keep the script as simple as possible - thus the comment "Note: Be sure to set the zoom parameter to something appropriate for the camera being used." You've probably noticed that all of the scripts I've submitted to the Completed and Working Scripts section (that use set_zoom statements) actually check the maximum zoom steps capable for each camera.

Sorry about any confusion.


Re: Set zoom problems
« Reply #8 on: 25 / October / 2011, 15:55:20 »
Thank you for all your diagnostic help.  I get back into town tomorrow and will gladly test this out. I did try to do a wait_click, but
not quite like you did. 

I certainly hope that I prove myself wrong and you right on this, as this is a critical step I need to do in my script.

Given your vastly greater experience writing scripts I'd say the odds are heavily in your favor on this.

*

Offline SkyWalker9

  • ****
  • 301
  • SX20 IS (fw 1.02b)
Re: Set zoom problems
« Reply #9 on: 26 / October / 2011, 08:32:50 »
I forgot to mention that when using the wait_click statements, the timeout must be added on the statement for some camera models; in these cases you may want add a delay (for example 5 secs) to something like wait_click 5000.
« Last Edit: 26 / October / 2011, 08:35:10 by SkyWalker9 »

 

Related Topics