Noob question, how to run multicam.lua on chdkptp - page 3 - General Help and Assistance on using CHDK stable releases - CHDK Forum

Noob question, how to run multicam.lua on chdkptp

  • 32 Replies
  • 25977 Views
Re: Noob question, how to run multicam.lua on chdkptp
« Reply #20 on: 13 / August / 2015, 05:29:56 »
Advertisements
Nope, any name should be fine
Works like a charm thanks!

All that is local Lua code, so you could also put the calls in a lua file (without the !), and execute it with something like -e"exec dofile('myfile.lua')"
("exec" is the same as !, but some unix-ish shells might do funny things to it, so "exec" is safer on the command line).  You'd need to remove or replace the "return" statements.

This would give you give you more flexibility if you need any actual logic in your script, or want to display the return output in a more user friendly manner. If the quoted code is all you need, then a chdkptp -r file should be fine.

Great thanks alot!

Note that the way you are doing things now, each camera will just execute the shoot command as soon as it arrives. multicam sends the commands sequentially, so there will be a gap between the first and last. If you want better sync, you should use init_sync and then shoot with a sync time, like
Code: [Select]
!mc:cmdwait('shoot',{syncat=100})

Off the top of my head, I'd expect you can get 8 cameras within 500ms without using init_sync. The "minimum sync delay" will give you an approximation of the amount of time it takes to send to all cameras.

Another note:
You may find you need some delay between things like rec and preshoot or shoot and play. You can insert a delay on the chdkptp side using sys.sleep(milliseconds)
Awesome! Now we have bought even more cameras and have 48 right now... So sync needs to be as close as possible.
I have put the init_sync right after the start command right now. Is that correct?
When using your shoot code with the sync time a number is written after every "shoot". How do I need to understand this value? Is it milliseconds? And my 3rd question: what time currency is minimum sync delay in?
Ahh and it is it possible somehow to start all cameras up with chdkptp?
Because turning on/off all 48 cameras could get annoying by the time... Or is it not possible?
« Last Edit: 13 / August / 2015, 06:02:18 by r0xx »

Re: Noob question, how to run multicam.lua on chdkptp
« Reply #21 on: 25 / August / 2015, 03:52:52 »
Anybody?

Re: Noob question, how to run multicam.lua on chdkptp
« Reply #22 on: 25 / August / 2015, 12:54:29 »
Ahh and it is it possible somehow to start all cameras up with chdkptp?
Because turning on/off all 48 cameras could get annoying by the time... Or is it not possible?
I think the idea is to keep the power button continuously pressed (e.g. http://chdk.setepontos.com/index.php?topic=11434.msg112223#msg112223)  and use script to shutdown.

I just added this to the multicam.lua camera side code [directly above function mc.idle()] and it seems to work ok...well, at least it turned 2 connected cams off  :)
Code: [Select]
function cmds.shutdown()
--e.g to run: !return mc:cmdwait('shutdown')
write_status(true, 'when (if) all cameras have shutdown turn mains power off, but keep the rubber band on')
shut_down()
end

Then switch the mains off.
Mains on to start cams again.

I'm embarassed but still haven't studied the sync code in detail (i'll try and get back at some stage if a higher authority doesn't first).

Some links i've found very useful in getting an idea of where this sophisticated work came from and hangs together:
http://chdk.setepontos.com/index.php?topic=4338.msg58684#msg58684
http://chdk.setepontos.com/index.php?topic=11776.msg115276#msg115276

and lua
http://phrogz.net/lua/LearningLua_ValuesAndMetatables.html
http://phrogz.net/lua/LearningLua_Scope.html
« Last Edit: 25 / August / 2015, 16:39:13 by andrew.stephens.754365 »

Re: Noob question, how to run multicam.lua on chdkptp
« Reply #23 on: 27 / August / 2015, 09:30:28 »
Awesome thanks!


Re: Noob question, how to run multicam.lua on chdkptp
« Reply #24 on: 08 / September / 2015, 14:12:11 »
I'm embarassed but still haven't studied the sync code in detail (i'll try and get back at some stage if a higher authority doesn't first).
I just got round to reading the code. The following is my understanding only - it may not be totally accurate but there is some truth.

