Thursday, August 17, 2017

Properly working AHK Script

Last night, I got the AutoHotKey script to work with the Pentax K10D.

Very slick and I can see how I might be able to script things like Maxim.

Here is the properly working code for reference.


#SingleInstance force
CoordMode, mouse, screen



; Get target time in a format we can:
;  - compare (with "<")
; < comparison should be safe as long as both are in the *exact* same format.
; time is 2305 format
; ====================================
; the values listed below are for the eclipse BE SURE TO UNCOMMENT
;filter1timeS = %A_YYYY%%A_MM%%A_DD%090643 ; 9:06:43 am
;filter1timeE = %A_YYYY%%A_MM%%A_DD%101830 ; 10:18:30 am 50 seconds to remove filters
;beads1timeS  = %A_YYYY%%A_MM%%A_DD%101920 ; 10:19:20 am 13 seconds to spam for beads
;beads1timeE  = %A_YYYY%%A_MM%%A_DD%101933 ; 10:19:33 am
;brackettimeS = %A_YYYY%%A_MM%%A_DD%101934 ; 10:19:34 am
;brackettimeE = %A_YYYY%%A_MM%%A_DD%102125 ; 10:21:25 am
;beads2timeS  = %A_YYYY%%A_MM%%A_DD%102135 ; 10:21:35 am 10 seconds to spam for beads
;beads2timeE  = %A_YYYY%%A_MM%%A_DD%102145 ; 10:21:45 am
;filter2timeS = %A_YYYY%%A_MM%%A_DD%102200 ; 10:22:15 am 30 seconds to apply filters
;filter2timeE = %A_YYYY%%A_MM%%A_DD%114102 ; 11:41:02 am

; ====================================
; the values listed below are for testing
filter1timeS = %A_YYYY%%A_MM%%A_DD%222000 ; 
filter1timeE = %A_YYYY%%A_MM%%A_DD%223000 ; 
beads1timeS  = %A_YYYY%%A_MM%%A_DD%223100 ; 
beads1timeE  = %A_YYYY%%A_MM%%A_DD%223115 ; 
brackettimeS = %A_YYYY%%A_MM%%A_DD%223120 ; 
brackettimeE = %A_YYYY%%A_MM%%A_DD%223420 ; 
beads2timeS  = %A_YYYY%%A_MM%%A_DD%223425 ; 
beads2timeE  = %A_YYYY%%A_MM%%A_DD%223435 ; 
filter2timeS = %A_YYYY%%A_MM%%A_DD%223510 ; 
filter2timeE = %A_YYYY%%A_MM%%A_DD%224000 ; 

; ====================================

; send filtersettings ; set single frame shooting with appropriate fstop and shutter speed 
Click 1452, 491 ; set bracket mode off
	SendInput {PgUp}
	SendInput {Enter}
click 1472, 452 ; set single shot
	SendInput {Down}
	SendInput {Enter}
click 1222, 485 ; set shutter speed to 4000 then down to 500 
	sendInput {PgUp}
	sendInput {Down 9}
	sendInput {Enter}
click 1222, 518 ; set f stop to max then to F5.6
	sendInput {PgUp}
	sendInput {Down 12}
	sendInput {Enter}
Click 1501, 14 ; click on shutter control window bar to make active
MouseMove 1565, 363 ; position mouse over shutter button

gosub, filter1

; remove filters audio warning


; send beadsettings ; set continuous shooting speed to Low with appropriate fstop and shutter speedset beads
Click 1452, 491 ; set bracket mode off
	SendInput {PgUp}
	SendInput {Enter}
click 1472, 452 ; set continuous
	SendInput {Down 2}
	SendInput {Enter}
click 1222, 485 ; set shutter speed to 4000
	sendInput {PgUp}
	sendInput {Enter}
Click 1501, 14 ; click on shutter control window bar to make active
MouseMove 1565, 363 ; position mouse over shutter button

gosub, beads1

; send bracketsettings
click 1472, 452 ; set single shot
	SendInput {Down}
	SendInput {Enter}
