USB Remote + PTP - How to add PTP functions on multicam.lua - page 2 - Script Writing - CHDK Forum supplierdeeply

USB Remote + PTP - How to add PTP functions on multicam.lua

  • 19 Replies
  • 15914 Views
Re: USB Remote + PTP - How to add PTP functions on multicam.lua
« Reply #10 on: 06 / January / 2017, 09:49:26 »
Advertisements
Just getting your 42 cameras to work (at ALL) is a very big first step, but a little more details on your rig (+ photo's) also would help.
And is your multi-camera built, by you, from scratch or partly bought second-hand. ??
I have a long story before I get here. But I'll tell everything in another time.
The whole project was done by myself. Without any help, just reading and learning in this forum. Many things were trial and error. I do not want to bother anyone.
I would like to share with you all the peculiarities of the project, with photos and everything, but first, I want to be 100% sure that works the way I expect.

And if not, your "42 cameras" what Canon model are they. ??
H-H
All the cameras I have are Canon PowerShot SX170 IS.

My guess is the devil is in the details regarding the "red wire SYNC USB-2 HACK".

Seriously, I'll try to understand what you're saying, if all other attempts fail, I'll look more closely until I understand that.

Edit #1   Also refer to the Multi-Camera post's regarding Rig Construction, USB-2 Wiring, Camera Power Supply etc.
I can tell you some little things about wiring that I learned from my project.
To start, usb 2.0 cables should only be used from the camera to the first hub, after it only usb 3.0 cables and usb 3.0 hubs. You gain more cable length and improve transmission quality. It sounds silly and wrong, but in practice, tested and approved.


Re: USB Remote + PTP - How to add PTP functions on multicam.lua
« Reply #11 on: 06 / January / 2017, 09:57:27 »
There is info about that in a few threads.  Start with this one ?
Re: Noob question, how to run multicam.lua on chdkptp

Before doing this firing method with usb_force_active, I did all the sicronism tests using these codes:

Code: [Select]
!mc:init_sync()
!return mc:cmdwait('shoot_hook_sync',{syncat=100})

The results were very variable, even with a higher value in the syncat code. If I did not want a almost perfect synchronism, it would be good. Some tests had 90% perfect synchronism between the cameras.
Others had a variation between 75% and 85% of synchronism between the cameras. What was already good too. The difference is almost imperceptible, for a stationary subject would work perfectly. But, very unstable for me.

Language never seems to be a problem for anyone using this forum. We manage.
Reading the forum I realized that you were always very helpful and polite, as far as possible. I just have to thank you for your attention and understanding.  :D

« Last Edit: 06 / January / 2017, 10:00:25 by lipefrs »

Re: USB Remote + PTP - How to add PTP functions on multicam.lua
« Reply #12 on: 06 / January / 2017, 10:05:50 »
In multicam, you can execute any Lua on all the cameras using the "call" or "pcall" commands
It was magical, worked perfectly. It was exactly what I was looking for.
I could kiss you right now.  ::)
Thanks a lot for the help. Now I can move on.  :D

I used this sequence of codes:
Code: [Select]
!mc=require('multicam')
!mc:connect()
!mc:start()
!return mc:cmdwait('rec')
!mc:cmdwait('call usb_force_active(1)')
!mc:cmd('call usb_sync_wait(1);shoot()')
!mc:cmd('exit')

For now, I was able to test on only two cameras, because I have only two hacked cables, but the next step is to make more cables and test with more cameras.
And I'm sure it will work.

Things that I still have to.
- Add in the multicam.lua the scripts that I did to download and delete the photos. To not need to exit a script and call another.
-Adapt a wireless trigger on the switch. Making a switch that I can remotely control, should not be a problem.

Then I'll be ready to test sync with the 42 cameras again.

Thanks again.


Re: USB Remote + PTP - How to add PTP functions on multicam.lua
« Reply #13 on: 06 / January / 2017, 10:09:22 »
I added that to multicam.lua and completed a quick test, on a single camera, here https://chdk.setepontos.com/index.php?topic=12827.msg128700#msg128700
I had already read your post. Even tried to add your code in multicam.lua, but I had no success, I got several error messages.


*

Offline reyalp

  • ******
  • 14080
