Example #1
0
        //public static SessionControl openSession;

        public static bool ImagingControl()
        {
            //Runs the photo shoot shebang
            //First a little housekeeping -- configuration update and make sure the clock is set right
            //if Autorun staging is set, wait on autostaging time, then run the staging app
            //if Autorun start is set, wait on autostart time, then run the starting app
            //Wait on Sequence start
            //
            //LogEvent lg = new LogEvent();
            LogEvent lg = FormHumason.StatusReportEvent;

            TargetEvent tg = new TargetEvent();

            SessionControl openSession = new SessionControl();

            //Run a quick check on all the things that might be wrong, based on past history
            //  the main thing being that there is at least one target plan queued.
            lg.LogIt("Running diagnostics");
            if (!Diagnostics.CheckUp())
            {
                lg.LogIt("Diagnostics abort");
                return(false);;
            }

            lg.LogIt("Diagnostics success");
            //All selected devices should be on-line and connected
            //Load the first target plan so we can pull some information for this session
            lg.LogIt("Loading first session target plan");
            if (!FormHumason.fPlanForm.IsTopPlanTargetName())
            {
                lg.LogIt("No Target Plan");
                return(false);
            }
            openSession.CurrentTargetName = FormHumason.fPlanForm.GetTopPlanTargetName();
            TargetPlan ftPlan = new TargetPlan(openSession.CurrentTargetName);

            //Flush it out, if we have to
            if (ftPlan.IsSparsePlan())
            {
                lg.LogIt("Sparse Plan -- filling out from default");
                ftPlan.FlushOutFromDefaultPlan();
            }
            //Update the form and regenerate the sequence
            tg.RaiseNewTargetPlan(ftPlan.TargetName);

            //Get the staging, start and shut down times from this initial target, although may not be used
            openSession.StagingTime = DateTime.Now;
            openSession.StartUpTime = ftPlan.SequenceStartTime;
            // openSession.ShutDownTime = fSequenceForm.DawnTimeBox.Value;
            openSession.ShutDownTime = ftPlan.SequenceDawnTime;

            //Save configuration set up, reset the progess bar and make sure that the TSX clock is set to current time
            //fSequenceForm.UpdateFormFromPlan();
            TSXLink.StarChart.SetClock(0, true);

            //Await Staging and Start Up
            //  If autorun enabled, then run the staging time autorun script/app
            if (openSession.IsAutoRunEnabled && openSession.IsStagingEnabled)
            {
                LaunchPad.WaitStaging();
            }
            //check for abort having been set.  Gracefully shut everything back down if it has.
            if (FormHumason.IsAborting())
            {
                GracefulAbort();
            }

            //  If autorun enabled, then run the start up time autorun script/app
            if (openSession.IsAutoRunEnabled && openSession.IsStartUpEnabled)
            {
                LaunchPad.WaitStartUp();
            }
            //check for abort having been set.  Gracefully shut everything back down if it has.
            if (FormHumason.IsAborting())
            {
                GracefulAbort();
            }

            //Both Staging and Start Up have been run. All devices should be powered, but not necessarily connected
            //Power up and connect devices (if not done already)
            lg.LogIt("Initializing system");
            InitializeSystem();

            //Remove all flat requests from the flats file
            //   No, don't
            //FlatManager nhFlat = new FlatManager();
            //nhFlat.FlatSetClearAll();
            //nhFlat = null;

            //Check for proximity to meridian flip
            //  if HA of target is within 10 minutes, then just wait it out at
            //Get target HA
            TSXLink.Target tgto;
            lg.LogIt("Checking for new target to clear meridian");
            string raS  = ftPlan.TargetRA.ToString();
            string decS = ftPlan.TargetDec.ToString();

            tgto = TSXLink.StarChart.FindTarget(raS + "," + decS);
            double ha = tgto.HA.TotalMinutes;

            while ((ha >= -10) && (ha <= 0))
            {
                System.Threading.Thread.Sleep(10000);
                tgto = TSXLink.StarChart.FindTarget(ftPlan.TargetName);
                ha   = tgto.HA.TotalMinutes;
            }
            lg.LogIt("New target is clear of meridian");

            //Make sure the mount is unparked
            TSXLink.Mount.UnPark();
            //Make sure tracking is turned on
            TSXLink.Mount.TurnTrackingOn();

            //Bring camera to temperature (if not already), then clear the objects
            AstroImage asti = new AstroImage()
            {
                Camera = AstroImage.CameraType.Imaging
            };

            TSXLink.Camera cCam = new TSXLink.Camera(asti);
            cCam.CCDTemperature = ftPlan.CameraTemperatureSet;
            cCam = null; asti = null;

            //************************  Starting up the target plans  *************************
            //
            //  This loop is to run each of the plans in the schedule list sequentially.
            //  The current plan has already progressed through any staging and starting scripts
            //      and the next step will be to wait on the starting time, if it hasn't passed already
            //  At the end of the loop, the current plan will be deleted from the schedule and the next one, if any
            //      loaded.  If none, then the shutdown script of the last plan will be run (if autorun is set for that plan).
            //
            while (FormHumason.fPlanForm.IsTopPlanTargetName())
            {
                //Load the top scheduled plan
                string tgtName = FormHumason.fPlanForm.GetTopPlanTargetName();
                openSession.CurrentTargetName = tgtName;
                TargetPlan tPlan = new TargetPlan(tgtName);

                lg.LogIt(" ******************* Imaging Target: " + openSession.CurrentTargetName);
                if (tPlan.IsSparsePlan())
                {
                    lg.LogIt("Sparse Plan -- filling out from default");
                    tPlan.FlushOutFromDefaultPlan();
                }
                //Try to move to target, if this fails just abort
                Sequencer imgseq = new Sequencer();
                if (!imgseq.CLSToTargetPlanCoordinates())
                {
                    GracefulAbort(); break;
                }

                //check for abort having been set.  Gracefully shut everything back down if it has.
                if (FormHumason.IsAborting())
                {
                    GracefulAbort(); break;
                }

                //Now lets get the rotator positioned properly, plate solve, then rotate, then plate solve
                if (tPlan.RotatorEnabled)
                {
                    lg.LogIt("Rotating to PA @ " + tPlan.TargetPA.ToString("0.00"));
                    if (!Rotator.RotateToImagePA(tPlan.TargetPA))
                    {
                        lg.LogIt("Failed to properly rotate. Aborting.");
                        GracefulAbort();
                    }
                    else
                    {
                        lg.LogIt("Rotation complete and verified");
                        // Because rotation may not be quite symmetrical, do another CLS to make sure
                        //  the guide star and target is still centered

                        lg.LogIt("CLS to center target after rotation");
                        if (!imgseq.CLSToTargetPlanCoordinates())
                        {
                            lg.LogIt("Failed to center target after rotation");
                            GracefulAbort();
                        }
                        ;
                    }
                }
                else
                {
                    lg.LogIt("Rotator not enabled");
                }

                //check for abort having been set.  Gracefully shut everything back down if it has.
                if (FormHumason.IsAborting())
                {
                    GracefulAbort(); break;
                }

                //Update the sequence for whatever time it is now
                try { imgseq.SeriesGenerator(); }
                catch
                {
                    lg.LogIt("Make Series Error");
                    GracefulAbort(); break;
                }
                //
                // Run Imaging Sequence
                imgseq.PhotoShoot();
                //
                //
                //All done.  Abort autoguiding, assuming is running -- should be off, but you never know
                AutoGuide.AutoGuideStop();
                //check for abort having been set.  Gracefully shut everything back down if it has.
                if (FormHumason.IsAborting())
                {
                    GracefulAbort(); break;
                }
                //Done with imaging on this plan.
                //Store the ending time
                tPlan.SequenceEndTime = DateTime.Now;
                //Save the plan in the sequence complete summary file
                openSession.AddSequenceCompleteSummary();
                //string tName = tPlan.GetItem(TargetPlan.sbTargetNameName); //why??
                //Remove the plan from the schedule and look for the next
                FormHumason.fPlanForm.RemoveTopPlan();
            }

            //done with imaging.  Check on flats  See if any flats have been requested

            FlatManager fmgr = new FlatManager();

            if (fmgr.HaveFlatsToDo() && !FormHumason.IsAborting())
            {
                fmgr.TakeFlats();
            }

            //If autorun set, then run it, or... just park the mount
            if (openSession.IsAutoRunEnabled)
            {
                LaunchPad.RunShutDownApp();
            }
            else
            {
                try { TSXLink.Mount.Park(); }
                catch (Exception ex) { lg.LogIt("Could not Park: " + ex.Message); }
            }
            return(true);
        }
Example #2
0
        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;
        }