Exemplo n.º 1
0
        public Interpolate(SpeedVector startSV, SpeedVector endSV, int updateSeconds)
        {
            //Linear interpolation of speed and direction changes
            WayPoints = new List <SpeedVector>();
            int    updatePeriods = (int)((endSV.Time_UTC - startSV.Time_UTC).TotalSeconds) / updateSeconds;
            double diffRate      = (endSV.Rate_ArcsecPerMinute - startSV.Rate_ArcsecPerMinute) / updatePeriods;
            double diffPA        = (endSV.PA_Degrees - startSV.PA_Degrees) / updatePeriods;
            double diffRARate    = (endSV.RA_Degrees - startSV.RA_Degrees) / updatePeriods;
            double diffDecRate   = (endSV.Dec_Degrees - startSV.Dec_Degrees) / updatePeriods;

            DateTime updateTime    = startSV.Time_UTC;
            double   updateRate    = startSV.Rate_ArcsecPerMinute;
            double   updatePA      = startSV.PA_Degrees;
            double   updateRARate  = startSV.Rate_RA_CosDec_ArcsecPerMinute;
            double   updateDecRate = startSV.Rate_Dec_ArcsecPerMinute;
            double   startRA       = startSV.RA_Degrees;
            double   startDec      = startSV.Dec_Degrees;

            while (updateTime < endSV.Time_UTC)
            {
                WayPoints.Add(new SpeedVector {
                    Time_UTC = updateTime, Rate_ArcsecPerMinute = updateRate, PA_Degrees = updatePA, RA_Degrees = startRA, Dec_Degrees = startDec, Rate_RA_CosDec_ArcsecPerMinute = updateRARate, Rate_Dec_ArcsecPerMinute = updateDecRate
                });
                updateTime    += TimeSpan.FromSeconds(updateSeconds);
                updateRate    += diffRate;
                updatePA      += diffPA;
                updateRARate  += diffRARate;
                updateDecRate += diffDecRate;
            }
        }
Exemplo n.º 2
0
        public static bool SetTargetTracking(SpeedVector sv, double topo_Adjustment_RA, double topo_Adjustment_Dec)
        {
            const int ionTrackingOn  = 1;
            const int ionTrackingOff = 0;
            const int ignoreRates    = 1;
            const int useRates       = 0;

            double tgtRateRA     = sv.Rate_RA_CosDec_ArcsecPerMinute;
            double tgtRateDec    = sv.Rate_Dec_ArcsecPerMinute;
            double adjtgtRateRA  = tgtRateRA * topo_Adjustment_RA;
            double adjtgtRateDec = tgtRateDec * topo_Adjustment_Dec;

            sky6RASCOMTele tsxmt = new sky6RASCOMTele();

            tsxmt.Connect();
            //double dRA1 = tsxmt.dRaTrackingRate;
            //double dDec1 = tsxmt.dDecTrackingRate;
            try
            {
                //TSX expects tracking rates in arcsec/sec: convert it from arcsec/min
                tsxmt.SetTracking(ionTrackingOn, useRates, adjtgtRateRA / 60.0, adjtgtRateDec / 60.0);
            }
            catch
            {
                return(false);
            }
            //double dRA2 = tsxmt.dRaTrackingRate;
            //double dDec2 = tsxmt.dDecTrackingRate;
            return(true);
        }
Exemplo n.º 3
0
        public static bool SlewToTarget(string tgtName, SpeedVector sv)
        {
            sky6RASCOMTele tsxmt   = new sky6RASCOMTele();
            double         tgtRAH  = Transform.DegreesToHours(sv.RA_Degrees);
            double         tgtDecD = sv.Dec_Degrees;

            tsxmt.Connect();
            try
            {
                tsxmt.SlewToRaDec(tgtRAH, tgtDecD, tgtName);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Slew Failed: " + ex.Message);
                return(false);
            }
            return(true);
        }
Exemplo n.º 4
0
        public bool CLSToTarget(SpeedVector sv)
        {
            int            clsStatus = 123;
            sky6RASCOMTele tsxmt     = new sky6RASCOMTele();
            ClosedLoopSlew tsx_cl    = new ClosedLoopSlew();
            sky6StarChart  tsxsc     = new sky6StarChart();
            //Clear any image reduction, otherwise full reduction might cause a problem
            ccdsoftCamera tsxcam = new ccdsoftCamera()
            {
                ImageReduction = ccdsoftImageReduction.cdNone,
                Asynchronous   = 1 //make sure nothing else happens while setting this up
            };

            //Abort any ongoing imaging
            tsxcam.Abort();

            double tgtRAH  = Transform.DegreesToHours(sv.RA_Degrees - RA_CorrectionD);
            double tgtDecD = sv.Dec_Degrees - Dec_CorrectionD;

            tsxsc.Find(tgtRAH.ToString() + ", " + tgtDecD.ToString());
            tsxmt.Connect();
            try
            {
                tsxmt.SlewToRaDec(tgtRAH, tgtDecD, TgtName);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Slew to target failed: " + ex.Message);
                return(false);
            }
            //********** CLS AVOIDANCE CODE FOR SIMULATOR DEBUGGING PURPOSES
            //tsxsc.Find(TgtName);
            //return true;
            //*********************
            try
            { clsStatus = tsx_cl.exec(); }
            catch (Exception ex)
            {
                tsxsc.Find(TgtName);
                return(false);
            }
            tsxsc.Find(TgtName);
            return(true);
        }
