IXUS160/ELPH160 Porting attempt - page 49 - DryOS Development - CHDK Forum

IXUS160/ELPH160 Porting attempt

  • 497 Replies
  • 233665 Views
Re: IXUS160/ELPH160 Porting attempt
« Reply #480 on: 21 / August / 2016, 08:52:30 »
Advertisements
Is it somehow possible to set/query mecha position from lua? (I'm willing to take the risk of damaging the camera)

I've attached an old short script that manually sets a focus position and then reads back the focus value and the mechanical position.  You will need to set Enable Lua Native Calls [ * ] in the Miscellaneous menu.

I couldn't find any thing where I had actually set the mechanical position and tested the script.  But here are a few links if you are feeling adventurous.

Re: Porting A410 - help wanted
Re: A570is- Latest Build from svn problem resolved (I think...)
Re: Manual Focus @ Infinity not working


Quote
Or is there some not-extremely-hard way to overwrite camera-given limits of focus value? (of course if there is a table which just ends too early then it does not help)
Nothing that I know about. You'll probably need to do a lot of disassembly and wading through the camera code to figure that one out.
Ported :   A1200    SD940   G10    Powershot N    G16

*

Offline reyalp

  • ******
  • 14117
Re: IXUS160/ELPH160 Porting attempt
« Reply #481 on: 21 / August / 2016, 15:48:11 »
On the second question: I used zoom 0 where manual focus works. Located subject at to distance 300, 400 and 500 and half-pressed shutter until the focus indicator turned green. Then immediately red get_focus(). Here's what I got: 300 -> 260,  400 -> 320,  500 -> 380
This is interesting.
Quote
It looks like values set by autofocus are somewhat constantly smaller than the actual distance. Probably not the source of the problem but might just make it worse.
One possible source of differences is mixing up distance to lens vs distance to sensor. There are some functions that make this distinction in the firmware, so if CHDK used the wrong one somewhere, that could result in discrepancies. However, that shouldn't result in >10cm difference on a compact like this.

Quote
Waterwingz theory matches with this test: I set zoom into 44. Lowest possible focus value seems to be 1014, which (assuming focus number equals subject distance) feels way too high. With half press, the camera is able to autofocus into subject at distance 400, producing nice sharp picture. And the camera still thinks the focus value is 1014 when queried by get_focus(). So it really looks like the camera has no clue about the actual distance, it just (intelligently) drives the focus motor back and forth until the centerpiece of the image is sharp enough.
Yeah, that makes sense, and fits with waterwingz theory.

FWIW, the specs give the ixus160 minimum focus distance at max zoom as 1.3 meters.
Don't forget what the H stands for.

Re: IXUS160/ELPH160 Porting attempt
« Reply #482 on: 22 / August / 2016, 05:29:15 »
I've attached an old short script that manually sets a focus position and then reads back the focus value and the mechanical position.

In the script, MoveFocusLensToDistance returned -1. I found somewhere the forum these:
call_event_proc("FA.Create")
call_event_proc("InitializeAdjustmentFunction")


After adding those, MoveFocusLensToDistance started to work. Although it does seem to do the same thing as set_focus() and obey same limits.

Quote
I couldn't find any thing where I had actually set the mechanical position and tested the script.  But here are a few links if you are feeling adventurous.

MoveFocusLensToPosition would likely be a sufficient workaround, but using it just hangs the camera. Maybe i160 does not have such function, at least the address not definened here

Re: IXUS160/ELPH160 Porting attempt
« Reply #483 on: 22 / August / 2016, 07:30:36 »
MoveFocusLensToPosition would likely be a sufficient workaround, but using it just hangs the camera. Maybe i160 does not have such function, at least the address not definened here
I don't believe it would be in your stubs_entry.S file unless it's used somewhere in the build. 

You can check for it here.  It shows up there as MoveFocusLensToPosition_FW.

I shouild know why the _FW is tagged onto the end and whether you need it in the string you pass to call_event_proc() but it escapes me at the moment. Hopefully srsa_4c will chime in here.

Did you look at all three function calls and experiment with the necessary parameters as posted here ?


edit  : I'll let @srsa_4c answer by proxy :  "Remove the _FW ending if you'd lke to use them from Lua" 
 
« Last Edit: 22 / August / 2016, 07:43:39 by waterwingz »
Ported :   A1200    SD940   G10    Powershot N    G16


Re: IXUS160/ELPH160 Porting attempt
« Reply #484 on: 22 / August / 2016, 20:12:19 »
Did you look at all three function calls and experiment with the necessary parameters as posted here ?

I can report some intermediate success here. MoveFocusLensToPosition hangs the camera but MoveFocusLensWithPosition was finally a  success. I tested with zoom 44 (of 100) where set_focus stops into 1023. I was  able to get beautifully sharp images of a subject at distance bit more then 40cm.

First parameter of MoveFocusLensWithPosition is the position as reported by GetFocusLensCurrentPosition and second seems to be speed. 100 is fast, 10 is slow and leaving the parameter out is horribly slow, causing crash in larger movement (maybe some timeout)

*

Offline reyalp

  • ******
  • 14117
Re: IXUS160/ELPH160 Porting attempt
« Reply #485 on: 22 / August / 2016, 21:36:12 »
First parameter of MoveFocusLensWithPosition is the position as reported by GetFocusLensCurrentPosition and second seems to be speed. 100 is fast, 10 is slow and leaving the parameter out is horribly slow, causing crash in larger movement (maybe some timeout)
Good information.

For eventprocs, leaving the parameter out will just use whatever garbage happens to be in memory / registers, so you definitely don't want to do that.
Don't forget what the H stands for.

Re: IXUS160/ELPH160 Porting attempt
« Reply #486 on: 23 / August / 2016, 16:02:17 »
For eventprocs, leaving the parameter out will just use whatever garbage happens to be in memory / registers, so you definitely don't want to do that.

Do you have any idea what MoveFocusLensWithPosition 3rd parameter could possibly be. Looks like after very long (focus-pos-searching) session camera starts to crash when position changed at max zoom. Probably due aforementioned garbage. Battery-off reboot fixes the matter

*

Offline reyalp

  • ******
  • 14117
Re: IXUS160/ELPH160 Porting attempt
« Reply #487 on: 23 / August / 2016, 16:50:57 »
Do you have any idea what MoveFocusLensWithPosition 3rd parameter could possibly be. Looks like after very long (focus-pos-searching) session camera starts to crash when position changed at max zoom. Probably due aforementioned garbage.
Possible.

You generally need to look at Canon firmware disassembly to know how many parameters there are and figure out what they do. From a quick look at the elph130 dump it's not obvious to me what the 3rd param does, but in other cases the firmware seems to pass 1 or 0 to the underlying function that uses the value, so those would be my first choices to try.

Note that calling hardware control functions with random values in unknown parameters is probably one of the more risky things you can do with CHDK ;)
Don't forget what the H stands for.


