CHDKPTP: S90 Primary Focal Plane Configuration - hacking out the CCD - page 60 - Creative Uses of CHDK - CHDK Forum

CHDKPTP: S90 Primary Focal Plane Configuration - hacking out the CCD

  • 704 Replies
  • 196845 Views
*

Offline SticK

  • *****
  • 779
Re: CHDKPTP: S90 Primary Focal Plane Configuration - hacking out the CCD
« Reply #590 on: 20 / August / 2013, 10:34:56 »
Advertisements
@srsa_4c

Thank you for all the useful info.

Quote
UI.CreatePublic: This registers lots of event procedures and consumes memory.
Indeed .. a huge 60K, chipping away at my decent pool!

Quote
Here's how to call the PTM event procedures directly (so you don't need UI.CreatePublic):
Ho!  // that's cool // I will certainly give it a shot today and report the results.  I'd rather hard-code the addresses than mess with FW any more than necessary!

Quote
What you could do - as I tried to explain earlier - is to drop ISO override from your shoot command, and control ISO using the PTM eventproc. If that's not enough, you could drop the Av and Tv overrides too, and control all these by the PTM eventproc - you can do it, you're in M mode.
Yes, I will get to it soon.  But I suppose you're getting to know me a bit too .. I like to move along incrementally (only because I have limited mental vision as reyalp well knows), understand things well, and produce a reliable working version of your new discovery based on the code I just posted.  It is working very well indeed !  I can go into Canon SET, change the liveview ISO, leave the Canon OSD in any state I want, and continue overriding with shoot_SticK(Tv, Sv): the interaction is gone.  I can also see now I can put up car-radio buttons on CHDKPTP to set liveview brightness instead of going into the SET menu.  That alone is a great help.  My upcoming instrument supervisory app will send shoot_SticK()-type messages to CHDKPTP via LAN, which will be running on a remote Beaglebone Black tethered to S90_101a (via USB of course).  This should be beautiful project, the generic part of which I hope to share with everyone.

What a great discovery, srsa!  :).
« Last Edit: 20 / August / 2013, 10:37:48 by SticK »

*

Offline SticK

  • *****
  • 779
Re: CHDKPTP: S90 Primary Focal Plane Configuration - hacking out the CCD
« Reply #591 on: 20 / August / 2013, 11:52:57 »
QUESTION on a UNIVERSAL shoot_SticK()

Now that the Lua code in my CHDKPTP is CanonFW-version-sensitive, hence using the same code on the 100c and 101a, is there a way I can detect the FW version at the entry of shoot_SticK() and vector the appropriate call_func_ptr addresses w/o having to worry which camera my code is running on?  This also may help future extended applications of the PTM discovery.

*

Offline srsa_4c

  • ******
  • 4451
Re: CHDKPTP: S90 Primary Focal Plane Configuration - hacking out the CCD
« Reply #592 on: 20 / August / 2013, 12:47:27 »
is there a way I can detect the FW version at the entry of shoot_SticK() and vector the appropriate call_func_ptr addresses w/o having to worry which camera my code is running on? 
Camera-side Lua: get_buildinfo().platsub

edit
The direct calls are working OK.  Could you please post the addresses for the other two FW versions?  I will put all four in.
I have updated that post, addresses for all 3 fw versions are there.
« Last Edit: 20 / August / 2013, 18:47:45 by srsa_4c »

*

Offline SticK

  • *****
  • 779
Re: CHDKPTP: S90 Primary Focal Plane Configuration - hacking out the CCD
« Reply #593 on: 20 / August / 2013, 12:55:39 »
@srsa_4c

The direct calls are working OK.  Could you please post the addresses for the other two FW version?  I will put all four three in.
« Last Edit: 22 / August / 2013, 13:13:11 by SticK »

*

Offline SticK

  • *****
  • 779
Re: CHDKPTP: S90 Primary Focal Plane Configuration - hacking out the CCD
« Reply #594 on: 22 / August / 2013, 12:31:49 »
REMOTE shoot_SticK(Tv, Av, Sv) M-MODE FUNCTION THAT IMPLEMENTS PTM EVENTS

DESCRIPTION