Exemplo n.º 5
0
        public bool ServerQueryToSpeedVectors(bool isMinutes, int updateInterval)
        {
            string    hzResultText;
            string    urlSearch;
            WebClient client = new WebClient();

            System.Net.ServicePointManager.ServerCertificateValidationCallback = (senderX, certificate, chain, sslPolicyErrors) => { return(true); };
            try
            {
                urlSearch    = URL_MPES_Search + MakeSearchQuery();
                hzResultText = client.DownloadString(urlSearch);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Download Error: " + ex.Message);
                return(false);
            };
            //Check result
            if (!hzResultText.Contains("Date"))
            {
                MessageBox.Show("Target not found");
                return(false);
            }
            //Convert Text to XML  -- JSON format is rudimentary and no better than text
            List <SpeedVector> BasicRateTable = new List <SpeedVector>();

            UpdateRateTable = new List <SpeedVector>();
            char[]   spc          = { ' ' };
            string[] mpcLineItems = hzResultText.Split('\n');
            int      soeIdx       = FindLine(mpcLineItems, "Date") + 2;
            int      eoeIdx       = FindLine(mpcLineItems, " These calculations have been performed on the") - 2;
            XElement ephmList     = new XElement("Ephemeris");

            for (int i = soeIdx; i < eoeIdx; i++)
            {
                XElement ephmRecord  = new XElement("Data");
                string   mpcDataLine = mpcLineItems[i];
                ephmRecord.Add(new XElement(mUTDate, mpcDataLine.Substring(colUTDateY, 4) + "-" + mpcDataLine.Substring(colUTDateM, 2) + "-" + mpcDataLine.Substring(colUTDateD, 2)));
                string timestring = mpcDataLine.Substring(colUTHrMin, 6);
                string sTime      = timestring[0].ToString() + timestring[1].ToString() + ":" + timestring[2].ToString() + timestring[3].ToString() + ":" + timestring[4].ToString() + timestring[5].ToString();
                ephmRecord.Add(new XElement(mUTHrMin, sTime));
                ephmRecord.Add(new XElement(mRA, mpcDataLine.Substring(colRA, 8)));
                ephmRecord.Add(new XElement(mDec, mpcDataLine.Substring(colDec, 9)));
                ephmRecord.Add(new XElement(mDelta, mpcDataLine.Substring(colDelta, 9)));
                ephmRecord.Add(new XElement(mr, mpcDataLine.Substring(colr, 7)));
                ephmRecord.Add(new XElement(mEl, mpcDataLine.Substring(colEl, 6)));
                ephmRecord.Add(new XElement(mPh, mpcDataLine.Substring(colPh, 5)));
                ephmRecord.Add(new XElement(mV, mpcDataLine.Substring(colV, 5)));
                ephmRecord.Add(new XElement(mdRACosD, mpcDataLine.Substring(coldRACosD, 8)));
                ephmRecord.Add(new XElement(mdDec, mpcDataLine.Substring(coldDec, 8)));
                ephmRecord.Add(new XElement(mAzi, mpcDataLine.Substring(colAzi, 6)));
                ephmRecord.Add(new XElement(mAlt, mpcDataLine.Substring(colAlt, 5)));
                ephmRecord.Add(new XElement(mSunAlt, mpcDataLine.Substring(colSunAlt, 5)));
                ephmRecord.Add(new XElement(mMoonPhase, mpcDataLine.Substring(colMoonPhase, 6)));
                ephmRecord.Add(new XElement(mMoonDist, mpcDataLine.Substring(colMoonDist, 5)));
                ephmRecord.Add(new XElement(mMoonAlt, mpcDataLine.Substring(colMoonAlt, 4)));

                ephmList.Add(ephmRecord);
            }

            //Convert XML to speed vector array
            SpeedVector currentSpeedVector;

            foreach (XElement ephX in ephmList.Elements("Data"))
            {
                string   sDate         = ephX.Element(mUTDate).Value;
                string   sTime         = ephX.Element(mUTHrMin).Value;
                string   sUTDateTime   = sDate + " " + sTime;
                DateTime sUT           = Convert.ToDateTime(sUTDateTime);
                double   sRA_D         = Convert.ToDouble(ephX.Element(mRA).Value);
                double   sDec_D        = Convert.ToDouble(ephX.Element(mDec).Value);
                double   sElevation_KM = MPC_Observatory.BestObservatory.MySiteElev;
                //Compute PA
                double sdDecdt = Convert.ToDouble(ephX.Element(mdDec).Value);    //arcsec/min
                double sdRAdt  = Convert.ToDouble(ephX.Element(mdRACosD).Value); //arcsec/min
                double sPA_D   = Math.Atan2(sdDecdt, sdRAdt);
                double sRange  = Convert.ToDouble(ephX.Element(mr).Value);
                currentSpeedVector = new SpeedVector
                {
                    Time_UTC = sUT,
                    Rate_RA_CosDec_ArcsecPerMinute = sdRAdt,
                    Rate_Dec_ArcsecPerMinute       = sdDecdt,
                    RA_Degrees   = sRA_D, //Scout delivers RA in degrees
                    Dec_Degrees  = sDec_D,
                    PA_Degrees   = sPA_D,
                    Range_AU     = sRange, //AU
                    Elevation_KM = sElevation_KM
                };
                BasicRateTable.Add(currentSpeedVector);
            }
            if (isMinutes)
            {
                UpdateRateTable = BasicRateTable;
            }
            else
            {
                //must add interpolated ephemeras
                //Horizons delivers a full day worth of data at 1 minute intervals
                // throwaway all but the first hour (60 readings) so we don't run out of memory interpolating
                for (int bIdx = 0; bIdx < BasicRateTable.Count - 1; bIdx++)
                {
                    if (BasicRateTable[bIdx].Time_UTC > DateTime.UtcNow && BasicRateTable[bIdx].Time_UTC < DateTime.UtcNow + TimeSpan.FromHours(1))
                    {
                        UpdateRateTable.Add(BasicRateTable[bIdx]);
                        Interpolate intp = new Interpolate(BasicRateTable[bIdx], BasicRateTable[bIdx + 1], updateInterval);
                        foreach (SpeedVector sv in intp.WayPoints)
                        {
                            UpdateRateTable.Add(sv);
                        }
                    }
                }
            }

            return(true);
        }
