Help with IXUS 220 HS (ELPH300HS) - PTP - page 2 - General Help and Assistance on using CHDK stable releases - CHDK Forum

Help with IXUS 220 HS (ELPH300HS) - PTP

  • 25 Replies
  • 16018 Views
*

Offline reyalp

  • ******
  • 14126
Re: Help with IXUS 220 HS (ELPH300HS) - PTP
« Reply #10 on: 06 / June / 2012, 16:13:17 »
Advertisements
Hello again !

I tried the multicam and it's really what i needed ! =D
The only problem is that as soon as i switch to rec mode using "!mc:cmdwait("rec")" the cameras became crazy and starts taking a lot of shoots ! I took a look on multicam.lua and it didn't look to came from the rec function, because it just do a switch_mode_usb.
That is quite odd. To see if it is somehow related to multicam, you could try just connecting in chdkptp and using
=switch_mode_usb(1)

Quote
EDIT : Another question, is it possible to launch a script which is on the camera using a chdkptp command ?
Yes, you can use regular Lua functions like require, or loadfile etc with the . (lua) or = (luar) commands. If you want to run a script that expects to be run from the camera UI, you'll need to set variables named a, b, c etc. for the menu parameters.

A few things to note:
1) you can only run one script at a time, so if the script does more than just run and exit and you want to control it, you'd need to use PTP messages like the multicam script does. If you use the low level execlua function, you can start a script without exiting the previous one, but this will lead to memory corruption! The higher level chdku functions prevent you from doing this unless you use the clobber option.
2) Multicam itself runs a long running script on the camera, so to run another script you'd have to exit the camera side multicam script, or load and run it within multicam
3) Require runs in a pcall environment. This allows lua to catch errors in the require'd script, but CHDK functions that need to yield (like shoot, wait_click etc) don't work in this environment. A useful pattern to run a camera script is:
loadfile('A/PATH/TO/SCRIPT.LUA')()
which loads the script and executes it.
Don't forget what the H stands for.

Re: Help with IXUS 220 HS (ELPH300HS) - PTP
« Reply #11 on: 07 / June / 2012, 06:46:56 »
Hello srsa_4c and reyalp !

First, thank you for all your advice, it's really helpful.
Hello again !

I tried the multicam and it's really what i needed ! =D
The only problem is that as soon as i switch to rec mode using "!mc:cmdwait("rec")" the cameras became crazy and starts taking a lot of shoots !
In case you're using "stable" (1.0) CHDK, try the development version: http://mighty-hoernsche.de/trunk/

I used that development version, and all seems to work perfectly.I don't have these "crazy shoots" any more.  :D

A few things to note:
1) you can only run one script at a time, so if the script does more than just run and exit and you want to control it, you'd need to use PTP messages like the multicam script does. If you use the low level execlua function, you can start a script without exiting the previous one, but this will lead to memory corruption! The higher level chdku functions prevent you from doing this unless you use the clobber option.
2) Multicam itself runs a long running script on the camera, so to run another script you'd have to exit the camera side multicam script, or load and run it within multicam
3) Require runs in a pcall environment. This allows lua to catch errors in the require'd script, but CHDK functions that need to yield (like shoot, wait_click etc) don't work in this environment. A useful pattern to run a camera script is:
loadfile('A/PATH/TO/SCRIPT.LUA')()
which loads the script and executes it.

I tried adding a command function to multicam.lua corresponding to the code of the script i wanted to launch. But it didn't work. The script i want to launch is "High Dynamic Range" script which take 3 shots and changes some camera parameters (like backlight). Is it possible to send a "loadfile('A/PATH/TO/SCRIPT.LUA')()" with multicam ?

EDIT : I tried loadfile('A/PATH/TO/SCRIPT.LUA')() command without multicam, with just one camera connected. And as soon as i send the command the camera turns off. I tested the script directly from the camera and CHDK menu, to know if the problem comes from the script or no, and the scripts worked correctly.
« Last Edit: 07 / June / 2012, 07:16:55 by VincentD »

*

Offline reyalp

  • ******
  • 14126
Re: Help with IXUS 220 HS (ELPH300HS) - PTP
« Reply #12 on: 07 / June / 2012, 16:55:12 »
I tried adding a command function to multicam.lua corresponding to the code of the script i wanted to launch. But it didn't work. The script i want to launch is "High Dynamic Range" script which take 3 shots and changes some camera parameters (like backlight). Is it possible to send a "loadfile('A/PATH/TO/SCRIPT.LUA')()" with multicam ?
The multicam 'call' command lets you run any code you want, you can see the 'testshots' function for some examples.

However, in this case, you'd probably be better of implementing the HDR shooting function you want inside the multicam camera side script (e.g. adding a shoot_hdr command). If I understood correctly you tried this and it "didn't work". If you can explain how it failed, maybe someone can help you fix it.

