chdkptp script with looping and com: port control - Creative Uses of CHDK - CHDK Forum

chdkptp script with looping and com: port control

  • 5 Replies
  • 5711 Views
chdkptp script with looping and com: port control
« on: 16 / November / 2015, 13:03:06 »
Advertisements
I am very happy using chdkptp with my SX130.  I want to script it to take a number (hundreds) of photos, and between each one pulse the DTR line of a COM: port (which will step a turntable).
I can make a loop work on the PC in Lua with
! for k = 4,13,2 print(k) end
I can use the CLI command shoot, and I can use the camera lua command
=shoot()
But I cannot see how to combine the PC loop with a CLI or camera 'shoot', and also bring in a Lua RS232 library (or even trigger a Windows command line executable).
Any suggestions, or pointers to chdkptp scripting examples, please.
Thanks
John

chdkptp script with looping and com: port control
« Reply #1 on: 16 / November / 2015, 16:12:05 »
I expect reyalp will post something helpful here when he in next online.   But for what it's worth, when I was under time pressure to get something like this done quickly,  I wrote my main program in C and then made system calls to send single CLI commands to chdkptp.
Ported :   A1200    SD940   G10    Powershot N    G16

*

Offline reyalp

  • ******
  • 14125
Re: chdkptp script with looping and com: port control
« Reply #2 on: 16 / November / 2015, 16:55:39 »
I want to script it to take a number (hundreds) of photos, and between each one pulse the DTR line of a COM: port (which will step a turntable).
I can make a loop work on the PC in Lua with
! for k = 4,13,2 print(k) end
I can use the CLI command shoot, and I can use the camera lua command
=shoot()
But I cannot see how to combine the PC loop with a CLI or camera 'shoot', and also bring in a Lua RS232 library (or even trigger a Windows command line executable).
Any suggestions, or pointers to chdkptp scripting examples, please.
You can invoke other executables from using os.execute() in local lua (! command). See http://www.lua.org/manual/5.2/manual.html#6.9 for the os lib.

You should also be able to use external lua libraries using require if they are on your Lua path, although it's possible some might be incompatible.

The simplest way to run a cli command like shoot from local lua code is cli:execute(). Just pass what you would enter on the command line as a single string, like
Code: [Select]
!cli:execute("shoot -tv=1/100")
The return values from cli.execute are status (true for success, false for an error) followed by any output or error message.

If you want to call camera side Lua equivalent to =shoot() from PC side code, you should use con:exec() or con:execwait().

See https://www.assembla.com/spaces/chdkptp/wiki/Scripting_Guide for some information.
Don't forget what the H stands for.

Re: chdkptp script with looping and com: port control
« Reply #3 on: 17 / November / 2015, 10:59:48 »
Interesting.

Not sure if it would be like using a hammer to crack a nut but you might consider using autoit https://www.autoitscript.com/site/autoit/ to send single camera multicam.lua commands http://chdk.setepontos.com/index.php?topic=11490.0 and redirect multicam.lua status to file for reading.

Some of this https://www.autoitscript.com/forum/topic/145771-communicting-with-an-arduino-via-com-port-serial-port/?do=findComment&comment=1030643 could help with COM? (haven't looked at that in any detail though)

Re: chdkptp script with looping and com: port control
« Reply #4 on: 20 / November / 2015, 12:17:08 »
Hello, thanks for the speedy and helpful replies.  (I was away for a few days, so have only just been able to implement the suggestions).

The important clue I had missed was to use cli:execute() within the local Lua script.
I now have this in a file which I manually 'require' after starting chdkptp, as in:

function take_n(n)
   for k = 1,n*2,2 do
      print(k,n);
      cli:execute("shoot ")
      os.execute("lua step_400ms.lua")
      print(k+1);
   end
end

I have another Lua script which pulses COM2:'s DTR line, which is used to drive a turntable under my SX130 rostrum camera.  I could not seem to get this bit of Lua code to work within chdkptp, so I used os.execute() to run it separately.  This uses luars232 - I had trouble with this library at first, as the dll version installed by Lua for Windows is old and does not support the set_dtr() method.

So, it is a little bit klunky, but it does what I want.

I am using a simple 'shoot' command, and it seems to take about 6 seconds per loop.  I think I will investigate using manual focus, as this could speed up the process - it that liekly?

Thanks again for your help.

John

   

*

Offline reyalp

  • ******
  • 14125
Re: chdkptp script with looping and com: port control
« Reply #5 on: 20 / November / 2015, 17:06:56 »
I could not seem to get this bit of Lua code to work within chdkptp, so I used os.execute() to run it separately.
If you can give a little more detail of how it fails under chdkptp, I may be able to help, or at least explain why it doesn't work.

Quote
I am using a simple 'shoot' command, and it seems to take about 6 seconds per loop.  I think I will investigate using manual focus, as this could speed up the process - it that liekly?
Unless the camera is spending a lot of time "hunting" using MF by itself probably won't help much. You will get a much bigger gain by doing some thing like the chdkptp rsint command does: either shoot in continuous mode using shoot hooks for synchronization, or a script that holds down half shoot and clicks full for each shot.  See lua/rsint.lua for this code. If you want to save the files to your PC, you may be able to re-use this pretty directly, just putting your own code in the main loop and not checking for user input.

You can also use the msg_shell rlib for a quick hack, something like
Code: [Select]
function take_n(n)
-- start msg_shell script on the camera
  con:exec('msg_shell.run(msg_shell)',{libs='msg_shell'})
-- press shoot_half for initial focus etc.
-- you could send code to set exposure etc before this.
   con:write_msg("exec press'shoot_half'")
-- give the camera some time to focus. In a real version, should have camera side to code to send a message back when ready and use wait_msg
   sys.sleep(1000)

   for k = 1,n*2,2 do
      print(k,n);
-- click the shutter
      con:write_msg("exec click'shoot_full_only'")
-- wait 2 sec for shot to finish. again, should use a status msg
     sys.sleep(2000)
      os.execute("lua step_400ms.lua")
      print(k+1);
   end
-- end msg_shell script, also release shoot_half
  con:write_msg("quit")
end
This isn't tested, but the individual calls con: calls are. As mentioned above, the sys.sleep calls should really wait for some feedback from the camera side code.

nb: msg_shell line would normally be msg_shell colon run() but some bizarre filtering on the forum gives me a 404 forbidden if I try to post with out. It's valid Lua either way.

Don't forget what the H stands for.

 

Related Topics


SimplePortal © 2008-2014, SimplePortal