Odd behaviour with gosub - Hello, I'm a NEWBIE - HELP!! (Newbies assistance, User Guides and thank you notes) - CHDK Forum

Odd behaviour with gosub

  • 5 Replies
  • 4395 Views
Odd behaviour with gosub
« on: 27 / January / 2012, 13:21:10 »
Advertisements
Hi all,

First post so please go easy on me!

I have an odd requirement - I fly my A570IS on high altitude balloons that go up into near space and take fantastic photos. For my next flight I have decided to do something different which really pushes the limits of the CHDK.
Basically, I want to continually take photos every 10 or so seconds, however when a "power pulse" is received (via usb) from my micro controller it will take a ~10 second video. Then switch back to taking stills.

I'm using this - http://www.zenoshrdlu.com/kapstuff/zchdk.html as it supports switching between still and video mode.

I have wrote a sample script (that doesn't include all the waits etc atm because I am just debugging). As the CHDK doesn't support interrupts (as far as I'm aware) that would allow switch to video mode as SOON as a "power pulse" is received; I have had to adopt the approach of continually polling the usb port using "get_usb_power".
However, I am getting very odd behaviour, initially when testing I was getting about 4 stills taken before it stopped and displayed "STACK FUL" - why is it saving photos onto the stack?!?  :o Now I am getting it halting after about 5 photos and the screen black (which is to do with the initial settings change) - but going completely unresponsive!

Code:
Code: [Select]
rem HABE2 A570 CHDK Script
rem VERSION 2.0
rem FOR CAMERA A570IS
rem Switches between stills and video

@title HABE2 2.0
rem Script to test varying between still & video mode


@param a Shoot count
@default a 1500
@param b Interval (Minutes)
@default b 0
@param c Interval (Seconds)
@default c 25

d=700

rem reset camera
sleep d
click "menu"
sleep d
click "right"
sleep d
click "up"
sleep d
click "set"
sleep d
click "right"
sleep d
click "set"
sleep 3000

rem power settings (auto shut down off & display off 30s)
sleep d
click "menu"
sleep d
click "right"
sleep d
click "down"
sleep d
click "down"
sleep d
click "down"
sleep d
click "down"
sleep d
click "set"
sleep d
click "right"
sleep d
click "down"
sleep d
click "left"
sleep d
click "menu"
sleep d
click "menu"

rem set menu values
sleep d
click "menu"
sleep d
click "down"
sleep d
click "down"
sleep d

rem digital zoom off
click "right"
sleep d
click "down"
sleep d
click "down"
sleep d

rem red-eye off
click "right"
sleep d
click "down"
sleep d

rem safety FE off
click "right"
sleep d
click "down"
sleep d

rem MF-Point Zoom off
click "right"
sleep d
click "down"
sleep d

rem Safety MF off
click "right"
sleep d
click "down"
sleep d

rem AF-Assist Beam off
click "right"
sleep d
click "down"
sleep d

rem Review off
click "left"
sleep d
click "down"
sleep d
click "down"
sleep d

rem IS Mode = shoot only
click "right"
sleep d
click "menu"
sleep d


rem set apeture to f4
sleep d
click "left"


rem select manual focus
sleep d
click "down"
sleep d
click "down"
sleep d
click "down"

rem set focus to infinity
for n=1 to 7
sleep d
click "right"
next n

rem set jpeg compression to minimal or superfine
sleep d
click "set"
sleep d
click "up"
sleep d
click "up"
sleep d
click "left"
sleep d
click "set"

rem ** Sleep for ~17mins - Should give enough time to put lid on payload/prepare for launch etc.. **
rem ** 17mins = 10 x 60 x 1000 = 1,000,000

rem sleep 999999

sleep 3000

click "display"
click "display"

:loop
   x = get_usb_power

   if x < 15 then gosub "still"
   if x > 15 then gosub "video"
   if x > 30 then print "error"

:still
  sleep 1000
  rem take a picture
  shoot
  sleep 1000
  gosub "loop"

:video
  print "Movie"
  press "dm_movie"
  sleep 1000
  press "shoot_full"
  sleep 300
  release "shoot_full"
  rem start of video delay loop
  sleep 5000
  rem shoot again to turn video off
  press "shoot_full"
  sleep 300
  release "shoot_full"
  sleep 1000
  release "dm_movie"
  gosub "loop"


rem END OF SCRIPT


If anyone could help me out I would really appreciate it!
Many thanks

Re: Odd behaviour with gosub
« Reply #1 on: 27 / January / 2012, 13:50:47 »
rather than comment on your CHDK script, you may be interested in the script we use for SDM balloon flights.

It runs straight 'out-of-the-box' and waits for you to remove lens-cap before starting image capture.

It captures images and movies and calculates near-space exposure using Bonomi's method of averaging the top percentage of one hundred readings.

This reduces errors caused by direct sun or large areas of black space.

The script is attached and a log file is below.


David

------------------------------------------------
            Stratospheric Balloon Mission       
------------------------------------------------

phaseA: Script started, wait for lens cap removal
Backlight turned off
Lens cap removed
Backlight turned on
------------------------------------------------

Liftoff movie
00:00:00 phaseB: Recording movie for 60  seconds
Flash off
------------------------------------------------

Low altitude fast shots
00:01:13 phaseC: Fast shots every 30 seconds for 300  seconds
Maximum ISO set to 400
Target shutter speed = 1 /4000
00:01:16 IMG_4863 shutter was 1/ 2332 at max ISO
00:01:50 IMG_4864 shutter was 1/ 2332 at max ISO
00:02:24 IMG_4865 shutter was 1/ 2349 at max ISO
00:02:57 IMG_4866 shutter was 1/ 2349 at max ISO
00:03:30 IMG_4867 shutter was 1/ 2349 at max ISO
00:04:03 IMG_4868 shutter was 1/ 2349 at max ISO
00:04:37 IMG_4869 shutter was 1/ 2349 at max ISO
00:05:10 IMG_4870 shutter was 1/ 2366 at max ISO
00:05:43 IMG_4871 shutter was 1/ 2366 at max ISO
------------------------------------------------

Higher altitude ascent movie
00:06:17 phaseB: Recording movie for 36  seconds
Flash off
------------------------------------------------

Higher altitude fast shots
00:07:06 phaseC: Fast shots every 30 seconds for 360  seconds
Maximum ISO set to 400
Target shutter speed = 1 /4000
00:07:09 IMG_4873 shutter was 1/ 2366 at max ISO
00:07:43 IMG_4874 shutter was 1/ 2383 at max ISO
00:08:16 IMG_4875 shutter was 1/ 2383 at max ISO
00:08:49 IMG_4876 shutter was 1/ 2383 at max ISO
00:09:23 IMG_4877 shutter was 1/ 2383 at max ISO
00:09:56 IMG_4878 shutter was 1/ 2400 at max ISO
00:10:29 IMG_4879 shutter was 1/ 2417 at max ISO
00:11:03 IMG_4880 shutter was 1/ 2417 at max ISO
00:11:36 IMG_4881 shutter was 1/ 2417 at max ISO
00:12:09 IMG_4882 shutter was 1/ 2417 at max ISO
00:12:42 IMG_4883 shutter was 1/ 2435 at max ISO
------------------------------------------------

00:13:16 Taking 100 brightness readings
------------------------------------------------

00:15:54 Fast shots using computed exposure
phaseF: Fast shots every 30 seconds for 300  seconds
Maximum ISO set to 400
Target shutter speed = 1 /4000
00:15:56 IMG_4884 Fast shoot at 84 ISO
00:16:28 IMG_4885 Fast shoot at 84 ISO
00:17:00 IMG_4886 Fast shoot at 84 ISO
00:17:32 IMG_4887 Fast shoot at 84 ISO
00:18:04 IMG_4888 Fast shoot at 84 ISO
00:18:36 IMG_4889 Fast shoot at 84 ISO
00:19:08 IMG_4890 Fast shoot at 84 ISO
00:19:40 IMG_4891 Fast shoot at 84 ISO
00:20:13 IMG_4892 Fast shoot at 84 ISO
00:20:45 IMG_4893 Fast shoot at 84 ISO
------------------------------------------------

High altitude movie
00:21:18 phaseB: Recording movie for 36  seconds
Flash off
------------------------------------------------

00:22:04 phaseE: Descent,exposure computed every 20 shots
Fast shots every 3 seconds for 240  seconds
00:22:06 IMG_4895 shutter was 1/ 2453 at max ISO
00:22:11 IMG_4896 shutter was 1/ 2453 at max ISO
00:22:16 IMG_4897 shutter was 1/ 2453 at max ISO
00:22:21 IMG_4898 shutter was 1/ 2453 at max ISO
00:22:26 IMG_4899 shutter was 1/ 2453 at max ISO
00:22:31 IMG_4900 shutter was 1/ 2453 at max ISO
00:22:36 IMG_4901 shutter was 1/ 2453 at max ISO
00:22:41 IMG_4902 shutter was 1/ 2453 at max ISO
00:22:46 IMG_4903 shutter was 1/ 2453 at max ISO
00:22:51 IMG_4904 shutter was 1/ 2453 at max ISO
00:22:57 IMG_4905 shutter was 1/ 2453 at max ISO
00:23:02 IMG_4906 shutter was 1/ 2453 at max ISO
00:23:07 IMG_4907 shutter was 1/ 2453 at max ISO
00:23:12 IMG_4908 shutter was 1/ 2453 at max ISO
00:23:17 IMG_4909 shutter was 1/ 2453 at max ISO
00:23:22 IMG_4910 shutter was 1/ 2453 at max ISO
00:23:27 IMG_4911 shutter was 1/ 2453 at max ISO
00:23:32 IMG_4912 shutter was 1/ 2453 at max ISO
00:23:37 IMG_4913 shutter was 1/ 2453 at max ISO
00:23:42 IMG_4914 shutter was 1/ 2453 at max ISO
00:23:47 IMG_4915 shutter was 1/ 2453 at max ISO
00:23:52 IMG_4916 shutter was 1/ 2453 at max ISO
00:23:57 IMG_4917 shutter was 1/ 2453 at max ISO
00:24:02 IMG_4918 shutter was 1/ 2453 at max ISO
00:24:07 IMG_4919 shutter was 1/ 2453 at max ISO
00:24:13 IMG_4920 shutter was 1/ 2453 at max ISO
00:24:18 IMG_4921 shutter was 1/ 2453 at max ISO
00:24:23 IMG_4922 shutter was 1/ 2453 at max ISO
00:24:28 IMG_4923 shutter was 1/ 2453 at max ISO
00:24:33 IMG_4924 shutter was 1/ 2453 at max ISO
00:24:38 IMG_4925 shutter was 1/ 2453 at max ISO
00:24:43 IMG_4926 shutter was 1/ 2453 at max ISO
00:24:48 IMG_4927 shutter was 1/ 2453 at max ISO
00:24:53 IMG_4928 shutter was 1/ 2453 at max ISO
00:24:59 IMG_4929 shutter was 1/ 2453 at max ISO
00:25:04 IMG_4930 shutter was 1/ 2453 at max ISO
00:25:09 IMG_4931 shutter was 1/ 2453 at max ISO
00:25:14 IMG_4932 shutter was 1/ 2453 at max ISO
00:25:19 IMG_4933 shutter was 1/ 2453 at max ISO
00:25:24 IMG_4934 shutter was 1/ 2453 at max ISO
00:25:29 IMG_4935 shutter was 1/ 2488 at max ISO
00:25:34 IMG_4936 shutter was 1/ 2488 at max ISO
00:25:39 IMG_4937 shutter was 1/ 2488 at max ISO
00:25:44 IMG_4938 shutter was 1/ 2488 at max ISO
00:25:49 IMG_4939 shutter was 1/ 2488 at max ISO
00:25:54 IMG_4940 shutter was 1/ 2488 at max ISO
00:25:59 IMG_4941 shutter was 1/ 2488 at max ISO
00:26:04 IMG_4942 shutter was 1/ 2488 at max ISO
00:26:09 IMG_4943 shutter was 1/ 2488 at max ISO
00:26:14 IMG_4944 shutter was 1/ 2488 at max ISO
00:26:19 IMG_4945 shutter was 1/ 2488 at max ISO
00:26:25 IMG_4946 shutter was 1/ 2488 at max ISO
00:26:30 IMG_4947 shutter was 1/ 2488 at max ISO
00:26:35 IMG_4948 shutter was 1/ 2488 at max ISO
00:26:40 IMG_4949 shutter was 1/ 2488 at max ISO
00:26:45 IMG_4950 shutter was 1/ 2488 at max ISO
00:26:50 IMG_4951 shutter was 1/ 2488 at max ISO
00:26:55 IMG_4952 shutter was 1/ 2488 at max ISO
00:27:00 IMG_4953 shutter was 1/ 2488 at max ISO
00:27:05 IMG_4954 shutter was 1/ 2488 at max ISO
------------------------------------------------

00:27:09 phaseB: Recording movie for 24  seconds
Flash off
------------------------------------------------




Re: Odd behaviour with gosub
« Reply #2 on: 27 / January / 2012, 13:52:06 »
Right - after spending some time running through the code I appear to have solved why the stack was filling up and hence no more photos being taken. Here's my interpretation:

I was using lots of "gosub"s and not returning from any of them - hence just nesting deeper and deeper inside subroutines. With every call of a subroutine I guess the CHDK was dumping all the registers' values onto the stack to preserve them, however after a good few nested subroutines the stack was full and therefore program stopped.

I have now added some returns and a "goto" which appears to have solved the problem. My altered code is below:

Code: [Select]

:loop
   x = get_usb_power

   if x < 15 then gosub "still"
   if x > 15 then gosub "video"
   if x > 30 then print "error"
goto "loop"

:still
  sleep 1000
  rem take a picture
  shoot
  sleep 1000
  return

:video
  print "Movie"
  press "dm_movie"
  sleep 1000
  press "shoot_full"
  sleep 300
  release "shoot_full"
  rem start of video delay loop
  sleep 5000
  rem shoot again to turn video off
  press "shoot_full"
  sleep 300
  release "shoot_full"
  sleep 1000
  release "dm_movie"
  return

Could someone with more experience weigh in and tell me if I'm correct in my debugging analysis :P ?! Thanks :)

Also - as it's a rather nasty hacky way to see if there is a "power pulse" at the moment, is there any other way that I would be best off doing?

Many thanks in advance

Re: Odd behaviour with gosub
« Reply #3 on: 27 / January / 2012, 13:54:55 »
rather than comment on your CHDK script, you may be interested in the script we use for SDM balloon flights.

It runs straight 'out-of-the-box' and waits for you to remove lens-cap before starting image capture.

It captures images and movies and calculates near-space exposure using Bonomi's method of averaging the top percentage of one hundred readings.

This reduces errors caused by direct sun or large areas of black space.

The script is attached and a log file is below.


David

Thanks David I will certainly take a look.

[edit] What version of CHDK did you use as there is a parsing error with the latest?
Also..
What size memory card did you use? I'm using a 4GB and should just be enough I think..

Cheers
« Last Edit: 27 / January / 2012, 14:19:33 by cuddykid »


Re: Odd behaviour with gosub
« Reply #4 on: 27 / January / 2012, 14:05:04 »
Could someone with more experience weigh in and tell me if I'm correct in my debugging analysis :P ?! Thanks :)
Your analysis of the problem is correct as is your modified code.  The only slight quibble is that CHDK does  not push registers into a stack when you call a subroutine in a script.  It does however push a return address each time which is what was causing your "stack full" problem.

Quote
Also - as it's a rather nasty hacky way to see if there is a "power pulse" at the moment, is there any other way that I would be best off doing?
Why do you call it a nasty hack ?  What you are doing is exactly what the get_usb_power function was written for.
Ported :   A1200    SD940   G10    Powershot N    G16

Re: Odd behaviour with gosub
« Reply #5 on: 27 / January / 2012, 14:37:33 »
What version of CHDK did you use as there is a parsing error with the latest?

SDM has specialised uBasic commands for this.

To try the script, temporarily rename your existing DISKBOOT.BIN and get version from here :-

http://stereo.jpn.org/eng/sdm/download.htm

General information here http://stereo.jpn.org/eng/sdm/index.htm

Quote
What size memory card did you use?

4GB.


David

 

Related Topics