Quote
EDIT : I tried loadfile('A/PATH/TO/SCRIPT.LUA')() command without multicam, with just one camera connected. And as soon as i send the command the camera turns off. I tested the script directly from the camera and CHDK menu, to know if the problem comes from the script or no, and the scripts worked correctly.
The camera probably needs to be in record mode before you start the script. Other than that, I'm not sure why it would crash. However, there are side effects from having PTP connected and various differences in the environment, so it's not a total surprise. Do you have a link to the specific script you are using ?
Don't forget what the H stands for.

Re: Help with IXUS 220 HS (ELPH300HS) - PTP
« Reply #13 on: 11 / June / 2012, 04:58:58 »
Hello reyalp,

I didn't see that "call" function, thank you for talk to me about that command, now it works fine. I can launch the script by sending the call('load(...)()') function. I didn't know why the first time i try launching the script the camera turns off because i think that i already switch to record mode.
Thank you for your help !

I also try to capture the moment when the photo is taken in a text file(with milliseconds). So what i tried was to capture the time before i send the USB command. But there was a 1.5~2 seconds delay between the time i saved and the time when the photo is taken. This delay is too big for what i need. Do you know if it is possible to do it directly in lua, just before the "shoot" command ?

Thank you very much for all your help !

EDIT : I'm also trying to download the last photos taken from all the camera connected. Something like executing "ls" command on all camera and recuperate the output in a file. Then use download command on the last photo. Is it possible to execute ls command with multicam ? ^^

VincentD
« Last Edit: 11 / June / 2012, 05:45:48 by VincentD »

*

Offline reyalp

  • ******
  • 14126
Re: Help with IXUS 220 HS (ELPH300HS) - PTP
« Reply #14 on: 11 / June / 2012, 16:29:28 »
I also try to capture the moment when the photo is taken in a text file(with milliseconds). So what i tried was to capture the time before i send the USB command. But there was a 1.5~2 seconds delay between the time i saved and the time when the photo is taken. This delay is too big for what i need. Do you know if it is possible to do it directly in lua, just before the "shoot" command ?
Yes, it's possible but I'm not exactly clear how you are shooting at this point and whether you want camera time or PC time. If you are just running some HDR script on the camera, then you'd have to modify it. The get_tick_count function on the gives you milliseconds since the camera started (with a precision of 10ms)

If you are shooting directly with the multicam code (like testshots), it already has code to schedule the shot at a specific PC time, which you could easily record. The syncat option to mc:cmd is the number of ms after the command is issue that it should be executed on the cameras, so you just log current time + syncat immediately before calling shoot.

Quote
EDIT : I'm also trying to download the last photos taken from all the camera connected. Something like executing "ls" command on all camera and recuperate the output in a file. Then use download command on the last photo. Is it possible to execute ls command with multicam ? ^^
Downloading from all cameras is not currently implemented multicam, but it should be pretty straightforward.

You can look mdownload function in chdku.lua, used by the mdl CLI command.

FWIW, the testshots function gets the camera image counter, which could be useful to find the name of the most recently created image.
Don't forget what the H stands for.

Re: Help with IXUS 220 HS (ELPH300HS) - PTP
« Reply #15 on: 12 / June / 2012, 09:58:43 »
Hello reyalp !

Thank you for your advice which are really helpful ! I managed saving the time in a file directly before the shoot command thanks to you !
I will try to see if i can do something for the download then. After that everything should work fine.

Thank you very much for your help !

Vincent DURIF

EDIT : I got a problem, when i launch !mc:cmd('hdr') syncat is not initialized, how can i have it ?

EDIT2 : Ok so i found a solution, i use min_sync_delay to initialize syncat ! =D But i still got one second delay between the time i send the command and the time the photos is taken. Is it normal ?
« Last Edit: 12 / June / 2012, 11:29:50 by VincentD »

*

Offline reyalp

  • ******
  • 14126
Re: Help with IXUS 220 HS (ELPH300HS) - PTP
« Reply #16 on: 13 / June / 2012, 01:53:13 »
EDIT2 : Ok so i found a solution, i use min_sync_delay to initialize syncat ! =D But i still got one second delay between the time i send the command and the time the photos is taken. Is it normal ?
Some delay is needed, but unless you have a lot of cameras it shouldn't need a second. The way synced commands work is they schedule something to happen at a certain time in the future, so all the command can be sent to all the cameras and they can be ready to shoot at the same time. This trades delay for better synchronization between cameras. The more cameras you have, the more delay will be needed.

I think you figured this out, but to use a synchronized command, you have to run mc:init_sync() once after the cameras are connected, and then send the sync time as an option to mc:cmd for each command you want synced. For example:
Code: [Select]
mc:cmd('shoot',{syncat=500})
would schedule all the cameras to shoot 500ms in the future. Of course, the delay has to be long enough for all the cameras to get the command and be ready. min_sync_delay might not be enough.

