CHDKPTP File Downloading - page 7 - General Help and Assistance on using CHDK stable releases - CHDK Forum

CHDKPTP File Downloading

  • 92 Replies
  • 36848 Views
Re: CHDKPTP File Downloading
« Reply #60 on: 28 / February / 2018, 16:47:29 »
Advertisements
Hello again, it's been a while. I've been working on my chdkptp mod on and off this past month trying to get a more optimized and user friendly GUI, and I'm fairly happy with how it's coming along.

I'm finally starting to work on list creation and there's a feature I'd like to add but I'm not sure how I'd do it. I'd like to have a button to save the list of connected camera's, but since I'm gonna be messing with the id's I don't want to overwrite my list accidentally. I want to display a message upon clicking it that says "are you sure?" with yes or no buttons.

While I was typing that last paragraph, I noticed that if I try to connect to the cameras using
Code: [Select]
mc:connect({list = 'camlist.txt'})I get an error message because camlist.txt doesn't exist, which is to be expected. I'm trying to make it so that when I get the error my code just connects without a list. I've never dealt with error handling in lua before so I'm struggling, and I'm gonna need to do a lot more of it. I figure this is a good primer.

I'm gonna attach the lua file, if you don't feel like downloading it just let me know and I'll copy paste the bits I need help with. The trouble starts at line 62.

*

Offline reyalp

  • ******
  • 14132
Re: CHDKPTP File Downloading
« Reply #61 on: 28 / February / 2018, 23:03:27 »
I want to display a message upon clicking it that says "are you sure?" with yes or no buttons.
You can use iup.Alarm for a simple modal messagebox, as in the file tree code:
https://app.assembla.com/spaces/chdkptp/subversion/source/831/trunk/lua/gui_tree.lua#ln210


Quote
While I was typing that last paragraph, I noticed that if I try to connect to the cameras using
Code: [Select]
mc:connect({list = 'camlist.txt'})I get an error message because camlist.txt doesn't exist, which is to be expected. I'm trying to make it so that when I get the error my code just connects without a list. I've never dealt with error handling in lua before so I'm struggling, and I'm gonna need to do a lot more of it. I figure this is a good primer.
In this case, I'd probably just check for the file existing before calling mc:connect, like
Code: [Select]
if lfs.attributes('camlist.txt','mode') then
 mc:connect({list='camlist.txt'})
else
 mc:connect()
end
The advantage of using this over error handling is that you really only want to do this on file not found, not every possible error. It would be possible to detect file not found errors, but more complicated.

Regarding the problem with error handling, pcall and xpcall expect a function. Your code calls mc:connect() and pcall tries to run whatever it returns as a function.

What you want to do is something like
Code: [Select]
local status,err = pcall(function() mc:connect({list='camlist.txt'}) end)
so the mc:connect call is wrapped in an anonymous function that pcall can call. 

You can also pass the function followed by the arguments to pcall, but IMO this is less readable. This would be done something like:
Code: [Select]
local status,err = pcall(mc.connect,mc,{list='camlist.txt'})
mc:connect is shorthand for mc.connect(mc...), but this only works when you are actually calling the method. To pass it to pcall, it needs to be spelled out as above.
Don't forget what the H stands for.

Re: CHDKPTP File Downloading
« Reply #62 on: 13 / March / 2018, 18:13:40 »
Quote
so the mc:connect call is wrapped in an anonymous function that pcall can call

Ahh okay, that makes sense.

So back to sync (sorry for jumping around so much), I'm trying to trigger the power sync by plugging 12 non-powered USB hubs with 6 cameras each (a total of 72 cameras) into one powered hub and cutting the power there. This seems to be working fine, all of the cameras take a picture with perfect sync, but when I try to reconnect to them I run into trouble. I'm not connecting with a list which might be part of the problem.

About 35% of the cameras reconnect fine but the rest fall victim to driver crashes. I get the message "USB device not recognized", and I have to restart my computer to fix it.

Any ideas?

Re: CHDKPTP File Downloading
« Reply #63 on: 13 / March / 2018, 20:30:42 »
Quote
so the mc:connect call is wrapped in an anonymous function that pcall can call
.....

So back to sync (sorry for jumping around so much), I'm trying to trigger the power sync by plugging 12 non-powered USB hubs with 6 cameras each (a total of 72 cameras) into one powered hub and cutting the power there. This seems to be working fine, all of the cameras take a picture with perfect sync, but when I try to reconnect to them I run into trouble. I'm not connecting with a list which might be part of the problem.