Exemplo n.º 6
0
        public static bool CLSToTarget(string tgtName, SpeedVector sv, bool IsPrecision = false)
        {
            //first, couple dome to telescope, if there is one
            sky6Dome tsxd = new sky6Dome();

            try
            {
                tsxd.Connect();
                tsxd.IsCoupled = 1;
            }
            catch (Exception ex)
            {
                //do nothing
            }

            int            clsStatus = 123;
            sky6RASCOMTele tsxmt     = new sky6RASCOMTele();
            ClosedLoopSlew tsx_cl    = new ClosedLoopSlew();
            sky6StarChart  tsxsc     = new sky6StarChart();
            sky6Utils      tsxu      = new sky6Utils();
            //Check to see if target is above horizon
            double tgtRAH  = Transform.DegreesToHours(sv.RA_Degrees);
            double tgtDecD = sv.Dec_Degrees;

            tsxu.ConvertRADecToAzAlt(tgtRAH, tgtDecD);
            double tgtAzmD = tsxu.dOut0;
            double tgtAltD = tsxu.dOut1;

            if (tgtAltD <= 0)
            {
                MessageBox.Show("Slew failure: Target is below the horizon");
                return(false);
            }
            //Clear any image reduction, otherwise full reduction might cause a problem
            ccdsoftCamera tsxcam = new ccdsoftCamera()
            {
                ImageReduction = ccdsoftImageReduction.cdNone,
                Asynchronous   = 1 //make sure nothing else happens while setting this up
            };

            //Abort any ongoing imaging
            tsxcam.Abort();

            bool returnStatus = true;
            // diagnostic
            string strRA  = Utils.HourString(tgtRAH, false);
            string strDec = Utils.DegreeString(tgtDecD, false);

            //
            tsxsc.Find(tgtRAH.ToString() + ", " + tgtDecD.ToString());
            tsxmt.Connect();
            tsxu.Precess2000ToNow(tgtRAH, tgtDecD);
            double jnRAH  = tsxu.dOut0;
            double jnDecD = tsxu.dOut1;

            //tsxmt.Asynchronous = 0;
            try
            {
                tsxmt.SlewToRaDec(jnRAH, jnDecD, tgtName);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Slew Failure: " + ex.Message);
                returnStatus = false;
            }
            if (IsPrecision && returnStatus)
            {
                //***  precision slew
                try
                {
                    clsStatus = tsx_cl.exec();
                }
                catch (Exception ex)
                {
                    returnStatus = false;
                }
            }
            try
            {
                tsxsc.Find(tgtName);
            }
            catch (Exception ex)
            {
                returnStatus = true;
            }
            return(returnStatus);
        }
