Exemplo n.º 1
0
        internal static void Limits_BuildLimitDef()
        {
            object[, , , , ] aa_hadec = null;
            int    idx = 0;
            double ha  = 0;
            double DEC = 0;

            // Because of the amount of maths involved to determine current limits we
            // maintain two arrays. LimitArray is a 'sparse' array used to file storage.
            // From this we construct LimitArray2 which holds limits for every degree of azimuth.
            // Limit and display code can therefore quickly access limits by using the current
            // azimuth as an index into LimitArray(2)

            for (idx = 0; idx <= 359; idx++)
            {
                LimitArray2[idx].Alt = Limits_GetAltLimit(Convert.ToDouble(idx));
                LimitArray2[idx].Az  = idx;
                object tempAuxVar = aa_hadec[Convert.ToInt32(EQMath.gLatitude * EQMath.DEG_RAD), Convert.ToInt32(LimitArray2[idx].Alt * EQMath.DEG_RAD), Convert.ToInt32(LimitArray2[idx].Az * EQMath.DEG_RAD), Convert.ToInt32(ha), Convert.ToInt32(DEC)];
                LimitArray2[idx].ha  = EQMath.Range24(ha * EQMath.RAD_HRS);
                LimitArray2[idx].DEC = DEC * EQMath.RAD_DEG;
            }
        }
Exemplo n.º 2
0
        internal static bool EQ_NPointAppend(double RightAscension, double Declination, double pLongitude, int pHemisphere)
        {
            bool   result       = false;
            object oLangDll     = null;
            object HC           = null;
            object StarEditform = null;

            double tRa   = 0;
            double tPier = 0;

            double DeltaRa  = 0;
            double DeltaDec = 0;

            int  i       = 0;
            int  Count   = 0;
            bool flipped = false;

            result = true;

            int curalign = gAlignmentStars_count + 1;

            // build alignment record
            int    ERa  = Common.EQGetMotorValues(0);
            int    EDec = Common.EQGetMotorValues(1);
            double vRA  = RightAscension;
            double vDEC = Declination;

            // look at current position and detemrine if flipped
            double RA_Hours = EQMath.Get_EncoderHours(EQMath.gRAEncoder_Zero_pos, Convert.ToDouble(ERa), EQMath.gTot_RA, EQMath.gHemisphere);

            if (RA_Hours > 12)
            {
                // Yes we're currently flipped!
                flipped = true;
            }
            else
            {
                flipped = false;
            }

            double tha = EQMath.RangeHA(vRA - EQMath.EQnow_lst(pLongitude * EQMath.DEG_RAD));

            if (tha < 0)
            {
                if (flipped)
                {
                    if (EQMath.gHemisphere == 0)
                    {
                        tPier = 0;
                    }
                    else
                    {
                        tPier = 1;
                    }
                    tRa = vRA;
                }
                else
                {
                    if (EQMath.gHemisphere == 0)
                    {
                        tPier = 1;
                    }
                    else
                    {
                        tPier = 0;
                    }
                    tRa = EQMath.Range24(vRA - 12);
                }
            }
            else
            {
                if (flipped)
                {
                    if (EQMath.gHemisphere == 0)
                    {
                        tPier = 1;
                    }
                    else
                    {
                        tPier = 0;
                    }
                    tRa = EQMath.Range24(vRA - 12);
                }
                else
                {
                    if (EQMath.gHemisphere == 0)
                    {
                        tPier = 0;
                    }
                    else
                    {
                        tPier = 1;
                    }
                    tRa = vRA;
                }
            }

            //Compute for Sync RA/DEC Encoder Values
            AlignmentStars[curalign].OrigTargetDEC = Declination;
            AlignmentStars[curalign].OrigTargetRA  = RightAscension;
            AlignmentStars[curalign].TargetRA      = EQMath.Get_RAEncoderfromRA(tRa, 0, pLongitude, EQMath.gRAEncoder_Zero_pos, EQMath.gTot_RA, pHemisphere);
            AlignmentStars[curalign].TargetDEC     = EQMath.Get_DECEncoderfromDEC(vDEC, tPier, EQMath.gDECEncoder_Zero_pos, EQMath.gTot_DEC, pHemisphere);
            AlignmentStars[curalign].EncoderRA     = ERa;
            AlignmentStars[curalign].EncoderDEC    = EDec;
            AlignmentStars[curalign].AlignTime     = DateTime.Now;

            DeltaRa  = AlignmentStars[curalign].TargetRA - AlignmentStars[curalign].EncoderRA;            //'  Difference between theoretical position and encode position.
            DeltaDec = AlignmentStars[curalign].TargetDEC - AlignmentStars[curalign].EncoderDEC;          //'  Difference between theoretical position and encode position.


            //UPGRADE_TODO: (1067) Member EncoderTimer is not defined in type Variant. More Information: https://www.mobilize.net/vbtonet/ewis/ewi1067
            HC.EncoderTimer.Enabled = true;

            if ((Math.Abs(DeltaRa) < EQMath.gEQ_MAXSYNC) && (Math.Abs(DeltaDec) < EQMath.gEQ_MAXSYNC) || Common.gDisableSyncLimit)
            {
                // Use this data also for next sync until a three star is achieved
                EQMath.gRA1Star  = DeltaRa;
                EQMath.gDEC1Star = DeltaDec;

                if (curalign < 3)
                {
                    //UPGRADE_TODO: (1067) Member GetLangString is not defined in type Variant. More Information: https://www.mobilize.net/vbtonet/ewis/ewi1067
                    //UPGRADE_TODO: (1067) Member Add_Message is not defined in type Variant. More Information: https://www.mobilize.net/vbtonet/ewis/ewi1067
                    HC.Add_Message(Conversion.Str(curalign) + " " + Convert.ToString(oLangDll.GetLangString(6009)));
                    gAlignmentStars_count++;
                }
                else
                {
                    if (curalign == 3)
                    {
                        gAlignmentStars_count = 3;
                        SendtoMatrix();
                    }
                    else
                    {
                        // add new point
                        Count = 1;
                        // copy points to temp array
                        int tempForEndVar = curalign - 1;
                        for (i = 1; i <= tempForEndVar; i++)
                        {
                            DeltaRa  = Math.Abs(AlignmentStars[i].EncoderRA - ERa);
                            DeltaDec = Math.Abs(AlignmentStars[i].EncoderDEC - EDec);
                            if (DeltaRa > ProximityRa || DeltaDec > ProximityDec)
                            {
                                // point is far enough away from the new point - so keep it
                                AlignmentStars[Count] = AlignmentStars[i];
                                Count++;
                            }
                            else
                            {
                                //                        HC.Add_Message ("Old Point too close " & CStr(deltaRA) & " " & CStr(deltadec) & " " & CStr(ProximityDec))
                            }
                        }

                        AlignmentStars[Count] = AlignmentStars[curalign];
                        curalign = Count;
                        gAlignmentStars_count = curalign;

                        SendtoMatrix();

                        //UPGRADE_TODO: (1067) Member RefreshDisplay is not defined in type Variant. More Information: https://www.mobilize.net/vbtonet/ewis/ewi1067
                        StarEditform.RefreshDisplay = true;
                    }
                }
            }
            else
            {
                // sync is too large!
                result = false;
                //UPGRADE_TODO: (1067) Member GetLangString is not defined in type Variant. More Information: https://www.mobilize.net/vbtonet/ewis/ewi1067
                //UPGRADE_TODO: (1067) Member Add_Message is not defined in type Variant. More Information: https://www.mobilize.net/vbtonet/ewis/ewi1067
                HC.Add_Message(oLangDll.GetLangString(6004));
                //UPGRADE_TODO: (1067) Member Add_Message is not defined in type Variant. More Information: https://www.mobilize.net/vbtonet/ewis/ewi1067
                HC.Add_Message("Target  RA=" + EQMath.FmtSexa(EQMath.gRA, false));
                //UPGRADE_TODO: (1067) Member Add_Message is not defined in type Variant. More Information: https://www.mobilize.net/vbtonet/ewis/ewi1067
                HC.Add_Message("Sync    RA=" + EQMath.FmtSexa(RightAscension, false));
                //UPGRADE_TODO: (1067) Member Add_Message is not defined in type Variant. More Information: https://www.mobilize.net/vbtonet/ewis/ewi1067
                HC.Add_Message("Target DEC=" + EQMath.FmtSexa(EQMath.gDec, true));
                //UPGRADE_TODO: (1067) Member Add_Message is not defined in type Variant. More Information: https://www.mobilize.net/vbtonet/ewis/ewi1067
                HC.Add_Message("Sync   DEC=" + EQMath.FmtSexa(Declination, true));
            }

            if (gSaveAPresetOnAppend == 1)
            {
                // don't write emtpy list!
                if (gAlignmentStars_count > 0)
                {
                    //idx = GetPresetIdx
                    string tempRefParam = "";
                    SaveAlignmentStars(GetPresetIdx(), ref tempRefParam);
                }
            }

            return(result);
        }