About 35% of the cameras reconnect fine but the rest fall victim to driver crashes.
I get the message "USB device not recognized", and I have to restart my computer to fix it.

Any ideas?
Re:- I get the message "USB device not recognized", and I have to restart my computer to fix it. & Any ideas?
Ref:- I'm trying to trigger the power sync by plugging 12 non-powered USB hubs with 6 cameras each
        (a total of 72 cameras) into one powered hub and cutting the power there.

My Guess for Usb-2 & Usb-3:-
a/ Is that you have not "modified" the (up-stream) powered hub correctly.
b/ Is that you have not "modified" the (down-stream) un-powered hub's correctly.
c/ Your host computer and your powered hub "should" have some sort of "current over load" protection in-built.
d/ What is most probably happening is that when attempting to sync the 72 cameras is that the "current over load" protection,
    usualy in the form of a a poly-fuse, is then triped thus disconecting the "synced-Usb" chain of devices.
e/ The "poly-fuse" or similar "current over load" protection (thermal) devices have a in-built time delay before auto-reseting.
f/  The 72 cameras will attempt to draw a small current from the Usb +5 volt un-powered hubs usually in the order of 1-2 ma.
     Any Usb-hub modifications should also allow for a minimium safety margin of 100x (1-2ma.)
g/ For all Usb-hubs the +5 volts, and associated filter capacitors, MUST, always be supplied/maintained to the Usb-hubs control IC's.
h/ The +5 Volt filter capacitors on the +5 Volt Usb-female-connector pin's can/should be removed or by-passed just by cutting the associated
     PCB-track's

Also note that "synced-Usb" by "switching" the +5 volt Usb supply is not part of the Usb specifactions.
CHDK is using/modifing the Usb "hot-plug" feature for "synced-Usb".

If you have the nessary skills you can modify the Usb-hubs.
If you dont have the nessary skills you can modify the Usb to camera cables as per the "standard" CHDK method.
OR ... Edit #1 (see the attached files)
You if you dont want to modify the Usb to camera cables can make/modify a Usb Male to Female adapter's (72x).

Edit #1 USB adapters can be "cut open" and the internal "PCB" +5 volt track is then cut.

H-H

Use USB Tree View. USB Device View and USB Log View, software, for a windows based computer to then monitor
the  "synced-Usb" chain of devices.
« Last Edit: 28 / March / 2018, 22:11:31 by Hardware_Hacker »

*

Offline reyalp

  • ******
  • 14132
Re: CHDKPTP File Downloading
« Reply #64 on: 14 / March / 2018, 01:52:45 »
So back to sync (sorry for jumping around so much), I'm trying to trigger the power sync by plugging 12 non-powered USB hubs with 6 cameras each (a total of 72 cameras) into one powered hub and cutting the power there.
Without known the specific commands and sequence of other actions, I don't know what is causing the problem, but if you are just switching the power off at the main hub I'm not surprised things are getting confused.

Ideally, you'd want to control the +5v line to each camera, without affecting the intermediate hubs. If this is done correctly, it should be possible to use hardware sync without affecting the USB connection at all.
Don't forget what the H stands for.

Re: CHDKPTP File Downloading
« Reply #65 on: 15 / March / 2018, 12:57:08 »
So if you were the one building this array, how exactly would you do it?

This is what you have:
  • 72 a3400 cameras.
  • An 8'x8' square frame with 12 towers, 1 on each corner and 2 per side.
  • Each tower has 6 cameras, 1 USB Hub, and 1 power supply.

Here are the factors to consider:
  • You must have nearly perfect sync, imagine you're trying to take a picture of a squirmy toddler (That also happens to be up to 6 feet tall).
  • Pictures must be downloaded after each shot, with shots being taken in fairly rapid succession (Like at least 1 shot per minute)
  • The system must work reliably in a high noise area, as in several thousand people on their phones around you and dozens of wireless networks. This means any and every modification to a USB line is a risk as it involves compromising the inner shielding of the wire.
  • My boss isn't much of a DIY guy. I can get away with doing a few modifications here and there, but anything more complicated than re-soldering some wires wouldn't go down too well with him. If you think of something that would require a large amount of customization but would be massively useful or necessary I can try to convince him.
  • Another thing regarding reliability; these cameras I'm working with are almost 5 years old, they cause enough trouble on their own. The less things that could go wrong, the better. I'm also not an electrician (which is probably obvious), I'm a researcher. I've done a good bit of work with electrical engineering but I'm by no means proficient, so the less chances I have to mess things up the better