Re: USB Remote + PTP - How to add PTP functions on multicam.lua
« Reply #14 on: 06 / January / 2017, 13:24:42 »
- Add in the multicam.lua the scripts that I did to download and delete the photos. To not need to exit a script and call another.
The current multicam code supports downloading and deleting, see
mc:download_images

Quote
Seriously, I'll try to understand what you're saying, if all other attempts fail, I'll look more closely until I understand that.
FWIW, I too have a great deal of trouble understanding Hardware_Hacker posts...
Don't forget what the H stands for.

Re: USB Remote + PTP - How to add PTP functions on multicam.lua
« Reply #15 on: 06 / January / 2017, 19:32:49 »
My guess is the devil is in the details regarding the "red wire SYNC USB-2 HACK".
What happens to the voltage between the USB-2 Black and Red wires a you progressively add more cameras.

"...Seriously, I'll try to understand what you're saying, if all other attempts fail, I'll look more closely until I understand that..."

"...I can tell you some little things about wiring that I learned from my project..."
"...To start, usb 2.0 cables should only be used from the camera to the first hub, after it only usb 3.0 cables and usb 3.0 hubs.
You gain more cable length and improve transmission quality. It sounds silly and wrong, but in practice, tested and approved...."

"...test sync with the 42 cameras again...."
My guess is, still, the details regarding what happens to the voltage between the USB-2 Black and Red wires and what happens
when you have no cameras and then progressively add more cameras.

I think what is happening is that the "red wire SYNC USB-2 HACK" is dropping below the switching threshold.
(A simple fix for this problem is possible.)

As an afterthought, if you have some electronics knowledge, you might be able to use a Texas Instruments LM3914 Driver and a
Dot/Bar Graph as a high speed voltage indicator across the USB-2 Red and Black wires.

And also how are you "..test(ing) sync with the 42 cameras..."

When your project is and rig working, perhaps you could add more (Cheap) computers closer to the cameras to
keep the USB cable and Hub cable lengths shorter. The disadvantage then is the added rig communication complexity.

H-H
« Last Edit: 06 / January / 2017, 19:42:40 by Hardware_Hacker »

Re: USB Remote + PTP - How to add PTP functions on multicam.lua
« Reply #16 on: 06 / January / 2017, 20:30:30 »
My guess is, still, the details regarding what happens to the voltage between the USB-2 Black and Red wires and what happens when you have no cameras and then progressively add more cameras.  I think what is happening is that the "red wire SYNC USB-2 HACK" is dropping below the switching threshold.
This is silly.  The "red" wire connects to the +5V pin on the USB connector which, on the camera connector, is simply a very high impedance sense input.  You could parallel up hundreds of those and still not cause a significant voltage drop on the "red" wire.

There are lots of other issues with wiring configuration and USB hubs and power supplies and grounding (many discussed at length in the links I posted earlier). But voltage drop in the "red" wire is not one of them.



Ported :   A1200    SD940   G10    Powershot N    G16

Re: USB Remote + PTP - How to add PTP functions on multicam.lua
« Reply #17 on: 08 / January / 2017, 13:01:14 »
FWIW, you should be able to return status in the normal way in the camera side code. What you probably don't want to do is used cmdwait while messing with the physical USB connection, since it tries to repeatedly poll the camera. All communication in the CHDK PTP protocol is actually initiated by the PC side, sending or returning from lua just queues a message.

You could use wait_status_msg (see the end of mc:cmd in multcam.lua) to get status after you know are done with the hardware USB trigger.

Thanks for that. I haven't yet purchased a microcontroller to test with so the following was with a single camera connected to a hub that has a manual 5V switch for the port.

I added this camera-side function to a fresh r690 (pre-built) chdkptp mulicam.lua:
Code: [Select]
function cmds.usb_sync_wait()
    usb_force_active(1)
    usb_sync_wait(1)
    press('shoot_full') -- if usb does not transistion from +5V to 0V within 10 secs, hook is automatically released   
   
    for i=1, 1000, 1 do
        sleep(10)
            if get_usb_power(1) == 0 then
                break
            end
    end
   
    sleep(mc.shoot_hold)
    release('shoot_full')
    wait_timeout_write_status(get_shooting,false,100,mc.shoot_complete_timeout,'get_shooting timeout')