Exemplo n.º 7
0
        public bool ServerQueryToSpeedVectors(bool isMinutes, int updateInterval)
        {
            string    hzResultText;
            string    urlSearch;
            WebClient client = new WebClient();

            System.Net.ServicePointManager.ServerCertificateValidationCallback = (senderX, certificate, chain, sslPolicyErrors) => { return(true); };
            try
            {
                urlSearch    = URL_Horizons_Search + MakeSearchQuery();
                hzResultText = client.DownloadString(urlSearch);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Download Error: " + ex.Message);
                return(false);
            };
            //Check result
            if (!hzResultText.Contains("$$SOE"))
            {
                MessageBox.Show("Target not found");
                return(false);
            }
            //Convert Text to XML  -- JSON format is rudimentary and no better than text
            List <SpeedVector> BasicRateTable = new List <SpeedVector>();

            UpdateRateTable = new List <SpeedVector>();
            char[]   spc         = { ' ' };
            string[] hzLineItems = hzResultText.Split('\n');
            int      soeIdx      = Array.IndexOf(hzLineItems, "$$SOE");
            int      eoeIdx      = Array.IndexOf(hzLineItems, "$$EOE");

            string[] headers  = hzLineItems[soeIdx - 2].Split(spc, StringSplitOptions.RemoveEmptyEntries);
            XElement ephmList = new XElement("Ephemeris");

            for (int i = soeIdx + 1; i < eoeIdx; i++)
            {
                XElement ephmRecord = new XElement("Data");
                string   cleanLine  = hzLineItems[i].Remove(22, 2); //Clear out some garbage that Horizons leaves in the line for some reason -- minutes? seconds?
                string[] columns    = cleanLine.Split(spc, StringSplitOptions.RemoveEmptyEntries);
                for (int r = 0; r < headers.Count(); r++)
                {
                    ephmRecord.Add(new XElement(headerNames[r], columns[r]));
                }
                ephmList.Add(ephmRecord);
            }

            //Convert XML to speed vector array
            SpeedVector currentSpeedVector;

            foreach (XElement ephX in ephmList.Elements("Data"))
            {
                string sDate       = ephX.Element(hzUTDate).Value;
                string sTime       = ephX.Element(hzUTHrMin).Value;
                string sUTDateTime = sDate + " " + sTime;
                sUTDateTime = sUTDateTime.Replace('.', ' ');
                DateTime sUT           = Convert.ToDateTime(sUTDateTime);
                double   sRA_D         = Convert.ToDouble(ephX.Element(hzRA).Value);
                double   sDec_D        = Convert.ToDouble(ephX.Element(hzDec).Value);
                double   sElevation_KM = MPC_Observatory.BestObservatory.MySiteElev;
                //Compute PA
                double sdDecdt = Convert.ToDouble(ephX.Element(hzdDec).Value) / 60;    //convert to arcsec/min
                double sdRAdt  = Convert.ToDouble(ephX.Element(hzdRACosD).Value) / 60; //convert to arcsec/min
                double sPA_D   = Math.Atan2(sdDecdt, sdRAdt);
                double sRange  = Convert.ToDouble(ephX.Element(hzr).Value);
                currentSpeedVector = new SpeedVector
                {
                    Time_UTC = sUT,
                    //Rate_ArcsecPerMinute = sRate,
                    Rate_RA_CosDec_ArcsecPerMinute = sdRAdt,
                    Rate_Dec_ArcsecPerMinute       = sdDecdt,
                    RA_Degrees   = sRA_D, //Scout delivers RA in degrees
                    Dec_Degrees  = sDec_D,
                    PA_Degrees   = sPA_D,
                    Range_AU     = sRange, //AU
                    Elevation_KM = sElevation_KM
                };
                BasicRateTable.Add(currentSpeedVector);
            }
            if (isMinutes)
            {
                UpdateRateTable = BasicRateTable;
            }
            else
            {
                //must add interpolated ephemeras
                //Horizons delivers a full day worth of data at 1 minute intervals
                // throwaway all but the first hour (60 readings) so we don't run out of memory interpolating
                for (int bIdx = 0; bIdx < BasicRateTable.Count - 1; bIdx++)
                {
                    if (BasicRateTable[bIdx].Time_UTC > DateTime.UtcNow && BasicRateTable[bIdx].Time_UTC < DateTime.UtcNow + TimeSpan.FromHours(1))
                    {
                        UpdateRateTable.Add(BasicRateTable[bIdx]);
                        Interpolate intp = new Interpolate(BasicRateTable[bIdx], BasicRateTable[bIdx + 1], updateInterval);
                        foreach (SpeedVector sv in intp.WayPoints)
                        {
                            UpdateRateTable.Add(sv);
                        }
                    }
                }
            }

            return(true);
        }
