Jump to content

SkySurveyBanner.jpg.21855908fce40597655603b6c9af720d.jpg

Maxim DL Scripts


russellhq

Recommended Posts

I've started looking into writing scripts for Maxim DL but Google is a bit thin on the ground with examples. My main interest is writing one that uses FocusMax to refocus during an imaging session.

I've joined some of the Yahoo groups and read through Maxim DL and FocusMax help files and example scripts but i'm not making much progress.

Does anyone know of a good resource or has examples they care to share?

Also, got a book from amazon, VBScript Programmer's Reference (Programmer to Programmer), but at over 700 pages long I imagine it's going to be a dry read.

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 weeks later...

I've done a bit of stuff with Maxim scripts (usually scripting maxim from an external programme). I don't have any examples to hand, but I always trip myself up by thinking it's more complex than it is! The interface and calling structure is very simple -- so much so it usually seems to me that it shouldn't work :-\

Link to comment
Share on other sites

Thanks.

I've been putting a bit a work into this and have a few things working at the moment. What I'm struggling with is finding a better (free) editor than Notepad!

Also, I've tried looking for the ASCOM properties and methods to call in VBscript, but don't see anything on their website. Maybe I'm missing the obvious!

Link to comment
Share on other sites

So here's my first attempt at a script. It takes the temperature reading from the focuser (via FocusMax) and compares it against the previous reading. If there is a difference greater than 1 degree in either direction, then it runs FocusMax aquirestar routine. This script can be added to Maxim to run after each image is taken.

Option ExplicitConst fsoForReading = 1Const fsoForWriting = 2Dim FMx Dim FMxFocDim PositionDim SysNameDim TemperatureDim PreviousTemperatureSet FMx = CreateObject("FocusMax.FocusControl")Set FMxFoc = CreateObject("FocusMax.Focuser")SysName =  FMx.SystemFileNameWScript.Sleep 8000PreviousTemperature = CDbl(LoadStringFromFile("C:temperature.txt"))Temperature = CDbl(FMxFoc.Temperature)DoFocus(ReFocusCheck(Temperature, PreviousTemperature))Set FMxFoc = nothingSet FMx = nothingSub DoFocus(Focus)If Focus Then    SaveStringToFile "C:\temperature.txt", Temperature    FMx.AcquireStarElseEnd IfEnd SubSub SaveStringToFile(filename, text)Dim fso, fSet fso = CreateObject("Scripting.FileSystemObject")Set f = fso.OpenTextFile(filename, fsoForWriting)f.Write textf.CloseEnd SubFunction ReFocusCheck(OldTemperature, NewTemperature)    If NewTemperature >= (OldTemperature + 1) then        ReFocusCheck = True        Msgbox "Temperature Changed"    Else        If NewTemperature <= (OldTemperature - 1) then            ReFocusCheck = True            Msgbox "Temperature Changed"        Else            ReFocusCheck = False            MsgBox "No Change"        End If    End IfEnd FunctionFunction LoadStringFromFile(filename)Dim fso, fSet fso = CreateObject("Scripting.FileSystemObject")Set f = fso.OpenTextFile(filename, fsoForReading)LoadStringFromFile = f.ReadAllf.CloseEnd Function
Link to comment
Share on other sites

This is way way out of my league.. But; I can see the value in it, is it a case of loading it into maxim and letting it run?

Ray

In Maxim, click the camera control and then click autosave. Then in the autosave window, for each slot there is a script setting that executes after every image is taken. You would load the script here and let it do its job.

Link to comment
Share on other sites

Here's a couple more scripts I've been working on for FocusMax. These are centred around the AquireStar method.  What I was aiming for was to have 2 scripts, the first would be run before focusing an LRGB image and the second would run before focusing a narrowband image. The scripts change the star magnitude search range for AquireStar and also changes the exposure time for the plate solve.

First is LRGB

'LRGB AquireStar setup parameters
Option Explicit
Dim FMx 
Dim FMxFoc
Dim Position
Dim SysName

Set FMx = CreateObject("FocusMax.FocusControl")
Set FMxFoc = CreateObject("FocusMax.Focuser")

SysName =  FMx.SystemFileName

FMx.AcquireStarMinMagTgtStar = 3.5
FMx.AcquireStarMaxMagTgtStar = 7.5
FMx.AcquireStarSolveExposure = 5
Set FMxFoc = nothing
Set FMx = nothing

Second is Narrowband

'Narrowband AquireStar setup parameters
Option Explicit
Dim FMx 
Dim FMxFoc
Dim Position
Dim SysName

Set FMx = CreateObject("FocusMax.FocusControl")
Set FMxFoc = CreateObject("FocusMax.Focuser")

SysName =  FMx.SystemFileName

FMx.AcquireStarMinMagTgtStar = 1
FMx.AcquireStarMaxMagTgtStar = 5
FMx.AcquireStarSolveExposure = 10
Set FMxFoc = nothing
Set FMx = nothing

