Example #1
0
        public GeoCoordinate GetGeodeticCoordinateNow()
        {
            var tleISS      = ParserTLE.parseTle(TleLine1, TleLine2, TleLine0);
            var currentTime = new EpochTime(DateTime.UtcNow);
            // TODO: use sdp4 for satellites with medium/high orbit.
            var data             = SatFunctions.getSatPositionAtTime(tleISS, currentTime, Sgp4.wgsConstant.WGS_84);
            var secondsFromStart = (currentTime.getEpoch() - Math.Truncate(currentTime.getEpoch())) * 24 * 60 * 60;
            var omega            = OMEGA_E * secondsFromStart;

            var C = MathNet.Numerics.LinearAlgebra.Double.DenseMatrix.OfArray(
                new double[, ] {
                { Math.Cos(omega), Math.Sin(omega), 0 },
                { -Math.Sin(omega), Math.Cos(omega), 0 },
                { 0, 0, 1 }
            });

            var p = MathNet.Numerics.LinearAlgebra.Double.DenseMatrix.OfArray(
                new double[, ] {
                { data.getX() * 1000 },
                { data.getY() * 1000 },
                { data.getZ() * 1000 }
            });

            var ecr = C * p;

            GpsUtils.EcefToGeodetic(ecr[0, 0], ecr[1, 0], ecr[2, 0], out var lat, out var lon, out var h);

            return(new GeoCoordinate(lat, lon, h));
        }
Example #2
0
        public bool IsVisibleFromPointNow(GeoCoordinate observer)
        {
            var tleISS      = ParserTLE.parseTle(TleLine1, TleLine2, TleLine0);
            var currentTime = new EpochTime(DateTime.UtcNow);
            var data        = One_Sgp4.SatFunctions.getSatPositionAtTime(tleISS, currentTime, Sgp4.wgsConstant.WGS_84);

            return(SatFunctions.isSatVisible(new Coordinate(observer.Latitude, observer.Longitude, observer.Altitude), 0, currentTime, data));
        }
Example #3
0
        public void TleParseFromLinesShouldSucceed()
        {
            //             0.........1.........2.........3.........4.........5.........6.........7
            string line1 = "1 42784U 17036Vvv 17175.91623346  .00001083  00000-0  52625-4 0  9993";
            string line2 = "2 42784  97.4499 235.6602 0011188 243.9018 116.1066 15.20524655   207";

            Tle t = ParserTLE.parseTle(line1, line2);

            Assert.That(t.isValidData, Is.True);
            Assert.That(t.getClassification(), Is.EqualTo(0));
            Assert.That(t.getDrag(), Is.EqualTo(0.000052625));
            Assert.That(t.getEccentriciy(), Is.EqualTo(0.0011188));
            Assert.That(t.getEphemeris(), Is.EqualTo(0));
            Assert.That(t.getEpochDay(), Is.EqualTo(175.91623346));
            Assert.That(t.getEpochYear(), Is.EqualTo(17));
            Assert.That(t.getFirstMeanMotion(), Is.EqualTo(.00001083));
            Assert.That(t.getInclination(), Is.EqualTo(97.4499));
            Assert.That(t.getMeanAnomoly(), Is.EqualTo(116.1066));
            Assert.That(t.getMeanMotion(), Is.EqualTo(15.20524655));
            Assert.That(t.getName(), Is.EqualTo("1736Vvv"));
            Assert.That(t.getNoradID(), Is.EqualTo("42784"));
            Assert.That(t.getPerigee(), Is.EqualTo(243.9018));
            Assert.That(t.getPice(), Is.EqualTo("Vvv"));
            Assert.That(t.getRelevationNumber(), Is.EqualTo(20));
            Assert.That(t.getRightAscendingNode(), Is.EqualTo(235.6602));
            Assert.That(t.getSatNumber(), Is.EqualTo(42784));
            Assert.That(t.getSecondMeanMotion(), Is.EqualTo(0));
            Assert.That(t.getSetNumber(), Is.EqualTo(999));
            Assert.That(t.getStartNr(), Is.EqualTo(36));
            Assert.That(t.getStartYear(), Is.EqualTo(17));

            t = ParserTLE.parseTle(line1, line2, "Pegasus");

            Assert.That(t.isValidData, Is.True);
            Assert.That(t.getClassification(), Is.EqualTo(0));
            Assert.That(t.getDrag(), Is.EqualTo(0.000052625));
            Assert.That(t.getEccentriciy(), Is.EqualTo(0.0011188));
            Assert.That(t.getEphemeris(), Is.EqualTo(0));
            Assert.That(t.getEpochDay(), Is.EqualTo(175.91623346));
            Assert.That(t.getEpochYear(), Is.EqualTo(17));
            Assert.That(t.getFirstMeanMotion(), Is.EqualTo(.00001083));
            Assert.That(t.getInclination(), Is.EqualTo(97.4499));
            Assert.That(t.getMeanAnomoly(), Is.EqualTo(116.1066));
            Assert.That(t.getMeanMotion(), Is.EqualTo(15.20524655));
            Assert.That(t.getName(), Is.EqualTo("Pegasus"));
            Assert.That(t.getNoradID(), Is.EqualTo("42784"));
            Assert.That(t.getPerigee(), Is.EqualTo(243.9018));
            Assert.That(t.getPice(), Is.EqualTo("Vvv"));
            Assert.That(t.getRelevationNumber(), Is.EqualTo(20));
            Assert.That(t.getRightAscendingNode(), Is.EqualTo(235.6602));
            Assert.That(t.getSatNumber(), Is.EqualTo(42784));
            Assert.That(t.getSecondMeanMotion(), Is.EqualTo(0));
            Assert.That(t.getSetNumber(), Is.EqualTo(999));
            Assert.That(t.getStartNr(), Is.EqualTo(36));
            Assert.That(t.getStartYear(), Is.EqualTo(17));
        }