I have put the init_sync right after the start command right now. Is that correct?
You can do it anywhere before you use a command that relies on "syncat" although I remember (edit: found that in this thread here ) reading a post that described the camera should be in record mode (since that's more a reflection of how busy the camera would be while shooting). Slightly related - the camera tick counter (ms since being turned on) and the PC system time will diverge over time e.g. http://chdk.setepontos.com/index.php?topic=8769.msg107950#msg107950

When using your shoot code with the sync time a number is written after every "shoot". How do I need to understand this value? Is it milliseconds?
It is ms. It is an approximation of what each cameras tick counter value will be at "syncat" future ms from the value captured by multicam function mc:cmd(cmd,opts) and assigned to variable "tstart" when ustime.new() is executed - "tstart" is the ms representation of the PC system µseconds that have passed since the "epoch".

Some more detail of how, I think, the initial synch works:

The following description is repeated for each camera -- function "mc:init_sync_cam(lcon,count)" records the PC system time in var "t0". At this same time command "tick" (the actual text value "tick") is sent to the camera script (which takes an unknown, as yet, transmission period) . On receipt of "tick" the camera script runs its function "cmds.tick() "get_tick_count()". This tick count value is sent back  (which also takes an unknown, as yet, transmission period) to the waiting "lcon:wait_msg(...)" and is assigned to variable "msg.status" and is ultimately passed to function "mc:init_sync_single_send" as parameter "rt0" (as is "t0" via parameter "lt0")

Now, if the "tick" command transmission period was zero (and other complications to be mentioned later did not arise) we would already have a very accurate relationship between the PC system time (since epoch) and each cam (ticks since turn on). For example, to calculate a particular cameras tick relating to the current instant all we would need do is take the difference between the current instantaneous PC ( since epoch) system time [which occurs in function mc:cmd(cmd,opts) and is assigned to variable "tstart" by "ustime.new()"] and the previously recorded "lt0" and add this difference value to the previously recorded camera tick count "rt0". To calculate a future tick value just add, say, "syncat" ms to this value (to allow for relevant "syncat" command transmission to all cameras). This is mentioned in code by multicam comment:
Code: [Select]
--[[
get camera tick matching tstart + syncat
<camera base time> + <tstart - local base time> + syncat
]]
       
In reality - if the transmission time period to send the "tick" command were known then it could be subtracted from "rt0" to align the Camera tick with the PC time (lt0).

This adjustment is modelled in the following PC side code:

Code: [Select]
function mc:init_sync_single_send(i,lcon,lt0,rt0,ticks,sends)
local tsend = ustime.new()
lcon:write_msg('tick')
sends[i] = ustime.diffms(tsend)

My understanding (without confidence) is that "lcon:write_msg('tick')" here involves both transmission to the camera and an acknowledgment feedback from it (ack e.g. whether camera script is running status) i.e. ustime.diffms(tsend) will not execute until after the camera acknowledgment is received. This round-trip period will vary. By default, the average of 10 of these round trip periods [ustime.diffms(tsend)] is calculated (recorded in "send_stats.mean") and, without better knowledge of how much of the trip relates to each path, is divided by 2. The result is that the camera tick is adjusted as:

Code: [Select]
rtadj = rt0 - send_stats.mean/2
I'm not currently sure the purpose of the 2nd adjustment (tick_stats.mean), to give the final camera tick relation to the PC time since epoch (lt0) as:
Code: [Select]
rtadj = rt0 - tick_stats.mean - send_stats.mean/2
And my 3rd question: what time currency is minimum sync delay in?

ms.

Some of the other concerns http://chdk.setepontos.com/index.php?topic=8769.msg107968#msg107968:

"but the sync is quite bad because:
1) get_tick_count only works in 10ms increments
2) sleep only works in 10ms increments"


