Esempio n. 1
0
        public HourAngle GetRA(AxisPosition axes)
        {
            double tempRA_hours = GetHourAngleFromAngle(axes.RAAxis.Value);
            double tRa          = LocalApparentSiderialTime + tempRA_hours;
            double tHa          = AstroConvert.RangeHA(tRa);
            double dec          = GetDec(axes);

            // System.Diagnostics.Debug.Write($"{axes.RAAxis.Value}/{axes.DecAxis.Value}\t{dec}\t{tHa}\t{tRa}");
            if (Hemisphere == HemisphereOption.Northern)
            {
                if (axes.DecFlipped)
                {
                    tRa = tRa - 12.0;
                    // System.Diagnostics.Debug.Write("\t tRa - tRa - 12");
                }
            }
            else
            {
                System.Diagnostics.Debug.Assert(false, "GetRA is not tested for Southern Hemisphere");
                if (axes.DecAxis.Value > 180)
                {
                    tRa = tRa + 12.0;
                }
            }
            return(new HourAngle(AstroConvert.RangeRA(tRa)));
        }
Esempio n. 2
0
        public void TestingHA()
        {
            double    ra  = 0.0;
            double    ha  = 0.0;
            HourAngle lst = new HourAngle(AstroConvert.LocalApparentSiderealTime(_Tools.Transform.SiteLongitude, _Now));

            System.Diagnostics.Debug.WriteLine($"LST = {lst.Value}");
            System.Diagnostics.Debug.WriteLine("\tRA\t\t\tHA");
            System.Diagnostics.Debug.WriteLine("\t==\t\t\t==");

            for (int i = 0; i < 24; i++)
            {
                ra = i * 1.0;
                ha = AstroConvert.RangeHA(ra - lst);
                System.Diagnostics.Debug.WriteLine($"\t{ra}\t\t{ha}");
            }

            Assert.IsTrue(true);
        }