Example #4
0
 public Satellite(long id, string name, string line1, string line2)
 {
     ID       = id;
     Name     = name;
     TleLine1 = line1;
     TleLine2 = line2;
     Tle      = ParserTLE.parseTle(
         line1,
         line2,
         name);
 }
Example #5
0
 public void TleParseFromLinesWithChecksumErrorShouldFail(string line1, string line2)
 {
     try
     {
         Tle t = ParserTLE.parseTle(line1, line2);
         Assert.Fail("This should raise an exception!");
     }
     catch (Exception ex)
     {
         Assert.That(ex, Is.TypeOf <InvalidDataException>());
         Assert.That(ex.Message, Contains.Substring("checksum error"));
     }
 }
Example #6
0
        public void TestSatContact()
        {
            Tle tleISS = ParserTLE.parseTle(
                "1 25544U 98067A   19356.46068278  .00000035  00000-0  86431-5 0  9990",
                "2 25544  51.6420 147.9381 0007793  61.6458  55.7201 15.50124783204461",
                "ISS 1");

            Coordinate position  = new Coordinate(35, 18, 0);
            EpochTime  startTime = new EpochTime(0, 0, 0, 2020, 1, 6);

            List <Pass> passes = SatFunctions.CalculatePasses(position, tleISS, startTime, 1, 1);

            Assert.AreEqual(8, passes.Count);
        }
Example #7
0
        public void TleParseFromCorruptLinesShouldFail()
        {
            string line1 = "1 42784U 17036V   17175.91623346  .00001083  00000 - 0  52625 - 4 0  9993";
            string line2 = "2 42784  97.4499 235.6602 0011188 243.9018 116.1066 15.20524655   207";

            try
            {
                Tle t = ParserTLE.parseTle(line1, line2);
                Assert.Fail("This should raise an exception!");
            }
            catch (Exception ex)
            {
                Assert.That(ex, Is.TypeOf <InvalidDataException>());
                Assert.That(ex.Message, Contains.Substring("parse error"));
            }
        }
