Simple question - Script Writing - CHDK Forum  

Simple question

  • 11 Replies
  • 2941 Views
Simple question
« on: 18 / March / 2013, 17:10:31 »
Advertisements
I am using the following lua code to make two functions one takes video the other takes picture
I am new to lua and cant seem to tell what I have done wrong
Any help would be appreciated:


capturemode=require("capmode")
function takevid ()
   capturemode.set ("VIDEO_STD")
   press("shoot_full")
    sleep(500)
    release("shoot_full")
    print("exiting video")
    press("shoot_full")
    sleep(500)
    release("shoot_full")
   --press ("video")
   --sleep (l)
   --release ("video")
end
function takephoto(s)
   capturemode.set ("P")
   for r=0,s,1 do
      shoot()
   print ("shot")
   end
end
takevid (60)
takephoto (2)
--shoot ()

Re: Simple question
« Reply #1 on: 18 / March / 2013, 18:14:10 »
Please don't post the same question in multiple threads.   
http://chdk.setepontos.com/index.php?topic=9560.0;topicseen#msg98008
The people who can help watch all postings and get grumpy when you do.    Especially as doing so tends to get the answers spit across the two threads.
Ported :   A1200    SD940   G10    Powershot N    G16

Re: Simple question
« Reply #2 on: 18 / March / 2013, 18:16:28 »
I am using the following lua code to make two functions one takes video the other takes picture
I am new to lua and cant seem to tell what I have done wrong.  Any help would be appreciated:
What does it do when you run the script ?
Ported :   A1200    SD940   G10    Powershot N    G16

Re: Simple question
« Reply #3 on: 18 / March / 2013, 19:38:40 »
I am using the following lua code to make two functions one takes video the other takes picture
I am new to lua and cant seem to tell what I have done wrong.  Any help would be appreciated:
What does it do when you run the script ?
It takes one picture really slowly
Then two at regular speed
Im using a Powershot A1200 if that helpss
« Last Edit: 18 / March / 2013, 19:57:26 by Gregor1212 »


*

Offline srsa_4c

  • ******
  • 4304
Re: Simple question
« Reply #4 on: 18 / March / 2013, 20:47:11 »
@Gregor1212
- Your takevid function doesn't have an argument, but you call it like this: takevid(60)
- you can find mode values here (see modemap): https://trac.assembla.com/chdk/browser/trunk/platform/a1200/shooting.c
- try to sleep() 1-2 seconds after changing the shooting mode
- you can also change shooting modes differently, see the set_capture_mode() and set_capture_mode_canon() functions: http://chdk.wikia.com/wiki/CHDK_Scripting_Cross_Reference_Page

Re: Simple question
« Reply #5 on: 18 / March / 2013, 22:20:59 »
Im using a Powershot A1200 if that helpss
I'll test on my A1200.
Ported :   A1200    SD940   G10    Powershot N    G16

Re: Simple question
« Reply #6 on: 18 / March / 2013, 22:44:41 »
Here you go.  The main problem with your script was that you started recording video and then immediately stopped it. I've changed it to use the passed parameter to the takevid(t) function as the length of the video filming interval.   I also inserted a few sleep() commands in a few other places.  Basically you need to allow the camera time to perform the shoot() operations unless you add code to check to see if shooting is complete.

Code: [Select]
--[[
@title Test Program
]]--
capturemode=require("capmode")
function takevid(t)
    print("starting a", t,"second video")
    capturemode.set("VIDEO_STD")
    press("shoot_full")
    sleep(500)
    release("shoot_full")
    sleep(t*1000) -- pause while video runs
    print("exiting video")
    press("shoot_full")
    sleep(500)
    release("shoot_full")
    sleep(500)
end

function takephoto(s)
   capturemode.set ("P")
   sleep(500)
   for r=1,s,1 do
      print ("shot", r)
      shoot()
      sleep(2000)
   end
end

takevid(5) -- take a 5 second video
takephoto(2)    -- take 2 pictures
Ported :   A1200    SD940   G10    Powershot N    G16

Re: Simple question
« Reply #7 on: 19 / March / 2013, 14:54:48 »
Here you go.  The main problem with your script was that you started recording video and then immediately stopped it. I've changed it to use the passed parameter to the takevid(t) function as the length of the video filming interval.   I also inserted a few sleep() commands in a few other places.  Basically you need to allow the camera time to perform the shoot() operations unless you add code to check to see if shooting is complete.

Code: [Select]
--[[
@title Test Program
]]--
capturemode=require("capmode")
function takevid(t)
    print("starting a", t,"second video")
    capturemode.set("VIDEO_STD")
    press("shoot_full")
    sleep(500)
    release("shoot_full")
    sleep(t*1000) -- pause while video runs
    print("exiting video")
    press("shoot_full")
    sleep(500)
    release("shoot_full")
    sleep(500)
end

function takephoto(s)
   capturemode.set ("P")
   sleep(500)
   for r=1,s,1 do
      print ("shot", r)
      shoot()
      sleep(2000)
   end
end

takevid(5) -- take a 5 second video
takephoto(2)    -- take 2 pictures
Got this to work
Thanks for the help
Just out of curiosity is their anyway to make the camera make noise in CHDK???


Re: Simple question
« Reply #8 on: 19 / March / 2013, 15:04:05 »
Just out of curiosity is their anyway to make the camera make noise in CHDK???
http://chdk.wikia.com/wiki/Script_commands#playsound

Might not work on every camera though.

Alternatively,  if you run the zoom lens in & out enough times under script control,  your camera will start making grinding noises all on its own ......

« Last Edit: 19 / March / 2013, 15:19:03 by waterwingz »
Ported :   A1200    SD940   G10    Powershot N    G16

Re: Simple question
« Reply #9 on: 19 / March / 2013, 16:35:25 »
Just out of curiosity is their anyway to make the camera make noise in CHDK???
http://chdk.wikia.com/wiki/Script_commands#playsound

Might not work on every camera though.

Alternatively,  if you run the zoom lens in & out enough times under script control,  your camera will start making grinding noises all on its own ......
lol
I got this to work as well
Is there an way to write files in CHDK?
I just want to put the info somewhere on the SD card
I tried the default lua way but that doesn't seem to work.......

 

Related Topics