Note that MinMag and MaxMag do not mean minimum brightness and maximum brightness as the help file would lead you to believe! This was my first assumption and cause all sorts of issues, namely AquireStar could not find a star!

Link to comment
Share on other sites

I've been working on a script to automate plate solving of captured images so I can use the astrometry mode when aligning/registering images.

The script can be run after the each capture or can be run on a collection of open documents. The script will loop through the collection of  open documents, plate solve each, save as 16bit FIT over existing file and close. The script need the full version of PinPoint to work.

Option Explicit

Dim Apps
Dim AllDocs
Dim lngIndex

Set Apps = CreateObject("MaxIm.Application")	 	
Set AllDocs = Apps.Documents

For lngIndex = 1 to AllDocs.Count
    With AllDocs.Item(lngIndex)
      .PinPointSolve
    Do
    loop while .PinPointStatus = 3
      .SaveFile .FilePath, 3, FALSE, 1
      .Close
    End With
Next
Link to comment
Share on other sites

I've been working on an alternative plate solve routine to PinPoint. I've been using PlateSolve2 and have created the following script which uses PlateSolve2 to sync the telescope from an image captured in MaxIm

Option Explicit
Dim APMfilename ' PlateSolve2 solved file filename
Dim tRa 'Telescopes right ascension
Dim tDec 'Telescopes declination
Dim sRa 'Solved right ascension J2000
Dim sDec 'Solved declination J2000
Dim DecNow 'Solved declination JNOW
Dim RaNow ' Solved right ascension JNOW
Dim imagescale 'Holds you image's arcsecperpixel value
Dim fpPlateSolve ' Filepath of PlateSolve2 executable
Dim TelescopeDriver 'ASCOM telescope driver name 
Dim FSO 'File system object
Dim LST 'Local Sidereal Time