It's worth noting that in some windows configurations, init_sync will behave very badly because it only gets time at 15ms resolution. This should be obvious in the output of init_sync, the "send" lines will all be 0 or 15.

If you don't care about having the cameras all shoot at the same time, you could just loop through the list of cameras and send each one a shoot command in turn.

I'm not sure how you are doing you hdr command or what your needs are, but if you want each shot to be synchronized and the time of each exposure accurately recorded, then you probably want to do something like testshots, where the individual shoots are synchronized, rather than the entire hdr sequence. In that case, you should be able to record the shot time pretty accurately by logging the current time + syncat just before you send the shoot command (there is some delay that isn't accounted for in the sync process, but it shouldn't be more than tens of milliseconds).

If you want to post your modified source, I can try to look at it, but no promises.
Don't forget what the H stands for.

Re: Help with IXUS 220 HS (ELPH300HS) - PTP
« Reply #17 on: 13 / June / 2012, 10:08:38 »
If you want to post your modified source, I can try to look at it, but no promises.

Yes sure, thank you very much for looking at it.

Code: [Select]
function mc:cmd(cmd,opts)
local tstart = ustime.new()
opts=util.extend_table({},opts)
if opts.flushmsgs then
self:flushmsgs()
end
local sendcmd = cmd
a=tstart.sec
b=tstart.usec
for i,lcon in ipairs(self.cams) do
local status,err
if opts.syncat then
sendcmd = string.format('%s %d',cmd,self:get_sync_tick(lcon,tstart,opts.syncat))
end
local status,err = lcon:write_msg(sendcmd)
printf('%s:%s\n',lcon.mc_id,sendcmd)
if not status then
warnf('%s: send %s cmd failed: %s\n',lcon.mc_id,tostring(sendcmd),tostring(err))
end
end
if cmd == 'hdr' then
b = math.floor(b/1000)
b = b+opts.syncat+self.min_sync_delay
while b > 999 do
b = b-1000
a = a+1
end
mydate = os.date("*t",a)
file = io.open("timeLog","a")
file:write(mydate.day,"/",mydate.month,"/",mydate.year," ",mydate.hour,":",mydate.min,":",mydate.sec,":",b,"\n")
file:close()
end
if not opts.wait then
return true
end

-- to match remote command name
local cmdname=string.match(cmd,'^(%w+)')

return self:wait_status_msg(cmdname,opts)
end

Code: [Select]
function cmds.hdr()
if get_drive_mode() ~= 1 then
  print( "set drive mode" )
  print( "to continuous" )
  sleep(1500)
  cannot_continue = true
end
t=800
set_zoom(0)
set_backlight(0)
i=get_iso_real()
set_iso_real(100)
set_iso_mode(100)
  p=500
  s=500
  set_tv96_direct(t)
  set_sv96(s)
  set_av96(p)
  wait_tick(tonumber(mc.args))
  shoot()   
set_backlight(0)
  set_aflock(1)
  set_tv96_direct(t-192)
  set_sv96(s)
  set_av96(p)
  shoot()
set_backlight(0)
  set_tv96_direct(t+192)
  set_sv96(s)
  set_av96(p)
  shoot()
set_backlight(0)
set_aflock(0)
set_backlight(0)
end

And the commands i launch are :
!mc=require('multicam')
!mc:connect()
!mc:start()
!mc:init_sync()
!mc:cmd('rec')
!mc:cmd('hdr',{syncat=500})

In order to evaluate if i save the right date of the shoot, i point my camera on my screen (where a counter is running) and then i compare the result i save and what is on the photo. And it appears that the time differs from ~1 second.

*

Offline reyalp

  • ******
  • 14126
Re: Help with IXUS 220 HS (ELPH300HS) - PTP
« Reply #18 on: 14 / June / 2012, 23:49:02 »
in cmds.hdr, you wait_tick precedes shoot. Shoot tries to do a full normal shooting sequence: half press, wait for focus and exposure, then shoot. How long this takes depends on the camera, shooting mode and scene, but it can easily take a large part of a second.

If you look at testshots, it does the half shoot first, and then sends the synced shot once everything is ready.

I haven't looked at the rest in any detail. The hdr command likes like it as a lot of stuff you don't need from the original script.
Don't forget what the H stands for.

Re: Help with IXUS 220 HS (ELPH300HS) - PTP
« Reply #19 on: 15 / June / 2012, 09:22:21 »
Hello reyalp !

I do the sane thing as in testshots, i mean do a half press, then wait with wait_tick and finally full_press. And now I can save the time of the shot with 100 ms of delay which is really better than 1 second. Thank you very much for all your help.  :)

VincentD

 

Related Topics


SimplePortal © 2008-2014, SimplePortal