Exemplo n.º 3
0
        // called from the encoder timer to supervise active gotos
        internal static void ManageGoto()
        {
            object oLangDll = null;

            object[] EQ_Beep  = null;
            object   HC       = null;
            double   ra_diff  = 0;
            double   dec_diff = 0;

            //'''''''''''''''''''''''''''''''''''''''''''''
            // Fixed rate slew
            //'''''''''''''''''''''''''''''''''''''''''''''
            if (gGotoParams.RA_SlewActive == 1 || gGotoParams.DEC_SlewActive == 1)
            {
                // Handle as fixed rate slew
                if (gGotoParams.RA_SlewActive != 0)
                {
                    if (gGotoParams.RA_Direction == 0)
                    {
                        if (EQMath.gRA_Encoder >= gGotoParams.RA_targetencoder)
                        {
                            EQMath.eqres = UpgradeSolution1Support.PInvoke.SafeNative.eqcontrl.EQ_MotorStop(0);
                            //                    Do
                            //                        eqres = EQ_GetMotorStatus(0)
                            //                        If (eqres = EQ_NOTINITIALIZED) Or (eqres = EQ_COMNOTOPEN) Or (eqres = EQ_COMTIMEOUT) Then GoTo MG1
                            //                    Loop While (eqres And EQ_MOTORBUSY) <> 0
                            //MG1:
                            gGotoParams.RA_SlewActive = 0;
                            EQMath.eqres = UpgradeSolution1Support.PInvoke.SafeNative.eqcontrl.EQ_StartRATrack(0, EQMath.gHemisphere, EQMath.gHemisphere);
                        }
                    }
                    else
                    {
                        if (EQMath.gRA_Encoder <= gGotoParams.RA_targetencoder)
                        {
                            EQMath.eqres = UpgradeSolution1Support.PInvoke.SafeNative.eqcontrl.EQ_MotorStop(0);
                            //                    Do
                            //                        eqres = EQ_GetMotorStatus(0)
                            //                        If (eqres = EQ_NOTINITIALIZED) Or (eqres = EQ_COMNOTOPEN) Or (eqres = EQ_COMTIMEOUT) Then GoTo MG2
                            //                    Loop While (eqres And EQ_MOTORBUSY) <> 0
                            //MG2:
                            gGotoParams.RA_SlewActive = 0;
                            EQMath.eqres = UpgradeSolution1Support.PInvoke.SafeNative.eqcontrl.EQ_StartRATrack(0, EQMath.gHemisphere, EQMath.gHemisphere);
                        }
                    }
                }

                if (gGotoParams.DEC_SlewActive != 0)
                {
                    if (gGotoParams.DEC_Direction == 0)
                    {
                        if (EQMath.gDec_Encoder >= gGotoParams.DEC_targetencoder)
                        {
                            EQMath.eqres = UpgradeSolution1Support.PInvoke.SafeNative.eqcontrl.EQ_MotorStop(1);
                            //                    Do
                            //                        eqres = EQ_GetMotorStatus(1)
                            //                       If (eqres = EQ_NOTINITIALIZED) Or (eqres = EQ_COMNOTOPEN) Or (eqres = EQ_COMTIMEOUT) Then GoTo MG3
                            //                    Loop While (eqres And EQ_MOTORBUSY) <> 0
                            //MG3:
                            gGotoParams.DEC_SlewActive = 0;
                        }
                    }
                    else
                    {
                        if (EQMath.gDec_Encoder <= gGotoParams.DEC_targetencoder)
                        {
                            EQMath.eqres = UpgradeSolution1Support.PInvoke.SafeNative.eqcontrl.EQ_MotorStop(1);
                            //                    Do
                            //                        eqres = EQ_GetMotorStatus(1)
                            //                        If (eqres = EQ_NOTINITIALIZED) Or (eqres = EQ_COMNOTOPEN) Or (eqres = EQ_COMTIMEOUT) Then GoTo MG4
                            //                    Loop While (eqres And EQ_MOTORBUSY) <> 0
                            //MG4:
                            gGotoParams.DEC_SlewActive = 0;
                        }
                    }
                }


                if (gGotoParams.RA_SlewActive == 0 && gGotoParams.DEC_SlewActive == 0)
                {
                    switch (gGotoParams.SuperSafeMode)
                    {
                    case 0:
                        // rough fixed rate slew complete
                        CalcEncoderTargets();
                        ra_diff  = Math.Abs(gGotoParams.RA_targetencoder - EQMath.gRA_Encoder);
                        dec_diff = Math.Abs(gGotoParams.DEC_targetencoder - EQMath.gDec_Encoder);
                        //UPGRADE_TODO: (1067) Member Add_Message is not defined in type Variant. More Information: https://www.mobilize.net/vbtonet/ewis/ewi1067
                        HC.Add_Message("Goto: FRSlew complete ra_diff=" + ra_diff.ToString() + " dec_diff=" + dec_diff.ToString());
                        if ((ra_diff < EQMath.gTot_RA / 360d) && (dec_diff < EQMath.gTot_DEC / 540d))
                        {
                            // initiate a standard itterative goto if within a 3/4 of a degree.
                            gGotoParams.rate = 0;
                            StartSlew(gGotoParams.RA_targetencoder, gGotoParams.DEC_targetencoder, gGotoParams.RA_currentencoder, gGotoParams.DEC_currentencoder);
                        }
                        else
                        {
                            // Do another rough slew.
                            //UPGRADE_TODO: (1067) Member Add_Message is not defined in type Variant. More Information: https://www.mobilize.net/vbtonet/ewis/ewi1067
                            HC.Add_Message("Goto: FRSlew");
                            gFRSlewCount++;
                            if (gFRSlewCount >= 5)
                            {
                                //if we can't get close after 5 attempts then abandon the FR slew
                                //and use the full speed iterative slew
                                gFRSlewCount     = 0;
                                gGotoParams.rate = 0;
                            }
                            StartSlew(gGotoParams.RA_targetencoder, gGotoParams.DEC_targetencoder, gGotoParams.RA_currentencoder, gGotoParams.DEC_currentencoder);
                        }

                        break;

                    case 1:
                        // move to RA target
                        CalcEncoderTargets();
                        gGotoParams.SuperSafeMode = 0;
                        StartSlew(gGotoParams.RA_targetencoder, gGotoParams.DEC_targetencoder, gGotoParams.RA_currentencoder, gGotoParams.DEC_currentencoder);

                        //                Case 2
                        //                    ' we're at a limit about to go to target
                        //                    Call CalcEncoderTargets
                        //                    gGotoParams.SuperSafeMode = 0
                        //                    Call StartSlew(gGotoParams.RA_targetencoder, gGotoParams.DEC_targetencoder, gGotoParams.RA_currentencoder, gGotoParams.DEC_currentencoder)

                        break;

                    case 3:
                        // were at a limit position
                        if (gGotoParams.RA_targetencoder > EQMath.RAEncoder_Home_pos)
                        {
                            // dual axis slew to limit position nearest to target
                            gGotoParams.SuperSafeMode = 1;
                            if (!Limits.RALimitsActive())
                            {
                                StartSlew(gRAMeridianWest, gGotoParams.DEC_targetencoder, EQMath.gEmulRA, EQMath.gEmulDEC);
                            }
                            else
                            {
                                StartSlew(EQMath.gRA_Limit_West, gGotoParams.DEC_targetencoder, EQMath.gEmulRA, EQMath.gEmulDEC);
                            }
                        }
                        else
                        {
                            // dual axis slew to limit position nearest to target
                            gGotoParams.SuperSafeMode = 1;
                            if (!Limits.RALimitsActive())
                            {
                                StartSlew(gRAMeridianEast, gGotoParams.DEC_targetencoder, EQMath.gEmulRA, EQMath.gEmulDEC);
                            }
                            else
                            {
                                StartSlew(EQMath.gRA_Limit_East, gGotoParams.DEC_targetencoder, EQMath.gEmulRA, EQMath.gEmulDEC);
                            }
                        }

                        break;
                    }
                }
                return;
            }

            //'''''''''''''''''''''''''''''''''''''''''''''
            // Iterative slew - variable rate
            //'''''''''''''''''''''''''''''''''''''''''''''
            if ((Convert.ToInt32(EQMath.gRAStatus) & Convert.ToInt32(Common.EQ_MOTORBUSY)) == 0)
            {
                //At This point RA motor has completed the slew
                EQMath.gRAStatus_slew = true;
                if ((Convert.ToInt32(EQMath.gDECStatus) & Convert.ToInt32(Common.EQ_MOTORBUSY)) != 0)
                {
                    // The DEC motor is still moving so start sidereal tracking to hold position in RA
                    EQMath.eqres = UpgradeSolution1Support.PInvoke.SafeNative.eqcontrl.EQ_StartRATrack(0, EQMath.gHemisphere, EQMath.gHemisphere);
                }
            }

            if ((Convert.ToInt32(EQMath.gDECStatus) & Convert.ToInt32(Common.EQ_MOTORBUSY)) == 0 && EQMath.gRAStatus_slew)
            {
                //DEC and RA motors have finished slewing at this point
                //We need to check if a new slew is needed to reduce the any difference
                //Caused by the Movement of the earth during the slew process

                switch (gGotoParams.SuperSafeMode)
                {
                case 0:
                    // decrement the slew retry count
                    gSlewCount--;

                    // calculate the difference (arcsec)  between target and current coords
                    ra_diff  = 3600 * Math.Abs(EQMath.gRA - gTargetRA);
                    dec_diff = 3600 * Math.Abs(EQMath.gDec - gTargetDec);

                    if ((gSlewCount > 0) && (EQMath.gTrackingStatus > 0))
                    {                             // Retry only if tracking is enabled
                        // aim to get within the goto resolution (default = 10 steps)
                        if (gGotoResolution > 0 && ra_diff <= gRAGotoRes && dec_diff <= gDECGotoRes)
                        {
                            goto slewcomplete;
                        }
                        else
                        {
                            //Re Execute a new RA-Only slew here
                            CalcEncoderTargets();
                            gGotoParams.rate = 0;
                            StartSlew(gGotoParams.RA_targetencoder, gGotoParams.DEC_targetencoder, gGotoParams.RA_currentencoder, gGotoParams.DEC_currentencoder);
                        }
                    }
                    else
                    {
                        goto slewcomplete;
                    }

                    break;

                case 1:
                    // move to target
                    gGotoParams.SuperSafeMode = 0;
                    CalcEncoderTargets();
                    gGotoParams.rate = 0;
                    //kick of an iterative slew to get us accurately to target RA
                    StartSlew(gGotoParams.RA_targetencoder, gGotoParams.DEC_targetencoder, gGotoParams.RA_currentencoder, gGotoParams.DEC_currentencoder);

                    //            Case 2
                    //                ' At a limit about to slew to target
                    //                Call CalcEncoderTargets
                    //                gGotoParams.SuperSafeMode = 0
                    //               Call StartSlew(gGotoParams.RA_targetencoder, gGotoParams.DEC_targetencoder, gEmulRA, gEmulDEC)

                    break;

                case 3:
                    // we are at a limit position
                    if (gGotoParams.RA_targetencoder > EQMath.RAEncoder_Home_pos)
                    {
                        // dual axis slew to limit position nearest to target
                        gGotoParams.SuperSafeMode = 1;
                        if (!Limits.RALimitsActive())
                        {
                            StartSlew(gRAMeridianWest, gGotoParams.DEC_targetencoder, EQMath.gEmulRA, EQMath.gEmulDEC);
                        }
                        else
                        {
                            StartSlew(EQMath.gRA_Limit_West, gGotoParams.DEC_targetencoder, EQMath.gEmulRA, EQMath.gEmulDEC);
                        }
                    }
                    else
                    {
                        // dual axis slew to limit position nearest to target
                        gGotoParams.SuperSafeMode = 1;
                        if (!Limits.RALimitsActive())
                        {
                            StartSlew(gRAMeridianEast, gGotoParams.DEC_targetencoder, EQMath.gEmulRA, EQMath.gEmulDEC);
                        }
                        else
                        {
                            StartSlew(EQMath.gRA_Limit_West, gGotoParams.DEC_targetencoder, EQMath.gEmulRA, EQMath.gEmulDEC);
                        }
                    }


                    break;
                }
            }
            return;

slewcomplete:
            EQMath.gSlewStatus           = false;
            EQMath.gRAStatus_slew        = false;
            Limits.gSupressHorizonLimits = false;

            // slew may have terminated early if parked
            if (EQMath.gEQparkstatus != 1)
            {
                // we've reached the desired target coords - resume tracking.
                switch (EQMath.gTrackingStatus)
                {
                case 0:
                case 1:
                    Tracking.EQStartSidereal();
                    break;

                case 2:
                case 3:
                case 4:
                    Tracking.RestartTracking();
                    break;
                }

                //UPGRADE_TODO: (1067) Member GetLangString is not defined in type Variant. More Information: https://www.mobilize.net/vbtonet/ewis/ewi1067
                //UPGRADE_TODO: (1067) Member Add_Message is not defined in type Variant. More Information: https://www.mobilize.net/vbtonet/ewis/ewi1067
                HC.Add_Message(Convert.ToString(oLangDll.GetLangString(5018)) + " " + EQMath.FmtSexa(EQMath.gRA, false) + " " + EQMath.FmtSexa(EQMath.gDec, true));
                //UPGRADE_TODO: (1067) Member Add_Message is not defined in type Variant. More Information: https://www.mobilize.net/vbtonet/ewis/ewi1067
                HC.Add_Message("Goto: SlewItereations=" + (gMaxSlewCount - gSlewCount).ToString());
                //UPGRADE_TODO: (1067) Member Add_Message is not defined in type Variant. More Information: https://www.mobilize.net/vbtonet/ewis/ewi1067
                HC.Add_Message("Goto: " + "RaDiff=" + StringsHelper.Format(Conversion.Str(ra_diff), "000.00") + " DecDiff=" + StringsHelper.Format(Conversion.Str(dec_diff), "000.00"));

                // goto complete
                object tempAuxVar = EQ_Beep[6];
            }

            if (gDisbleFlipGotoReset == 0)
            {
                //UPGRADE_TODO: (1067) Member ChkForceFlip is not defined in type Variant. More Information: https://www.mobilize.net/vbtonet/ewis/ewi1067
                HC.ChkForceFlip.value = 0;
            }
        }
