public void PassPrediction() { List <PassDetails> knownPasses = SetupKnownPasses(); CoordGeodetic geo = new CoordGeodetic(41.760612, -111.819384, 1.394); Tle tle = new Tle("ISS (ZARYA)", "1 25544U 98067A 15090.55997958 .00016867 00000-0 24909-3 0 9997", "2 25544 51.6467 111.8303 0006284 156.4629 341.9393 15.55450652935952"); SGP4 sgp4 = new SGP4(tle); /* * generate 7 day schedule */ DateTime start_date = new DateTime(2015, 4, 13, 0, 0, 0); //DateTime.Now (true); DateTime end_date = start_date.AddDays(7); //new DateTime (System.DateTime.Now.AddDays (7)); List <PassDetails> pass_list = new List <PassDetails>(); ; //Console.WriteLine("Start time: " + start_date.ToString()); //Console.WriteLine("End time : " + end_date.ToString()); /* * generate passes */ pass_list = GeneratePassList(geo, sgp4, start_date, end_date, 180); Assert.AreEqual(knownPasses.Count, pass_list.Count); for (int i = 0; i < pass_list.Count; ++i) { Assert.AreEqual(knownPasses[i].ToString(), pass_list[i].ToString()); } }
public double[][] getRV(double minutesAfterEpoch) { double [] r = new double[3]; double [] v = new double[3]; rec.error = 0; SGP4.sgp4(rec, minutesAfterEpoch, r, v); sgp4Error = rec.error; double [][] outv = new double[2][]; outv[0] = r; outv[1] = v; return(outv); }
/** * Set the values to the ElsetRec object. */ protected void setValsToRec() { double deg2rad = Math.PI / 180.0; // 0.0174532925199433 double xpdotp = 1440.0 / (2.0 * Math.PI); // 229.1831180523293 rec.elnum = elnum; rec.revnum = revnum; rec.satid = objectID; rec.bstar = bstar; rec.inclo = incDeg * deg2rad; rec.nodeo = raanDeg * deg2rad; rec.argpo = argpDeg * deg2rad; rec.mo = maDeg * deg2rad; rec.ecco = ecc; rec.no_kozai = n / xpdotp; rec.ndot = ndot / (xpdotp * 1440.0d); rec.nddot = nddot / (xpdotp * 1440.0d * 1440.0d); SGP4.sgp4init('a', rec); }
/** * Parse the tle epoch format to a date. * * @param str * @return */ protected DateTime parseEpoch(String str) { int year = (int)Double.Parse(str.Substring(0, 2).Trim()); rec.epochyr = year; if (year > 56) { year += 1900; } else { year += 2000; } int doy = (int)Double.Parse(str.Substring(2, 5 - 2).Trim()); double dfrac = Double.Parse("0" + str.Substring(5).Trim(), CultureInfo.InvariantCulture); rec.epochdays = doy; rec.epochdays += dfrac; dfrac *= 24.0d; int hr = (int)dfrac; dfrac = 60.0d * (dfrac - hr); int mn = (int)dfrac; dfrac = 60.0d * (dfrac - mn); int sc = (int)dfrac; dfrac = 1000.0d * (dfrac - sc); int milli = (int)dfrac; /* * gc.set(Calendar.YEAR, year); * gc.set(Calendar.DAY_OF_YEAR, doy); * gc.set(Calendar.HOUR_OF_DAY, hr); * gc.set(Calendar.MINUTE, mn); * gc.set(Calendar.SECOND, sc); * gc.set(Calendar.MILLISECOND, milli); */ DateTime mepoch = new DateTime(year, 1, 1); mepoch = mepoch.AddDays(doy - 1); mepoch = mepoch.AddHours(hr); mepoch = mepoch.AddMinutes(mn); mepoch = mepoch.AddSeconds(sc); mepoch = mepoch.AddMilliseconds(dfrac); // Specify that this is UTC mepoch = DateTime.SpecifyKind(mepoch, DateTimeKind.Utc); double sec = ((double)sc) + dfrac / 1000.0d; int mon = mepoch.Month; int day = mepoch.Day; double [] jd = SGP4.jday(year, mon, day, hr, mn, sec); rec.jdsatepoch = jd[0]; rec.jdsatepochF = jd[1]; return(mepoch); }
public static DateTime FindCrossingPoint(CoordGeodetic user_geo, SGP4 sgp4, DateTime initial_time1, DateTime initial_time2, bool finding_aos) { Observer obs = new Observer(user_geo); bool running; int cnt; DateTime time1 = new DateTime(initial_time1.Ticks()); DateTime time2 = new DateTime(initial_time2.Ticks()); DateTime middle_time = null; running = true; cnt = 0; while (running && cnt++ < 16) { middle_time = time1.AddSeconds((time2 - time1).TotalSeconds() / 2.0); /* * calculate satellite position */ Eci eci = sgp4.FindPosition(middle_time); CoordTopocentric topo = obs.GetLookAngle(eci); if (topo.elevation > 0.0) { /* * satellite above horizon */ if (finding_aos) { time2 = middle_time; } else { time1 = middle_time; } } else { if (finding_aos) { time1 = middle_time; } else { time2 = middle_time; } } if ((time2 - time1).TotalSeconds() < 1.0) { /* * two times are within a second, stop */ running = false; /* * remove microseconds */ int us = middle_time.Microsecond(); middle_time = middle_time.AddMicroseconds(-us); /* * step back into the pass by 1 second */ middle_time = middle_time.AddSeconds(finding_aos ? 1 : -1); } } /* * go back/forward 1second until below the horizon */ running = true; cnt = 0; while (running && cnt++ < 6) { Eci eci = sgp4.FindPosition(middle_time); CoordTopocentric topo = obs.GetLookAngle(eci); if (topo.elevation > 0) { middle_time = middle_time.AddSeconds(finding_aos ? -1 : 1); } else { running = false; } } return(middle_time); }
public static double FindMaxElevation(CoordGeodetic user_geo, SGP4 sgp4, DateTime aos, DateTime los) { Observer obs = new Observer(user_geo); bool running; double time_step = (los - aos).TotalSeconds() / 9.0; DateTime current_time = aos; //! current time DateTime time1 = aos; //! start time of search period DateTime time2 = los; //! end time of search period double max_elevation; //! max elevation running = true; do { running = true; max_elevation = -99999999999999.0; while (running && current_time < time2) { /* * find position */ Eci eci = sgp4.FindPosition(current_time); CoordTopocentric topo = obs.GetLookAngle(eci); if (topo.elevation > max_elevation) { /* * still going up */ max_elevation = topo.elevation; /* * move time along */ current_time = current_time.AddSeconds(time_step); if (current_time > time2) { /* * dont go past end time */ current_time = time2; } } else { /* * stop */ running = false; } } /* * make start time to 2 time steps back */ time1 = current_time.AddSeconds(-2.0 * time_step); /* * make end time to current time */ time2 = current_time; /* * current time to start time */ current_time = time1; /* * recalculate time step */ time_step = (time2 - time1).TotalSeconds() / 9.0; } while (time_step > 1.0); return(max_elevation); }
public static List <PassDetails> GeneratePassList(CoordGeodetic user_geo, SGP4 sgp4, DateTime start_time, DateTime end_time, int time_step) { List <PassDetails> pass_list = new List <PassDetails>(); Observer obs = new Observer(user_geo); DateTime aos_time = null; DateTime los_time = null; bool found_aos = false; DateTime previous_time = new DateTime(start_time.Ticks()); DateTime current_time = new DateTime(start_time.Ticks()); while (current_time < end_time) { bool end_of_pass = false; /* * calculate satellite position */ Eci eci = sgp4.FindPosition(current_time); CoordTopocentric topo = obs.GetLookAngle(eci); if (!found_aos && topo.elevation > 0.0) { /* * aos hasnt occured yet, but the satellite is now above horizon * this must have occured within the last time_step */ if (start_time == current_time) { /* * satellite was already above the horizon at the start, * so use the start time */ aos_time = start_time; } else { /* * find the point at which the satellite crossed the horizon */ aos_time = FindCrossingPoint( user_geo, sgp4, previous_time, current_time, true); } found_aos = true; } else if (found_aos && topo.elevation < 0.0) { found_aos = false; /* * end of pass, so move along more than time_step */ end_of_pass = true; /* * already have the aos, but now the satellite is below the horizon, * so find the los */ los_time = FindCrossingPoint(user_geo, sgp4, previous_time, current_time, false); PassDetails pd = new PassDetails(); pd.aos = aos_time; pd.los = los_time; pd.max_elevation = FindMaxElevation(user_geo, sgp4, aos_time, los_time); pass_list.Add(pd); } /* * save current time */ previous_time = current_time; if (end_of_pass) { /* * at the end of the pass move the time along by 30mins */ current_time = current_time.AddMinutes(30); } else { /* * move the time along by the time step value */ current_time = current_time.AddSeconds(180); } if (current_time > end_time) { /* * dont go past end time */ current_time = end_time; } } ; if (found_aos) { /* * satellite still above horizon at end of search period, so use end * time as los */ PassDetails pd = new PassDetails(); pd.aos = aos_time; pd.los = end_time; pd.max_elevation = FindMaxElevation(user_geo, sgp4, aos_time, end_time); pass_list.Add(pd); } return(pass_list); }