Toggle LED Night MD - Script Writing - CHDK Forum

Toggle LED Night MD

  • 9 Replies
  • 4142 Views
Toggle LED Night MD
« on: 29 / August / 2011, 17:48:57 »
Advertisements
Hi I am new to CHDK and using a Powershot A470. I would like to use the motion detection script in the dark at night to catch animals. I was wondering if it is possible to use the MD script and alter it to turn the focus assist light on just before and after the motion detection part so that the camera can see. (Turned off again before taking the photo with the flash so that the subject does not come out orange from the LED.)

I tried adding some lines to the FAST MD script on the scripts page but when I run it my camera instantly turns off without retracting the lens.

    set_led 9 1
    md_detect_motion a, b, f, n, d, c, 1, t, i, j+1, l+1, a-k, b-m, 9, h, e
    set_led 9 0

Thanks for your time.

*

Offline zeno

  • *****
  • 891
Re: Toggle LED Night MD
« Reply #1 on: 30 / August / 2011, 07:10:23 »
I'm afraid what you're asking is not possible. Motion detection works by looking for changes in the image seen by the camera (specifically changes in what's displayed on the LCD). So unless there is enough light to switch on pixels on the LCD, motion detection can't do it's job. You can't therefore switch on the light when you detect motion, the light already has to be on. In other words, there needs to be a constant (low) level of general illumination to use motion detection.

It is possible to use infra-red lighting (which most cameras can detect somewhat) instead of visible lighting to illuminate the scene in a way that animals won't be disturbed by.
A570, S100, Ixus 127
Author of ASSIST, STICK, WASP, ACID, SDMInst, LICKS, WICKS, MacBoot, UBDB, CFGEdit

Re: Toggle LED Night MD
« Reply #2 on: 30 / August / 2011, 09:38:59 »
"You can't therefore switch on the light when you detect motion, the light already has to be on." Yes this is exactly what I want to do. Switch on the front LED permanently to light the scene for MD. Only tern it off to take the photo.

Re: Toggle LED Night MD
« Reply #3 on: 30 / August / 2011, 14:00:58 »
You need to add set_led(number,1) function before md_detect_motion(). Then, just before shoot() function you need to add set_led(number,0) and after shoot() again set_led(number,1).

number means the number of the led. I don't remember the correct number.

This will turn on the led just before the motion detection start, then, after motion is detected it will turn off the led, take a photo and again turn on the led.
if (2*b || !2*b) {
    cout<<question
}

Compile error: poor Yorick

Re: Toggle LED Night MD
« Reply #4 on: 30 / August / 2011, 18:26:29 »
Thanks for the reply. My A470 (latest chdk) just turns off every time I execute the script. Ive tried number 0-9.

The MD works without the set_led lines.

Code: [Select]
rem Author: MLuna - based om MX3 sample script
rem Tested on S3IS only
rem Requires Fingalo's build v 119
rem Use with caution!

@title Motion Detection

rem Shot without auto-focus/with auto-focus/continuously (need to put in continuous mode manually)
rem T implies test mode with MD cells drawing and no shots taken
@param a Shot (0=nf/1=f/2=c/3=t)
@default a 1

rem How long the shutter button will be pressed in continuous mode
@param b Continuos shoot (secs)
@default b 10

@param c Threshold (0-255)
@default c 5

@param d Compare Interval (msecs)
@default d 20

@param e Compare Interval (secs)
@default e 0

rem If this value is too small, the camera goes continuously shooting after the 1st shot.
rem Experiment with this value to find one fitted to your needs
@param f Begin Delay (secs)
@default f 5

@param g Pix step(speed/accuracy adj)
@default g 5

@param h Columns
@default h 6

@param i Rows
@default i 6

rem Frame width in which no MD is performed (in cell units)
@param j Dead frame
@default j 0

if a<0 then let a=0
if a>3 then let a=3
if c<0 then let c=0
if d<0 then let d=0
if e<0 then let e=0
if g<1 then let g=1
if h<1 then let h=1
if i<1 then let i=1
if j<0 then let j=0

rem Conversions secs to msecs
let b=b*1000
let e=e*1000
let f=f*1000

let d=d+e

rem This is the timeout in msecs. After this period, the motion trap is rearmed.
let T=600000

rem Parameters for the Dead Frame
let J=j+1
let H=h-j
let I=i-j

let t=0

print "press Shutter Button to Stop"

:repete
set_led 9, 1
md_detect_motion h, i, 1, T, d, c, 1, t, 1, J, J, H, I, 0, g, f
set_led 9, 0
if a=0 and t>0 then click "shoot_full"
if a=1 and t>0 then shoot
if a=2 and t>0 then goto "continuos"
if a=3 then goto "test"
set_led 9, 1
let t=0

goto "repete"

:continuos
let X=get_tick_count
set_led 9, 0
press "shoot_full"

:contloop
let U=get_tick_count
let V=(U-X)
if V<b then goto "contloop"

release "shoot_full"
set_led 9, 1
goto "repete"

:test
if t>0 then print "Detected cells: ",t else print "No detection in 10 min!"
let t=0
goto "repete"

end

*

Offline reyalp

  • ******
  • 14128
Re: Toggle LED Night MD
« Reply #5 on: 31 / August / 2011, 00:09:30 »
I believe the correct syntax for set_led in ubasic is
set_led X Y
without a comma. If I try to use a comma, it generates a syntax error.

It's quite possible that set_led is broken on this port. Which canon firmware version of the A470 do you have ?

If you use lua, you can use poke with the memory addresses found here: http://chdk.wikia.com/wiki/A470 to turn the LED on and off directly. 0x46 turns on, 0x44 turns off. If this doesn't make any sense to you, just ignore it :)

If the camera tries to activate the AF assist after you turn on the LED (for example, the half press for fast MD), it will (probably) turn off when the camera is done with it.

As an aside, I would be wary of running the AF led continuously for long periods. I would expect it was not designed to do this and might cause premature failure. However, if you are willing to risk this, we'd certainly love know the results :)


Don't forget what the H stands for.

Re: Toggle LED Night MD
« Reply #6 on: 31 / August / 2011, 13:56:43 »
Thank you Reyalp your suggestions were very useful. I found a lua MD script on the forums at http://chdk.setepontos.com/index.php/topic,2649.0.html and added a few pokes.

Working well so far but I have not tried for extended periods yet. Il leave it running tonight and post an update with the results. If leaving it on for extended periods does cause problems maybe I can script for cooling periods.

An alternative might be to replace the AF LED with an infrared LED so that it does not disturb wildlife or a more power efficient LED such as those in LED torches for a longer battery duration.

Code: [Select]
--[[
@title NightMD

rem Based on work done by  MLuna - based om MX3 sample script

rem Shot without auto-focus/with auto-focus/continuously (need to put in continuous mode manually)
rem T implies test mode with MD cells drawing and no shots taken
@param a Shot (0=nf/1=f/2=c/3=t)
@default a 1

rem How long the shutter button will be pressed in continuous mode
@param b Continuos shoot (secs)
@default b 10

@param c Threshold (0-255)
@default c 5

@param d Compare Interval (msecs)
@default d 20

@param e Compare Interval (secs)
@default e 0

rem If this value is too small, the camera goes continuously shooting after the 1st shot.
rem Experiment with this value to find one fitted to your needs
@param f Begin Delay (secs)
@default f 5

@param g Pix step(speed/accuracy adj)
@default g 5

@param h Columns
@default h 6

@param i Rows
@default i 6

rem Frame width in which no MD is performed (in cell units)
@param j Dead frame
@default j 0


]]

if a<0 then
  a=0
end

if a>3 then
  a=3
end

if c<0 then
 c=0
end

if d<0 then
  d=0
end

if e<0 then
  e=0
end

if g<1 then
  g=1
end

if h<1 then
  h=1
end

if i<1 then
  i=1
end

if j<0 then
  j=0
end


-- Conversions secs to msecs
b=b*1000
e=e*1000
f=f*1000

d=d+e

-- This is the timeout in msecs. After this period, the motion trap is rearmed.
T=600000

-- Parameters for the Dead Frame
J=j+1
H=h-j
I=i-j

t=0

print( "press Shutter to Stop")



while (  1 ) do


status = poke(0xC0220080,0x46)

        rectangles = 0

        rectangles = md_detect_motion( h, i, 1, T, d, c, 1, t, 1, J, J, H, I, 0, g, f)


        t=rectangles

        if t>0 then status = poke(0xC0220080,0x44) end

        if a==0 and t>0 then click "shoot_full" end
        if a==1 and t>0 then shoot() end
        if a==2 and t>0 then

          X=get_tick_count()

          press("shoot_full")

          while (V<b) do

                 U=get_tick_count()
                 V=(U-X)
          end

          release( "shoot_full" )

        end

        -- Test Mode Output
        if a==3 then

          if t>0 then
              print( "Detected cells: ",t)
          else
              print( "No detection in 10 min!" )

          end

          t=0

        end




-- end of while loop

end




print("END")

Re: Toggle LED Night MD
« Reply #7 on: 02 / September / 2011, 09:43:42 »
I dont know about the failure rate over the long term but I can now confirm using my a470 that with 2 Contour 2750mah AA batteries the camera will run MD with the AF LED permanently on for at least 3.5 hours. (And it still works)
I tested in my back garden at night and came back to find a few photos of moths and one of a hedgehog. First test photo was captured at 9.30pm with the last at 2am. (Photos captured with flash). They came out blurry, It might be better to reduce the flash power.

*

Offline blackhole

  • *****
  • 946
  • A590IS 101b
    • Planetary astrophotography
Re: Toggle LED Night MD
« Reply #8 on: 08 / May / 2012, 03:22:13 »
 :-[ :-X

Re: Toggle LED Night MD
« Reply #9 on: 08 / May / 2012, 11:18:23 »
8 months later?
if (2*b || !2*b) {
    cout<<question
}

Compile error: poor Yorick

 

Related Topics


SimplePortal © 2008-2014, SimplePortal