In CHDKPTP the remote shoot -tv= -av= -sv= function causes the liveview to fall back to ISO 100 if user-set via the Canon SET menu to any value other than ISO 100.  This has the effect of darkening liveview after a shoot, if for example, liveview is at ISO1600.  This implementation solves the problem by getting the current ISO value, shooting and resetting the ISO to restore the original liveview brightness.  This code also auto-detects the camera then vectoring out the correct PTM Get and Set addresses, and executes file transfer from the camera to PC after shoot using dcimdl().  I designed the logic so that the camera model is probed only once, ie on the first call to shoot_SticK().  At present, it handles all three known firmware versions of the S90.  Please note that this code is not exclusive to the hacked S90 with its CCD hanging out: if you have a remote application with any camera where you want liveview stable in M mode, it will work so long as you find the Get and Set address pointers for your camera.

ADDING A NEW EVENT

First obtain the PTM Get and Set addresses for call_func_ptr() for your camera if it is not in the cam_funcs table already (might be tricky).  Add your new event ID (ISO is already coded-in).   The code has know which camera_fwversion you have: from the CHDKPTP command line, say !ShowModel() and use that to make a new entry in cam_table.  Change my PC_destdir to yours.  Detailed instructions are given in the code.

Code: [Select]
--[[  *** shoot_SticK(Tv, Av, Sv) ***
Mechanism to shoot an S90 in M mode via shoot_SticK(Tv, Av, Sv) call.
Copyright (c) 2013 SticK
License:  free and unrestricted use.

Current implementation is for resetting liveview ISO (brightness) to
the value prior to shoot using PTM events.

Steps:  1) For a camera not in the table, from the CHDKPTP command line
   say !ShowModel() and note your camera model_version.  Ignore
   any warning message.
        2) Using model_version, create a new entry in the cam_funcs table
   and define the PTM_Get and PTM_Set addresses for the event.
3) Add a new PTM event ID eg: local CamPTM_ISO_ID = "0x8006"
]]

local PC_destdir = "G:\\CANON_S90\\"   -- Give your PC destination folder for camera image files here --  DO NOT use spaces .. it will truncate.

-- Add a new CamPTM_XXX_ID here (step 3)
local CamPTM_ISO_ID = "0x8006" 

local cam_funcs =
{
-- Add an entry here with the PTM Get and Set pointers for your camera. (step 2)
s90_100c =
{
PTM_Get = '0xff8950cc',
PTM_Set = '0xff993e2c',
},
s90_101a =
{
PTM_Get = '0xff8950f8',
PTM_Set = '0xff993e80',
},
s90_101c =
{
PTM_Get = '0xff895148',
PTM_Set = '0xff99403c',
}
    }

local current_cam = nil

local function PTM_Get(event_id)  -- a return value of -1 indicates Get failure
    local l,r = con:execwait(string.format('return call_func_ptr(%s, %s)', current_cam.PTM_Get, event_id))
    if l == nil then
        warnf('PTM_Get failed %s\n',tostring(r))
        return -1
    end
    return r
end

local function PTM_Set(event_id, to_value)  -- Returns true if Set successful, false if not.
    local l,r = con:execwait(string.format('return call_func_ptr(%s, %s, %d)', current_cam.PTM_Set, event_id, to_value))
    if l == nil then
        warnf('PTM_Set failed %s\n',tostring(r))
        return false
    end
    return true
end

local function set_CameraModel(do_show)  --sets the camera Canon FW version (100c, 101a etc) for vectoring call_func_ptr() calls.
    local l,bi = con:execwait('return get_buildinfo()')
    if l == nil then
        warnf('set_CameraModel(): get_buildinfo() failed: %s. Some operations will fail.\n', tostring(bi))
        current_cam = nil
        return false
    end
local cam = bi.platform .. '_' .. bi.platsub
if do_show == true then
printf('Camera: %s\n', cam)  -- use this result to define a new table entry for your camera. (step 1)
end
    current_cam = cam_funcs[cam] -- will be nil if not known in table
    if current_cam == nil then
        warnf('Failed to set camera model %s (not found in table). Some operations will fail.\n', cam)
        return false
end
return true
end

function ShowModel()  -- (step 1)
set_CameraModel(true)
end
-- ==============================================================================

