# $Header: https://oberon.oapd.inaf.it/shins/trunk/shins/src/scripts/templates/tpl/testOB_tcs_PresetTelescope.py 3808 2022-01-25 12:43:04Z depa $

import sys
import Ice
from util.shinsLogger import logger
from util import exception
from util import variables as uvars
from util import functions as ufun
from shinsapp import SHINSApp
import Basda

# cp /home/shinsmgr/shins/src/scripts/templates/tpl/testOB_tcs_PresetTelescope.py /opt/tan/lib/python/site-packages/shins/templates/tpl/

class testOB_tcs_PresetTelescope(SHINSApp):

    @exception.handler_for_run
    def run(self, ins_s=None, det_s=None, tel_s=None, rtc_s=None, **kwargs):
        '''Try some tcs command
        '''
        logger.info(__name__)

        self.status = uvars.EXIT_SUCCESS
            
        obsController = self.obsController

        #######################################################
        #################    Preset Telescope   ###############
        #######################################################

        tel_s = {
            "CoordinateSystem":"RADEC",
            "Epoch":"2022.5",
            "Equinox": "j2000",
            "OBJEQUIN":"2000",

            # "OBJRA":"0.41",
            # "GSRA":"0.402",
            # "AORA":"0.43",
            # "OBJDEC":"1.51",
            # "GSDEC":"1.502",
            # "AODEC":"1.53",

            "OBJECTNAME":"M31",
            "OBJRA":"310.3579",
            "OBJDEC":"45.2803",

            "PMRA":"0",
            "PMDEC":"0",
            "PMGSRA":"0",
            "PMGSDEC":"0",
            "PMAORA":"0",
            "PMAODEC":"0",
            "BinocularFlag":"OFF",
            #"TelescopeMode": "TRACK",
            "TelescopeMode": "ADAPTIVEACE_TRACK",
            "TelescopeSide": "LEFT",
            "AOMODE":"REPOINT"
        }

        tel_s["OBJECTNAME"] = "Deneb"
        objra_degree = 15*(20 + 41/60. + 27.41/3600.)
        tel_s["OBJRA"] = str(objra_degree*3.141592653/180)
        objdec_degree = 45 + 16/60. + 40.4/3600.
        tel_s["OBJDEC"] = str(objdec_degree*3.141592653/180)
        
        tel_s["OBJECTNAME"] = "Undefined"
        objra_degree = 15*(2 + 36/60. + 6.07/3600.)
        tel_s["OBJRA"] = str(objra_degree*3.141592653/180)
        objdec_degree = 0 + 6/60. + 46.2/3600.
        tel_s["OBJDEC"] = str(objdec_degree*3.141592653/180)

        tel_s["OBJECTNAME"] = "HIP 109268"
        objra_degree = 15*(22 + 8/60. + 15.41/3600.)
        tel_s["OBJRA"] = str(objra_degree*3.141592653/180)
        objdec_degree = -(46 + 57/60. + 29.5/3600.)
        tel_s["OBJDEC"] = str(objdec_degree*3.141592653/180)

        tel_s["OBJECTNAME"] = "Fomalhaut"
        objra_degree = 15*(22 + 57/60. + 40.14/3600.)
        tel_s["OBJRA"] = str(objra_degree*3.141592653/180)
        objdec_degree = -(29 + 37/60. + 14.5/3600.)
        tel_s["OBJDEC"] = str(objdec_degree*3.141592653/180)

        tel_s["OBJECTNAME"] = "HIP 33165" # Eruptive variable star in carnis major
        objra_degree = 15*(6 + 54/60. + 11.59/3600.)
        tel_s["OBJRA"] = str(objra_degree*3.141592653/180)
        objdec_degree = -(23 + 55/60. + 42.4/3600.)
        tel_s["OBJDEC"] = str(objdec_degree*3.141592653/180)

        tel_s["OBJECTNAME"] = "M3"
        objra_degree = 15*(13 + 42/60. + 12.08/3600.)
        tel_s["OBJRA"] = str(objra_degree*3.141592653/180)
        objdec_degree = 28 + 22/60. + 48.4/3600.
        tel_s["OBJDEC"] = str(objdec_degree*3.141592653/180)

        tel_s["OBJECTNAME"] = "Gumball GC"
        objra_degree = 15*(16 + 47/60. + 15.41/3600.)
        tel_s["OBJRA"] = str(objra_degree*3.141592653/180)
        objdec_degree = -( + 56/60. + 54.1/3600.)
        tel_s["OBJDEC"] = str(objdec_degree*3.141592653/180)

        tel_s["OBJECTNAME"] = "Leo Triplet"
        objra_degree = 15*(11 + 19/60. + 50.0/3600.)
        tel_s["OBJRA"] = str(objra_degree*3.141592653/180)
        objdec_degree = 13 + 17/60. + 0.0/3600.
        tel_s["OBJDEC"] = str(objdec_degree*3.141592653/180)

        tel_s["OBJECTNAME"] = "M31"
        objra_degree = 15*(0 + 42/60. + 44.05/3600.)
        tel_s["OBJRA"] = str(objra_degree*3.141592653/180)
        objdec_degree = 41 + 15/60. + 54.5/3600.
        tel_s["OBJDEC"] = str(objdec_degree*3.141592653/180)

        tel_s["OBJECTNAME"] = "Galaxy cluster in Coma Berenices"
        objra_degree = 15*(12 + 59/60. + 52.26/3600.)
        tel_s["OBJRA"] = str(objra_degree*3.141592653/180)
        objdec_degree = 27 + 57/60. + 54.1/3600.
        tel_s["OBJDEC"] = str(objdec_degree*3.141592653/180)

        tel_s["OBJECTNAME"] = "M81-Area"
        objra_degree = 15*(14 + 24/60. + 58.3/3600.)
        tel_s["OBJRA"] = str(objra_degree*3.141592653/180)
        objdec_degree = 69 + 12/60. + 6.0/3600.
        tel_s["OBJDEC"] = str(objdec_degree*3.141592653/180)
        tel_s["OBJECTNAME"] = "Pleiades"
        objra_degree = 15*(3 + 47/60. + 35.1/3600.)
        tel_s["OBJRA"] = str(objra_degree*3.141592653/180)
        objdec_degree = 24 + 15/60. + 29.4/3600.
        tel_s["OBJDEC"] = str(objdec_degree*3.141592653/180)


        tel_s["OBJECTNAME"] = "Stella Passante vicino zenit"
        objra_degree = 15*(15 + 25/60. + 11.1/3600.)
        tel_s["OBJRA"] = str(objra_degree*3.141592653/180)
        objdec_degree = (29 +0/60. + 00.5/3600.) # Max ~ 32 7 0
        tel_s["OBJDEC"] = str(objdec_degree*3.141592653/180)

        logger.info("ObjectName : %s; Obj RA : %s; Obj DEC : %s" % (tel_s["OBJECTNAME"], tel_s["OBJRA"], tel_s["OBJDEC"]))

        logger.info("Running: PresetTelescope")
        status = obsController.PresetTelescope(tel_s)
        ufun.error_handler(status, "PresetTelescope")


#        logger.info("Running: trackingStartHere")
#        status = obsController.trackingStartHere()
#        logger.info("trackingStartHere returned : %d" % status)
    
# cp /home/shinsmgr/shins/src/scripts/templates/tpl/testOB_tcs_PresetTelescope.py /opt/tan/lib/python/site-packages/shins/templates/tpl/


