示例#1
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);
        }
示例#2
0
        /// <summary>
        /// Slews degrees from current position using the goto from the server
        /// </summary>
        /// <param name="degrees"></param>
        /// <param name="direction"></param>
        /// <param name="axis"></param>
        private int SlewAxis(double degrees, AxisId axis, bool direction = false)
        {
            if (SkyServer.AutoHomeStop)
            {
                return(-3);                        //stop requested
            }
            if (SkyServer.Tracking)
            {
                SkyServer.TrackingSpeak = false;
                SkyServer.Tracking      = false;
            }

            var positions = Axes.MountAxis2Mount();

            switch (axis)
            {
            case AxisId.Axis1:
                degrees = direction ? Math.Abs(degrees) : -Math.Abs(degrees);
                if (SkyServer.SouthernHemisphere)
                {
                    degrees = direction ? -Math.Abs(degrees) : Math.Abs(degrees);
                }
                SkyServer.SlewAxes(positions[0] + degrees, positions[1], SlewType.SlewMoveAxis);
                break;

            case AxisId.Axis2:
                degrees = direction ? -Math.Abs(degrees) : Math.Abs(degrees);
                if (SkyServer.SouthernHemisphere)
                {
                    degrees = direction ? Math.Abs(degrees) : -Math.Abs(degrees);
                }
                SkyServer.SlewAxes(positions[0], positions[1] + degrees, SlewType.SlewMoveAxis);
                break;

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

            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  = $"{positions[0]},{positions[1]},{degrees},{axis},{direction}"
            };

            MonitorLog.LogToMonitor(monitorItem);

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

            var _ = new SkyAxisStop(0, axis);

            //Thread.Sleep(1500);
            return(0);
        }
示例#3
0
        /// <summary>
        /// Start auto home process per axis with max degrees default at 90
        /// </summary>
        /// <param name="axis"></param>
        /// <param name="offSetDec"></param>
        /// <param name="maxMove"></param>
        /// <returns></returns>
        public int StartAutoHome(AxisId axis, int maxMove = 100, int offSetDec = 0)
        {
            var _ = new SkyAxisStop(0, axis);

            if (SkyServer.Tracking)
            {
                SkyServer.Tracking = false;
            }
            //StartCount = GetEncoderCount(axis);
            var totalmove = 0.0;
            // ReSharper disable once RedundantAssignment
            var  clockwise  = false;
            var  startovers = 0;
            bool?status;
            bool?loopstatus = null;

            SkyServer.AutoHomeProgressBar += 5;

            // slew away from those that start at home position
            var slew = SlewAxis(3.3, axis);

            totalmove += 3.3;
            if (slew != 0)
            {
                return(slew);
            }


            #region 5 degree loops to look for sensor
            for (var i = 0; i <= (maxMove / 5); i++)
            {
                if (SkyServer.AutoHomeStop)
                {
                    return(-3);                        //stop requested
                }
                if (totalmove >= maxMove)
                {
                    return(-2);                      // home not found
                }
                if (startovers >= 2)
                {
                    return(-4);                 // too many restarts
                }
                status = GetValidStatus(axis);
                var laststatus = status;
                // check status last loop vs this loop and see if status changed
                if (status != null && loopstatus != null)      // home not found and not first loop
                {
                    if (status != loopstatus)                  // status changed but no detection of home
                    {
                        slew = SlewAxis(2.7, axis, clockwise); //slew 5 degrees
                        if (slew != 0)
                        {
                            return(slew);
                        }
                        status = GetHomeSensorStatus(axis); // check sensor
                        if (status != null)
                        {
                            i = 0;
                            //total move = 0.0;
                            startovers++;
                            continue; //start over
                        }
                        break;        //found home
                    }
                    if (totalmove >= maxMove)
                    {
                        return(-2);                      // home not found
                    }
                }
                switch (status)
                {
                case null:
                    return(SkyServer.AutoHomeStop ? -3 : -1);

                case true:
                    clockwise = true;
                    break;

                case false:
                    clockwise = false;
                    break;
                }

                SkyServer.AutoHomeProgressBar += 1;

                slew = SlewAxis(5.0, axis, clockwise); //slew 5 degrees
                if (slew != 0)
                {
                    return(slew);
                }
                totalmove += 5.0;                       // keep track of how far moved
                status     = GetHomeSensorStatus(axis); // check sensor
                loopstatus = status;
                if (status != null)                     // home not found
                {
                    if (status == laststatus)
                    {
                        continue;
                    }
                    slew = SlewAxis(2.5, axis, clockwise); //slew 5 degrees
                    if (slew != 0)
                    {
                        return(slew);
                    }
                    status     = GetHomeSensorStatus(axis); // check sensor
                    loopstatus = status;
                    if (status != null)
                    {
                        i = 0;
                        //total move = 0.0;
                        startovers++;
                        continue; //start over
                    }
                }
                break;//found home
            }
            if (SkyServer.AutoHomeStop)
            {
                return(-3);                        //stop requested
            }
            if (totalmove >= maxMove)
            {
                return(-2);                      // home not found
            }
            if (startovers >= 2)
            {
                return(-4);                 // too many restarts
            }
            #endregion

            #region slew to detected home
            slew = SlewToHome(axis);
            if (slew != 0)
            {
                return(slew);
            }
            #endregion

            SkyServer.AutoHomeProgressBar += 5;

            #region 3.7 degree slew away from home for a validation move
            slew = SlewAxis(3.7, axis); // slew away from home
            if (slew != 0)
            {
                return(slew);
            }
            status = GetValidStatus(axis);
            switch (status)
            {
            case null:
                return(SkyServer.AutoHomeStop ? -3 : -1);

            case true:
                clockwise = true;
                break;

            case false:
                clockwise = false;
                break;
            }
            #endregion

            SkyServer.AutoHomeProgressBar += 5;

            #region slew back over home to validate home position
            slew = SlewAxis(5, axis, clockwise); // slew over home
            if (slew != 0)
            {
                return(slew);
            }
            status = GetHomeSensorStatus(axis); // check sensor
            switch (status)
            {
            case null:
                // home found
                break;

            case true:
                return(-2);    // home not found

            case false:
                return(-2);    // home not found
            }
            #endregion

            SkyServer.AutoHomeProgressBar += 5;

            #region slew back to remove backlash
            slew = SlewAxis(3, axis, !clockwise); // slew over home
            if (slew != 0)
            {
                return(slew);
            }
            #endregion

            SkyServer.AutoHomeProgressBar += 5;

            //slew to home
            slew = SlewToHome(axis);

            // Dec offset for side saddles
            if (Math.Abs(offSetDec) > 0 && axis == AxisId.Axis2)
            {
                slew = SlewAxis(Math.Abs(offSetDec), axis, offSetDec < 0);
                if (slew != 0)
                {
                    return(slew);
                }
            }

            return(slew != 0 ? slew : 0);
        }