Problem with new @range - Script Writing - CHDK Forum

Problem with new @range

  • 7 Replies
  • 2010 Views
Problem with new @range
« on: 13 / June / 2012, 16:58:47 »
Advertisements
I'm celebrating the addition of the @range specification in scripts by writing a script that sets the zoom and focus.

Last year I experimented with shooting and assembling panoramas, and I found myself frustrated, trying to get exactly the right focal length (zoom).  Even with the S3's dual-speed zoom motor I found myself overshooting the exact zoom level I wanted for the (I hoped) perfect balance between depth of detail from telephoto shots vs. the simplicity of combining a few wide-angle shots.

So I wrote a script.  uBASIC allows me to set any of 129 zoom levels and any focus distance from 1 to 65535mm.

Here's what I have, so far:
Code: [Select]
rem CHDK script to set zoom and focus
rem by Eric Sandbo (kidtree) June 13, 2012
rem intended for precise setting of zoom ratio & hyperfocal for panoramas
rem Enabling hyperfocal overrides your focus setting
rem Put camera in manual Focus before starting.
@title Zoom set
@param z Zoom number (1 - 129)
@range z 1 129
@default z 10
@param h Set to hyperfocal?
@range h 0 1
@default h 1
@param f Focus distance, mm
@range f 1 65535
@default f 65535
if get_focus_mode<>1 then goto "not_manual"
set_zoom_speed 20
set_zoom z
sleep 1000
rem set Focus to either hyperfocal or set number
if h then F=get_hyp_dist else F=f
set_focus F
sleep 500
goto "restore"
:not_manual
print "Put camera in Manual Focus."
sleep 900
goto "restore"
:restore
exit_alt
end
It seems to work, mostly, as long as I want to focus on the hyperfocal distance, which is exactly what I anticipate for its intended use.  But if I want to set the input parameter to some specific distance, it goes immediately to -1, and I can't get it out of that number.  I have a range set for that variable (f) to go anywhere from 1 to 65535mm, and default is set at the maximum.  I should be unable to reach -1 from either direction.  Instead, I not only reach it, I get stuck there.
I tried deleting CHDK.CFG, but that didn't help.
Any ideas?

Thanks,
Eric
Powershot S3 IS, CHDK build 1907

Here's one of my favorite panos.  Note the audience at the left end:
http://o-o.preferred.cbf01t01.v8.cache4.c.bigcache.googleapis.com/static.panoramio.com/photos/original/57789028.jpg?ms=tsu&mt=1339620302&cms_redirect=yes&redirect_counter=2
S3 IS with LensMate filter/hood adapter

Re: Problem with new @range
« Reply #1 on: 13 / June / 2012, 17:38:09 »
Can you use 65535 value without the @range?

I think that the problem might be that the param is too big. If the data type for this value is too small, then the max value can be far limited. I haven't look deeply in the script.c code, but it seems to be int, so should be enough...

Try to perform following tests:

-use @range with smaller max value
-use @param without @range
« Last Edit: 13 / June / 2012, 17:40:05 by outslider »
if (2*b || !2*b) {
    cout<<question
}

Compile error: poor Yorick

*

Online philmoz

  • *****
  • 3163
    • Photos
Re: Problem with new @range
« Reply #2 on: 13 / June / 2012, 18:25:56 »
I have a range set for that variable (f) to go anywhere from 1 to 65535mm, and default is set at the maximum.

The @range min and max values are stored together in a single int so are only 16 bits each.
In the current implementation they are treated as 16 bit signed values so the allowed 'range' is -32768 to 32767.

The system is based on the current menu implementation in CHDK so it's limited by the constraints in that.
There is an option for menus to allow the min/max values to be treated as 16 bit unsigned (allowing 0 to 65535) - I'll look at seeing if it can be easily extended to allow this as well.

Phil.
CHDK ports:
  sx30is (1.00c, 1.00h, 1.00l, 1.00n & 1.00p)
  g12 (1.00c, 1.00e, 1.00f & 1.00g)
  sx130is (1.01d & 1.01f)
  ixus310hs (1.00a & 1.01a)
  sx40hs (1.00d, 1.00g & 1.00i)
  g1x (1.00e, 1.00f & 1.00g)
  g5x (1.00c, 1.01a, 1.01b)

