CHDK Forum

Using CHDK => General Help and Assistance on using CHDK stable releases => Topic started by: VincentD on 15 / May / 2012, 09:35:20

Title: Help with IXUS 220 HS (ELPH300HS) - PTP
Post by: VincentD on 15 / May / 2012, 09:35:20
Hello,

I'm a french student, i discovered CHDK last week. I'm actually working on a project where i need to control an IXUS 220 HS with computer (in order to take photos and download them). And i need your help  :).
So i looked for some way to control the camera using USB command and i found PTP protocol. I wanted to use ptpcam or chdkptp, then i downloaded binaries and try to connect my camera to the PC using the USB wire. It appears that, as soon as i connect the camera to the PC the camera screen becomes black and the camera lens close.
However, the connection with ptpcam or chdkptp works and i can download photos from the camera to the PC. But i can't take photos, the camera lens stay close.
With chdkptp the error is : "error initializing live streaming: api is not compatible"
Does anybody know if it's possible to take photos using chdkptp with an IXUS 220 HS ?

Thank you for your help !

CHDK version : CHDK-DE 1.1.0          Revision : 994
Camera : ixus220_elph300hs
Firmware version : 101g

PS : I hope that i'm posting in the right place, sorry if it's not.
Title: Re: Help with IXUS 220 HS (ELPH300HS) - PTP
Post by: Microfunguy on 16 / May / 2012, 07:24:27
Hello and welcome.

Quote
as soon as i connect the camera to the PC the camera screen becomes black and the camera lens close.

camera is probably switching to 'Playback' mode.

Quote
But i can't take photos, the camera lens stay close.

You have to switch to Record mode to take photos.

I do not use CHDK or its PTP applications but try command 'mode 1' (or something similar) to switch to Record mode first.


David
Title: Re: Help with IXUS 220 HS (ELPH300HS) - PTP
Post by: VincentD on 16 / May / 2012, 11:08:40
Hello Microfunguy !

First of all, thank you for your response !  :)
I already tried to switch to record mode with chdkptp but it didn't work. I got a message saying something like "Script : x" (where x is a number).
However, i'm going to try again soon (i don't have the camera right now), maybe i did something wrong. I will tell you more after testing.
Thank you,

Vincent. :)
Title: Re: Help with IXUS 220 HS (ELPH300HS) - PTP
Post by: reyalp on 17 / May / 2012, 02:22:47
With chdkptp the error is : "error initializing live streaming: api is not compatible"
Just to be clear, this error only means that live view display will not work. All other functionality should be fine.
Quote
It appears that, as soon as i connect the camera to the PC the camera screen becomes black and the camera lens close
The screen going black may indicate that some windows service or software is interfering. See http://chdk.setepontos.com/index.php?topic=4338.msg68620#msg68620 (http://chdk.setepontos.com/index.php?topic=4338.msg68620#msg68620)
Title: Re: Help with IXUS 220 HS (ELPH300HS) - PTP
Post by: VincentD on 17 / May / 2012, 11:08:42
Hello reyalp,

Thank you for your answer, it's might be something like this. I'm going to try blocking other services  :)

Thank you !
Title: Re: Help with IXUS 220 HS (ELPH300HS) - PTP
Post by: VincentD on 01 / June / 2012, 08:42:55
Hello again,

I just wanted to say that now i can take photos with the cameras. I just needed to use inf-wizard after installing libusb. (thank you reyalp for that !).  :)

Now my new problem is that it would be great if i could take synchronized photos connecting cameras with USB and PTP, I mean take photos with multiple cameras by sending a command. What i already try was to use a HUB (i thought that if i send a command, it would have been executed by each camera connecting to the HUB) but unfortunately it doesn't look as simple as that. Does anybody knows if it's possible to do it ?

Thank you for all your help,

VincentD

EDIT : I found a "solution" which consist in launching 2 chdk ptp using 2 programs. But the problem is that i got a 2 second delay between each shot. Moreover, i try to launch chdkptp.exe -c"-s="my_camera_id" -e"lua switch_mode_usb(1)" -e"lua shoot() ". But it just switch to record mode and i got an error "a script is already running". I have to wait the end of the first command before launching the next one.

EDIT2 : Ok so i'm just a noob, i just had to write "lua switch_mode_usb(1) shoot()" instead of separating the commands.
Title: Re: Help with IXUS 220 HS (ELPH300HS) - PTP
Post by: reyalp on 01 / June / 2012, 15:53:47
EDIT : I found a "solution" which consist in launching 2 chdk ptp using 2 programs. But the problem is that i got a 2 second delay between each shot. Moreover, i try to launch chdkptp.exe -c"-s="my_camera_id" -e"lua switch_mode_usb(1)" -e"lua shoot() ". But it just switch to record mode and i got an error "a script is already running". I have to wait the end of the first command before launching the next one.
If you are up for some lua scripting, you can control multiple cameras with a single instance of chdkptp. See http://chdk.setepontos.com/index.php?topic=6231.msg81330#msg81330 (http://chdk.setepontos.com/index.php?topic=6231.msg81330#msg81330)