(can't quote as normal from that comment for some reason)



Edit: some other related comment

All that said, I think ~30 ms max deviation is about the as good as the current code can do:
The 10ms tick counter means that the "same" time on two cameras could be ~20ms apart, and the handoff from kbd_task to capt_seq that uses a 10ms sleep loop.

and some basis for calculation http://chdk.setepontos.com/index.php?topic=8769.msg107985#msg107985
« Last Edit: 10 / September / 2015, 10:18:37 by andrew.stephens.754365 »

Re: Noob question, how to run multicam.lua on chdkptp
« Reply #25 on: 29 / October / 2015, 09:04:02 »
Edit:

solved - if file does not exist, it is created  :-[




Probably embarrassing but not sure how to debug this...in attempting to redirect multicam.lua status (based on r658-win32) to a file, I added the following to

function mc:wait_status_msg(cmd,opts)
...[]...
if complete == #self.selected then

addition ->

Code: [Select]
local s= "true, " .. util.serialize(results)
local path = "C:\\CHDKPTP\\results\\results.txt" --file must preexist to be overwritten, otherwise error
local fh,err=io.open(path,'wb')

if not fh then
error(err)
end
fh:write(s)
fh:close()

As a test, I deleted file "results.txt" prior to running a multicam preshoot command but the file was created by multicam anyway ??

For the record, here's post creation file content:

Code: [Select]
true, {
 [1]={
  failed=false,
  done=true,
  status={
   cmd="preshoot",
   status=true,
  },
 },
 [2]={
  failed=false,
  done=true,
  status={
   cmd="preshoot",
   status=true,
  },
 },
}
« Last Edit: 29 / October / 2015, 10:10:59 by andrew.stephens.754365 »

Re: Noob question, how to run multicam.lua on chdkptp
« Reply #26 on: 10 / May / 2016, 10:01:11 »

I recently ran a multi-muliticam.lua (r692) with a bunch of cameras. One instance created this listfile table:
Code: [Select]
{
 ["9A952438E0A647E9AC0179DDC30582D5"]={
  id=2,
 },
 ["449A58C8297A4CCDAD05327C6BDD6FC2"]={
  id=4,
 },
 ["689D5005104943C09E988E4EA8301E22"]={
  id=1,
 },
 E21B7D737E5D4291B5DD048230963CF6={
  id=3,
 },}

I have some Autoit code (Lookahead and Lookbehind Zero-Length Assertions), which usually pulls that into an array (which is then displayed in a gui which can then be edited on screen to change the camera id assignment):
Code: [Select]
$sData = FileRead("listfile"); Read file
$aArray = StringRegExp($sData, '((?<=").*(?=")|id=\d+)', 3) ; Split into array

but, due to the missing speech mark, that doesn't work for id = 3

I haven't looked at the multicam.lua code for a while but assume my issue is due to the final serial key starting with a non numeric character. Is the missing speech mark created by (rather, not created by) multicam.lua to be expected?

*

Offline reyalp

  • ******
  • 14121
Re: Noob question, how to run multicam.lua on chdkptp
« Reply #27 on: 10 / May / 2016, 16:01:47 »
I haven't looked at the multicam.lua code for a while but assume my issue is due to the final serial key starting with a non numeric character.

Is the missing speech mark created by (rather, not created by) multicam.lua to be expected?
Yes. The content of the list file is a Lua table constructor generated by util.serialize, with the serial numbers as keys. In Lua, any value except nil or NaN can be table key, but to specify keys that don't look like normal Lua identifiers, the keys need to be enclosed in [].  The value starting with E is a valid name, while the ones starting with numbers are not.

The call to util.serialize in mc:save_list turns the camera list into a Lua table constructor. util.serialize only adds the [" where needed, because the unquoted values are more readable, and more compact when sending to the camera.

I will add an option to util.serialize to produce consistent formatting (putting all keys in []), since that seems generally useful for cases where serialize output may be parsed outside of Lua.
Don't forget what the H stands for.


Re: Noob question, how to run multicam.lua on chdkptp
« Reply #28 on: 10 / May / 2016, 16:42:50 »
Had just started to read through util.lua when I seen your detailed reply - thanks.

Will also look forward to the option sometime too...based in a little more recent familiarity with Autoit, unfortunately it's likely i'll do a kludge from that side. 
« Last Edit: 10 / May / 2016, 17:22:58 by andrew.stephens.754365 »

*

Offline reyalp

  • ******
  • 14121
Re: Noob question, how to run multicam.lua on chdkptp
« Reply #29 on: 11 / May / 2016, 22:47:02 »
Will also look forward to the option sometime too...
multicam.lua in chdkptp r700 should quote all the serial numbers consistently. No C code changes, you should be able to just use the latest lua files.
Don't forget what the H stands for.

 

Related Topics


SimplePortal 2.3.6 © 2008-2014, SimplePortal