Exemplo n.º 4
0
        internal static void StartSlew(double targetRAEncoder, double targetDECEncoder, double currentRAEncoder, double currentDECEncoder)
        {
            int DeltaRAStep  = 0;
            int DeltaDECStep = 0;

            try
            {
                // calculate relative amount to move
                DeltaRAStep  = Convert.ToInt32(Math.Abs(targetRAEncoder - currentRAEncoder));
                DeltaDECStep = Convert.ToInt32(Math.Abs(targetDECEncoder - currentDECEncoder));

                if (DeltaRAStep != 0)
                {
                    // Compensate for the smallest discrepancy after the final slew
                    if (EQMath.gTrackingStatus > 0)
                    {
                        if (targetRAEncoder > currentRAEncoder)
                        {
                            if (EQMath.gHemisphere == 0)
                            {
                                DeltaRAStep += gRA_Compensate;
                            }
                            else
                            {
                                DeltaRAStep -= gRA_Compensate;
                            }
                        }
                        else
                        {
                            if (EQMath.gHemisphere == 0)
                            {
                                DeltaRAStep -= gRA_Compensate;
                            }
                            else
                            {
                                DeltaRAStep += gRA_Compensate;
                            }
                        }
                        if (DeltaRAStep < 0)
                        {
                            DeltaRAStep = 0;
                        }
                    }

                    if (targetRAEncoder > currentRAEncoder)
                    {
                        gGotoParams.RA_Direction = 0;
                        switch (gGotoParams.rate)
                        {
                        case 0:
                            // let mount decide on slew rate
                            gGotoParams.RA_SlewActive = 0;
                            EQMath.eqres = Common.EQStartMoveMotor(0, 0, 0, DeltaRAStep, Convert.ToInt32(EQMath.GetSlowdown(DeltaRAStep)));
                            break;

                        default:
                            gGotoParams.RA_SlewActive = 1;
                            EQMath.eqres = UpgradeSolution1Support.PInvoke.SafeNative.eqcontrl.EQ_Slew(0, 0, 0, Convert.ToInt32(gGotoParams.rate));
                            break;
                        }
                    }
                    else
                    {
                        gGotoParams.RA_Direction = 1;
                        switch (gGotoParams.rate)
                        {
                        case 0:
                            gGotoParams.RA_SlewActive = 0;
                            EQMath.eqres = Common.EQStartMoveMotor(0, 0, 1, DeltaRAStep, Convert.ToInt32(EQMath.GetSlowdown(DeltaRAStep)));
                            break;

                        default:
                            gGotoParams.RA_SlewActive = 1;
                            EQMath.eqres = UpgradeSolution1Support.PInvoke.SafeNative.eqcontrl.EQ_Slew(0, 0, 1, Convert.ToInt32(gGotoParams.rate));
                            break;
                        }
                    }
                }

                if (DeltaDECStep != 0)
                {
                    if (targetDECEncoder > currentDECEncoder)
                    {
                        gGotoParams.DEC_Direction = 0;
                        switch (gGotoParams.rate)
                        {
                        case 0:
                            // let mount decide on slew rate
                            gGotoParams.DEC_SlewActive = 0;
                            EQMath.eqres = Common.EQStartMoveMotor(1, 0, 0, DeltaDECStep, Convert.ToInt32(EQMath.GetSlowdown(DeltaDECStep)));
                            break;

                        default:
                            gGotoParams.DEC_SlewActive = 1;
                            EQMath.eqres = UpgradeSolution1Support.PInvoke.SafeNative.eqcontrl.EQ_Slew(1, 0, 0, Convert.ToInt32(gGotoParams.rate));
                            break;
                        }
                    }
                    else
                    {
                        gGotoParams.DEC_Direction = 1;
                        switch (gGotoParams.rate)
                        {
                        case 0:
                            // let mount decide on slew rate
                            gGotoParams.DEC_SlewActive = 0;
                            EQMath.eqres = Common.EQStartMoveMotor(1, 0, 1, DeltaDECStep, Convert.ToInt32(EQMath.GetSlowdown(DeltaDECStep)));
                            break;

                        default:
                            gGotoParams.DEC_SlewActive = 1;
                            EQMath.eqres = UpgradeSolution1Support.PInvoke.SafeNative.eqcontrl.EQ_Slew(1, 0, 1, Convert.ToInt32(gGotoParams.rate));
                            break;
                        }
                    }
                }

                // Activate Asynchronous Slew Monitoring Routine
                EQMath.gRAStatus      = Common.EQ_MOTORBUSY;
                EQMath.gDECStatus     = Common.EQ_MOTORBUSY;
                EQMath.gRAStatus_slew = false;
            }
            catch
            {
            }


            EQMath.gSlewStatus = true;
        }