Exemplo n.º 8
0
        private bool GeoToSiteCalibration()
        {
            //MPC_Observatory must be set before calibration
            string    mpcResultText;
            string    urlSearch;
            WebClient client = new WebClient();

            System.Net.ServicePointManager.ServerCertificateValidationCallback = (senderX, certificate, chain, sslPolicyErrors) => { return(true); };
            //Get geocentric ephemeris for this target at eph start
            try
            {
                urlSearch     = URL_NEO_search + MakeSearchQuery(GetTargetName());
                mpcResultText = client.DownloadString(urlSearch);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Geocentric Ephemeris Download Error: " + ex.Message);
                return(false);
            };
            XDocument geoResultsX = JsonConvert.DeserializeXNode(mpcResultText, "Root");
            XElement  sEphXGeo    = geoResultsX.Element("Root").Element("eph");

            if (sEphXGeo == null)
            {
                return(false);
            }
            IEnumerable <XElement> gPositionX    = sEphXGeo.Element("data").Elements("data");
            List <XElement>        gPositionList = gPositionX.ToList();
            SpeedVector            geoResultsSV  = new SpeedVector
            {
                Time_UTC             = Convert.ToDateTime(sEphXGeo.Element("time").Value),
                Rate_ArcsecPerMinute = Convert.ToDouble(gPositionList[idx_rate].Value),
                PA_Degrees           = (Convert.ToDouble(gPositionList[idx_pa].Value)),
                RA_Degrees           = Convert.ToDouble(gPositionList[idx_ra].Value),
                Dec_Degrees          = Convert.ToDouble(gPositionList[idx_dec].Value),
                Range_AU             = Convert.ToDouble(gPositionList[idx_reG].Value)
            };

            //Get topocentric ephemeris for the observatory nearest this site
            try
            {
                urlSearch     = URL_NEO_search + MakeSearchQuery(GetTargetName(), MPC_Observatory.BestObservatory.MPC_Code);
                mpcResultText = client.DownloadString(urlSearch);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Topocentric Ephemeris Download Error: " + ex.Message);
                return(false);
            };
            XDocument mpcResultsX                = JsonConvert.DeserializeXNode(mpcResultText, "Root");
            XElement  mpcEphXTopo                = mpcResultsX.Element("Root").Element("eph");
            IEnumerable <XElement> mPositionX    = mpcEphXTopo.Element("data").Elements("data");
            List <XElement>        mPositionList = mPositionX.ToList();
            SpeedVector            mpcResultsSV  = new SpeedVector
            {
                Time_UTC             = Convert.ToDateTime(mpcEphXTopo.Element("time").Value),
                Rate_ArcsecPerMinute = Convert.ToDouble(mPositionList[idx_rate].Value),
                PA_Degrees           = (Convert.ToDouble(mPositionList[idx_pa].Value)),
                RA_Degrees           = Convert.ToDouble(mPositionList[idx_ra].Value),
                Dec_Degrees          = Convert.ToDouble(mPositionList[idx_dec].Value),
                Range_AU             = Convert.ToDouble(mPositionList[idx_reO].Value)
            };

            //New try using spherical coordinates and ranges to compute site sky location
            //Convert the geocentric Range/RA/Dec point to spherical radius/phi/theta point
            AstroMath.Spherical.PointRangeRADec geoNEO_RD = new Spherical.PointRangeRADec()
            {
                Range = geoResultsSV.Range_AU * Utils.Astronomical_Unit,      // convert to km,
                Dec   = Transform.DegreesToRadians(geoResultsSV.Dec_Degrees), //radians
                RA    = Transform.DegreesToRadians(geoResultsSV.RA_Degrees)   //radians
            };
            //Convert to spherical point
            AstroMath.Spherical.PointSph geoNEO_Sph = AstroMath.Spherical.RADecToSpherical(geoNEO_RD);
            //Convert site location to spherical coordinates
            AstroMath.Spherical.PointRangeRADec MySite_RD = new Spherical.PointRangeRADec()
            {
                Range = Utils.Earth_Radius,  //in km
                Dec   = Transform.DegreesToRadians(MPC_Observatory.BestObservatory.MySiteLat),
                RA    = Transform.DegreesToRadians(-MPC_Observatory.BestObservatory.MySiteLong)
            };
            //Convert site location to spherical
            AstroMath.Spherical.PointSph MySite_Sph = AstroMath.Spherical.RADecToSpherical(MySite_RD);
            //Translate neo location to siteLocation coordinates
            AstroMath.Spherical.PointSph transNEO_Sph = Spherical.TranslateSpherical(geoNEO_Sph, MySite_Sph);
            //Convert new neo coordinates to RADec
            AstroMath.Spherical.PointRangeRADec transNEO_RD = Spherical.SphericalToRADec(transNEO_Sph);

            Site_Corrected_Range = transNEO_RD.Range / Utils.Astronomical_Unit;
            Site_Corrected_Dec   = Transform.RadiansToDegrees(transNEO_RD.Dec);
            Site_Corrected_RA    = Transform.RadiansToDegrees(transNEO_RD.RA);

            Dec_CorrectionD      = mpcResultsSV.Dec_Degrees - Site_Corrected_Dec; //degrees Dec
            RA_CorrectionD       = mpcResultsSV.RA_Degrees - Site_Corrected_RA;   //degrees RA
            Diff_Dec_CorrectionD = 1.0 / (1.0 + Math.Pow(Dec_CorrectionD, 2));    //degrees per arcdegree
            Diff_RA_CorrectionD  = 1.0 / (1.0 + Math.Pow(RA_CorrectionD, 2));     //degrees per arcdegree
            RangeAU            = mpcResultsSV.Range_AU;                           //AU
            Range_CorrectionAU = RangeAU - Site_Corrected_Range;                  //AU
            return(true);
        }
