Thursday, June 9, 2011

Automated Astrophotography with Python - Part 2c

TELESCOPE CONTROL
The last features to add to the 'cMount' class are the ability to control pointing of the telescope and to synchronize the control system to a particular point in the sky. All these functions are found in the RASCOMTele class of the Sky6. As in previous posts, instead of showing the complete 'cMount' class listing, here I show only the changes to the listing presented in the previous post. The first listing shows the one new line that must be added to the class constructor ('__init__' method) to create an instance of the Sky6 RASCOMTele class. Here is the listing for that change:
self.__MOUNT = win32com.client.Dispatch("TheSky6.RASCOMTele")
The next listing shows the three new methods added to 'cMount' that call methods from the Sky6 RASCOMTele class:
def slewToObject(self,obj,delay=2.0):
    if not self.findObject(obj):
        coords = self.getCoordinates()
        print "Slewing telescope to %s..." % obj
        JnowRA = self.__UTIL.ConvertAngleToDMS(coords['RA Now'])
        print "JNow RA : %02dh %02dm %0.2fs" % (JnowRA[0],JnowRA[1],
                                                JnowRA[2])
        JnowDEC = self.__UTIL.ConvertAngleToDMS(coords['DEC Now'])
        print "JNow DEC: %02d deg %02d' %0.2f\"" % (JnowDEC[0],JnowDEC[1],
                                                    JnowDEC[2])
        try:
            self.__MOUNT.SlewToRaDec(coords['RA Now'],coords['DEC Now'],obj)
        except:
            print "ERROR: During slew to Object"
            return ERROR
        else:
            print "Done slewing!"
            # delay (default = 2.0 seconds)
            time.sleep(delay)
            return NOERROR
    else:
        print "%s could not be found." % obj
        return ERROR
    

def slewToAzAlt(self,azimuth,altitude,name,delay=2.0):
    print "Slewing to Azimuth: %0.1f and Altitude: %0.1f..." % (azimuth,
                                                                altitude)
    try:
        self.__MOUNT.SlewToAzAlt(azimuth,altitude,name)
    except:
        print "ERROR: During slew to altitude/azimuth position"
        return ERROR
    else:
        print "Done slewing!"
        # delay (default = 2.0 seconds)
        time.sleep(delay)
        return NOERROR

def syncToObject(self,RA,Dec,Obj):
    self.__MOUNT.Sync(RA,Dec,Obj)
The first new method is 'slewToObject()'. This method attempts to locate the object in the Sky6's database. If successful, the current epoch equatorial coordinates are extracted and printed to screen. The method then calls the 'RASCOMTele' method 'SlewToRaDec()' in a try, except, else block to trap any exceptions. After the slew completes, a delay (default of 2 sec) is entered before the method returns to the calling routine. Similarly, the 'slewToAzAlt()' method calls the 'RASCOMTele' method 'SlewToAzAlt()' in a try, except, else block again to trap any exceptions. The final new method is 'syncToObject()' and calls the 'Sync()' method of 'RASCOMTele' to synchronize the control system to the specified coordinates.

cMOUNT UNIT TEST
The following listing shows the unit test code for this version of the 'cMount' class. After creating an instance of the class, the user is prompted to enter the name of an object. If a valid object name is entered, the simulator is commanded to slew to the object. This test is then repeated for a second object. Next, the user is prompted to enter the name of another object. This object is then located in the database and the telescope control system is synced to the location of that object. (The telescope pointing "bull's eye" jumps to the location of the object.) Finally, the user is prompted to enter azimuth and altitude values. Assuming valid values have been entered, the simulator will slew to the location specified by the entered azimuth and altitude.
if __name__ == "__main__":
    
    # create an instance of the cMount object
    testMount = cMount()

    # prompt for name of object to locate
    print
    obj = raw_input("Enter first object to slew to: ")
    # test slewToObject()
    testMount.slewToObject(obj)

    # prompt for name of object to locate
    print
    obj = raw_input("Enter second object to slew to: ")
    # test slewToObject()
    testMount.slewToObject(obj)

    # prompt for name of object for sync
    print
    obj = raw_input("Enter object to sync to: ")
    if not testMount.findObject(obj):
        coords = testMount.getCoordinates()
        # test syncToObject()
        print "Syncing control system to %s" % obj
        testMount.syncToObject(coords['RA Now'],coords['DEC Now'],obj)
    else:
        print "%s could not be found." % obj

    # prompt for azimuth and altitude for slew
    print
    azimuth = raw_input("Enter azimuth for slew: ")
    azimuth = float(azimuth)
    altitude = raw_input("Enter altitude for slew: ")
    altitude = float(altitude)

    # test slewToAzAlt()
    testMount.slewToAzAlt(azimuth,altitude,"park")
RUNNING THE SCRIPT
In order to test this version of the 'cMount' class you must first load the Sky6 and manually connect the telescope control system to the simulator. This is done by clicking on the 'Telescope' pull-down menu tab then selecting the 'Setup...' option. In the 'Telescope Setup' dialog box, select 'Simulator' in the selection box under 'Name:'. Click on the 'Close' button then re-click the 'Telescope' pull-down menu tab then select the 'Server Settings...' option. In the 'Server Settings' dialog box, make sure the 'Allow sync' and 'Allow goto' boxes are checked then click the 'OK' button. (Note: the changes to the 'Telescope Setup' and 'Server Settings' dialog boxes only need to be made the first time the simulator is used.) The connection to the simulator is then made by clicking on the 'Telescope' pull-down menu tab then hovering over the 'Link' option. Move the mouse pointer over to and click on 'Establish' to make the connection. (You can also just click on the green telescope icon on the menu bar.) After a moment, the white bull's eye will appear that indicates the current location of the scope control system. The python script can now be executed from the IDE in the normal manner. The source listing for 'cMount' can be downloaded from cMount_2c.zip. Experiment with the script by running it multiple times and selecting different objects for The Sky6 to locate, slew to, and sync to. (When testing is complete, click on the red telescope icon the menu bar to terminate the connection.)

WHAT'S NEXT?
This post completes discussion of the 'cMount' class (although additional methods may be added to the class in later posts). In the next post, I will create a script that creates an instance of the 'cMount' class and an instance of the 'cCamera' class to demonstrate how these classes can be used in combination to generate practical scripts for slewing and imaging of objects.

CLICK HERE FOR NEXT POST IN THIS SERIES

No comments:

Post a Comment