'''''''''''''''''''''''''Define your constants here''''''''''''''''''''''''''''''''''''''''''
fpPlateSolve = "C:\PlateSolve2.28\PlateSolve2.exe" 'Set this to your platesolve2 filepath
imagescale = 7.2 'Set value to your image scale. Upload file to astrometry.net if unknown.
TelescopeDriver = "EQMOD.Telescope" 'Set this to your ASCOM telescope driver
'TelescopeDriver = GetASCOMtelescopeDriverName ' Use the chooser to find your TelescopeDriver string
'''''''''''''''''''''''''Define your constants here''''''''''''''''''''''''''''''''''''''''''

ReadTelescopePosition
PlateSolve
ReadAPMFile (APMfilename)
PrecessTarget
SyncTelescope

Sub ReadTelescopePosition 'Gets current telescope position for image centre in Ra and Dec JNOW
   Dim Tel ' ASCOM telescope
   Set Tel = Nothing
   Set Tel = CreateObject(TelescopeDriver)
	tRa = Tel.RightAscension 'Right ascension, units of decimal hours
	tDec = Tel.Declination 'Declination, units of decimal degrees
	Set Tel = Nothing
End Sub

Sub PlateSolve 'Plate solve open document in Maxim
   Dim aMaxIm 'MaxIm application object
   Dim dMaxIm 'MaxIm document object
   Dim PS2 'Shell object to run executable
   Dim aArguments(6) 'Array for PlateSolve2 arguments
   
   Set PS2 = CreateObject("WScript.Shell")
   Set aMaxIm = CreateObject("MaxIm.Application")
   'Set dMaxIm = CreateObject("MaxIm.Document")
   
   aArguments(0) = RaToRadians (tRa) 'Right ascension in radians
   aArguments(1) = D2R (tDec) 'Declination in radians
   aArguments(2) = PixelToRadians (imagescale, aMaxIm.CurrentDocument.XSize) ' x dimension in radians
   aArguments(3) = PixelToRadians (imagescale, aMaxIm.CurrentDocument.YSize) ' y dimension in radians
   aArguments(4) = 999 ' Number of regions to search
   aArguments(5) = aMaxIm.CurrentDocument.FilePath
   aArguments(6) = fpPlateSolve 'PlateSolve2 executable file path
   LST = LocalSiderealTime 'Set LST
	PS2.Run BuildPlateSolve2ArgString(aArguments), 0, True
	APMfilename = BuildAPMfilename (aMaxIm.CurrentDocument.FilePath)'Convert filename to apm
   
End Sub

Sub ReadAPMFile (fName) 'Parses PlateSolve2 apm file
	Const ForReading = 1
	Dim objFSO
	Dim objFile
	Dim strContents
	Dim strLine
	Dim arrFields
	
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	Set objFile = objFSO.OpenTextFile(fName, ForReading)

	strLine = objFile.ReadLine
	arrFields = Split(strLine, ",")	
	objFile.Close
	sRa = Radians2Ra (arrFields(0))
	sDec = R2D (arrFields(1))
   Set objFSO = Nothing
   Set objFile = Nothing
   
End Sub

Sub PrecessTarget 'Precesses passed coordinates from J2000 to JNOW apparent
	Dim trn
	Set trn = CreateObject("ASCOM.Astrometry.Transform.Transform")
	trn.SetJ2000 sRa, sDec
	trn.refresh
	RaNow = trn.RAApparent 'Units of decimal hours
	DecNow = trn.DecApparent 'Units of decimal degrees
	Set trn = nothing
End Sub

Sub SyncTelescope 'syncs telescope to passed coordinates
   Dim Tel ' ASCOM telescope
   Dim HA ' Hour Angle
   Set Tel = Nothing
   Set Tel = CreateObject(TelescopeDriver)
   'PrintLn(RaNow)
   'PrintLn(DecNow)
   Tel.SyncToCoordinates RaNow, DecNow 'JNOW coordinates
   
   If LST - RaNow < 0 Then
	HA = LST - RaNow + 24
   Else
	If LST - RaNow > 24 Then
	HA = LST - RaNow - 24
	Else
	HA = LST - RaNow
	End If
   End If
   SaveStringToFile "point1.txt", HA & "," & DecNow
   'Tel.SlewToCoordinates RaNow, DecNow 'JNOW coordinates
   'Tel.SyncToCoordinates sRa, sDec 'J2000 coordinates
   'Tel.SlewToCoordinates sRa, sDec 'J2000 coordinates
   Set Tel = Nothing
End Sub

Function GetASCOMtelescopeDriverName 'Opens ASCOM chooser dialogue and returns driver string
   Dim ASCOMchooser
   Set ASCOMchooser = CreateObject("ASCOM.Utilities.Chooser")
   GetASCOMtelescopeDriverName=ASCOMchooser.Choose("")
   MsgBox "Your driver string is:" & vbCr & GetASCOMtelescopeDriverName
End Function

Function PixelToRadians(scale, pixels) 'Converts image pixel size to Radians
   PixelToRadians=D2R(pixels*scale/60/60)
End Function

Function RaToRadians(val) 'Converts Right Ascension hours to Radians
   val = val*15 ' Convert hours to degrees
   RaToRadians = D2R(val) ' Convert degrees to radians
End Function

Function Radians2Ra(val) 'Converts Radians to Right Ascension hours
   Radians2Ra=R2D(val)/15
End Function 

Function D2R(val) 'Converts decimal degrees to Radians
    D2R = val*Pi/180
End Function

Function R2D(val) 'Converts Radians to decimal degrees
    R2D = val*180/Pi
End Function

Function Pi() ' Returns Pi
    Pi = 4 * Atn(1)
End Function

Function Degrees2DMS(ByVal val) 'Converts decimal degrees to D:M:S format
   Dim AsUtil 'ASCOM Utilities object
   Set AsUtil = CreateObject("ASCOM.Utilities.Util")
   Degrees2DMS = AsUtil.DegreesToDMS(val, "D ", "M ", "S ", 0)
End Function

Function Degrees2HMS(ByVal val) 'Converts decimal degrees to H:M:S format
   Dim AsUtil 'ASCOM Utilities object
   Set AsUtil = CreateObject("ASCOM.Utilities.Util")
   Degrees2HMS = AsUtil.DegreesToHMS(val, "H ", "M ", "S ", 0)
End Function

Function BuildPlateSolve2ArgString (strArg) 'Builds executable string for Shell function
   Dim i
   BuildPlateSolve2ArgString = strArg(6)&" "&strArg(0)
   For i = 1 to 5
      BuildPlateSolve2ArgString = BuildPlateSolve2ArgString & ","&strarg(i)
   Next
End Function

Function BuildAPMfilename(ByVal strImagePath)
	BuildAPMfilename = getFilepath(strImagePath) & "\" & getFilename(strImagePath) & ".apm"
End Function

Function getFilename(ByVal strImagePath) 'Strips path and extension
	Dim objFSO
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	getFilename = objFSO.GetBasename(strImagePath)
	Set objFSO = Nothing
End Function

Function getFilepath(ByVal strImagePath) 'Strips filename and extension
	Dim objFSO
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	getFilepath = objFSO.GetParentFolderName(strImagePath)
	Set objFSO = Nothing
End Function

Sub SaveStringToFile(filename, text) 'saves text to file
    Dim fso, f
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.OpenTextFile(filename, 2)
    f.Write text
    f.Close
	Set f = Nothing
	Set fso = Nothing
End Sub

Function PrintLn (val)
	Dim fso
	Dim stdout
	Set fso = CreateObject ("Scripting.FileSystemObject")
	Set stdout = fso.GetStandardStream (1)
	stdout.WriteLine val
	Set fso = nothing
	Set stdout = nothing
End Function

Function LocalSiderealTime
   Dim Tel ' ASCOM telescope
   Dim TelescopeDriver 'Telescope driver
   Dim sTime
   Set Tel = Nothing
   TelescopeDriver = "EQMOD.Telescope" 
   Set Tel = CreateObject(TelescopeDriver)
   sTime = Tel.SiderealTime
   Set Tel = Nothing
   LocalSiderealTime = sTime
End Function
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. By using this site, you agree to our Terms of Use.