Exemplo n.º 5
0
        internal static void CalcEncoderGotoTargets(double tRa, double tDec, ref double RaEnc, ref double DecEnc)
        {
            eqmodvector.Coordt tmpcoord = new eqmodvector.Coordt();
            double             tPier    = 0;

            double tha = EQMath.RangeHA(tRa - EQMath.EQnow_lst(EQMath.gLongitude * EQMath.DEG_RAD));

            if (tha < 0)
            {
                if (EQMath.gHemisphere == 0)
                {
                    tPier = 1;
                }
                else
                {
                    tPier = 0;
                }
                tRa = EQMath.Range24(tRa - 12);
            }
            else
            {
                if (EQMath.gHemisphere == 0)
                {
                    tPier = 0;
                }
                else
                {
                    tPier = 1;
                }
            }

            //Compute for Target RA/DEC Encoder
            RaEnc  = EQMath.Get_RAEncoderfromRA(tRa, 0, EQMath.gLongitude, EQMath.gRAEncoder_Zero_pos, EQMath.gTot_RA, EQMath.gHemisphere);
            DecEnc = EQMath.Get_DECEncoderfromDEC(tDec, tPier, EQMath.gDECEncoder_Zero_pos, EQMath.gTot_DEC, EQMath.gHemisphere);

            if (Alignment.gThreeStarEnable)
            {
                // Transform target using model
                switch (Common.gAlignmentMode)
                {
                case 2:
                    // n-star+nearest
                    tmpcoord = EQMath.DeltaSyncReverse_Matrix_Map(RaEnc - EQMath.gRASync01, DecEnc - EQMath.gDECSync01);
                    break;

                case 1:
                    // n-star
                    tmpcoord = EQMath.Delta_Matrix_Map(RaEnc - EQMath.gRASync01, DecEnc - EQMath.gDECSync01);
                    break;

                default:
                    // nearest
                    tmpcoord = EQMath.Delta_Matrix_Map(RaEnc - EQMath.gRASync01, DecEnc - EQMath.gDECSync01);

                    if (tmpcoord.f == 0)
                    {
                        tmpcoord = EQMath.DeltaSyncReverse_Matrix_Map(RaEnc - EQMath.gRASync01, DecEnc - EQMath.gDECSync01);
                    }
                    break;
                }
                RaEnc  = tmpcoord.x;
                DecEnc = tmpcoord.Y;
            }
        }