end

and ran it as follows:
Code: [Select]
!mc=require('multicam')
!mc:connect({list='C:/CHDKPTP/listfile'})
!mc:start()
!return mc:cmdwait('rec')
!return mc:cmdwait('preshoot')
!mc:cmd('usb_sync_wait') -->> then waited a couple of seconds after black lcd and manually switched port from +5V to 0V
!return mc:wait_status_msg('usb_sync_wait',{}) -->> probably about 30 seconds later

Status was returned as I had expected - full record of that at end of post.

  • At what instant could it be safer to start polling the camera for status again (I would plan to send the ucontroller voltage change command from the same Autoit script that performs the !return mc:wait_status_msg('usb_sync_wait',{}) command)? ...e.g a specific number of ms after USB transistion.
Full trace of console commands / status:
Code: [Select]
C:\WINDOWS\system32>c:/chdkptp-test/chdkptp -i
___> !mc=require('multicam')
___> !mc:connect({list='C:/CHDKPTP/listfile'})
+ 1:Canon PowerShot SX150 IS b=\\.\libusb0-0001--0x04a9-0x3234 d=bus-0 s=689D500
5104943C09E988E4EA8301E22
___> !mc:start()
___> !return mc:cmdwait('rec')
rec
=true,{
 [1]={
  failed=false,
  done=true,
  status={
   cmd="rec",
   status=true,
  },
 },
}
___> !return mc:cmdwait('preshoot')
preshoot
=true,{
 [1]={
  failed=false,
  done=true,
  status={
   cmd="preshoot",
   status=true,
  },
 },
}
___> !mc:cmd('usb_sync_wait')
usb_sync_wait
___> !return mc:wait_status_msg('usb_sync_wait',{})
=true,{
 [1]={
  failed=false,
  done=true,
  status={
   cmd="usb_sync_wait",
   status=true,
  },
 },
}
___>

« Last Edit: 08 / January / 2017, 13:19:30 by andrew.stephens.754365 »


*

Offline reyalp

  • ******
  • 14080
Re: USB Remote + PTP - How to add PTP functions on multicam.lua
« Reply #18 on: 08 / January / 2017, 14:13:52 »
*Am I correct to imagine the loop I inserted in the camera-side code could seriously impact an actual multicam implementation synchronisation
It shouldn't, and I don't see the connection to the linked post. The shooting process will start once the camera recognizes that shoot_full is pressed. With usb_sync_wait the CHDK code will wait until it sees USB power go low, independent of script.

I don't think you need that loop at all though, the final wait_status will wait for the shot to complete, which can only happen after the USB signal (or something times out). All you have to do is ensure shoot_full is held long enough to trigger the shot, which is handled by sleep(mc.shoot_hold)


Quote
At what instant could it be safer to start polling the camera for status again (I would plan to send the ucontroller voltage change command from the same Autoit script that performs the !return mc:wait_status_msg('usb_sync_wait',{}) command)? ...e.g a specific number of ms after USB transistion.
I don't know, I'm not sure it's a problem to poll when the +5v is cut, I was thinking of some testing I did before but that actually involved plugging/unplugging the whole cable just cutting the +5v.

If it's needed at all, I don't see any reason you should need to wait more a few tens of ms, i.e.: don't try to do USB protocol communication at the same moment you are messing with the +5v. Even if it's mostly OK, there likely some potential for EMI.
Don't forget what the H stands for.

Re: USB Remote + PTP - How to add PTP functions on multicam.lua
« Reply #19 on: 08 / January / 2017, 14:31:24 »
I don't think you need that loop at all though, the final wait_status will wait for the shot to complete, which can only happen after the USB signal (or something times out). All you have to do is ensure shoot_full is held long enough to trigger the shot, which is handled by sleep(mc.shoot_hold)

Ah, of course  :-[


If it's needed at all, I don't see any reason you should need to wait more a few tens of ms, i.e.: don't try to do USB protocol communication at the same moment you are messing with the +5v. Even if it's mostly OK, there likely some potential for EMI.

Excellent - thanks a lot...i'll try to remember to post eventual findings on this thread.

 

Related Topics