Esempio n. 1
0
        ///// <summary>
        ///// get current step count
        ///// </summary>
        ///// <param name="axis"></param>
        ///// <returns></returns>
        //private int GetEncoderCount(AxisId axis)
        //{
        //    var stepsSky = new SkyGetEncoderCount(SkyQueue.NewId, axis);
        //    var steps = (int[])SkyQueue.GetCommandResult(stepsSky).Result;
        //    if (!stepsSky.Successful && stepsSky.Exception != null) throw stepsSky.Exception;
        //    switch (axis)
        //    {
        //        case AxisId.Axis1:
        //            return steps[0];
        //        case AxisId.Axis2:
        //            return steps[1];
        //        default:
        //            throw new ArgumentOutOfRangeException(nameof(axis), axis, null);
        //    }
        //}

        /// <summary>
        /// Gets the direction to home sensor or if null then TripPosition was set
        /// </summary>
        /// <param name="axis"></param>
        /// <returns></returns>
        private bool?GetHomeSensorStatus(AxisId axis)
        {
            var sensorStatusSky = new SkyGetHomePosition(SkyQueue.NewId, axis);
            var sensorStatus    = (long)SkyQueue.GetCommandResult(sensorStatusSky).Result;

            var monitorItem = new MonitorEntry
            {
                Datetime = HiResDateTime.UtcNow,
                Device   = MonitorDevice.Telescope,
                Category = MonitorCategory.Server,
                Type     = MonitorType.Information,
                Method   = MethodBase.GetCurrentMethod().Name,
                Thread   = Thread.CurrentThread.ManagedThreadId,
                Message  = $"{sensorStatus}"
            };

            MonitorLog.LogToMonitor(monitorItem);

            switch (sensorStatus)
            {
            case 16777215:
                return(false);

            case 0:
                return(true);

            default:
                TripPosition = Convert.ToInt32(sensorStatus);
                return(null);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Slew to home based on TripPosition already being set
        /// </summary>
        /// <param name="axis"></param>
        private int SlewToHome(AxisId axis)
        {
            if (SkyServer.AutoHomeStop)
            {
                return(-3);                        //stop requested
            }
            //convert position to mount degrees
            var a      = TripPosition -= 0x00800000;
            var skyCmd = new SkyGetStepToAngle(SkyQueue.NewId, axis, a);
            var b      = (double)SkyQueue.GetCommandResult(skyCmd).Result;
            var c      = Units.Rad2Deg1(b);

            var positions = Axes.MountAxis2Mount();

            switch (axis)
            {
            case AxisId.Axis1:
                var d = Axes.AxesMountToApp(new[] { c, 0 });     // Convert to local
                if (SkyServer.SouthernHemisphere)
                {
                    d[0] = d[0] + 180;
                }

                SkyServer.SlewAxes(d[0], positions[1], SlewType.SlewMoveAxis);
                break;

            case AxisId.Axis2:
                var e = Axes.AxesMountToApp(new[] { 0, c });     // Convert to local
                if (SkyServer.SouthernHemisphere)
                {
                    e[1] = 180 - e[1];
                }

                SkyServer.SlewAxes(positions[0], e[1], SlewType.SlewMoveAxis);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(axis), axis, null);
            }

            while (SkyServer.IsSlewing)
            {
                //Console.WriteLine(@"slewing");
                Thread.Sleep(300);
            }

            var _ = new SkyAxisStop(0, axis);

            //Thread.Sleep(1500);
            return(0);
        }
Esempio n. 3
0
        /// <summary>
        /// Initialize
        /// </summary>
        private void Initialize()
        {
            var canHomeSky = new SkyCanHomeSensors(SkyQueue.NewId);
            var hasHome    = (bool)SkyQueue.GetCommandResult(canHomeSky).Result;

            if (!canHomeSky.Successful && canHomeSky.Exception != null)
            {
                throw canHomeSky.Exception;
            }
            if (!hasHome)
            {
                throw new Exception("Home sensor not supported");
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Process queue items monitor the pulse
        /// </summary>
        /// <param name="entry"></param>
        private static void ProcessPulseStatusQueue(PulseStatusEntry entry)
        {
            try
            {
                if (!SkyServer.Tracking || SkyServer.IsSlewing)
                {
                    ResetGuiding(entry);
                    return;
                }
                entry.ProcessDateTime = HiResDateTime.UtcNow;

                bool pulseRunning;
                switch (SkySettings.Mount)
                {
                case MountType.Simulator:
                    if (entry.Axis == 0)
                    {
                        var statuscmd = new CmdPulseRaRunning(MountQueue.NewId);
                        pulseRunning = Convert.ToBoolean(MountQueue.GetCommandResult(statuscmd).Result);
                    }
                    else
                    {
                        var statuscmd = new CmdPulseDecRunning(MountQueue.NewId);
                        pulseRunning = Convert.ToBoolean(MountQueue.GetCommandResult(statuscmd).Result);
                    }
                    break;

                case MountType.SkyWatcher:
                    if (entry.Axis == 0)
                    {
                        var statussky = new SkyPulseRaRunning(SkyQueue.NewId);
                        pulseRunning = Convert.ToBoolean(SkyQueue.GetCommandResult(statussky).Result);
                    }
                    else
                    {
                        var statussky = new SkyPulseDecRunning(SkyQueue.NewId);
                        pulseRunning = Convert.ToBoolean(SkyQueue.GetCommandResult(statussky).Result);
                    }
                    break;

                default:
                    pulseRunning = false;
                    break;
                }
                ResetGuiding(entry.Axis, pulseRunning);

                var curtime     = HiResDateTime.UtcNow;
                var processtime = (int)(curtime - entry.ProcessDateTime).TotalMilliseconds;
                var alltime     = (int)(curtime - entry.CreateDateTime).TotalMilliseconds;
                var monitorItem = new MonitorEntry
                {
                    Datetime = curtime, Device = MonitorDevice.Telescope, Category = MonitorCategory.Mount, Type = MonitorType.Data, Method = MethodBase.GetCurrentMethod().Name, Thread = Thread.CurrentThread.ManagedThreadId, Message = $"Complete,{alltime},{processtime}-{entry.Duration}={processtime - entry.Duration}"
                };
                MonitorLog.LogToMonitor(monitorItem);
            }
            catch (Exception ex)
            {
                ResetGuiding(entry.Axis, false);

                var monitorItem = new MonitorEntry
                {
                    Datetime = HiResDateTime.UtcNow, Device = MonitorDevice.Telescope, Category = MonitorCategory.Mount, Type = MonitorType.Error, Method = MethodBase.GetCurrentMethod().Name, Thread = Thread.CurrentThread.ManagedThreadId, Message = $"{ex.Message}"
                };
                MonitorLog.LogToMonitor(monitorItem);
            }
        }