Exemplo n.º 9
0
        private bool ServerQueryToSpeedVectors(bool isMinutes, int updateInterval)
        {
            string    neoResultText;
            string    urlSearch;
            WebClient client = new WebClient();

            System.Net.ServicePointManager.ServerCertificateValidationCallback = (senderX, certificate, chain, sslPolicyErrors) => { return(true); };
            try
            {
                urlSearch     = URL_NEO_search + MakeSearchQuery(GetTargetName(), MPC_Observatory.BestObservatory.MPC_Code);
                neoResultText = client.DownloadString(urlSearch);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Download Error: " + ex.Message + "\n Possibly the NEO target is not available on Scout for ephemeris.");
                return(false);
            };
            List <SpeedVector> BasicRateTable = new List <SpeedVector>();

            UpdateRateTable = new List <SpeedVector>();
            ScoutResultsX   = JsonConvert.DeserializeXNode(neoResultText, "Root");
            IEnumerable <XElement> sEphXList        = ScoutResultsX.Element("Root").Elements("eph");
            SpeedVector            priorSpeedVector = null;
            SpeedVector            currentSpeedVector;
            double changeRaArcSec  = 0;
            double changeDecArcSec = 0;

            foreach (XElement ephX in sEphXList)
            {
                IEnumerable <XElement> sPositionX    = ephX.Element("data").Elements("data");
                List <XElement>        sPositionList = sPositionX.ToList();
                currentSpeedVector = new SpeedVector
                {
                    Time_UTC             = Convert.ToDateTime(ephX.Element("time").Value),
                    Rate_ArcsecPerMinute = Convert.ToDouble(sPositionList[idx_rate].Value), //Arcsec/min
                    PA_Degrees           = (Convert.ToDouble(sPositionList[idx_pa].Value)),
                    RA_Degrees           = Convert.ToDouble(sPositionList[idx_ra].Value),   //Scout delivers RA in degrees
                    Dec_Degrees          = Convert.ToDouble(sPositionList[idx_dec].Value),
                    Elevation_KM         = Convert.ToDouble(sPositionList[idx_el].Value),
                    Range_AU             = Convert.ToDouble(sPositionList[idx_reO].Value) //AU
                };

                if (priorSpeedVector != null)
                {
                    //This is not the first vector,
                    //  Calculate the change in RA and Dec, save it in the prior vector and save the prior vector
                    //  then set the current vector as the prior vector
                    double interval_Minutes = (currentSpeedVector.Time_UTC - priorSpeedVector.Time_UTC).TotalMinutes;
                    changeRaArcSec = Transform.DegreesToArcSec(currentSpeedVector.RA_Degrees - priorSpeedVector.RA_Degrees);
                    priorSpeedVector.Rate_RA_CosDec_ArcsecPerMinute = changeRaArcSec / interval_Minutes;
                    changeDecArcSec = Transform.DegreesToArcSec(currentSpeedVector.Dec_Degrees - priorSpeedVector.Dec_Degrees);
                    priorSpeedVector.Rate_Dec_ArcsecPerMinute = changeDecArcSec / interval_Minutes;
                    BasicRateTable.Add(priorSpeedVector);
                    priorSpeedVector = currentSpeedVector;
                }
                else
                {
                    priorSpeedVector = currentSpeedVector;   //This is the first vector.  Set it as prior and get the next one.
                }
            }
            //The last prior vector will not have been saved, nor the RA and Dec rates filled in
            //  and there is no next vector to calculate RA and Dec differences, so use the last ones because
            //  the Scout dRA/dDec data is all f****d up
            priorSpeedVector.Rate_RA_CosDec_ArcsecPerMinute = changeRaArcSec;
            priorSpeedVector.Rate_Dec_ArcsecPerMinute       = changeDecArcSec;
            BasicRateTable.Add(priorSpeedVector);

            if (isMinutes)
            {
                UpdateRateTable = BasicRateTable;
            }
            else
            {
                for (int bIdx = 0; bIdx < BasicRateTable.Count - 1; bIdx++)
                {
                    UpdateRateTable.Add(BasicRateTable[bIdx]);
                    Interpolate intp = new Interpolate(BasicRateTable[bIdx], BasicRateTable[bIdx + 1], updateInterval);
                    foreach (SpeedVector sv in intp.WayPoints)
                    {
                        UpdateRateTable.Add(sv);
                    }
                }
            }
            return(true);
        }
