コード例 #1
0
ファイル: FlatManager.cs プロジェクト: rrskybox/Humason
        private Flat GetLeastRotatedFlat()
        {
            //Get the current rotation position, if any
            SessionControl openSession = new SessionControl();
            double         nowRotAngle = 0;

            if (openSession.IsRotationEnabled)
            {
                nowRotAngle = Rotator.RealRotatorPA;
            }

            //Get the list of flat requests
            List <Flat> flatSet = GetFlats();

            //Create a return Flat and set to first of the flat set, return null if none
            if (flatSet.Count == 0)
            {
                return(null);
            }
            Flat flatOut = flatSet[0];

            foreach (Flat flt in flatSet)
            {
                if ((Math.Abs(flatOut.RotationPA - nowRotAngle)) > (Math.Abs(flt.RotationPA - nowRotAngle)))
                {
                    flatOut = flt;
                }
            }
            return(flatOut);
        }
コード例 #2
0
ファイル: FlatManager.cs プロジェクト: rrskybox/Humason
        public void RemoveFlat(Flat flt)
        {
            //Removes a flat from the flat entries based on Side of Pier and Rotator PA
            //Find entry, if any
            string   tpFilePath = nhDir + "\\" + HumasonFlatStackFilename;
            XElement tpPlanX    = XElement.Load(tpFilePath);
            XElement sectionX   = tpPlanX.Element(fmFlatSetName);

            //Check for flats section, if doesn't exist, then return null
            if (sectionX == null)
            {
                return;
            }
            //Otherwise, load the flat definition entries, if any
            Flat[] flatOut = new Flat[sectionX.Elements(fmFlatSetRequiredName).Count()];
            int    fi      = 0;

            foreach (XElement flatX in sectionX.Elements(fmFlatSetRequiredName))
            {
                if (CompareFlat(flatX, flt))
                {
                    flatX.Remove();
                    tpPlanX.Save(tpFilePath);
                    return;
                }
                fi++;
            }
            return;
        }
コード例 #3
0
ファイル: FlatManager.cs プロジェクト: rrskybox/Humason
        public void AddFlat(Flat flt)
        {
            //Add an entry to the flats file, if it isn't there already

            //Create Xelement for flat entry
            XElement fltXreq = new XElement(fmFlatSetRequiredName);
            XElement tNameX  = new XElement(fmFlatSetRequiredTargetName, flt.TargetName);
            XElement sopX    = new XElement(fmFlatSetRequiredSideOfPierName, flt.SideOfPier);
            XElement rPAX    = new XElement(fmFlatSetRequiredRotationPAName, flt.RotationPA.ToString());
            XElement filName = new XElement(fmFlatSetRequiredFilterNameName, flt.FlatFilter.Name.ToString());
            XElement filIdx  = new XElement(fmFlatSetRequiredFilterIndexName, flt.FlatFilter.Index.ToString());
            XElement filRep  = new XElement(fmFlatSetRequiredRepetitionsName, flt.FlatFilter.Repeat.ToString());

            fltXreq.Add(tNameX);
            fltXreq.Add(sopX);
            fltXreq.Add(rPAX);
            fltXreq.Add(filName);
            fltXreq.Add(filIdx);
            fltXreq.Add(filRep);

            //Now lets add it, if it isn't already there
            string   tpFilePath = nhDir + "\\" + HumasonFlatStackFilename;
            XElement tpPlanX    = XElement.Load(tpFilePath);
            XElement sectionX   = tpPlanX.Element(fmFlatSetName);

            //Check for flats section, if doesn't exist, then create section
            if (sectionX == null)
            {
                XElement fltSetX = new XElement(fmFlatSetName);
                fltSetX.Add(fltXreq);
                tpPlanX.Add(fltSetX);
                //Save the xml back to the file and return
                tpPlanX.Save(tpFilePath);
                return;
            }
            else
            {
                //Otherwise, check for a duplication, if one then return, if not add the element
                foreach (XElement flatX in sectionX.Elements(fmFlatSetRequiredName))
                {
                    if (CompareFlat(flatX, flt))
                    {
                        return;
                    }
                }
                sectionX.Add(fltXreq);
                //Save the xml back to the file and return
                tpPlanX.Save(tpFilePath);
                return;
            }
        }