Esempio n. 3
0
        /// <summary>
        /// Refreshes the NCP and current positions if more than 500ms have elapsed since the last refresh.
        /// </summary>
        private void RefreshCurrentPosition()
        {
            DateTime     now          = DateTime.Now;
            bool         axisHasMoved = false;
            double       tolerance;
            AxisPosition axisPosition; //= _previousAxisPosition;

            lock (Controller)
            {
                _AxisState   = Controller.MCGetAxesStates();
                axisPosition = Controller.MCGetAxisPositions();
                tolerance    = Controller.AngularResolutionDegrees;
            }
#if DEBUG
            //string raStatus = Convert.ToString(axesStatus[RA_AXIS], 2);
            //string decStatus = Convert.ToString(axesStatus[DEC_AXIS], 2); ;
            //System.Diagnostics.Debug.WriteLine($"\nAxis states - RA: {raStatus}, Dec : {decStatus}\n");
            //AxisState raStatus = _AxisState[RA_AXIS];
            //AxisState decStatus = _AxisState[DEC_AXIS];
            //System.Diagnostics.Debug.WriteLine($"\nRA : Slewing-{raStatus.Slewing}, SlewingTo-{raStatus.SlewingTo}, Forward-{!raStatus.MeshedForReverse}, FullStop-{raStatus.FullStop}, Tracking-{raStatus.Tracking}");
            //System.Diagnostics.Debug.WriteLine($"Dec: Slewing-{decStatus.Slewing}, SlewingTo-{decStatus.SlewingTo}, Forward-{!decStatus.MeshedForReverse}, FullStop-{decStatus.FullStop}, Tracking-{decStatus.Tracking}");
#endif
            if (!axisPosition.Equals(_previousAxisPosition, tolerance))
            //if (!_AxisState[RA_AXIS].FullStop || !_AxisState[DEC_AXIS].FullStop)
            {
                // One or the other axis is moving
                axisHasMoved = true;
                if (_previousPointingSOP == PierSide.pierUnknown)
                {
                    // First move away from home (NCP/SCP) position.
                    if (_TargetPosition != null)
                    {
                        System.Diagnostics.Debug.WriteLine("Initialising SOP from goto target.");
                        System.Diagnostics.Debug.WriteLine($"Target Axes: {_TargetPosition.ObservedAxes.RAAxis.Value}/{_TargetPosition.ObservedAxes.DecAxis.Value}\t{_TargetPosition.ObservedAxes.DecFlipped}\tRA/Dec: {_TargetPosition.Equatorial.RightAscension}/{_TargetPosition.Equatorial.Declination}\t{_TargetPosition.PointingSideOfPier}");
                        axisPosition.DecFlipped = _TargetPosition.ObservedAxes.DecFlipped;
                        _previousPointingSOP    = _TargetPosition.PointingSideOfPier;
                    }
                }
                else
                {
                    // Keep the axis position the same
                    axisPosition.DecFlipped = _previousAxisPosition.DecFlipped;
                }
            }
            else
            {
                // Check if parking.
                if (Settings.ParkStatus == ParkStatus.Parking)
                {
                    // Update the parked axis position decflipped setting if it isn't set.
                    _ParkedAxisPosition.DecFlipped = _previousAxisPosition.DecFlipped;
                    if (axisPosition.Equals(_ParkedAxisPosition, tolerance))
                    {
                        LogMessage("Command", "Park - complete");
                        Settings.ParkStatus = ParkStatus.Parked;
                        SaveSettings();
                    }
                    else
                    {
                        //if (_NeedSlowToStopStep)
                        //{
                        // Need to keep going
                        Controller.MCAxisSlewTo(_ParkedAxisPosition, Hemisphere);
                        //   _NeedSlowToStopStep = false;
                        //}
                    }
                }

                axisPosition.DecFlipped = _previousAxisPosition.DecFlipped;
            }

            // Update current position
            _CurrentPosition.MoveRADec(axisPosition, _AscomToolsCurrentPosition, now);

            if (!_decFlippedConfirmed && _CurrentPosition.PointingSideOfPier != PierSide.pierUnknown)
            {
                double ha = AstroConvert.RangeHA(SiderealTime - _CurrentPosition.Equatorial.RightAscension.Value);
                if (_CurrentPosition.PointingSideOfPier == PierSide.pierWest)
                {
                    if (ha >= 0)
                    {
                        // need to flip the DEC axis as it is reporting the wrong RA
                        axisPosition.DecFlipped = !axisPosition.DecFlipped;
                        _CurrentPosition.MoveRADec(axisPosition, _AscomToolsCurrentPosition, now);
                    }
                }
                else
                {
                    if (ha < 0)
                    {
                        // need to flip the DEC axis as it is reporting the wrong RA
                        axisPosition.DecFlipped = !axisPosition.DecFlipped;
                        _CurrentPosition.MoveRADec(axisPosition, _AscomToolsCurrentPosition, now);
                    }
                }
                _decFlippedConfirmed = true;
            }

            //// Just check that we have the DecFlipped setting correct
            //if (!_decFlippedConfirmed && _IsSlewing)
            //{
            //   double deltaRa = _TargetPosition.Equatorial.RightAscension - _CurrentPosition.Equatorial.RightAscension;
            //   if (_previousDeltaRa.HasValue)
            //   {
            //      if (deltaRa > _previousDeltaRa.Value)
            //      {
            //         // Going in the wrong direction so flip the Dec axis
            //         axisPosition.DecFlipped = !axisPosition.DecFlipped;
            //         _CurrentPosition.MoveRADec(axisPosition, _AscomToolsCurrentPosition, now);
            //      }
            //      _decFlippedConfirmed = true;
            //   }
            //   else {
            //      // Get it on the next cycle
            //      _previousDeltaRa = deltaRa;
            //   }
            //}

            if (_previousPointingSOP != PierSide.pierUnknown)
            {
                // See if pointing has moved across the meridian
                if (_CurrentPosition.PointingSideOfPier != _previousPointingSOP)
                {
                    System.Diagnostics.Debug.WriteLine("** Crossing the meridian **");
                    // Pointing has moved across the meridian so toggle the DecFlipped value;
                    axisPosition.DecFlipped = !_previousAxisPosition.DecFlipped;
                    _CurrentPosition.MoveRADec(axisPosition, _AscomToolsCurrentPosition, now);
                }
            }


            if (Settings.ParkStatus == ParkStatus.Parking)
            {
                System.Diagnostics.Debug.WriteLine($"Parking to: {_ParkedAxisPosition.RAAxis.Value}/{_ParkedAxisPosition.RAAxis.Value}\t{_ParkedAxisPosition.DecFlipped}");
            }

            if (_TargetPosition != null)
            {
                System.Diagnostics.Debug.WriteLine($"Target Axes: {_TargetPosition.ObservedAxes.RAAxis.Value}/{_TargetPosition.ObservedAxes.DecAxis.Value}\t{_TargetPosition.ObservedAxes.DecFlipped}\tRA/Dec: {_TargetPosition.Equatorial.RightAscension}/{_TargetPosition.Equatorial.Declination}\t{_TargetPosition.PointingSideOfPier}");
            }
            if (Settings.ParkStatus == ParkStatus.Parked)
            {
                System.Diagnostics.Debug.WriteLine("Parked");
            }
            else
            {
                // System.Diagnostics.Debug.WriteLine($"Current Axes: {axisPosition.RAAxis.Value}/{axisPosition.DecAxis.Value}\t{axisPosition.DecFlipped}\tRA/Dec: {_CurrentPosition.Equatorial.RightAscension}/{_CurrentPosition.Equatorial.Declination}\t{_CurrentPosition.PointingSideOfPier}\n");
            }

            _previousAxisPosition = axisPosition;
            // See if we can sort out the initial SideOfPier
            if (_previousPointingSOP == PierSide.pierUnknown)
            {
                // Only initialise the previous pointing SOP if we know for certain what it should be
                if (axisHasMoved && (_IsSlewing || _IsMoveAxisSlewing))
                {
                    // Remember the current pointing side of the pier.
                    // Until the SOP has been determined from a SLEW or GOTO it should not be updated.
                    _previousPointingSOP = _CurrentPosition.PointingSideOfPier;
                }
            }
            else
            {
                _previousPointingSOP = _CurrentPosition.PointingSideOfPier;
            }

            // If the axis has stopped moving there are some bit to clear up
            if (_wasMoving && !axisHasMoved)
            {
                // See if we need to refine a goto.
                if (_RefineGoto)
                {
                    _RefineGoto = false;
                    System.Diagnostics.Debug.WriteLine("Refining GOTO");
                    SlewToEquatorialCoordinate(TargetRightAscension, TargetDeclination);
                }
                else
                {
                    if (Settings.ParkStatus == ParkStatus.Unparked)
                    {
                        // Check if slew finished
                        if (_IsSlewing)
                        {
                            _IsSlewing = false;
                            // Announce("Slew complete.");
                        }
                        if (_IsMoveAxisSlewing)
                        {
                            _IsMoveAxisSlewing = false;
                        }
                        if (!_IsMoveAxisSlewing && !_IsSlewing)
                        {
                            if (TrackingState != TrackingStatus.Off)
                            {
                                System.Diagnostics.Debug.WriteLine("Restarting tracking");
                                LogMessage("Command", "Restarting tracking {0}", TrackingState);
                                StartTracking();
                            }
                        }
                    }
                }
            }

            _wasMoving = axisHasMoved;
        }