Exemplo n.º 10
0
        private bool ServerQueryToSpeedVectors(bool isMinutes, int updateInterval)
        {
            string    neoResultText;
            string    urlSearch;
            WebClient client = new WebClient();

            System.Net.ServicePointManager.ServerCertificateValidationCallback = (senderX, certificate, chain, sslPolicyErrors) => { return(true); };
            try
            {
                urlSearch     = URL_NEO_search + MakeSearchQuery(TgtName, MPC_Observatory.BestObservatory.MPC_Code);
                neoResultText = client.DownloadString(urlSearch);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Download Error: " + ex.Message + "\n Possibly the NEO target is not available on Scout for ephemeris.");
                return(false);
            };
            List <SpeedVector> BasicRateTable = new List <SpeedVector>();

            UpdateRateTable = new List <SpeedVector>();
            ScoutResultsX   = JsonConvert.DeserializeXNode(neoResultText, "Root");
            IEnumerable <XElement> sEphXList = ScoutResultsX.Element("Root").Elements("eph");
            SpeedVector            currentSpeedVector;

            foreach (XElement ephX in sEphXList)
            {
                IEnumerable <XElement> sPositionX    = ephX.Element("data").Elements("data");
                List <XElement>        sPositionList = sPositionX.ToList();
                currentSpeedVector = new SpeedVector
                {
                    Time_UTC             = Convert.ToDateTime(ephX.Element("time").Value),
                    Rate_ArcsecPerMinute = Convert.ToDouble(sPositionList[idx_rate].Value), //Arcsec/min
                    PA_Degrees           = (Convert.ToDouble(sPositionList[idx_pa].Value)),
                    RA_Degrees           = Convert.ToDouble(sPositionList[idx_ra].Value),   //Scout delivers RA in degrees
                    Dec_Degrees          = Convert.ToDouble(sPositionList[idx_dec].Value),
                    Elevation_KM         = Convert.ToDouble(sPositionList[idx_el].Value),
                    Range_AU             = Convert.ToDouble(sPositionList[idx_reO].Value) //AU
                };
                currentSpeedVector.Rate_RA_CosDec_ArcsecPerMinute = Utils.PARateToRA(currentSpeedVector.PA_Degrees, currentSpeedVector.Rate_ArcsecPerMinute);
                currentSpeedVector.Rate_Dec_ArcsecPerMinute       = Utils.PARateToDec(currentSpeedVector.PA_Degrees, currentSpeedVector.Rate_ArcsecPerMinute);
                BasicRateTable.Add(currentSpeedVector);
            }
            if (isMinutes)
            {
                UpdateRateTable = BasicRateTable;
            }
            else
            {
                //must add interpolated ephemeras
                for (int bIdx = 0; bIdx < BasicRateTable.Count - 1; bIdx++)
                {
                    UpdateRateTable.Add(BasicRateTable[bIdx]);
                    Interpolate intp = new Interpolate(BasicRateTable[bIdx], BasicRateTable[bIdx + 1], updateInterval);
                    foreach (SpeedVector sv in intp.WayPoints)
                    {
                        UpdateRateTable.Add(sv);
                    }
                }
            }
            return(true);
        }
