Enabling Live view between Interval Shots - LUA Scripting - CHDK Forum

Enabling Live view between Interval Shots

  • 5 Replies
  • 4052 Views
Enabling Live view between Interval Shots
« on: 28 / April / 2020, 15:07:35 »
Advertisements
Hi All,

First post here. To start, thanks to all those who've put the work into the chdkptp. Pretty amazing the functionality that is unlocked on Point and Shoot's with this software.

I'm using CHDK PTP gui and am looking to get some advice on a means to write some LUA that will allow me to execute a shoot and download command at a user defined interval (basic intervalometer functionality) and will then yield functionality back to the GUI's live view functions in between shots. The camera will be mounted in a pressure housing deployed on a ROV, down to 1000 ft and thus I'd like the ability to see what is being shot in real time through the live view. Essentially, I'm trying to run:

 "shoot -dl="..dest_dir.."\\"..dive_number.."${ldate}${ext}"

Where the variables dest_dir and dive_number are pulled from iup.text{} functions I've add to the GUI. This all works fine, and the camera (a G5X) shoots and download the expected files when I run this command.

I've then configured a new button in gui.lua to run the attached code snippet, which starts shooting and downloading files at the user defined interval. As I gather is expected, when I try to run this code as a LUA function for interval shooting and call sleep() between shots, the live view functionality of the GUI is unavailable since it is blocked by the LUA code I am running in the repeat loop used for interval shooting.

I've also tried running a Camera side script, which does allow me to have the live view active while doing interval shots, but as far I can tell, there is no camera-side function to allow me effect a photo download operation (or have I missed it?).

I've thought about running some Python to just send messages through cli to chdkptp at the shooting interval that I desire, but I feel like a solution doesn't require a second, external script to run is a better bet an ultimately would be simpler for other users who may be using the system I'm putting together.

Any tips would be greatly appreciated. I've read this post https://chdk.setepontos.com/index.php?topic=12773.0 , which seems similar to what I'm trying to do, but I'm new to LUA (just trying to pick it up for this project) and couldn't work out which variables I'd need to access if I were try to piggy back off the timer functions being used for the live view.

Thanks

*

Offline reyalp

  • ******
  • 14126
Re: Enabling Live view between Interval Shots
« Reply #1 on: 28 / April / 2020, 16:52:49 »
Any tips would be greatly appreciated. I've read this post https://chdk.setepontos.com/index.php?topic=12773.0 , which seems similar to what I'm trying to do, but I'm new to LUA (just trying to pick it up for this project) and couldn't work out which variables I'd need to access if I were try to piggy back off the timer functions being used for the live view.
Sounds like a fun project. The chdkptp codebase can be intimidating, but if you're familiar with python, Lua should be pretty easy to pick up.

Using timers should be a reasonable approach. An example of this is the code that populates the device dropdown could be an example, see timer_update_connection_status in gui.lua.

I've attached a very simple module that uses this for shooting. Note the live view and GUI will be frozen while the shot and download are actually happening, but it will update in between. For this to work, the interval needs to be longer than the actual shooting time.

Console usage
Code: [Select]
!gi=require'gui_intervalomter'
!gi.start(5000,'c:/path/to/files',1)
...
!gi.cancel()
I'm sure you can hook this into a button.

If you have the capability to stream video, an alternative might be to use the cameras HDMI out. G5X is one of the few cameras that supports HDMI out while shooting.
Don't forget what the H stands for.

Re: Enabling Live view between Interval Shots
« Reply #2 on: 29 / April / 2020, 12:08:29 »
Thanks for great tips there. I've got the intervalometer up and running using the usb connection status timer, as you've described.


If you have the capability to stream video, an alternative might be to use the cameras HDMI out. G5X is one of the few cameras that supports HDMI out while shooting.

This is a good idea, and good to know it's a potential option (hardware wise) down the road. However, I think using the live view is probably the best option for me at present since it seems to drop frames gracefully if the connection is overtaxed; not sure how I'd fare with this trying to pipe an HDMI feed up to surface. If I get this working, I'll be sure to put up a post about it.

On a somewhat related note, I've noticed two things while testing this new setup. First,  if I call the gui_intervalometer.start() function through the GUI by means of a button, I see that I can make multiple calls to this function. For example, if a user selects a 15 second shot interval and clicks the 'shoot' button twice, the camera will take a picture at time=15 seconds, and then again at something like time=15.5 seconds. Is there a best practice to ensure that the function doesn't get called twice. Maybe a line a call to gui_intervalometer.cancel() in the line before .start() to catch and stop active calls to the function before starting a new call? Or maybe this type of functionality is better handled using iup.toggle functionality, with the 'state' argument turning the intervalometer on/off?

The second question (more of a nuisance) is that I've found that the iup.text boxes I created to capture dive number/name reads text backwards, for example if I the user wants to enter 'Dive1', they need to type '1eviD'. I'm vaguely aware that sometimes localizations (Arabic?) are set to read text in the opposite direction, but maybe I'm just missing some obvious argument to an iup.text call? I looked here https://www.tecgraf.puc-rio.br/iup/ for the function documentation, but nothing jumped out.

Thanks again for the help with this.

*

Offline reyalp

  • ******
  • 14126
