Beispiel #1
0
        // Get the progress of settling
        public override SettleProgress CheckSettling()
        {
            CheckConnected();

            SettleProgress ret = new SettleProgress();

            lock (m_sync)
            {
                if (mSettle == null)
                {
                    throw new GuiderException("not settling");
                }

                if (mSettle.Done)
                {
                    // settle is done
                    ret.Done   = true;
                    ret.Status = mSettle.Status;
                    ret.Error  = mSettle.Error;
                    mSettle    = null;
                }
                else
                {
                    // settle in progress
                    ret.Done       = false;
                    ret.Distance   = mSettle.Distance;
                    ret.SettlePx   = settle_px;
                    ret.Time       = mSettle.Time;
                    ret.SettleTime = mSettle.SettleTime;
                }
            }

            return(ret);
        }
Beispiel #2
0
        // Dither guiding with the given dither amount and settling parameters. Call CheckSettling()
        // periodically to see when settling is complete.
        public override void Dither(double ditherPixels, double settlePixels, double settleTime, double settleTimeout)
        {
            CheckConnected();

            SettleProgress s = new SettleProgress();

            s.Done       = false;
            s.Distance   = ditherPixels;
            s.SettlePx   = settlePixels;
            s.Time       = 0.0;
            s.SettleTime = settleTime;
            s.Status     = 0;

            lock (m_sync)
            {
                if (mSettle != null && !mSettle.Done)
                {
                    throw new GuiderException("cannot dither while settling");
                }

                mSettle = s;
            }

            try
            {
                JArray param = new JArray();
                param.Add(ditherPixels);
                param.Add(false);
                param.Add(SettleParam(settlePixels, settleTime, settleTimeout));

                Call("dither", param);
                settle_px = settlePixels;
            }
            catch (Exception)
            {
                // call failed - remove the settle state
                lock (m_sync)
                {
                    mSettle = null;
                }
                throw;
            }
        }
Beispiel #3
0
        // Check if phd2 is currently in the process of settling after a Guide or Dither
        public override bool IsSettling()
        {
            CheckConnected();

            lock (m_sync)
            {
                if (mSettle != null)
                {
                    return(true);
                }
            }

            // for app init, initialize the settle state to a consistent value
            // as if Guide had been called

            JObject res = Call("get_settling");

            bool val = (bool)res["result"];

            if (val)
            {
                SettleProgress s = new SettleProgress();
                s.Done       = false;
                s.Distance   = -1.0;
                s.SettlePx   = 0.0;
                s.Time       = 0.0;
                s.SettleTime = 0.0;
                s.Status     = 0;
                lock (m_sync)
                {
                    if (mSettle == null)
                    {
                        mSettle = s;
                    }
                }
            }

            return(val);
        }
Beispiel #4
0
        private void handle_event(JObject ev)
        {
            string e = (string)ev["Event"];

            if (e == "AppState")
            {
                lock (m_sync)
                {
                    AppState = (string)ev["State"];
                    if (is_guiding(AppState))
                    {
                        AvgDist = 0.0;   // until we get a GuideStep event
                    }
                }
            }
            else if (e == "Version")
            {
                lock (m_sync)
                {
                    Version   = (string)ev["PHDVersion"];
                    PHDSubver = (string)ev["PHDSubver"];
                }
            }
            else if (e == "StartGuiding")
            {
                accum_active = true;
                accum_ra.Reset();
                accum_dec.Reset();

                GuideStats stats = accum_get_stats(accum_ra, accum_dec);

                lock (m_sync)
                {
                    Stats = stats;
                }
            }
            else if (e == "GuideStep")
            {
                GuideStats stats = null;
                if (accum_active)
                {
                    accum_ra.Add((double)ev["RADistanceRaw"]);
                    accum_dec.Add((double)ev["DECDistanceRaw"]);
                    stats = accum_get_stats(accum_ra, accum_dec);
                }

                lock (m_sync)
                {
                    AppState = "Guiding";
                    AvgDist  = (double)ev["AvgDist"];
                    if (accum_active)
                    {
                        Stats = stats;
                    }
                }
            }
            else if (e == "SettleBegin")
            {
                accum_active = false;  // exclude GuideStep messages from stats while settling
            }
            else if (e == "Settling")
            {
                SettleProgress s = new SettleProgress();
                s.Done       = false;
                s.Distance   = (double)ev["Distance"];
                s.SettlePx   = settle_px;
                s.Time       = (double)ev["Time"];
                s.SettleTime = (double)ev["SettleTime"];
                s.Status     = 0;
                lock (m_sync)
                {
                    mSettle = s;
                }
            }
            else if (e == "SettleDone")
            {
                accum_active = true;
                accum_ra.Reset();
                accum_dec.Reset();

                GuideStats stats = accum_get_stats(accum_ra, accum_dec);

                SettleProgress s = new SettleProgress();
                s.Done   = true;
                s.Status = (int)ev["Status"];
                s.Error  = (string)ev["Error"];

                lock (m_sync)
                {
                    mSettle = s;
                    Stats   = stats;
                }
            }
            else if (e == "Paused")
            {
                lock (m_sync)
                {
                    AppState = "Paused";
                }
            }
            else if (e == "StartCalibration")
            {
                lock (m_sync)
                {
                    AppState = "Calibrating";
                }
            }
            else if (e == "LoopingExposures")
            {
                lock (m_sync)
                {
                    AppState = "Looping";
                }
            }
            else if (e == "LoopingExposuresStopped" || e == "GuidingStopped")
            {
                lock (m_sync)
                {
                    AppState = "Stopped";
                }
            }
            else if (e == "StarLost")
            {
                lock (m_sync)
                {
                    AppState = "LostLock";
                    AvgDist  = (double)ev["AvgDist"];
                }
            }
            else
            {
                Debug.WriteLine(String.Format("todo: handle event {0}", e));
            }
        }