click 1222, 485 ; set shutter speed to 1/8 from 4000
	sendInput {Down 27}
	sendInput {Enter}
Click 1452, 491 ; set bracket mode on with 5 shots
	SendInput {Down 2}
	SendInput {Enter}
Click 1501, 14 ; click on shutter control window bar to make active
MouseMove 1565, 363 ; position mouse over shutter button

gosub, totality

; beads2
; set beads ; set continuous shooting speed to Low with appropriate fstop and shutter speed
Click 1452, 491 ; set bracket mode off
	SendInput {Up 2}
	SendInput {Enter}
click 1472, 452 ; set continuous
	SendInput {Down 2}
	SendInput {Enter}
click 1222, 485 ; reset shutter speed to 4000 max
	sendInput {PgUp}
	sendInput {Enter}
click 1222, 518 ; set f stop to max then to F5.6
	sendInput {PgUp}
	sendInput {Down 12}
	sendInput {Enter}
Click 1501, 14 ; click on shutter control window bar to make active
MouseMove 1565, 363 ; position mouse over shutter button

gosub, beads2

; apply filters audio warning

;set final filter settings
Click 1452, 491 ; set bracket mode off
	SendInput {PgUp}
	SendInput {Enter}
click 1472, 452 ; set single shot
	SendInput {Down}
	SendInput {Enter}
click 1222, 485 ; set shutter speed to 500 from earlier 4000
	sendInput {down 9}
	sendInput {Enter}
Click 1501, 14 ; click on shutter control window bar to make active
MouseMove 1565, 363 ; position mouse over shutter button
gosub, filter2

goto, terminate

; ====================================

; subroutines

; ====================================

filter1:
; this is first to second contact
; send a picture click once a minute


if (A_Now >= filter1timeS)  
	{ 
	Loop
		{ 
			MouseClick, left, 1565, 363, 1, 10  ; click slowly to ensure shutter register
			sleep 60000 ; wait a minute
			if (A_Now >= filter1timeE)
				break 
			if (A_Now < filter1timeE)
				continue
		}}
	else
		{ 
			Sleep 60000 ; wait a minute
			goto filter1 ; go back to the start of the subroutine
		}
	
return

; ====================================

beads1:
; this is the beads1 subroutine

; press and hold shutter button while beads active
if (A_Now > beads1timeS)
	{
	Loop
		{
			MouseClick, left, 1565, 363, 1, 10, D ; Press and hold shutter button
			if (A_Now >= beads1timeE)
				{
				MouseClick, left, 1563, 363, 1, 10, U ; release shutter button
				Break 
				}
			if (A_Now < beads1timeE)
				sleep 1000 ; wait a second
				continue
		}}
	else
		{ 
			Sleep 1000 ; wait a second
			goto beads1 ; go back to the start of the subroutine
		}
	
return
	
; ====================================

totality:
; this is the subroutine for totality with bracketing

	
if (A_Now > brackettimeS)
	{
	Loop
		{
			MouseClick, left, 1565, 363, 1, 10
			Sleep 3000  ; click every 3 seconds
			if (A_Now >= brackettimeE)
				Break 
			If (A_Now < brackettimeE)
				continue
		}}
	else
				{ 
			Sleep 1000 ; wait a second
			goto totality ; go back to the start of the subroutine
		}
	
return

; ====================================	
	
beads2:
; this is the second beads routine


if (A_Now > beads2timeS)
	{
	Loop
		{
			MouseClick, left, 1565, 363, 1, 10, D ; Press and hold shutter button
			if (A_Now >= beads2timeE)
				{
				MouseClick, left, 1563, 363, 1, 10, U ; release shutter button
				Break 
				}
			if (A_Now < beads2timeE)
				sleep 1000 ; wait a second
				continue
		}}
	else
		{ 
			Sleep 1000 ; wait a second
			goto beads2 ; go back to the start of the subroutine
		}
	
return

; ====================================
			
filter2:
; this is from 3rd to 4th contact