Exemplo n.º 6
0
        internal static void CalcEncoderTargets()
        {
            object HC = null;
            double targetRAEncoder   = 0;
            double targetDECEncoder  = 0;
            double currentRAEncoder  = 0;
            double currentDECEncoder = 0;

            eqmodvector.Coordt tmpcoord = new eqmodvector.Coordt();
            double             tRa      = 0;
            double             tha      = 0;
            double             tPier    = 0;

            try
            {
                EQMath.gSlewStatus = false;

                //stop the motors
                PEC.PEC_StopTracking();
                EQMath.eqres = UpgradeSolution1Support.PInvoke.SafeNative.eqcontrl.EQ_MotorStop(2);
                //    eqres = EQ_MotorStop(0)
                //    eqres = EQ_MotorStop(1)

                //    'Wait for motor stop , Need to add timeout routines here
                //    Do
                //        eqres = EQ_GetMotorStatus(0)
                //        If (eqres = EQ_NOTINITIALIZED) Or (eqres = EQ_COMNOTOPEN) Or (eqres = EQ_COMTIMEOUT) Then GoTo SL01
                //    Loop While (eqres And EQ_MOTORBUSY) <> 0
                //
                //SL01:
                //    Do
                //        eqres = EQ_GetMotorStatus(1)
                //        If (eqres = EQ_NOTINITIALIZED) Or (eqres = EQ_COMNOTOPEN) Or (eqres = EQ_COMTIMEOUT) Then GoTo SL02
                //    Loop While (eqres And EQ_MOTORBUSY) <> 0
                //
                //SL02:

                // read current
                currentRAEncoder  = Common.EQGetMotorValues(0);
                currentDECEncoder = Common.EQGetMotorValues(1);

                tha = EQMath.RangeHA(gTargetRA - EQMath.EQnow_lst(EQMath.gLongitude * EQMath.DEG_RAD));
                if (tha < 0)
                {
                    if (gCWUP)
                    {
                        if (EQMath.gHemisphere == 0)
                        {
                            tPier = 0;
                        }
                        else
                        {
                            tPier = 1;
                        }
                        tRa = gTargetRA;
                    }
                    else
                    {
                        if (EQMath.gHemisphere == 0)
                        {
                            tPier = 1;
                        }
                        else
                        {
                            tPier = 0;
                        }
                        tRa = EQMath.Range24(gTargetRA - 12);
                    }
                }
                else
                {
                    if (gCWUP)
                    {
                        if (EQMath.gHemisphere == 0)
                        {
                            tPier = 1;
                        }
                        else
                        {
                            tPier = 0;
                        }
                        tRa = EQMath.Range24(gTargetRA - 12);
                    }
                    else
                    {
                        if (EQMath.gHemisphere == 0)
                        {
                            tPier = 0;
                        }
                        else
                        {
                            tPier = 1;
                        }
                        tRa = gTargetRA;
                    }
                }

                //Compute for Target RA/DEC Encoder
                targetRAEncoder  = EQMath.Get_RAEncoderfromRA(tRa, 0, EQMath.gLongitude, EQMath.gRAEncoder_Zero_pos, EQMath.gTot_RA, EQMath.gHemisphere);
                targetDECEncoder = EQMath.Get_DECEncoderfromDEC(gTargetDec, tPier, EQMath.gDECEncoder_Zero_pos, EQMath.gTot_DEC, EQMath.gHemisphere);

                if (gCWUP)
                {
                    //UPGRADE_TODO: (1067) Member Add_Message is not defined in type Variant. More Information: https://www.mobilize.net/vbtonet/ewis/ewi1067
                    HC.Add_Message("Goto: CW-UP slew requested");
                    // if RA limits are active
                    //UPGRADE_TODO: (1067) Member ChkEnableLimits is not defined in type Variant. More Information: https://www.mobilize.net/vbtonet/ewis/ewi1067
                    if (Convert.ToDouble(HC.ChkEnableLimits.value) == 1 && EQMath.gRA_Limit_East != 0 && EQMath.gRA_Limit_West != 0)
                    {
                        // check that the target position is within limits
                        if (EQMath.gHemisphere == 0)
                        {
                            if (targetRAEncoder < EQMath.gRA_Limit_East || targetRAEncoder > EQMath.gRA_Limit_West)
                            {
                                // target position is outside limits
                                gCWUP = false;
                            }
                        }
                        else
                        {
                            if (targetRAEncoder > EQMath.gRA_Limit_East || targetRAEncoder < EQMath.gRA_Limit_West)
                            {
                                // target position is outside limits
                                gCWUP = false;
                            }
                        }

                        // if target position is outside limits
                        if (!gCWUP)
                        {
                            //UPGRADE_TODO: (1067) Member Add_Message is not defined in type Variant. More Information: https://www.mobilize.net/vbtonet/ewis/ewi1067
                            HC.Add_Message("Goto: RA Limits prevent CW-UP slew");
                            //then abandon Counter Weights up Slew and recalculate for a standard slew.
                            if (tha < 0)
                            {
                                if (EQMath.gHemisphere == 0)
                                {
                                    tPier = 1;
                                }
                                else
                                {
                                    tPier = 0;
                                }
                                tRa = EQMath.Range24(gTargetRA - 12);
                            }
                            else
                            {
                                if (EQMath.gHemisphere == 0)
                                {
                                    tPier = 0;
                                }
                                else
                                {
                                    tPier = 1;
                                }
                                tRa = gTargetRA;
                            }
                            targetRAEncoder  = EQMath.Get_RAEncoderfromRA(tRa, 0, EQMath.gLongitude, EQMath.gRAEncoder_Zero_pos, EQMath.gTot_RA, EQMath.gHemisphere);
                            targetDECEncoder = EQMath.Get_DECEncoderfromDEC(gTargetDec, tPier, EQMath.gDECEncoder_Zero_pos, EQMath.gTot_DEC, EQMath.gHemisphere);
                        }
                    }
                }

                if (!Alignment.gThreeStarEnable)
                {
                    Alignment.gSelectStar = 0;
                    currentRAEncoder      = EQMath.Delta_RA_Map(currentRAEncoder);
                    currentDECEncoder     = EQMath.Delta_DEC_Map(currentDECEncoder);
                }
                else
                {
                    // Transform target using model
                    switch (Common.gAlignmentMode)
                    {
                    case 2:
                        // n-star+nearest
                        tmpcoord = EQMath.DeltaSyncReverse_Matrix_Map(targetRAEncoder - EQMath.gRASync01, targetDECEncoder - EQMath.gDECSync01);
                        break;

                    case 1:
                        // n-star
                        tmpcoord = EQMath.Delta_Matrix_Map(targetRAEncoder - EQMath.gRASync01, targetDECEncoder - EQMath.gDECSync01);
                        break;

                    default:
                        // nearest
                        tmpcoord = EQMath.Delta_Matrix_Map(targetRAEncoder - EQMath.gRASync01, targetDECEncoder - EQMath.gDECSync01);

                        if (tmpcoord.f == 0)
                        {
                            tmpcoord = EQMath.DeltaSyncReverse_Matrix_Map(targetRAEncoder - EQMath.gRASync01, targetDECEncoder - EQMath.gDECSync01);
                        }
                        break;
                    }
                    targetRAEncoder  = tmpcoord.x;
                    targetDECEncoder = tmpcoord.Y;
                }

                //Execute the actual slew
                gGotoParams.RA_targetencoder   = targetRAEncoder;
                gGotoParams.RA_currentencoder  = currentRAEncoder;
                gGotoParams.DEC_targetencoder  = targetDECEncoder;
                gGotoParams.DEC_currentencoder = currentDECEncoder;
                //UPGRADE_TODO: (1067) Member Add_Message is not defined in type Variant. More Information: https://www.mobilize.net/vbtonet/ewis/ewi1067
                HC.Add_Message("Goto: " + EQMath.FmtSexa(gTargetRA, false) + " " + EQMath.FmtSexa(gTargetDec, true));
                //    HC.Add_Message "Goto: RaEnc=" & CStr(currentRAEncoder) & " Target=" & CStr(targetRAEncoder)
                //    HC.Add_Message "Goto: DecEnc=" & CStr(currentDECEncoder) & " Target=" & CStr(targetDECEncoder)
            }
            catch
            {
            }
        }