local function dcimdl(destdir,del,pretend)  -- transfers image files from SD card to PC and erases them from SD card.
    if pretend then
        pretend = '-pretend '
      else
        pretend = ''
    end
    local dcim,err=con:listdir('A/DCIM')
    if not dcim then
        printf('error listing directory %s\n',tostring(err))
    return
    end
    for i,dname in ipairs(dcim) do
        if dname ~= 'CANONMSC' then
            cli:print_status(cli:execute('mdl '..pretend..' -fmatch=%.[JDC][PNR][G2W]$ DCIM/'..dname..' '..destdir))
        end
    end
if del then
cli:print_status(cli:execute('rm '..pretend..' -skip_topdirs DCIM'))
end
end

local function local_shoot(tv, av, canon_sv, destdir)  -- usage: >!local_shoot(1/8, 2.8, 400, "C:\\CANON_S90\\")
local sv = canon_sv / 1.6461 -- ISO correction for S90 so that CHDK EXIF data is the same as Canon.
cli:print_status(cli:execute('shoot -tv='..tv..' -av='..av..' -sv='..sv..''))
sys.sleep(2400)
local l,r=con:execwait('return get_meminfo().free_size')
print(" free", r)         -- in DOS cmd box
printf(" free: %s\n",r)   -- in CHDKPTP log window
dcimdl(destdir, true, false)
end

function shoot_SticK(Tv, Av, Sv) 
if current_cam == nil then
if (set_CameraModel(false) == false) then
warnf("WARNING: shoot_SticK(): call request not executed: function pointer addresses missing.\n");
return
end
end
local r = PTM_Get(CamPTM_ISO_ID)  -- save the current ISO index for liveview
if r == -1 then
warnf("shoot_SticK(): call request not executed: function pointer addresses missing.\n");
return
end
-- printf("Current ISO index setting=%s\n", r)
local_shoot(Tv, Av, Sv, PC_destdir)
sys.sleep(20)    
local l = PTM_Set(CamPTM_ISO_ID, r)  -- restore the current ISO index for liveview
if l == false then
warnf("shoot_SticK(): unable to set PTM: camera state may be indeterminate.\n");
return
end
sys.sleep(20)    
con:execwait('press("shoot_half")') -- update liveview brightness
con:execwait('release("shoot_half")')
end
Usage:  CHDKPTP command line example:
        !shoot_SticK(1/8,5.6,200)
« Last Edit: 23 / August / 2013, 13:04:41 by SticK »

*

Offline reyalp

  • ******
  • 14128
Re: CHDKPTP: S90 Primary Focal Plane Configuration - hacking out the CCD
« Reply #595 on: 22 / August / 2013, 22:13:34 »
@reyalp
Could you please inspect this code and tell me if it could be improved for error-trapping?
I haven't gone through it in detail, but you make a number of ptp calls without checking or reporting the status, which will make it more difficult to debug if something doesn't work right.

For example, if
local l,r = con:execwait(string.format('return call_func_ptr(%s, %s)', CamPTM_Get_adrs, CamPTM_ISO_ID))

fails (l is false), r will be the error message. So the following
 cli:print_status(con:execwait(string.format('call_func_ptr(%s, %s, %d)', CamPTM_Set_adrs, CamPTM_ISO_ID, r)))   

will would try to use the error message as the 3rd param. That could be bad if it went through, but string.format will probably complain when you try to format a argument that isn't number-like with %d.

As a more general note, the SelectCamera stuff could be simplified a lot. For example, you could just set the addresses in a table that is indexed by platform, something like (totally off the top of my head untested)

Code: [Select]
local cam_funcs = {
s90_100c = {
PTM_Get = '0xff8950cc',
PTM_Set = '0xff993e2c',
},
-- ... same for other cams
}

local current_cam

local function set_CameraModel()  --sets the camera Canon FW version (100c, 101a etc) for vectoring call_func_ptr() calls.
    local l,bi = con:execwait('return get_buildinfo()')
if not l then
warnf('failed to set camera model %s',tostring(bi))
current_cam = nil
return
end
current_cam = cam_funcs[bi.platform .. '_' .. bi.platsub] -- will be nil if not known in table
end

local function PTM_Get(id)
-- this will error if cam isn't set, because you will be trying to index nil
local l,r = con:execwait(string.format('return call_func_ptr(%s, %s)', current_cam.PTM_Get, id))
if not l then
warnf('PTM_Get failed %s',tostring(r))
return false
end
return r
end
Don't forget what the H stands for.

*

Offline SticK

  • *****
  • 779
