コード例 #1
0
ファイル: FlatManager.cs プロジェクト: rrskybox/Humason
        public void TakeFlats()
        {
            //Pulls flat requests from the flat stack (file) and services accordingly
            LogEvent       lg          = new LogEvent();
            SessionControl openSession = new SessionControl();

            lg.LogIt("Checking for flat requests");

            //Opt out if no flats to look at
            if (!HaveFlatsToDo())
            {
                lg.LogIt("No flats to do");
                return;
            }
            else
            {
                lg.LogIt("Have flats do: Starting Flats");
            }

            //Fire off flatman if enabled, otherwise point the telescope up for dawn or dusk flats
            // Sort flats by filter and source (i.e. twightlight or dawn)
            if (openSession.IsFlatManEnabled)
            {
                //Stage the mount to the flatman
                FlatMan flmn = new FlatMan();
                lg.LogIt("Staging FlatMan");
                bool stgResult = flmn.FlatManStage();
                if (!stgResult)
                {
                    lg.LogIt("FlatMan Staging Failed -- aborting flats");
                    return;
                }
                //If Manual Setup is selected, then pause for user to position the FlatMan for flats
                //  Disconnect imaging devices before attaching panel, then reconnect afterwards
                //    this keeps the SBIG driver from freaking out when the guider USB is hot swapped
                //    with the FlatMan USB (Build 182+)
                if (openSession.IsFlatManManualSetupEnabled)
                {
                    lg.LogIt("Pausing to attach FlatMan panel");
                    lg.LogIt("Disconnecting imaging devices");
                    TSXLink.Connection.DisconnectDevice(TSXLink.Connection.Devices.Camera);
                    TSXLink.Connection.DisconnectDevice(TSXLink.Connection.Devices.Guider);
                    TSXLink.Connection.DisconnectDevice(TSXLink.Connection.Devices.Focuser);
                    TSXLink.Connection.DisconnectDevice(TSXLink.Connection.Devices.Rotator);
                    MessageBox.Show("Attach the FlatMan, then press OK");
                    lg.LogIt("Connecting imaging devices");
                    TSXLink.Connection.ConnectDevice(TSXLink.Connection.Devices.Camera);
                    TSXLink.Connection.ConnectDevice(TSXLink.Connection.Devices.Guider);
                    TSXLink.Connection.ConnectDevice(TSXLink.Connection.Devices.Focuser);
                    TSXLink.Connection.ConnectDevice(TSXLink.Connection.Devices.Rotator);
                }
                //Turn on Flatman panel, if it hasn't been done already
                lg.LogIt("Lighting up FlatMan panel");
                flmn.Light = true;
            }
            else //Dusk or dawn flats
            {
                //Unpark mount, if parked, which it often is to do dusk flats
                TSXLink.Mount.UnPark();
                //point telescope essentially up
                lg.LogIt("Pointing telescope just west of zenith");
                TSXLink.Mount.SlewAzAlt(200.0, (60), "Flat Spot");
                //Turn tracking off
                TSXLink.Mount.TurnTrackingOff();
            }

            //Alright, all ready to go.
            //Loop on the flat entries in the flat stack file, if any
            while (HaveFlatsToDo())
            {
                switch (openSession.FlatLightSource)
                {
                case (LightSource.lsNone):
                {
                    break;
                }

                case (LightSource.lsFlatMan):
                {
                    if (openSession.IsFlatManEnabled)
                    {
                        // **********************  Use Flatman
                        //Rotate to PA, if there is a rotator is enabled
                        Flat iFlat = GetLeastRotatedFlat();
                        if (openSession.IsRotationEnabled)
                        {
                            Rotator.RotateToRotatorPA(iFlat.RotationPA);
                        }
                        Imaging nhi = new Imaging();
                        nhi.DoFlatManFlats(iFlat.TargetName, iFlat.RotationPA, iFlat.SideOfPier, iFlat.FlatFilter);
                        RemoveFlat(iFlat);          //remove flat from flat stack file
                    }
                    break;
                }

                case (LightSource.lsDusk):
                {
                    //  ********************  Use Dusk
                    Flat    iFlat = GetLowestIndexFlat();
                    Imaging nhi   = new Imaging();
                    nhi.DoTwilightFlats(iFlat, true);
                    RemoveFlat(iFlat);          //remove flat from flat stack file
                    break;
                }

                case (LightSource.lsDawn):
                {
                    //  ********************  Use Dawn
                    Flat    iFlat = GetHighestIndexFlat();
                    Imaging nhi   = new Imaging();
                    nhi.DoTwilightFlats(iFlat, false);
                    RemoveFlat(iFlat);          //remove flat from flat stack file
                    break;
                }

                default: break;
                }
            }
            //If FlatMan was used, then shut it down
            if (openSession.IsFlatManEnabled)
            {
                //Turn off flatman functions
                FlatMan flmn = new FlatMan();
                lg.LogIt("Terminating FlatMan");
                //Turn on Flatman panel, if it hasn't been done already
                lg.LogIt("Turning off FlatMan panel");
                flmn.Light = false;
                //If Manual Setup is selected, then pause for user to position the FlatMan for flats
                if (openSession.IsFlatManManualSetupEnabled)
                {
                    lg.LogIt("Pausing to detach FlatMan panel");
                    MessageBox.Show("Detach the FlatMan, then press OK");
                }
            }

            //Turn tracking on
            TSXLink.Mount.TurnTrackingOn();
            //Park the mount
            TSXLink.Mount.Park();
            return;
        }