Example #8
0
    /*****************************************************************************
    * @function name : calECIDateAndVelocity
    * @author : Kaguya
    * @date : 2020/12/3 12:38
    * @inparam :
    * @outparam :
    * @last change :
    * @usage : 基于one_sgp4项目,计算航天器基于ECI坐标系下的位置和速度
    *****************************************************************************/
    public void calECIDateAndVelocity()
    {
        Tle       tleISS    = ParserTLE.parseTle(first, second, "ISS 1");
        DateTime  t         = new DateTime(data[0], data[1], data[2], data[3], data[4], data[5]);
        EpochTime startTime = new EpochTime(t);
        Sgp4Data  sate      = SatFunctions.getSatPositionAtTime(tleISS, startTime, Sgp4.wgsConstant.WGS_84);

        One_Sgp4.Point3d position = sate.getPositionData();
        ECI    = new double[3];
        ECI[0] = position.x;
        ECI[1] = position.y;
        ECI[2] = position.z;

        velocity    = new double[3];
        velocity[0] = sate.getVelocityData().x;
        velocity[1] = sate.getVelocityData().y;
        velocity[2] = sate.getVelocityData().z;
        velocity    = getECEF(velocity, data);
    }
Example #9
0
        public void TestSatGroundPosition(int hh, int mm, int ss, int yyyy, int MM, int dd)
        {
            Tle tleISS = ParserTLE.parseTle(
                "1 25544U 98067A   19356.46068278  .00000035  00000-0  86431-5 0  9990",
                "2 25544  51.6420 147.9381 0007793  61.6458  55.7201 15.50124783204461",
                "ISS 1");


            EpochTime testTime = new EpochTime(hh, mm, ss, yyyy, MM, dd);
            Sgp4Data  data     = SatFunctions.getSatPositionAtTime(tleISS, testTime, Sgp4.wgsConstant.WGS_84);

            Assert.IsNotNull(data);
            Coordinate ground = SatFunctions.calcSatSubPoint(testTime, data, Sgp4.wgsConstant.WGS_84);

            Assert.Greater(ground.getHeight(), 0);
            Assert.LessOrEqual(ground.getLongitude(), 180.0);
            Assert.Greater(ground.getLongitude(), -180.0);
            Assert.LessOrEqual(ground.getLatitude(), 90.0);
            Assert.Greater(ground.getLatitude(), -90.0);
        }