Exemplo n.º 7
0
        internal static double Limits_TimeToHorizon()
        {
            double result = 0;
            int    i      = 0;
            double ha     = 0;
            double tmp    = 0;

            // Establish the time the scaope will take, at sidereal rate, to reach the horizon

            // -1 indicates never reaches horizon
            result = -1;

            try
            {
                if (EQMath.gHemisphere == 0)
                {
                    // only consider western horizon (stars just don't set in the east!)
                    for (i = 180; i <= 359; i++)
                    {
                        // search for the point where the horizon declination is greater or equal to our scope declination
                        ha  = LimitArray2[i].ha;
                        tmp = LimitArray2[i].DEC;


                        if (tmp >= EQMath.gDec)
                        {
                            // calulate difference between horizon hour angle and scope hour angle

                            tmp = ha - EQMath.Range24(EQMath.EQnow_lst(EQMath.gLongitude * EQMath.DEG_RAD) - EQMath.gRA);
                            if (tmp < 0)
                            {
                                tmp = 24 + tmp;
                            }
                            result = tmp;

                            throw new Exception();
                        }
                    }
                }
                else
                {
                    // only consider western horizon (stars just don't set in the east!)
                    for (i = 180; i <= 359; i++)
                    {
                        // search for the point where the horizon declination is greater or equal to our scope declination
                        ha  = LimitArray2[i].ha;
                        tmp = LimitArray2[i].DEC;


                        if (tmp >= EQMath.gDec)
                        {
                            // calulate difference between horizon hour angle and scope hour angle

                            tmp = ha - EQMath.Range24(EQMath.EQnow_lst(EQMath.gLongitude * EQMath.DEG_RAD) - EQMath.gRA);
                            if (tmp < 0)
                            {
                                tmp = 24 + tmp;
                            }
                            result = tmp;

                            throw new Exception();
                        }
                    }
                }
            }
            catch
            {
            }



            return(result);
        }