Re: Problem with new @range
« Reply #3 on: 13 / June / 2012, 18:37:46 »
Thanks for the quick advice! Here's what I found:
Before messing with @range, I reduce the default by 1mm, just in case the problem was having a default right at a range limit.  It didn't help.  Neither did setting the default to 1000.  With a range of 1 to 65534 and a default of 1000, as soon as I try to step to 1001 or 999, it goes to -1.
I "commented out" the range statement, and it worked.  I could set the value of 'f' beyond 64K.
This is my latest combination:
@range 1 20000
@default 1000
This works as it should.  I can step up to 20000 or down to 1, but no further in either direction.

The more I think about this, the more pointless it seems, anyway.  I either want my script to give me hyperfocal distance, or I want to manually focus.  I can eliminate the focus setting from the script, except the choice of hyperfocal or not.  But I wanted to see what was messing up the script.

It looks like CHDK is interpreting the unsigned 16-bit number as a signed one, so any value above 2^15 is seen as negative.  Once I have a negative number, I can't step back into the valid range.

In fact, Parameter set 0 is still stuck with that -1.  Maybe if I comment out the range statement, i can fix it.  I'm surprised that deleting the CHDK.CFG file didn't.  Once I get my displays set the way I want again, I'll save the file to save me the heartache of starting over.

Thanks again for the work you put into all this.  I read a tutorial about HDR last night, and it had all kinds of "If only Nikon or Canon DSLRs would allow this and that" kind of stuff.  And I kept thinking, "Stop whining, and try CHDK!"
« Last Edit: 13 / June / 2012, 18:39:32 by kidtree »
S3 IS with LensMate filter/hood adapter


Re: Problem with new @range
« Reply #4 on: 13 / June / 2012, 18:43:49 »
Looks like we agree on the cause -- that's reassuring, anyway.  Don't rush into fixing it on my behalf.  I'm happy with what I have, but I suppose someone will stumble over it in some other project.  Thanks again for the help.
S3 IS with LensMate filter/hood adapter

*

Online philmoz

  • *****
  • 3163
    • Photos
Re: Problem with new @range
« Reply #5 on: 14 / June / 2012, 04:14:09 »
I've updated the code for '@range' to support signed and unsigned ranges (within the limits of the current CHDK menu code).

If both the min and max values of the range are >= 0 then the parameter menu item is set to unsigned allowing a range limit of 0 .. 65535.

Otherwise the parameter menu item is signed and the range limit is -9999 .. 32767.

Note: the -9999 negative limit is hard wired into the menu handling code and is due to the fact that the menu only display 5 characters for integer values. This is probably something else that needs fixing.

Phil.
CHDK ports:
  sx30is (1.00c, 1.00h, 1.00l, 1.00n & 1.00p)
  g12 (1.00c, 1.00e, 1.00f & 1.00g)
  sx130is (1.01d & 1.01f)
  ixus310hs (1.00a & 1.01a)
  sx40hs (1.00d, 1.00g & 1.00i)
  g1x (1.00e, 1.00f & 1.00g)
  g5x (1.00c, 1.01a, 1.01b)

Re: Problem with new @range
« Reply #6 on: 14 / June / 2012, 12:32:46 »
Perfect!
I feel dumb about deleting my CHDK.CFG file, when all I had to do was reset the script parameters to their defaults.  Especially after having read all the discussion about that before you released the new feature.

Live and learn... sometimes.

Eric
S3 IS with LensMate filter/hood adapter

Re: Problem with new @range
« Reply #7 on: 14 / June / 2012, 12:41:03 »
I feel dumb about deleting my CHDK.CFG file, when all I had to do was reset the script parameters to their defaults. 
Especially as the @params are not stored in the CHDK.CFG file - they get their own file(s).
Ported :   A1200    SD940   G10    Powershot N    G16


 

Related Topics