def initSteppers(indiclient, telescope, serialport, backlashCorrection): print ("Initializing steppers") #Disconnect telescope mount from INDI to free up serial port for Alt/Az adjustments indi.disconnectScope(indiclient, telescope) #Increase both Az & Alt by approximately 16-steps LX200.sendCommand(f":MAZ{backlashCorrection[0]}#", serialport) LX200.sendCommand(f":MAL{backlashCorrection[1]}#", serialport) time.sleep(3) #Re-connect telescope mount to INDI before disconnecting from the INDI server indi.connectScope(indiclient, telescope) return
def polarcalibrate(axis, indiclient, iteration, observing_location, telescope, ccd, serialport, radius, exposure, calibration_distance, RA, DEC, backlashCorrection, pixel_resolution): #iers.conf.auto_download = False #iers.conf.auto_max_age = None if (iteration % 2) == 0: backlashCorrection[0] = backlashCorrection[0] * -1 backlashCorrection[1] = backlashCorrection[1] * -1 calibration_distance = calibration_distance * -1 #Initialize steppers to a known backlash position initSteppers(axis, indiclient, telescope, serialport, backlashCorrection) p1RA, p1DEC, p1Time = captureSolve(indiclient, RA, DEC, radius, exposure, telescope, ccd, blobEvent, pixel_resolution, "altazCalibration1.fits") p1Time = datetime.utcfromtimestamp(p1Time) #Disconnect telescope mount from INDI to free up serial port for Alt/Az adjustments print(f"Disconnecting {telescope} from INDI server") indi.disconnectScope(indiclient, telescope) print("Disconnected.") #Adjust alt/az axis if axis.lower() == "az": print(f"Adjusting azimuth by {calibration_distance} arcminutes") LX200.sendCommand(f":MAZ{calibration_distance}#", serialport) elif axis.lower() == "alt": print(f"Adjusting altitude by {calibration_distance} arcminutes") LX200.sendCommand(f":MAL{calibration_distance}#", serialport) waitForMotors( serialport ) #FUTURE - poll the OAT for motor status and automatically resume calibration once they have stopped moving #input("When Alt/Az has stopped moving, press Enter to continue.") #time.sleep(40) #Re-connect telescope mount to INDI before disconnecting from the INDI server print(f"Reconnecting {telescope} to INDI server") indi.connectScope(indiclient, telescope) p2RA, p2DEC, p2Time = captureSolve(indiclient, RA, DEC, radius, exposure, telescope, ccd, blobEvent, pixel_resolution, "altazCalibration2.fits") p2Time = datetime.utcfromtimestamp(p2Time) p1 = SkyCoord(p1RA, p1DEC, frame='itrs', unit='deg', representation_type='spherical', obstime=Time(p1Time)) p2 = SkyCoord(p2RA, p2DEC, frame='itrs', unit='deg', representation_type='spherical', obstime=Time(p2Time)) p1AzAlt = p1.transform_to( AltAz(obstime=Time(p1Time), location=observing_location)) p2AzAlt = p2.transform_to( AltAz(obstime=Time(p1Time), location=observing_location)) print( f"First capture Az./Alt.: {p1AzAlt.az.to_string(u.hour, precision=2)}/{p1AzAlt.alt.to_string(u.deg, precision=2)}." ) print( f"Second capture Az./Alt.: {p2AzAlt.az.to_string(u.hour, precision=2)}/{p2AzAlt.alt.to_string(u.deg, precision=2)}." ) #Calculate delta between solves #Normalize the azimuth values to between -180 and 180 degrees prior to determining offset. deltaAz = (((p2AzAlt.az.deg + 180) % 360 - 180) - ((p1AzAlt.az.deg + 180) % 360 - 180)) * 60 deltaAlt = (p2AzAlt.alt.deg - p1AzAlt.alt.deg) * 60 return (deltaAz, deltaAlt)
#Execute polar alignment routine to capture and solve three times 30 degrees apart p1, p1Time = slewCaptureSolve(indiclient, (targetRA % 360), targetDEC, radius, exposure, telescope, ccd, blobEvent, pixel_resolution, "capture1.fits") p2, p2Time = slewCaptureSolve(indiclient, ((targetRA+30) % 360), targetDEC, radius, exposure, telescope, ccd, blobEvent, pixel_resolution, "capture2.fits") p3, p3Time = slewCaptureSolve(indiclient, ((targetRA+60) % 360), targetDEC, radius, exposure, telescope, ccd, blobEvent, pixel_resolution, "capture3.fits") #Calculate capture time based on the average timestamps of each image observing_time = datetime.utcfromtimestamp(mean((p1Time, p2Time, p3Time))) print (f"Time of captures is {observing_time} (UTC).") #Calculate polar alignment error result = platesolve.polarCalc(mylat, mylong, myelev, observing_time, p1, p2, p3) print(f"Azimuth error correction is: {result[0]:.4f} arcminutes.") print(f"Altitude error correction is: {result[1]:.4f} arcminutes.") if not nomove: #Disconnect telescope mount from INDI to free up serial port for Alt/Az adjustments print (f"Disconnecting {telescope} from INDI server") indi.disconnectScope(indiclient, telescope) print ("Disconnected.") #Adjust alt/az axis print ("Adjusting altitude/azimuth axes.") platesolve.adjustAltAz(result, serialport, backlashCorrection) #Re-connect telescope mount to INDI before disconnecting from the INDI server indi.connectScope(indiclient, telescope) #Disconnect from indi server indi.indiserverDisconnect(indiclient) print (f"Polar alignment took {time.strftime('%Mm%Ss', time.gmtime(time.time() - startTime))}.")