*

Offline c10ud

  • ***
  • 245
Re: IXUS160/ELPH160 Porting attempt
« Reply #488 on: 07 / February / 2017, 11:18:10 »
For eventprocs, leaving the parameter out will just use whatever garbage happens to be in memory / registers, so you definitely don't want to do that.

Do you have any idea what MoveFocusLensWithPosition 3rd parameter could possibly be. Looks like after very long (focus-pos-searching) session camera starts to crash when position changed at max zoom. Probably due aforementioned garbage. Battery-off reboot fixes the matter
Did you have any success with those tests?

I remember having such a problem with zooming (e.g. camera going out of focus) at a "normal" value (iirc 60 or so..)

Also set_focus(-1) couldn't fix such problem..


EDIT: script is like this (I want to focus infinity)

set_iso(100)
set_zoom(60)
set_focus(-1)
shoot()

EDIT2: the script was much more complex and it looks like some press() calls might have screwed the whole thing up! now it's working flawless...fingers crossed!
« Last Edit: 06 / March / 2017, 13:37:09 by c10ud »

*

Offline Hacki

  • ****
  • 359
  • EOS 80D
Re: IXUS160/ELPH160 Porting attempt
« Reply #489 on: 17 / February / 2018, 18:08:45 »
So, since i'm currently in the process of building a DIY bookscanner from two IXUS 160's, i naturally ran into the problem of the broken subject distance override thing. I dont want to rely on the autofocus to re-focus after each shot and would rather set the focus manually to a fixed value.


I want to share some of my findings which builds on the stuff of the last couple of posts:


Setting a custom focus distance via LUA works with the following call:

Code: [Select]
call_event_proc("MoveFocusLensWithPosition", a, 100)

Where "a" is a value from around 0 to 1840 indicating the focus position, and 100 being the focussing speed.


Whats very interesting:


a.) Using 1840 moves the minimum focus distance at zoom level 0 inside the front lense as you can see from the almost in focus dirt in pic 1.


b.) It reduces the minimum focussing distance at full zoom to a mere 50 centimeters which gives this nice magnification you see in pic 2. 


c.) The reported subject distance that CHDK gets maxes out long before the MoveFocusLensWithPosition command is done moving the lens. It stops at around 1.3 meters reported subject distance (which is also the minimum focussing distance of this camera according to the datasheet).





Now i have no idea if that could damage the camera in the long term, but i think since it's willingly executing those commands they are safe. Anything above a value of 1840 will crash the camera immediately.


I'll be using that for my bookscanner together with aflock. From the few tests i have been running this method looks far more precise and reproducable than using the sd override.


Perhaps the subject distance override function for this particular ixus model (or others that suffer from this peculiar behaviour) could be overwritten to use MoveFocusLensWithPosition instead of MoveFocusLensToDistance?


« Last Edit: 17 / February / 2018, 18:11:50 by Hacki »

 

Related Topics


SimplePortal 2.3.6 © 2008-2014, SimplePortal