Re: Enabling Live view between Interval Shots
« Reply #3 on: 29 / April / 2020, 13:36:45 »
This is a good idea, and good to know it's a potential option (hardware wise) down the road. However, I think using the live view is probably the best option for me at present since it seems to drop frames gracefully if the connection is overtaxed;
Out of curiosity, how are you sending the live view to the surface? Is chdkptp running on a device on the ROV with a remote desktop, or somehow extending the USB connection?
Quote
On a somewhat related note, I've noticed two things while testing this new setup. First,  if I call the gui_intervalometer.start() function through the GUI by means of a button, I see that I can make multiple calls to this function.
Yeah, it should probably have a sanity check. One way to do that would be just to make it automatically cancel the current time, like:
Code: [Select]
function m.start(interval, dest_dir, dive_number)
m.cancel()
m.dest_dir = dest_dir
m.dive_number = dive_number
m.job = gui.sched.run_repeat(interval,m.shoot)
end

Quote
The second question (more of a nuisance) is that I've found that the iup.text boxes I created to capture dive number/name reads text backwards, for example if I the user wants to enter 'Dive1', they need to type '1eviD'. I'm vaguely aware that sometimes localizations (Arabic?) are set to read text in the opposite direction, but maybe I'm just missing some obvious argument to an iup.text call?
That's odd. I don't think I've seen that for regular text inputs, and the default text direction should be fine unless the system locale is set to something Arabic or Hebrew.

Does the console input (left of the execute button) work normally?
If you post an example of the misbehaving code, I can take a look.
Also, what platform is this running on?
Don't forget what the H stands for.

Re: Enabling Live view between Interval Shots
« Reply #4 on: 30 / April / 2020, 14:31:34 »
Always happy to talk about the ROV end of things! The live view is being send to surface via an USB over Ethernet data stream. On the hardware end of things, the camera's USB connection is connected to a Raspberry Pi 4 and I'm running an instance of VirtualHere (https://www.virtualhere.com/usb_server_software) on the Pi. On the surface, there is client instance of VirtualHere on a Windows 10 PC, which is also running the chdkptp GUI. There is another step in the chain where the Ethernet signal is muxed/demuxed over a Fiber optic line to surface (to allow for the 1000 ft data transmission distance) and the Ethernet data stream recovered at surface.

I'm sure there is some overhead to doing software USB --> Ethernet through the Pi, but I'm also using the Pi to control some relays and read an orientation sensor subsurface. It seems like I am able to maintain about 12 fps in the live view GUI with the Overlays UI turned off, which is sufficient for my needs. For anyone that's interested, attached is a pic of the subsea 'can' that holds the Camera and all its electronics; this project is an upgrade to this system (which currently has lots of Legacy components that are getting harder to work with/get replacements for)

I've implemented the sanity check that you suggested, and its working well. Thanks for that.

Quote
That's odd. I don't think I've seen that for regular text inputs, and the default text direction should be fine unless the system locale is set to something Arabic or Hebrew.

Does the console input (left of the execute button) work normally?
If you post an example of the misbehaving code, I can take a look.
Also, what platform is this running on?

I had another look at the code I had, and did some more experimenting and found that If I added the line self.caretpos = string.len(tostring(d)) it seems to have fixed the issue. I also doubled checked the Win 10 localization and its set correctly for me.

Code: [Select]
function m.divenum_ui()
   local gui_frame = iup.frame{
     title="Dive Number", iup.vbox{
       iup.text{
         multiline = "NO",
         expansion = "YES",
         action = function(self,c,newdive)
           local d = tostring(newdive)
           self.value = d
           self.caretpos = string.len(tostring(d))
           dive_number = self.value
         return iup.IGNORE
         end,
         valuechanged_cb = function(self,newdive)
           dive_number = newdive
        end
        }
      }
    }
  return gui_frame
end

*

Offline reyalp

  • ******
  • 14126
Re: Enabling Live view between Interval Shots
« Reply #5 on: 30 / April / 2020, 17:42:43 »
Always happy to talk about the ROV end of things!
We're always happy to hear about the rest of the project or results here. Seeing what people do with this stuff is one of the most rewarding parts of working on CHDK. Please feel free to post any results you want to share after it's up and running :)

Quote
The live view is being send to surface via an USB over Ethernet data stream. On the hardware end of things, the camera's USB connection is connected to a Raspberry Pi 4 and I'm running an instance of VirtualHere (https://www.virtualhere.com/usb_server_software) on the Pi. On the surface, there is client instance of VirtualHere on a Windows 10 PC, which is also running the chdkptp GUI. There is another step in the chain where the Ethernet signal is muxed/demuxed over a Fiber optic line to surface (to allow for the 1000 ft data transmission distance) and the Ethernet data stream recovered at surface.
Thanks, I wasn't aware of virtualhere. Seems like a good solution if it works. I played with usbip a while back (https://chdk.setepontos.com/index.php?topic=13339.0) and found it usable but I don't think I'd trust it for mission critical stuff without more testing.

There have been issues reported with USB extenders https://chdk.setepontos.com/index.php?topic=13893.msg141518#msg141518

If you want to check USB stability for chdkptp, you can run the following from the command line:
Code: [Select]
chdkptp -e"exec require'camtests'.runbatch{bench=true,filexfer=true,xfersizebugs=true}"

The xfer test will also give you an indication of raw USB throughput.

Another approach you could do on the same hardware is run the chdkptp GUI on the pi and remote display it over ethernet with VNC or X, but not obvious this would be better than your current setup. To be clear, not suggesting you switch, only mentioning it as an option in case someone needs it.
Quote
I had another look at the code I had, and did some more experimenting and found that If I added the line self.caretpos = string.len(tostring(d)) it seems to have fixed the issue.
Now that you mention it, it seems like I did something similar in FPS control in gui_live.lua so I guess that's normal. It's been a long time since I touched that code  :-[
Don't forget what the H stands for.

 

Related Topics


SimplePortal © 2008-2014, SimplePortal