if (A_Now >= filter2timeS)  
	{ 
	Loop
		{ 
			MouseClick, left, 1565, 363, 1, 10  ; click slowly to ensure shutter register
			sleep 60000 ; wait a minute
			if (A_Now >= filter2timeE)
				break 
			if (A_Now < filter2timeE)
				continue
		}}
	else
		{ 
			Sleep 1000 ; wait a second
			goto filter2 ; go back to the start of the subroutine
		}
	
return

; ====================================




terminate:
	exit
	
Esc::ExitApp	

Wednesday, August 16, 2017

Auto Hot Key and Time Controls

I've been languishing with my AHK script.

The earlier example that was posted assumed that I understood how time controls worked. I tested these ideas last night and found my knowledge lacking.

While I was able to get the coordinates and button clicks working with the Pentax K10D camera, I found that my "while" flow control was poorly managed.

Here's what I wrote:

#SingleInstance force
CoordMode, mouse, screen

; Get target time in a format we can:
;  - compare (with "<")
; < comparison should be safe as long as both are in the *exact* same format.
; target_time is 2305 format
filter1timeS = %A_YYYY%%A_MM%%A_DD%%212500 ; 21:05 pm
filter1timeE = %A_YYYY%%A_MM%%A_DD%%213000 ; 21:10 pm
beads1timeS = %A_YYYY%%A_MM%%A_DD%%213100 ; 21:11 pm
beads1timeE = %A_YYYY%%A_MM%%A_DD%%213130 ; 21:1130 pm
brackettimeS = %A_YYYY%%A_MM%%A_DD%%213020 ; 21:1140 pm
brackettimeE = %A_YYYY%%A_MM%%A_DD%%213320 ; 21:1320 pm
beads2timeS = %A_YYYY%%A_MM%%A_DD%%213325 ; 21:1320 pm
beads2timeE = %A_YYYY%%A_MM%%A_DD%%213400 ; 21:14 pm
filter2timeS = %A_YYYY%%A_MM%%A_DD%%213410 ; 21:1410 pm
filter2timeE = %A_YYYY%%A_MM%%A_DD%%214000 ; 21:20 pm

; send filtersettings ; set single frame shooting with appropriate fstop and shutter speed 
click 1472, 452 ; set single shot
SendInput {Down}
SendInput {Enter}
click 1222, 485 ; set shutter speed to 500 from default 125
sendInput {Up 6}
sendInput {Enter}
click 1222, 518 ; set f stop 5.6 from default 8
sendInput {Up 3}
sendInput {Enter}

MouseMove 1565, 363
Click 1501, 14

while ((A_Now >= filter1timeS) and (A_Now <= filter1timeE)) ; this is first to second contact
{ ; send a picture click once a minute
MouseClick, left, 1565, 363, 1, 10
SendInput {Space}
sleep 60000
}


; remove filters audio warning
; beads1
; send beadsettings ; set continuous shooting speed to Low with appropriate fstop and shutter speedset beads
click 1472, 452 ; set continuous
SendInput {Down 2}
SendInput {Enter}
click 1222, 485 ; set shutter speed to 4000 from 500
sendInput {Up 9}
sendInput {Enter}

MouseMove 1565, 363
Click 1501, 14
while ((A_Now >= beads1timeS) and (A_Now <= beads1timeE)) ; this is when first beads goes
{ ; spam beads
MouseClick, left, 1565, 363, 1, 100, D
SendInput {Space}
; at the start 
 ; hold button until the end of beads time
}
MouseClick, left, 1563, 363, 1, 100, U
; click ; at the end, click again to stop the continuous shooting mode

; send bracketsettings
click 1472, 452 ; set single shot
SendInput {Down}
SendInput {Enter}
click 1222, 485 ; set shutter speed to 1/8 from 4000
sendInput {Down 27}
sendInput {Enter}
Click 1452, 491 ; set bracket mode on
SendInput {Down 2}