Exemplo n.º 8
0
        private static TLIMIT_STATUS Limits_Detect()
        {
            TLIMIT_STATUS result   = new TLIMIT_STATUS();
            object        oLangDll = null;

            object[] EQ_Beep = null;
            object   HC      = null;

            double Alt           = 0;
            bool   LimitDetected = false;

            result.LimitDetected = false;
            result.Horizon       = false;
            result.RA            = false;

            // Routine to handle RA LIMIT processing
            if ((EQMath.gRA_Limit_East != 0) && (EQMath.gEmulRA < EQMath.gRAEncoder_Zero_pos))
            {
                if (EQMath.gEmulRA < EQMath.gRA_Limit_East)
                {
                    if (gAutoFlipEnabled)
                    {
                        switch (AutoFlipState)
                        {
                        case 0:
                            //we've hit the RA limit so initiate autoflip!
                            Goto.gTargetRA  = EQMath.gRA;
                            Goto.gTargetDec = EQMath.gDec;
                            //UPGRADE_TODO: (1067) Member GetLangString is not defined in type Variant. More Information: https://www.mobilize.net/vbtonet/ewis/ewi1067
                            //UPGRADE_TODO: (1067) Member Add_Message is not defined in type Variant. More Information: https://www.mobilize.net/vbtonet/ewis/ewi1067
                            HC.Add_Message("CoordSlew: " + Convert.ToString(oLangDll.GetLangString(105)) + "[ " + EQMath.FmtSexa(Goto.gTargetRA, false) + " ] " + Convert.ToString(oLangDll.GetLangString(106)) + "[ " + EQMath.FmtSexa(Goto.gTargetDec, true) + " ]");
                            Goto.gSlewCount = Goto.gMaxSlewCount;                                      //NUM_SLEW_RETRIES               'Set initial iterative slew count
                            object tempAuxVar = EQ_Beep[2];
                            Goto.radecAsyncSlew(Goto.gGotoRate);
                            AutoFlipState = 1;
                            break;

                        default:
                            break;
                        }
                    }
                    else
                    {
                        result.RA = true;
                    }
                    goto endsub;
                }
                else
                {
                    AutoFlipState = 0;
                }
            }

            if ((EQMath.gRA_Limit_West != 0) && (EQMath.gEmulRA > EQMath.gRAEncoder_Zero_pos))
            {
                if (EQMath.gEmulRA > EQMath.gRA_Limit_West)
                {
                    if (gAutoFlipEnabled)
                    {
                        switch (AutoFlipState)
                        {
                        case 0:
                            //we've hit the RA limit so initiate autoflip!
                            Goto.gTargetRA  = EQMath.gRA;
                            Goto.gTargetDec = EQMath.gDec;
                            //UPGRADE_TODO: (1067) Member GetLangString is not defined in type Variant. More Information: https://www.mobilize.net/vbtonet/ewis/ewi1067
                            //UPGRADE_TODO: (1067) Member Add_Message is not defined in type Variant. More Information: https://www.mobilize.net/vbtonet/ewis/ewi1067
                            HC.Add_Message("CoordSlew: " + Convert.ToString(oLangDll.GetLangString(105)) + "[ " + EQMath.FmtSexa(Goto.gTargetRA, false) + " ] " + Convert.ToString(oLangDll.GetLangString(106)) + "[ " + EQMath.FmtSexa(Goto.gTargetDec, true) + " ]");
                            Goto.gSlewCount = Goto.gMaxSlewCount;                                      //NUM_SLEW_RETRIES               'Set initial iterative slew count
                            object tempAuxVar2 = EQ_Beep[2];
                            Goto.radecAsyncSlew(Goto.gGotoRate);
                            AutoFlipState = 1;
                            break;

                        default:
                            break;
                        }
                    }
                    else
                    {
                        result.RA = true;
                    }
                    goto endsub;
                }
                else
                {
                    AutoFlipState = 0;
                }
            }

endsub:
            // get altitude limit for current azimuth
            if (!gSupressHorizonLimits)
            {
                if (EQMath.gAlt <= LimitArray2[Convert.ToInt32(EQMath.gAz)].Alt)
                {
                    result.Horizon = true;
                }
            }
            else
            {
                result.Horizon = false;
            }


            result.LimitDetected = result.Horizon || result.RA;
            return(result);
        }
Exemplo n.º 9
0
        internal static void Limits_ReadFile(string FileName)
        {
            object[, , , , ] aa_hadec = null;
            object HC         = null;
            int    pos        = 0;
            int    size       = 0;
            int    redimcount = 0;
            string temp1      = "";
            string temp2      = "";
            double ha         = 0;
            double DEC        = 0;

            LimitArray = ArraysHelper.InitializeArray <LIMIT>(1);
            try
            {
                if (FileName != "")
                {
                    FileSystem.FileClose(1);
                    FileSystem.FileOpen(1, FileName, OpenMode.Input, OpenAccess.Default, OpenShare.Default, -1);
                    LimitArray = ArraysHelper.InitializeArray <LIMIT>(101);
                    size       = 0;
                    redimcount = 0;
                    while (!FileSystem.EOF(1))
                    {
                        temp1 = FileSystem.LineInput(1);
                        temp2 = temp1.Substring(0, Math.Min(1, temp1.Length));
                        if (temp2 != "#" && temp2 != " ")
                        {
                            pos = (temp1.IndexOf(' ') + 1);
                            if (pos != 0)
                            {
                                temp2 = temp1.Substring(0, Math.Min(pos - 1, temp1.Length));
                                temp1 = temp1.Substring(Math.Max(temp1.Length - (Strings.Len(temp1) - pos), 0));
                                LimitArray[size].Az  = Double.Parse(temp2);
                                LimitArray[size].Alt = Double.Parse(temp1);
                                object tempAuxVar = aa_hadec[Convert.ToInt32(EQMath.gLatitude * EQMath.DEG_RAD), Convert.ToInt32(LimitArray[size].Alt * EQMath.DEG_RAD), Convert.ToInt32(LimitArray[size].Az * EQMath.DEG_RAD), Convert.ToInt32(ha), Convert.ToInt32(DEC)];
                                LimitArray[size].ha  = EQMath.Range24(ha * EQMath.RAD_HRS);
                                LimitArray[size].DEC = DEC * EQMath.RAD_DEG;
                                size++;
                                redimcount++;
                                if (redimcount > 90)
                                {
                                    redimcount = 0;
                                    LimitArray = ArraysHelper.RedimPreserve(LimitArray, new int[] { size + 101 });
                                }
                            }
                        }
                    }
                    LimitArray = ArraysHelper.RedimPreserve(LimitArray, new int[] { size + 1 });
                }
                Limits_BuildLimitDef();
            }
            catch
            {
                //UPGRADE_TODO: (1067) Member Add_Message is not defined in type Variant. More Information: https://www.mobilize.net/vbtonet/ewis/ewi1067
                HC.Add_Message("Error reading limits file");
            }
            finally
            {
                FileSystem.FileClose(1);
            }
        }