Exemplo n.º 11
0
        private void ScoutButton_Click(object sender, EventArgs e)
        {
            if (InPursuit)
            {
                return;
            }
            InPursuit             = true;
            ScoutButton.BackColor = Color.Salmon;
            ClearFields();
            ScoutData = new SearchScout();
            //Retrieve current target name from TSX and set in ss
            if (LookUpCheckBox.Checked)
            {
                ScoutData.TgtName = TargetBox.Text;
            }
            else
            {
                ScoutData.TgtName = Utils.GetTargetName();
            }
            TargetBox.Text = ScoutData.TgtName;
            //Handle exceptions
            if (ScoutData.TgtName == null)
            {
                UpdateStatusLine("No target is found.  Check TheSkyX for target assignment.");
                CleanupOnFault();
                return;
            }
            UpdateStatusLine("Now targetting: " + ScoutData.TgtName);
            //fill in Filters list
            FiltersListBox.Items.AddRange(Filters.FilterNameSet());
            FiltersListBox.SelectedIndex = Properties.Settings.Default.FilterIndexZeroBased;
            this.Show();
            //Set start time for ephemeris to current UTC, then set update step period from form
            ScoutData.EphStart = DateTime.UtcNow;
            if (MinutesButton.Checked)
            {
                ScoutData.EphStep = TimeSpan.FromMinutes((double)UpdateBox.Value);
            }
            else
            {
                ScoutData.EphStep = TimeSpan.FromMinutes(1);
            }
            ScoutData.EphEnd = ScoutData.EphStart + TimeSpan.FromMinutes((100 * ScoutData.EphStep.TotalMinutes));
            //Update ss with ephemeris data from scout -- handle problems if they occur
            if (!ScoutData.LoadTargetData(MinutesButton.Checked, (int)UpdateBox.Value))
            {
                UpdateStatusLine("Problem with loading target data. The target may no longer be in the CNEOS Listing.");
                CleanupOnFault();
                return;
            }
            UpdateStatusLine("Closest observatory: " + ScoutData.MPC_Observatory.BestObservatory.MPC_Code +
                             " (" + ScoutData.MPC_Observatory.BestObservatory.Description + ")" +
                             " Variance: " + Utils.HourString(ScoutData.MPC_Observatory.BestObservatory.VarianceRA, true) +
                             "(Lat) / " + Utils.DegreeString(ScoutData.MPC_Observatory.BestObservatory.VarianceDec, true) +
                             " (Lon)");
            //Fire off first tracking instruction
            SpeedVector nextUpdateSV = ScoutData.GetNextRateUpdate(ScoutData.EphStart);

            //CLS to where target should be currently, deal with CLS failure
            if (!Utils.CLSToTarget(ScoutData.TgtName, nextUpdateSV, CLSBox.Checked))
            {
                UpdateStatusLine("Tracking failed: Problem with Slew.");
                CleanupOnFault();
                return;
            }
            (double r, double d) = GetCurrentTelePosition();
            //Prompt for imaging
            ImageButton.BackColor = Color.LightGreen;
            //Set custom tracking
            if (!Utils.SetTargetTracking(nextUpdateSV, ScoutData.Topo_RA_Correction_Factor, ScoutData.Topo_Dec_Correction_Factor))
            {
                TargetBox.BackColor = Color.LightSalmon;
            }
            else
            {
                TargetBox.BackColor = Color.LightGreen;
            }
            RARateBox.Text     = nextUpdateSV.Rate_RA_CosDec_ArcsecPerMinute.ToString("0.000");
            DecRateBox.Text    = nextUpdateSV.Rate_Dec_ArcsecPerMinute.ToString("0.000");
            CorrectionBox.Text = Utils.HourString(ScoutData.RA_CorrectionD, true) + "/" + Utils.DegreeString(ScoutData.Dec_CorrectionD, true);
            RangeBox.Text      = nextUpdateSV.Range_AU.ToString("0.00");
            DateTime nextUpdate = nextUpdateSV.Time_UTC;

            if (MinutesButton.Checked)
            {
                nextUpdate += TimeSpan.FromMinutes((int)UpdateBox.Value);
            }
            else
            {
                nextUpdate += TimeSpan.FromSeconds((int)UpdateBox.Value);
            }
            NextUpdateBox.Text = (nextUpdate - DateTime.UtcNow).TotalSeconds.ToString("0");
            //**************************  site location status code
            UpdateStatusLine("This site astometry: " +
                             ScoutData.Site_Corrected_Range.ToString("0.00") + " AU:  " +
                             Utils.HourString(Transform.DegreesToHours(ScoutData.Site_Corrected_RA), false) + " / " +
                             Utils.DegreeString(ScoutData.Site_Corrected_Dec, false) + " (RA/Dec)");
            //**************************
            //Update status
            UpdateStatusLine("Ephemeris @" + nextUpdateSV.Time_UTC.ToString("HH:mm:ss") + " (UTC)\r\n" +
                             "    MPC Obs " + ScoutData.MPC_Observatory.BestObservatory.MPC_Code + ": " + Utils.HourString(Transform.DegreesToHours(nextUpdateSV.RA_Degrees), false) +
                             " / " + Utils.DegreeString((nextUpdateSV.Dec_Degrees), false) + "(RA/Dec) " +
                             "    Site corrected: " + Utils.HourString(Transform.DegreesToHours(nextUpdateSV.RA_Degrees - ScoutData.RA_CorrectionD), false) +
                             " / " + Utils.DegreeString((nextUpdateSV.Dec_Degrees - ScoutData.Dec_CorrectionD), false) + "(RA/Dec)");

            //Set up for next tracking instruction
            while (!AbortRequested)
            {
                //the next target ephemeris has been loaded into the ss object, but assume not
                nextUpdateSV = ScoutData.GetNextRateUpdate(DateTime.UtcNow);
                if (nextUpdateSV != null)
                {
                    nextUpdate = nextUpdateSV.Time_UTC;
                    while (DateTime.UtcNow < nextUpdate)
                    {
                        OneSecondPulse(ScoutButton);
                        NextUpdateBox.Text = (nextUpdate - DateTime.UtcNow).TotalSeconds.ToString("0");
                        CheckImaging();
                        if (AbortRequested)
                        {
                            break;
                        }
                    }
                    if (!Utils.SetTargetTracking(nextUpdateSV, ScoutData.Topo_RA_Correction_Factor, ScoutData.Topo_Dec_Correction_Factor))
                    {
                        TargetBox.BackColor = Color.LightSalmon;
                    }
                    else
                    {
                        TargetBox.BackColor = Color.LightGreen;
                    }
                    RARateBox.Text  = nextUpdateSV.Rate_RA_CosDec_ArcsecPerMinute.ToString("0.000");
                    DecRateBox.Text = nextUpdateSV.Rate_Dec_ArcsecPerMinute.ToString("0.000");
                    RangeBox.Text   = nextUpdateSV.Range_AU.ToString("0.00");
                    //Update status
                    UpdateStatusLine("Ephemeris @" + nextUpdateSV.Time_UTC.ToString("HH:mm:ss") + " (UTC)\r\n" +
                                     "    MPC Obs " + ScoutData.MPC_Observatory.BestObservatory.MPC_Code + ": " + Utils.HourString(Transform.DegreesToHours(nextUpdateSV.RA_Degrees), false) +
                                     " / " + Utils.DegreeString((nextUpdateSV.Dec_Degrees), false) + "(RA/Dec) " +
                                     "    Site corrected: " + Utils.HourString(Transform.DegreesToHours(nextUpdateSV.RA_Degrees - ScoutData.RA_CorrectionD), false) +
                                     " / " + Utils.DegreeString((nextUpdateSV.Dec_Degrees - ScoutData.Dec_CorrectionD), false) + "(RA/Dec)");
                    //
                }
                else //no new update -- go get another
                {
                    ScoutData          = new SearchScout();
                    ScoutData.EphStart = DateTime.UtcNow;
                    ScoutData.EphStep  = TimeSpan.FromMinutes((double)UpdateBox.Value);
                    ScoutData.EphEnd   = ScoutData.EphStart + TimeSpan.FromMinutes((100 * ScoutData.EphStep.TotalMinutes));
                    ScoutData.LoadTargetData(MinutesButton.Checked, (int)UpdateBox.Value);
                }
            }
            CleanupOnFault();
            return;
        }