Click 1501, 14
MouseMove 1565, 363
while ((A_Now >= brackettimeS) and (A_Now <= brackettimeE)) ; this is totality
{ ; spam brackets
MouseClick, left, 1565, 363, 1, 100
Sleep 3000
; click every 3 seconds
}



; beads2
; set beads ; set continuous shooting speed to Low with appropriate fstop and shutter speed
Click 1452, 491 ; set bracket mode off
SendInput {Up 2}
click 1472, 452 ; set continuous
SendInput {Down 2}
SendInput {Enter}
click 1222, 485 ; reset shutter speed to 4000 max
sendInput {PgUp}
sendInput {Enter}
click 1222, 518 ; set f stop to max then to F5.6
sendInput {PgUp}
sendInput {Down 12}
sendInput {Enter}

Click 1501, 14
MouseMove 1565, 357
while ((A_Now >= beads2timeS) and (A_Now <= beads2timeE)) ; this is when second beads goes
{ ; spam beads
MouseClick, left, 1565, 363, 1, 100, D ; at the start 
}
MouseClick, left, 1565, 363, 1, 100, U ; at the end, click again to stop the continuous shooting mode

 ; apply filters audio warning

;set final filter settings
click 1472, 452 ; set single shot
SendInput {Down}
SendInput {Enter}
click 1222, 485 ; set shutter speed to 500 from default 125
sendInput {down 9}
sendInput {Enter}

Click 1501, 14
MouseMove 1565, 357

while ((A_Now >= filter2timeS) and (A_Now <= filter2timeE)) ; this is 3rd to 4th contact
{ ; send a picture click once a minute
MouseClick, left, 1565, 363, 1, 100
sleep 60000
}

return





As far as I can tell, none of the time controls worked.  I will need to go back to the original target_time AHK examples and see where I went wrong. 

The way the script runs now is that the mouse darts around, clicking buttons, changing settings, but the shutter is never fired because the "while" values are never true.  What I'd like to see would be that the script waits until the "while" values are true, executes, then moves to the next step.

I see a few possibilities to solve this problem:
  • Build nested "if...then" flow to catch all variations and wrap it all in a loop that waits a minute to try again.
  • Build a collection of separate AHK files and call them from the Windows Task Scheduler at the right times.

I think that the latter solution might be the easiest since I can test each step independently.




On review, I realize that the Task Scheduler won't stop a script at a certain time. 

So I'm back to the flow control within AHK.  I think that working with loops may be a better solution.

I'm going to try replacing the "while" with logic like this:

if (A_Now > filter1timeS)
 { 
 Loop
  { 
   MouseClick, left, 1565, 363, 1, 10
   sleep 60000
   if (A_Now >= filter1timeE)
    break
   if (A_Now < filter1timeE)
    continue
  }
 }



After playing with the loops, I see where the time controls failed - it was because of an extra "%" as this prevented the time values to be seen as a number.  Still, I rewrote the flow control using if and else and put the bits into subroutines.

Here's how it looks now and I'll try it out tonight:

#SingleInstance force
CoordMode, mouse, screen

; Get target time in a format we can:
;  - compare (with "<")
; < comparison should be safe as long as both are in the *exact* same format.
; time is 2305 format
; ====================================
; the values listed below are for the eclipse BE SURE TO UNCOMMENT
;filter1timeS = %A_YYYY%%A_MM%%A_DD%090643 ; 9:06:43 am
;filter1timeE = %A_YYYY%%A_MM%%A_DD%101830 ; 10:18:30 am 50 seconds to remove filters
;beads1timeS  = %A_YYYY%%A_MM%%A_DD%101920 ; 10:19:20 am 13 seconds to spam for beads
;beads1timeE  = %A_YYYY%%A_MM%%A_DD%101933 ; 10:19:33 am
;brackettimeS = %A_YYYY%%A_MM%%A_DD%101934 ; 10:19:34 am
;brackettimeE = %A_YYYY%%A_MM%%A_DD%102125 ; 10:21:25 am
;beads2timeS  = %A_YYYY%%A_MM%%A_DD%102135 ; 10:21:35 am 10 seconds to spam for beads
;beads2timeE  = %A_YYYY%%A_MM%%A_DD%102145 ; 10:21:45 am
;filter2timeS = %A_YYYY%%A_MM%%A_DD%102200 ; 10:22:15 am 30 seconds to apply filters
;filter2timeE = %A_YYYY%%A_MM%%A_DD%114102 ; 11:41:02 am