Esempio n. 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="targetRA"></param>
        /// <param name="targetDec"></param>
        /// <param name="tools"></param>
        /// <param name="futureOffset">Offset in future in seconds (if any)</param>
        /// <returns></returns>
        public AxisPosition GetAxisPositionForRADec(double targetRA, double targetDec, AscomTools tools, double futureOffset = 0.0)
        {
            bool   flipDEC;
            double adjustedRA = targetRA;
            double targetHA   = AstroConvert.RangeHA(targetRA - LocalApparentSiderialTime + (futureOffset / 3600.0));

            if (targetHA < 0) // Target is to the west.
            {
                if (ForceMeridianFlip)
                {
                    if (Hemisphere == HemisphereOption.Northern)
                    {
                        flipDEC = false;
                    }
                    else
                    {
                        flipDEC = true;
                    }
                    adjustedRA = targetRA;
                }
                else
                {
                    if (Hemisphere == HemisphereOption.Northern)
                    {
                        flipDEC = true;
                    }
                    else
                    {
                        flipDEC = false;
                    }
                    adjustedRA = AstroConvert.RangeRA(targetRA - 12);
                }
            }
            else
            {
                if (ForceMeridianFlip)
                {
                    if (Hemisphere == HemisphereOption.Northern)
                    {
                        flipDEC = true;
                    }
                    else
                    {
                        flipDEC = false;
                    }
                    adjustedRA = AstroConvert.RangeRA(targetRA - 12);
                }
                else
                {
                    if (Hemisphere == HemisphereOption.Northern)
                    {
                        flipDEC = false;
                    }
                    else
                    {
                        flipDEC = true;
                    }
                    adjustedRA = targetRA;
                }
            }


            // Compute for Target RA/DEC angles
            Angle RAAxis  = GetAxisPositionForRA(adjustedRA, 0.0, futureOffset);
            Angle DecAxis = GetAxisPositionForDec(targetDec, flipDEC);

            // System.Diagnostics.Debug.WriteLine($"RA/Dec:{targetHA}/{targetDec} Axes:{ RAAxis.Value}/{ DecAxis.Value} FlipDec: {flipDEC}");
            return(new AxisPosition(RAAxis.Value, DecAxis.Value, flipDEC));
        }