You definitely cannot do this kind of thing with a hub, a distinct USB protocol connection to each device is required.
Title: Re: Help with IXUS 220 HS (ELPH300HS) - PTP
Post by: VincentD on 06 / June / 2012, 08:40:07
Hello reyalp,

Thank you very much for your help, i'm going to take a look on that topic.  :)

VincentD
Title: Re: Help with IXUS 220 HS (ELPH300HS) - PTP
Post by: VincentD on 06 / June / 2012, 10:22:46
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.

Thank you very much !

VincentD

EDIT : Another question, is it possible to launch a script which is on the camera using a chdkptp command ?
Title: Re: Help with IXUS 220 HS (ELPH300HS) - PTP
Post by: srsa_4c on 06 / June / 2012, 10:32:31
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/ (http://mighty-hoernsche.de/trunk/)
Title: Re: Help with IXUS 220 HS (ELPH300HS) - PTP
Post by: reyalp on 06 / June / 2012, 16:13:17
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.
Title: Re: Help with IXUS 220 HS (ELPH300HS) - PTP
Post by: VincentD 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/ (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.
Title: Re: Help with IXUS 220 HS (ELPH300HS) - PTP
Post by: reyalp 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 ?
Title: Re: Help with IXUS 220 HS (ELPH300HS) - PTP
Post by: VincentD 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
Title: Re: Help with IXUS 220 HS (ELPH300HS) - PTP
Post by: reyalp 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.
Title: Re: Help with IXUS 220 HS (ELPH300HS) - PTP
Post by: VincentD 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 ?
Title: Re: Help with IXUS 220 HS (ELPH300HS) - PTP
Post by: reyalp 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.
Title: Re: Help with IXUS 220 HS (ELPH300HS) - PTP
Post by: VincentD 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.
Title: Re: Help with IXUS 220 HS (ELPH300HS) - PTP
Post by: reyalp 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.
Title: Re: Help with IXUS 220 HS (ELPH300HS) - PTP
Post by: VincentD 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
Title: Re: Help with IXUS 220 HS (ELPH300HS) - PTP
Post by: SanderC on 22 / November / 2012, 17:39:05

I managed to boot CHDK on my IXUS 220HS (works great!), i installed libusb and ptpcamgui, but it doesn't really work.
console displays
>> reset
>> reset
>> reset
>> reset
>> reset
, and so on
and it waits for camera constantly, i thought i was so close to get it working on, but i falied, please do help, i'm a dummy!
Title: Re: Help with IXUS 220 HS (ELPH300HS) - PTP
Post by: reyalp on 22 / November / 2012, 18:05:10

I managed to boot CHDK on my IXUS 220HS (works great!), i installed libusb and ptpcamgui, but it doesn't really work.
console displays
>> reset
>> reset
>> reset
>> reset
>> reset
, and so on
and it waits for camera constantly, i thought i was so close to get it working on, but i falied, please do help, i'm a dummy!
Do you "USB remote" enabled in chdk menu by any chance? This setting must be off to use PTP (this is confusing, but the USB remote is something different...)
Title: Re: Help with IXUS 220 HS (ELPH300HS) - PTP
Post by: SanderC on 22 / November / 2012, 19:09:59
Thanks a bunch!

It works! It works!

I guess I was so excited CHDK was working, that I started to fiddle in menu, then I actually found out  that remote USB was something different i was expecting (ptp was), and forgot to change it.
Title: Re: Help with IXUS 220 HS (ELPH300HS) - PTP
Post by: andrew.stephens.754365 on 07 / November / 2013, 18:12:39
You definitely cannot do this kind of thing with a hub, a distinct USB protocol connection to each device is required.

Does this mean that multicam.lua function mc:connect() cannot be used to connect multiple hub connected cameras ? (or has something changed in the meantime).  Thanks.
Title: Re: Help with IXUS 220 HS (ELPH300HS) - PTP
Post by: reyalp on 07 / November / 2013, 21:34:34
Does this mean that multicam.lua function mc:connect() cannot be used to connect multiple hub connected cameras ?
No, it means nothing of the sort. That post was written to answer a specific question. If you read the question, the answer should make sense.

Hubs are completely transparent to the USB protocol connection chdkptp uses, just like any other regular USB device it doesn't know or care if they are present.
Title: Re: Help with IXUS 220 HS (ELPH300HS) - PTP
Post by: andrew.stephens.754365 on 08 / November / 2013, 03:24:37
No, it means nothing of the sort.

Good. Thanks [as usual] for the clarification.