; ====================================
; the values listed below are for testing
filter1timeS = %A_YYYY%%A_MM%%A_DD%212000 ; 
filter1timeE = %A_YYYY%%A_MM%%A_DD%213000 ; 
beads1timeS  = %A_YYYY%%A_MM%%A_DD%213100 ; 
beads1timeE  = %A_YYYY%%A_MM%%A_DD%213115 ; 
brackettimeS = %A_YYYY%%A_MM%%A_DD%213120 ; 
brackettimeE = %A_YYYY%%A_MM%%A_DD%213420 ; 
beads2timeS  = %A_YYYY%%A_MM%%A_DD%213425 ; 
beads2timeE  = %A_YYYY%%A_MM%%A_DD%213435 ; 
filter2timeS = %A_YYYY%%A_MM%%A_DD%213510 ; 
filter2timeE = %A_YYYY%%A_MM%%A_DD%214000 ; 

; ====================================

; send filtersettings ; set single frame shooting with appropriate fstop and shutter speed 
click 1472, 452 ; set single shot
 SendInput {Down}
 SendInput {Enter}
click 1222, 485 ; set shutter speed to 4000 then down to 500 
 sendInput {PgUp}
 sendInput {Down 9}
 sendInput {Enter}
click 1222, 518 ; set f stop to max then to F5.6
 sendInput {PgUp}
 sendInput {Down 12}
 sendInput {Enter}


gosub, filter1

; remove filters audio warning


; send beadsettings ; set continuous shooting speed to Low with appropriate fstop and shutter speedset beads
click 1472, 452 ; set continuous
 SendInput {Down 2}
 SendInput {Enter}
click 1222, 485 ; set shutter speed to 4000
 sendInput {PgUp}
 sendInput {Enter}

gosub, beads1

; send bracketsettings
click 1472, 452 ; set single shot
 SendInput {Down}
 SendInput {Enter}
click 1222, 485 ; set shutter speed to 1/8 from 4000
 sendInput {Down 27}
 sendInput {Enter}
Click 1452, 491 ; set bracket mode on with 5 shots
 SendInput {Down 2}

gosub, totality

; beads2
; set beads ; set continuous shooting speed to Low with appropriate fstop and shutter speed
Click 1452, 491 ; set bracket mode off
 SendInput {Up 2}
click 1472, 452 ; set continuous
 SendInput {Down 2}
 SendInput {Enter}
click 1222, 485 ; reset shutter speed to 4000 max
 sendInput {PgUp}
 sendInput {Enter}
click 1222, 518 ; set f stop to max then to F5.6
 sendInput {PgUp}
 sendInput {Down 12}
 sendInput {Enter}

gosub, beads2

; apply filters audio warning

;set final filter settings
click 1472, 452 ; set single shot
 SendInput {Down}
 SendInput {Enter}
click 1222, 485 ; set shutter speed to 500 from earlier 4000
 sendInput {down 9}
 sendInput {Enter}

gosub, filter2


; ====================================

; subroutines

; ====================================

filter1:
; this is first to second contact
; send a picture click once a minute
Click 1501, 14 ; click on shutter control window bar to make active
MouseMove 1565, 363 ; position mouse over shutter button

if (A_Now >= filter1timeS)  
 { 
 Loop
  { 
   MouseClick, left, 1565, 363, 1, 10  ; click slowly to ensure shutter register
   sleep 60000 ; wait a minute
   if (A_Now >= filter1timeE)
    break
   if (A_Now < filter1timeE)
    continue
  }
 else
  { 
   Sleep 60000 ; wait a minute
   gosub, filter1 ; go back to the start of the subroutine
  }
 }