One last thing, I just wanted to thank you again for all of the help you've given me. I've never been one to post questions on the internet, I usually just google around until I find the answer, and when I don't find it I just figure it out by trial and error. Since I've always taught myself I've never had anyone I could ask questions to, but in talking to all of you guys I've learned a ton.

Re: CHDKPTP File Downloading
« Reply #66 on: 15 / March / 2018, 13:51:21 »
So if you were the one building this array, how exactly would you do it?

I don't plan on trying it but you could perhaps be interested in something like this:
 https://chdk.setepontos.com/index.php?topic=13226.msg134379#msg134379

Not sure of the implications of inelegantly pulling the camera power though:

You would then need to
  • turn all cameras off/on by their power button - or via an external switch but having the camera power button permanaently pressed (but that could be bad?).
  • reconnect & power-up your hub network

Edit:

perhaps adding a relevant sleep after write_status(true) in the indicated
function cmds.usb_sync_wait()
followed by an elegant
shutdown

could be a suitable workaround?
« Last Edit: 15 / March / 2018, 15:16:00 by andrew.stephens.754365 »

Re: CHDKPTP File Downloading
« Reply #67 on: 15 / March / 2018, 15:18:21 »
Hmm that's an interesting thought, I'll experiment with it.

Quick question, I looked in some forum threads about this but all I could find were really old posts so I'm not sure if they're still relevant.

It would be super useful for my sync testing if I could physically see how far apart the pictures were taken. Is there a way to set the camera date and time on all the cameras through ptp commands? How precise can I make the cameras clocks? down to the second? Millisecond?

It would be great if I could sync up the camera time to my system time and have the cameras put a timestamp on the images it takes, maybe as a value I can return through download_images?

Re: CHDKPTP File Downloading
« Reply #68 on: 15 / March / 2018, 15:42:38 »
If you have a crt you can use this:
http://www.3dtv.at/knowhow/Synctest_en.aspx
to check the difference between 2 images - my crt is 0.0207ms per horizontal line and I can generally read the image to the closest bold 5 line tick. I think the upper limit of that technique is somewhere between a 30&50ms delta.

Edit:
I suppose if you had a big crt you could take a picture of it with 5 or 6 cameras and do successive comparisons in the Excel spreadsheet provided withe crt tester software.

Something like this:
https://chdk.setepontos.com/index.php?topic=8312.msg104805#msg104805
for the absolute time since transistion to 0V (that won't provide same accuracy though).

How to measure very accurately for a multitude of cameras is a bit beyond me.

It would be great if I could sync up the camera time to my system time and have the cameras put a timestamp on the images it takes, maybe as a value I can return through download_images?

I had a go at trying to understanding reyalp's ptp based sync here:
https://chdk.setepontos.com/index.php?topic=11490.msg124541#msg124541
at the time it mostly made sense  :)
« Last Edit: 15 / March / 2018, 16:07:55 by andrew.stephens.754365 »

*

Offline reyalp

  • ******
  • 14132
Re: CHDKPTP File Downloading
« Reply #69 on: 15 / March / 2018, 17:50:17 »
So if you were the one building this array, how exactly would you do it?
I would probably reject the requirements as unreasonable. As the old saying goes: Fast, cheap, reliable - Pick two.

In this particular case, if you want hardware USB remote triggering to play nice with PTP software control, you are going to have to do some fairly serious electrical DIY.

FWIW, on cameras that use non-AA batteries it is also possible to trigger the "remote" using the ADC converter that normally measures battery temperature. This needs to be enabled per port, but allows you to separate the USB wiring from the control wiring. I don't  remember if anyone has benchmarked how good the sync is with this method. I can make builds with this enabled for A3400 if you are interested.

See https://chdk.setepontos.com/index.php?topic=10385.10 for background.

You'd still need to come up with dummy batteries that have the third terminal wired to your trigger, but it would leave less room for interfering with the USB protocol stuff or RFI from compromised USB cables.

Another alternative might be to control shooting entirely with USB hardware remote, and only use PTP for downloading. Shooting would be like

Root, powered hub unplugged from PC, on
Shooting is controlled by CHDK remote settings (which can be set via script using set_config_value) or a camera side script.
Shoot by turning the hub off / on.
When shooting is done, connect hub to PC, run multicam, download_images

One big downside of this is you don't get the to control all the shooting settings like zoom, exposure etc from the PC.
Don't forget what the H stands for.

 

Related Topics


SimplePortal © 2008-2014, SimplePortal