Exemplo n.º 10
0
        //UPGRADE_NOTE: (2041) The following line was commented. More Information: https://www.mobilize.net/vbtonet/ewis/ewi2041
        //[DllImport("kernel32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
        //extern public static int GetTickCount();

        private void EncoderTimer_Timer()
        {
            eqmodvector.Coordt tmpcoord = new eqmodvector.Coordt();
            double             tRa      = 0;
            double             tAlt     = 0;
            double             tAz      = 0;
            object             tmpRa    = null;
            int tmpDec = 0;

            //Avoid overruns
            if (EncoderTimerFlag)
            {
                EncoderTimerFlag = false;
                //UPGRADE_TODO: (1067) Member CheckRASync is not defined in type HC. More Information: https://www.mobilize.net/vbtonet/ewis/ewi1067
                //Read true motor positions
                tmpRa  = Common.EQGetMotorValues(0);
                tmpDec = Common.EQGetMotorValues(1);

                EQMath.gEmulRA      = Convert.ToDouble(tmpRa);
                EQMath.gEmulDEC     = tmpDec;
                EQMath.gEmulRA_Init = EQMath.gEmulRA;
                EQMath.gLast_time   = EQMath.EQnow_lst_norange();
                EQMath.gEmulOneShot = false;

                if (!Alignment.gThreeStarEnable)
                {
                    Alignment.gSelectStar = 0;
                    EQMath.gRA_Encoder    = EQMath.Delta_RA_Map(EQMath.gEmulRA);
                    EQMath.gDec_Encoder   = EQMath.Delta_DEC_Map(EQMath.gEmulDEC);
                }
                else
                {
                    switch (Common.gAlignmentMode)
                    {
                    case 2:
                        tmpcoord            = EQMath.DeltaSync_Matrix_Map(EQMath.gEmulRA, EQMath.gEmulDEC);
                        EQMath.gRA_Encoder  = tmpcoord.x;
                        EQMath.gDec_Encoder = tmpcoord.Y;

                        break;

                    case 1:
                        tmpcoord            = EQMath.Delta_Matrix_Reverse_Map(EQMath.gEmulRA, EQMath.gEmulDEC);
                        EQMath.gRA_Encoder  = tmpcoord.x;
                        EQMath.gDec_Encoder = tmpcoord.Y;

                        break;

                    default:
                        tmpcoord            = EQMath.Delta_Matrix_Reverse_Map(EQMath.gEmulRA, EQMath.gEmulDEC);
                        EQMath.gRA_Encoder  = tmpcoord.x;
                        EQMath.gDec_Encoder = tmpcoord.Y;
                        if (tmpcoord.f == 0)
                        {
                            tmpcoord            = EQMath.DeltaSync_Matrix_Map(EQMath.gEmulRA, EQMath.gEmulDEC);
                            EQMath.gRA_Encoder  = tmpcoord.x;
                            EQMath.gDec_Encoder = tmpcoord.Y;
                        }

                        break;
                    }
                }

                //Convert RA_Encoder to Hours
                if ((EQMath.gRA_Encoder < 0x1000000))
                {
                    EQMath.gRA_Hours = EQMath.Get_EncoderHours(EQMath.gRAEncoder_Zero_pos, EQMath.gRA_Encoder, EQMath.gTot_RA, EQMath.gHemisphere);
                }

                //Convert DEC_Encoder to DEC Degrees
                EQMath.gDec_DegNoAdjust = EQMath.Get_EncoderDegrees(EQMath.gDECEncoder_Zero_pos, EQMath.gDec_Encoder, EQMath.gTot_DEC, EQMath.gHemisphere);
                if (EQMath.gDec_Encoder < 0x1000000)
                {
                    EQMath.gDec_Degrees = EQMath.Range_DEC(EQMath.gDec_DegNoAdjust);
                }

                tRa = EQMath.EQnow_lst(EQMath.gLongitude * EQMath.DEG_RAD) + EQMath.gRA_Hours;
                if (EQMath.gHemisphere == 0)
                {
                    if ((EQMath.gDec_DegNoAdjust > 90) && (EQMath.gDec_DegNoAdjust <= 270))
                    {
                        tRa -= 12;
                    }
                }
                else
                {
                    if ((EQMath.gDec_DegNoAdjust <= 90) || (EQMath.gDec_DegNoAdjust > 270))
                    {
                        tRa += 12;
                    }
                }
                tRa = EQMath.Range24(tRa);

                //assign global RA / Dec
                EQMath.gRA  = tRa;
                EQMath.gDec = EQMath.gDec_Degrees;
                EQMath.gha  = tRa - EQMath.EQnow_lst(EQMath.gLongitude * EQMath.DEG_RAD);

                //calc alt/ az poition
                ((Array)hadec_aa).GetValue(Convert.ToInt32(EQMath.gLatitude * EQMath.DEG_RAD), Convert.ToInt32(EQMath.gha * EQMath.HRS_RAD), Convert.ToInt32(EQMath.gDec_Degrees * EQMath.DEG_RAD), Convert.ToInt32(tAlt), Convert.ToInt32(tAz));
                //asign global Alt / Az
                EQMath.gAlt = tAlt * EQMath.RAD_DEG;         // convert to degrees from Radians
                EQMath.gAz  = 360d - (tAz * EQMath.RAD_DEG); //  convert to degrees from Radians

                //Poll the Motor Status while slew is active
                if (EQMath.gSlewStatus)
                {
                    EQMath.gRAStatus  = UpgradeSolution1Support.PInvoke.SafeNative.eqcontrl.EQ_GetMotorStatus(0);
                    EQMath.gDECStatus = UpgradeSolution1Support.PInvoke.SafeNative.eqcontrl.EQ_GetMotorStatus(1);
                    if (EQMath.gEQparkstatus == 0)
                    {
                        Goto.ManageGoto();
                    }
                }

                //UPGRADE_TODO: (1067) Member Caption is not defined in type Variant. More Information: https://www.mobilize.net/vbtonet/ewis/ewi1067
                AlignmentCountLbl.Caption = Alignment.gAlignmentStars_count.ToString();

                do
                {
                    limit management


                    Limits.Limits_Execute();
                }

                EncoderTimerFlag = true;
            }
        }