コード例 #4
0
ファイル: FlatManager.cs プロジェクト: rrskybox/Humason
        private bool CompareFlat(XElement flat1X, Flat flat2)
        {
            //Convert the element to a flat class, then compare
            Flat flat1 = new Flat(flat1X);

            if (CompareFlat(flat1, flat2))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #5
0
ファイル: FlatManager.cs プロジェクト: rrskybox/Humason
 private bool CompareFlat(Flat flat1, Flat flat2)
 {
     if ((flat1.TargetName == flat2.TargetName) &&
         (flat1.SideOfPier == flat2.SideOfPier) &&
         (flat1.RotationPA == flat2.RotationPA) &&
         (flat1.FlatFilter.Index == flat2.FlatFilter.Index) &&
         (flat1.FlatFilter.Repeat == flat2.FlatFilter.Repeat))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
コード例 #6
0
ファイル: FormFlats.cs プロジェクト: rrskybox/Humason
        private void MakeFlatsButton_Click(object sender, EventArgs e)
        {
            //Make flat request entries based on current target name and rotator info
            LogEvent       lg          = new LogEvent();
            SessionControl openSession = new SessionControl();
            TargetPlan     tPlan       = new TargetPlan(openSession.CurrentTargetName);
            FlatManager    nhFlat      = new FlatManager();

            //Get filter set
            List <Filter> fset = tPlan.FilterWheelList;

            if (fset == null)
            {
                lg.LogIt("No filters have been configured");
                return;
            }
            string tname           = tPlan.TargetName;
            double rPA             = (double)RotatorPANum.Value;
            int    flatRepetitions = openSession.FlatsRepetitions;
            //If the last image was shot to the west, then the rotator should alread be in the west position,
            //  which will mean that a single set will have the rotator already positioned collectly
            string sop = "East";

            foreach (Filter fi in fset)
            {
                fi.Repeat = flatRepetitions;
                Flat iFlat = new Flat(tname, sop, rPA, fi, openSession.IsFlatFlipEnabled);
                nhFlat.AddFlat(iFlat);
            }
            //Check to see if there is a rotator enabled, if so, and flip is enabled, then make a second set for the east side
            if ((openSession.IsFlatsRotationEnabled) && (openSession.IsFlatFlipEnabled))
            {
                rPA = AstroMath.Transform.NormalizeDegreeRange(rPA + 180);
                sop = "West";
                foreach (Filter fi in fset)
                {
                    fi.Repeat = flatRepetitions;
                    Flat iFlat = new Flat(tname, sop, rPA, fi, openSession.IsFlatFlipEnabled);
                    nhFlat.AddFlat(iFlat);
                }
            }
        }
コード例 #7
0
ファイル: FlatManager.cs プロジェクト: rrskybox/Humason
        private List <Flat> GetFlats()
        {
            string   fsFilePath = nhDir + "\\" + HumasonFlatStackFilename;
            XElement tpPlanX    = XElement.Load(fsFilePath);
            XElement sectionX   = tpPlanX.Element(fmFlatSetName);

            //Check for flats section, if doesn't exist, then return null
            if (sectionX == null)
            {
                return(null);
            }
            //Otherwise, load the flat definition entries, if any
            List <Flat> flatOut = new List <Flat>();

            foreach (XElement flatX in sectionX.Elements(fmFlatSetRequiredName))
            {
                Flat flt = new Flat(flatX);
                flatOut.Add(flt);
            }
            return(flatOut);
        }
コード例 #8
0
ファイル: FlatManager.cs プロジェクト: rrskybox/Humason
        private Flat GetHighestIndexFlat()
        {
            //find the flat request with the highest filter index
            //Get the list of flat requests
            List <Flat> flatSet = GetFlats();

            //Create a return Flat and set to first of the flat set, return null if none
            if (!HaveFlatsToDo())
            {
                return(null);
            }
            int  mostIndex = 0; //just pick the minimum filter index
            Flat flatOut   = flatSet[0];

            foreach (Flat flt in flatSet)
            {
                if (flt.FlatFilter.Index > mostIndex)
                {
                    flatOut   = flt;
                    mostIndex = flt.FlatFilter.Index;
                }
            }
            return(flatOut);
        }
コード例 #9
0
ファイル: FlatManager.cs プロジェクト: rrskybox/Humason
        private Flat GetLowestIndexFlat()
        {
            //find the flat request with the lowest filter index
            //Get the list of flat requests
            List <Flat> flatSet = GetFlats();

            //Create a return Flat and set to first of the flat set, return null if none
            if (!HaveFlatsToDo())
            {
                return(null);
            }
            int  leastIndex = 12; //just pick the maximum number of filters that I can think of
            Flat flatOut    = flatSet[0];

            foreach (Flat flt in flatSet)
            {
                if (flt.FlatFilter.Index < leastIndex)
                {
                    flatOut    = flt;
                    leastIndex = flt.FlatFilter.Index;
                }
            }
            return(flatOut);
        }
コード例 #10
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;
        }