Example #10
0
        static void Main(string[] args)
        {
            //Parse three line element
            Tle tleISS = ParserTLE.parseTle(
                "1 25544U 98067A   19132.30925117  .00001081  00000-0  24694-4 0  9993",
                "2 25544  51.6426 179.4820 0001363 344.4861  92.2261 15.52657683169680",
                "ISS 1");

            //Parse tle from file
            if (System.IO.File.Exists("tleData.txt"))
            {
                List <Tle> tleList = ParserTLE.ParseFile("tleData.txt");
            }

            //Get TLE from Space-Track.org
            //list of satellites by their NORAD ID
            string[] noradIDs = { "8709", "43572" };
            try
            {
                One_Sgp4.SpaceTrack.GetSpaceTrack(noradIDs, "USERNAME", "PASSWORD");
            }
            catch { Console.Out.WriteLine("Error could not retrive TLE's from Space-Track, Login credentials might be wrong"); }


            //Create Time points
            EpochTime startTime   = new EpochTime(DateTime.UtcNow);
            EpochTime anotherTime = new EpochTime(2018, 100.5); //(Year 2018, 100 day at 12:00 HH)
            EpochTime stopTime    = new EpochTime(DateTime.UtcNow.AddHours(1));

            //get time difference
            double daysSince = startTime - anotherTime;
            //throws exception if first time > second time
            //double daysSince = anotherTime - startTime;

            //compare Time points
            EpochTime compareTime = new EpochTime(2018, 100.5); //(Year 2018, 100 day at 12:00 HH)
            bool      equals      = anotherTime == compareTime;
            bool      notequals   = startTime != anotherTime;
            bool      greater     = startTime > anotherTime;
            bool      smaler      = anotherTime < startTime;

            //Add 15 Seconds to EpochTime
            anotherTime.addTick(15);
            //Add 20 Min to EpochTime
            anotherTime.addMinutes(15);
            //Add 1 hour to EpochTime
            anotherTime.addHours(1);
            //Add 2 Days to EpochTime
            anotherTime.addDays(2);
            Console.Out.WriteLine(anotherTime.ToString());

            //Calculate Satellite Position and Speed
            One_Sgp4.Sgp4 sgp4Propagator = new Sgp4(tleISS, Sgp4.wgsConstant.WGS_84);
            //set calculation parameters StartTime, EndTime and caclulation steps in minutes
            sgp4Propagator.runSgp4Cal(startTime, stopTime, 1 / 30.0); // 1/60 => caclulate sat points every 2 seconds
            List <One_Sgp4.Sgp4Data> resultDataList = new List <Sgp4Data>();

            //Return Results containing satellite Position x,y,z (ECI-Coordinates in Km) and Velocity x_d, y_d, z_d (ECI-Coordinates km/s)
            resultDataList = sgp4Propagator.getRestults();

            //Coordinate of an observer on Ground lat, long, height(in meters)
            One_Sgp4.Coordinate observer = new Coordinate(35.00, 18.0, 0);
            //Convert to ECI coordinate system
            One_Sgp4.Point3d eci = observer.toECI(startTime.getLocalSiderealTime());
            //Get Local SiderealTime for Observer
            double localSiderealTime = startTime.getLocalSiderealTime(observer.getLongitude());

            //Calculate if Satellite is Visible for a certain Observer on ground at certain timePoint
            bool satelliteIsVisible = One_Sgp4.SatFunctions.isSatVisible(observer, 0.0, startTime, resultDataList[0]);

            //Calculate Sperical Coordinates from an Observer to Satellite
            //returns 3D-Point with range(km), azimuth(radians), elevation(radians) to the Satellite
            One_Sgp4.Point3d spherical = One_Sgp4.SatFunctions.calcSphericalCoordinate(observer, startTime, resultDataList[0]);

            //Calculate the Next 5 Passes over a point
            //for a location, Satellite, StartTime, Accuracy in Seconds = 15sec, MaxNumber of Days = 5 Days, Wgs constant = WGS_84
            //Returns pass with Location, StartTime of Pass, EndTime Of Pass, Max Elevation in Degrees
            List <Pass> passes = One_Sgp4.SatFunctions.CalculatePasses(observer, tleISS, new EpochTime(DateTime.UtcNow), 15, 5, Sgp4.wgsConstant.WGS_84);

            foreach (var p in passes)
            {
                Console.Out.WriteLine(p.ToString());
            }
            Console.Out.WriteLine("Done");
        }