Re: CHDKPTP: S90 Primary Focal Plane Configuration - hacking out the CCD
« Reply #596 on: 23 / August / 2013, 12:29:56 »
@reyalp
Thank you for your extensive explanation ... it really helped.  I like your vectoring method so I have edited a new version in the original post:
http://chdk.setepontos.com/index.php?topic=8801.msg104366#msg104366
I left the cli:print_status(cli:execute()) as-is because I'm not sure if they follow the same error-reporting convention as the others.  If that can be improved, please show me how.

This new functionality is working beautifully on the 101a.

*

Offline SticK

  • *****
  • 779
Re: CHDKPTP: S90 Primary Focal Plane Configuration - hacking out the CCD
« Reply #597 on: 24 / August / 2013, 15:19:42 »
@srsa_4c

The system is working beautifully, this project is about to move into its next major phase, I am ready to call a milestone and present new hardware.  But before I do, while recent events are still fresh in your mind, and while you have explained the difficulties already, could you please give liveview vignetting one more chance?   Of course it is not absolutely required for scientific-grade performance // that's here already // but, it would make things easier for optical alignment and of course give a very nice uniform and pleasant image in the liveview window while in use navigating specimens etc, which is most of the time.   Also, it would leave everyone's combined effort for the current solution in a very elegant state, if one can call a long series of hacks elegant, yours certainly are.  If you feel there might be chance with no unreasonable impact on your time and not much danger to the working code, that would be the cherry on the cake.  Thanks a million!

*

Offline srsa_4c

  • ******
  • 4451
Re: CHDKPTP: S90 Primary Focal Plane Configuration - hacking out the CCD
« Reply #598 on: 25 / August / 2013, 09:50:16 »
could you please give liveview vignetting one more chance?
This is "on my list", but - as I mentioned already - seems pretty difficult to find. I agree in its usefulness - it could help people who try to shoot "movies" with changed / replaced optics. I intend to continue with this once I have time to do so, but can't promise anything.

*

Offline SticK

  • *****
  • 779
Re: CHDKPTP: S90 Primary Focal Plane Configuration - hacking out the CCD
« Reply #599 on: 25 / August / 2013, 10:56:07 »
DEVELOPMENT MILESTONE ANNOUNCEMENT

I declare CHDK FW development phase for the PFP CCD solution a major milestone: functionality has been achieved for scientific purposes.  This also means that I will no longer refer to the S90_101a as a "camera" but as an "imager".  Congratulations to the entire CHDK development team for this great achievement, especially to reyalp and srsa, please accept my appreciation of your talent, expertise and kind help.

The next phase is actually a couple branches.  The S90 imager is almost ready to be installed in the instrument.  That should happen within a week or two.  The other more interesting branch for readers, and a new adventure I feel relevant to this thread, is integration for a stand-alone remote-controlled system running under the BeagleBone Black.  This is a credit-card 2000 MIPS ARM SOC with a 4-banger FPU, so I think it should be able to handle the floating point code in CHDKPTP and its dependencies, if all is compiled with the appropriate switches.  The newer BBB v3.8.x kernel supports device tree overlays making this SOC much more flexible for embedded applications than previous BB models.  I have the machine already running using Eclipse C/C++ CDT (Ubuntu in an Oracle VirtualBox on my Win PC) cross-compiler with remote debug capability.  The BBB hardware is presently being raw-tested and ramped-up (plus a learning curve for me).

Hence I will be looking forward to your help more with logistics, possibilities, ideas and directives than actual code development, as I expect most if not all, will be in my hands.  But before turning to that page, to complement all your efforts, I have the new hardware to present.  It will be presented in a few parts, and I am asking you that once you see my first post with "PART X of [I don't know yet]" in red on the title line, please hold off on your replies until I have posted all parts in sequence for easy reading.  When I turn the red to black in those posts, then I would welcome your feedback. 

I intend to continue with this once I have time to do so, but can't promise anything.
Even if you can't find a solution, you can be sure no one here will knock you -- it just means the only person who can do it is the guy who coded Canon  ;).   But, if you happen to be skillfully lucky, please advise right away.  If you're back looking into it, let us first test on the 100c with only that mod, if possible.
« Last Edit: 25 / August / 2013, 11:08:59 by SticK »

 

Related Topics


SimplePortal © 2008-2014, SimplePortal