return

; ====================================

beads1:
; this is the beads1 subroutine
Click 1501, 14 ; click on shutter control window bar to make active
MouseMove 1565, 363 ; position mouse over shutter button
; press and hold shutter button while beads active
if (A_Now > beads1timeS)
 {
 Loop
  {
   MouseClick, left, 1565, 363, 1, 10, D ; Press and hold shutter button
   if (A_Now >= beads1timeE)
    {
    MouseClick, left, 1563, 363, 1, 10, U ; release shutter button
    Break
    }
   if (A_Now < beads1timeE)
    continue
  }
  else
  { 
   Sleep 1000 ; wait a second
   gosub, beads1 ; go back to the start of the subroutine
  }
 }
return
 
; ====================================

totality:
; this is the subroutine for totality with bracketing
Click 1501, 14
MouseMove 1565, 363
 
if (A_Now > brackettimeS)
 {
 Loop
  {
   MouseClick, left, 1565, 363, 1, 10
   Sleep 3000  ; click every 3 seconds
   if (A_Now >= brackettimeE)
    Break
   If (A_Now < brackettimeE)
    continue
  }
  else
    { 
   Sleep 1000 ; wait a second
   gosub, totality ; go back to the start of the subroutine
  }
 }
return

; ==================================== 
 
beads2:
; this is the second beads routine

Click 1501, 14
MouseMove 1565, 357

if (A_Now > beads2timeS)
 {
 Loop
  {
   MouseClick, left, 1565, 363, 1, 10, D ; Press and hold shutter button
   if (A_Now >= beads2timeE)
    {
    MouseClick, left, 1563, 363, 1, 10, U ; release shutter button
    Break
    }
   if (A_Now < beads2timeE)
    continue
  }
  else
  { 
   Sleep 1000 ; wait a second
   gosub, beads2 ; go back to the start of the subroutine
  }
 }
return

; ====================================
   
filter2:
; this is from 3rd to 4th contact
Click 1501, 14
MouseMove 1565, 357

if (A_Now >= filter2timeS)  
 { 
 Loop
  { 
   MouseClick, left, 1565, 363, 1, 10  ; click slowly to ensure shutter register
   sleep 60000 ; wait a minute
   if (A_Now >= filter2timeE)
    break
   if (A_Now < filter2timeE)
    continue
  }
 else
  { 
   Sleep 1000 ; wait a second
   gosub, filter2 ; go back to the start of the subroutine
  }
 }
return

; ====================================


exit

Tuesday, August 15, 2017

Eclipse Hardware and Software Changes

Last night I needed to test some behavior of the tethering solutions for the cameras to check responsiveness and the duration required for bracketing.  I'm glad that I did this effort because it was quickly apparent that the open-source software for the Pentax cameras is not stable enough to rely on it for the project.

I tried:
  • PK Tether:
    Freezing and unstable when several pictures were in the queue and changing settings on the fly
  • PK Triggercord:
    Was never able to get it running properly because of GTK theme issues
  • Gphoto2:
    Was able to install on Windows, but unable to control the camera via CLI

My fallback method was to install the original tethering software that was developed for the Pentax K10D.  Glad that I have a few of these bodies still functioning!

This changes the selected cameras to the K1 with the 400mm EDIF lens and the K10D with the 300mm lens.  I will continue to use the K5IIs bodies to shoot video and people scenes leading up to and during the eclipse.

The current lens configuration weighs 28 lbs -- right at the limit for the GM8.  I'm going to use this mount because I'm limited for space in the vehicle rather than switch to the G11.

I checked the images from the glass solar filters and was disappointed by the softness.  I've become spoiled by viewing the sun with the Herschel Wedge.  On advice by Anthony DLC, I'm going to cut the Baader film for the cameras and will retire the glass filters eventually.

Tuesday, August 8, 2017

How I plan to shoot the eclipse

I spent some time on the weekend to assemble the cameras into position to check balance and ability to all align to the same point.