Example #11
0
        static void Main(string[] args)
        {
            //Parse three line element
            Tle tleISS = ParserTLE.parseTle(
                "1 25544U 98067A   19097.23063721 -.00000469  00000-0  00000+0 0  9999",
                "2 25544  51.6449 353.9503 0002279 151.1697 290.4275 15.52495932164239",
                "ISS 1");

            //Parse tle from file
            if (System.IO.File.Exists("tleData.txt"))
            {
                List <Tle> tleList = ParserTLE.ParseFile("tleData.txt");
            }

            //Get TLE from Space-Track.org
            //list of satellites by their NORAD ID
            string[] noradIDs = { "8709", "43572" };
            try
            {
                One_Sgp4.SpaceTrack.GetSpaceTrack(noradIDs, "USERNAME", "PASSWORD");
            }
            catch { Console.Out.WriteLine("Error could not retrive TLE's from Space-Track, Login credentials might be wrong"); }


            //Create Time points
            EpochTime startTime   = new EpochTime(DateTime.UtcNow);
            EpochTime anotherTime = new EpochTime(2018, 100.5); //(Year 2017, 100 day at 12:00 HH)
            EpochTime stopTime    = new EpochTime(DateTime.UtcNow.AddHours(1));

            //Add 15 Seconds to EpochTime
            anotherTime.addTick(15);
            //Add 20 Min to EpochTime
            anotherTime.addMinutes(15);
            //Add 1 hour to EpochTime
            anotherTime.addHours(1);
            //Add 2 Days to EpochTime
            anotherTime.addDays(2);
            Console.Out.WriteLine(anotherTime.ToString());


            //Calculate Satellite Position and Speed
            One_Sgp4.Sgp4 sgp4Propagator = new Sgp4(tleISS, Sgp4.wgsConstant.WGS_84);
            //set calculation parameters StartTime, EndTime and caclulation steps in minutes
            sgp4Propagator.runSgp4Cal(startTime, stopTime, 1 / 30.0); // 1/60 => caclulate sat points every 2 seconds
            List <One_Sgp4.Sgp4Data> resultDataList = new List <Sgp4Data>();

            //Return Results containing satellite Position x,y,z (ECI-Coordinates in Km) and Velocity x_d, y_d, z_d (ECI-Coordinates km/s)
            resultDataList = sgp4Propagator.getRestults();

            //Coordinate of an observer on Ground lat, long, height(in meters)
            One_Sgp4.Coordinate observer = new Coordinate(35.554595, 18.888574, 0);
            //Convert to ECI coordinate system
            One_Sgp4.Point3d eci = observer.toECI(startTime.getLocalSiderealTime());
            //Get Local SiderealTime for Observer
            double localSiderealTime = startTime.getLocalSiderealTime(observer.getLongitude());

            //TESTING MIR

            //TEST ECI
            EpochTime T_eciTime = new EpochTime(09, 00, 00, 1995, 10, 1);

            //Test GMST
            if (T_eciTime.getLocalSiderealTime() == 2.524218)
            {
            }
            Coordinate T_eciCoo = new Coordinate(40, -75);
            var        t_eci    = T_eciCoo.toECI(T_eciTime.getLocalSiderealTime());
            //Coordinate equals x' = 1703.295 km, y' = 4586.650 km, z' = 4077.984 km.


            EpochTime  t_time = new EpochTime(12, 46, 0, 1995, 11, 18);
            Coordinate t_cord = new Coordinate(45.0, -93);
            Sgp4Data   mirPos = new Sgp4Data();

            mirPos.setX(-4400.594);
            mirPos.setY(1932.870);
            mirPos.setZ(4760.712);
            var lookAngels = SatFunctions.calcSphericalCoordinate(t_cord, t_time, mirPos);
            var onGround   = SatFunctions.calcSatSubPoint(t_time, mirPos, Sgp4.wgsConstant.WGS_72);
            var r          = t_cord.toECI(t_time.getLocalSiderealTime());


            //Calculate if Satellite is Visible for a certain Observer on ground at certain timePoint
            bool satelliteIsVisible = One_Sgp4.SatFunctions.isSatVisible(observer, 0.0, startTime, resultDataList[0]);

            //Calculate Sperical Coordinates from an Observer to Satellite
            //returns 3D-Point with range(km), azimuth(radians), elevation(radians) to the Satellite
            One_Sgp4.Point3d spherical = One_Sgp4.SatFunctions.calcSphericalCoordinate(observer, startTime, resultDataList[0]);

            //Calculate the Next 5 Passes over a point
            //for a location, Satellite, StartTime, Accuracy in Seconds = 15sec, MaxNumber of Days = 5 Days, Wgs constant = WGS_84
            //Returns pass with Location, StartTime of Pass, EndTime Of Pass, Max Elevation in Degrees
            List <Pass> passes = One_Sgp4.SatFunctions.CalculatePasses(observer, tleISS, new EpochTime(DateTime.UtcNow), 15, 5, Sgp4.wgsConstant.WGS_84);

            foreach (var p in passes)
            {
                Console.Out.WriteLine(p.ToString());
            }
        }