//! ContactWindowsVector constructor. /*! * \param ContactWindowsVector * Creates a new object from a ContactWindowsVector */ public ContactWindowsVector(ContactWindowsVector contacts) { contactsList = new List <ContactWindow>(contacts.getAllContacts()); satelliteNameList = new List <string>(contacts.getSatelliteNames()); stationNameList = new List <string>(contacts.getStationNames()); starttime = new One_Sgp4.EpochTime(contacts.getStartTime()); stoptime = new One_Sgp4.EpochTime(contacts.getStopTime()); calcualteTimesOfAllContacst(); }
//! InView constructor. /*! * \param Station groundstation used to calculate visibilty * \param One_Sgp4.EpochTime starttime * \param List<One_Sgp4.Sgp4Data> satelliteposition list x,y,z coordinates * \param string satellite name for to calculate visibilty * \param double tick time dime difference between every coordinate set */ public InView(Station groundstation, One_Sgp4.EpochTime time, List <One_Sgp4.Sgp4Data> satPosData, string satName, double tick) { results = new List <ContactWindow>(); _station = groundstation; _time = time; _satPosData = satPosData; _satName = satName; _tick = tick; }
//! Calculate Contact windows /*! * /param EpochTime starting time * /param Epoch Time stoping time * /param string Logfile * cacluated the orbits of selected satellites and then the contact windows * for each station in the given time frame */ private void CalculateContacts(One_Sgp4.EpochTime start, One_Sgp4.EpochTime stop, string logfile) { TimeMeasurement timeMessurmentOribt = new Performance.TimeMeasurement(); timeMessurmentOribt.activate(); contactsVector = MainFunctions2.calculateContactWindows(satTleData, stationData, start, stop, logfile, this); string perfResCalc = timeMessurmentOribt.getValueAndDeactivate(); updateLog(logfile, "Contact Windows Calculated in: " + perfResCalc + "sec."); }
//! gets the selected stop time /*! * /return EpochTime stopTime */ private One_Sgp4.EpochTime getStopTime() { int stop_year = stopDatePicker.Value.Year; int stop_month = stopDatePicker.Value.Month; int stop_day = stopDatePicker.Value.Day; int stop_hh = stopTimePicker.Value.Hour; int stop_mm = stopTimePicker.Value.Minute; int stop_ss = stopTimePicker.Value.Second; One_Sgp4.EpochTime stopTime = new One_Sgp4.EpochTime(stop_hh, stop_mm, (double)stop_ss, stop_year, stop_month, stop_day); return(stopTime); }
private Global.Structs.priority priority = (Structs.priority) 4; /*!< Global.Structs.priority - Priority of Request */ //! ContactWindow constructor /*! * \param TimeDate Starttime * \param TimeDate Stoptime * \param string SatelliteName * \param string GroundStationName */ public ContactWindow(One_Sgp4.EpochTime start, One_Sgp4.EpochTime stop, string satelliteName, string groundStationName) { satName = satelliteName; stationName = groundStationName; startTime = new One_Sgp4.EpochTime(start); stopTime = new One_Sgp4.EpochTime(stop); sheduled = false; exluded = false; calcDuration(); id = System.Guid.NewGuid(); List <TrackingData> trackingData = new List <TrackingData>(); }
//! Draw selected satellite path to image. /*! * \param One_Sgp4.Tle tle data from selected Satellite * \return Image bmp-Image */ public static Image drawSatellite(One_Sgp4.Tle tleData) { Image imgSatellite = Properties.Resources.worldsmaller; try { One_Sgp4.Sgp4 task = new One_Sgp4.Sgp4(tleData, Properties.Settings.Default.orbit_Wgs); One_Sgp4.EpochTime starttime = new One_Sgp4.EpochTime(DateTime.UtcNow); One_Sgp4.EpochTime stoptime = new One_Sgp4.EpochTime(DateTime.UtcNow.AddHours(4)); task.setStart(starttime, stoptime, 30.0 / 60.0); Task thread = new Task(task.starThread); thread.Start(); Task.WaitAll(thread); List <One_Sgp4.Sgp4Data> calcPposData = null; calcPposData = task.getRestults(); Pen penRest = new Pen(Color.Red, 1); Pen penSat = new Pen(Color.Red, 10); using (var graphics = Graphics.FromImage(imgSatellite)) { for (int i = 0; i < calcPposData.Count; i++) { One_Sgp4.Coordinate oneSubPoint = One_Sgp4.SatFunctions.calcSatSubPoint(starttime, calcPposData[i]); Definition.GeoCoordinate subPoint = new Definition.GeoCoordinate(oneSubPoint.getLatetude(), oneSubPoint.getLongitude(), oneSubPoint.getHeight()); Point p = subPoint.toPoint(imgSatellite.Width, imgSatellite.Height); graphics.DrawRectangle(penRest, p.X - 1, p.Y - 1, 2, 2); if (i == 0) { graphics.DrawRectangle(penSat, p.X - 5, p.Y - 5, 2, 2); } starttime.addTick(30.0); } } } catch { imgSatellite = Properties.Resources.worldsmaller; } return(imgSatellite); }
//! set the stop time /*! * \param TimeDate stoping time for schedule */ public void setStopTime(One_Sgp4.EpochTime stop) { stoptime = stop; }
//! set the start time /*! * \param TimeDate starting time for schedule */ public void setStartTime(One_Sgp4.EpochTime start) { starttime = start; }
//! returns local sidreal time at any given time /*! * \pram TimeDate current time * \return double LocalSidrealTime */ public double getLocalSidrealTime(One_Sgp4.EpochTime time) { return(time.getLocalSiderealTime(geoCoordinate.getLongitude())); }
//! setStopTime /*! * \param TimeDate * sets the stoptime of Contact */ public void setStopTime(One_Sgp4.EpochTime time) { stopTime = new One_Sgp4.EpochTime(time); calcDuration(); }
//! setStartTime /*! * \param TimeDate * sets the starttime of Contact */ public void setStartTime(One_Sgp4.EpochTime time) { startTime = new One_Sgp4.EpochTime(time); }
//! Calculate Schedule /*! * Calculates the orbit positions of the selected Satellites for the * given time period and then the contact windows for each selected * ground station. The calculation of the orbits and contact windows * is done in multiple threads to save time. Afterwards the selected * scheduler will compute a solution. * New schedulers can be added inside this function below. */ private void startSchedule(bool useBruteForce = false) { string logFile = MainFunctions.getLogFileName(); prepareStart(); updateLog(logFile, "Starting"); //Set Start and Stop Time One_Sgp4.EpochTime startTime = getStartTime(); One_Sgp4.EpochTime stopTime = getStopTime(); updateLog(logFile, "StartTime: " + startTime.ToString()); updateLog(logFile, "StartTime: " + stopTime.ToString()); // create empty Lists and data containers for Data satTleData = new List <One_Sgp4.Tle>(); stationData = new List <Ground.Station>(); //check if contacts vector has not been already created or loaded //from save file bool resetScenario = true; if (contactsVector == null || changedParameters == true) { contactsVector = new Definition.ContactWindowsVector(); contactsVector.setStartTime(startTime); contactsVector.setStopTime(stopTime); //get selected Satellites to calculate Orbits satTleData = getSatelliteData(logFile); stationData = getStationData(logFile); //starting with the orbit calculations updateLog(logFile, "Staring Orbit Calculations"); //Calculate Orbits and Contact Windows CalculateContacts(startTime, stopTime, logFile); } else { // resuse old ContactWindows startTime = contactsVector.getStartTime(); stopTime = contactsVector.getStopTime(); resetScenario = false; } AutoSave(logFile); updateLog(logFile, "Setting Up Scheduler"); //Set Scheduling Problem //set Objective Function setObjectiveFunction(); string test = objectivefunct.ToString(); //objectivefunct = new ObjectiveFunction(Global.Structs.ObjectiveEnum.DURATION, // Global.Structs.ObjectiveEnum.FAIRNESSATELITE, Global.Structs.ObjectiveEnum.FAIRNESSTATION, // Global.Structs.ObjectiveEnum.SCHEDULEDCONTACTS); SchedulingProblem problem = RunScheduler.setSchedulingProblem(contactsVector, objectivefunct); /* Generate the selected Scenarios * These are defined in the SchedulingProblem Class * Other Scenarios can be selected here if they are added */ if (resetScenario != false) { getScenario(problem); } //enable time measurment Class TimeMeasurement tm = new Performance.TimeMeasurement(); startScheduleButton.Enabled = true; scheduler = null; //create new scheduler object and set settings if (radioGenetic.Checked) { scheduler = RunScheduler.setScheduler(new GeneticScheduler(), this); } if (radioEFTGreedy.Checked) { scheduler = RunScheduler.setScheduler(new EftGreedyScheduler(), this); } if (radioGreedy.Checked) { scheduler = RunScheduler.setScheduler(new GreedyScheduler(), this); } if (radioHillClimber.Checked) { scheduler = RunScheduler.setScheduler(new HillClimberScheduler(), this); } //----------------------------------------------------------------- //---------------------------Add New SCHEDULER HERE----------------- //----------------------------------------------------------------- /* * if (radioNEW.Checked * { * scheduler = RunScheduler.setScheduler(new Scheduler.ExampleScheduler(), this); * } */ //----------------------------------------------------------------- //----------------------------------------------------------------- //----------------------------------------------------------------- updateLog(logFile, "starting " + scheduler.ToString()); //start Time Meassurment tm.activate(); if (!useBruteForce) { RunScheduler.startScheduler(scheduler, problem); } else { RunScheduler.startBruteForce(scheduler, problem, this); } //get Time Measurment updateCalculationTime(tm.getValueAndDeactivate()); //display resulst on main Page RunScheduler.displayResults(this, scheduler); //finisch clean up and write to logs if necesarry finischSchedule(scheduler.ToString(), logFile); }
//! Open and Load saved scheduling data /*! * \param string path to Load file * \param Main Form to update loading bar */ public static ContactWindowsVector loadFile(string filepath, Main f) { Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.GetCultureInfo("en-US"); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(filepath); XmlNodeList dataNodes = xmlDoc.SelectNodes("//Contacts/ContactWindow"); f.setProgressBar(dataNodes.Count); int startYear = Int32.Parse(xmlDoc.SelectSingleNode("//Contacts/StartYear").InnerText); double startEpoch = double.Parse(xmlDoc.SelectSingleNode("//Contacts/StartEpoch").InnerText); int stopYear = Int32.Parse(xmlDoc.SelectSingleNode("//Contacts/StopYear").InnerText); double stopEpoch = double.Parse(xmlDoc.SelectSingleNode("//Contacts/StopEpoch").InnerText); One_Sgp4.EpochTime start = new One_Sgp4.EpochTime(startYear, startEpoch); One_Sgp4.EpochTime stop = new One_Sgp4.EpochTime(stopYear, stopEpoch); ContactWindowsVector saved = new ContactWindowsVector(); saved.setStartTime(start); saved.setStopTime(stop); int count = 0; foreach (XmlNode node in dataNodes) { string sa = node.SelectSingleNode("SatName").InnerText; string st = node.SelectSingleNode("StaName").InnerText; int year = Int32.Parse(node.SelectSingleNode("StartYear").InnerText); double epoch = double.Parse(node.SelectSingleNode("StartTime").InnerText); ContactWindow cw = new ContactWindow(sa, st); One_Sgp4.EpochTime starttime = new One_Sgp4.EpochTime(year, epoch); cw.setStartTime(starttime); year = Int32.Parse(node.SelectSingleNode("StopYear").InnerText); epoch = double.Parse(node.SelectSingleNode("StopTime").InnerText); One_Sgp4.EpochTime stoptime = new One_Sgp4.EpochTime(year, epoch); cw.setStopTime(stoptime); if (node.SelectSingleNode("Scheduled").InnerText != "False") { cw.setSheduled(); } cw.setExclusion(bool.Parse(node.SelectSingleNode("Scheduled").InnerText)); cw.setID(Guid.Parse(node.SelectSingleNode("ID").InnerText)); cw.setRequestID(Guid.Parse(node.SelectSingleNode("RequID").InnerText)); cw.setPriority(Global.Funktions.ParseEnum <Global.Structs.priority>(node.SelectSingleNode("Priority").InnerText)); XmlNodeList children = node.SelectNodes("TrackingData/Data"); foreach (XmlNode childNode in children) { double azi = double.Parse(childNode.SelectSingleNode("Azimuth").InnerText); double ele = double.Parse(childNode.SelectSingleNode("Elevation").InnerText); double ran = double.Parse(childNode.SelectSingleNode("Range").InnerText); double ranR = double.Parse(childNode.SelectSingleNode("RangeRate").InnerText); string time = childNode.SelectSingleNode("TimeStamp").InnerText; TrackingData td = new TrackingData(azi, ele, ran, time); cw.addTrackingData(td); } f.updateProgressBar(count++); System.Windows.Forms.Application.DoEvents(); saved.add(cw); } f.resetProgressBar(); return(saved); }
//! Draw Conatact Windows. /*! * \param ContactWindowsVector Contacts * \param bool Draw All if false only scheduled contacts will be drawn * \return Image bmp-Image * Creates a bmp Image and returns it */ public static Image drawContacts(ContactWindowsVector contacts, bool drawAll) { if (contacts != null) { //sort by Groundstations contacts.sort(Structs.sortByField.GROUNDSTATION); List <string> satNameList = contacts.getSatelliteNames(); List <string> staNameList = contacts.getStationNames(); int x_offset = 100; int y_offset = 20; int satBoxheight = 20; //calculate Size of Image double timeLength = contacts.getStopTime().getEpoch() - contacts.getStartTime().getEpoch(); int imWidth = Convert.ToInt32(timeLength = 8640 * timeLength); int imHeight = satNameList.Count() * staNameList.Count() * 20; Image dest = new Bitmap(imWidth + x_offset, imHeight + y_offset); //Generate Front and Brusch for drawing System.Drawing.Graphics g; System.Drawing.Pen pen = new System.Drawing.Pen(Color.Black, 1F); Font drawFont = new Font("Arial", 10); SolidBrush brush = new SolidBrush(Color.Black); g = Graphics.FromImage(dest); g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit; //Start Drawing Contact Windows for (int i = 0; i < contacts.Count(); i++) { //Draw only if scheduled unless drawAll = true if (contacts.getAt(i).getSheduledInfo() || drawAll) { int satPosY = satNameList.IndexOf(contacts.getAt(i).getSatName()); int staPosY = staNameList.IndexOf(contacts.getAt(i).getStationName()); int y = 0; int x = 0; int satBoxhWidth = 0; y = satPosY * 20 + staPosY * satNameList.Count() * 20 + y_offset; double satx = 8640 * (contacts.getAt(i).getStartTime().getEpoch() - contacts.getStartTime().getEpoch()); x = Convert.ToInt32(satx) + x_offset; satBoxhWidth = Convert.ToInt32(contacts.getAt(i).getDuration() / 10.0); //brush = new SolidBrush(Color.FromArgb(contacts.getAt(i).getHash())); if (drawAll && !contacts.getAt(i).getSheduledInfo()) { brush = new SolidBrush(Color.FromArgb(215, 215, 215)); g.FillRectangle(brush, new Rectangle(x, y, satBoxhWidth, satBoxheight)); g.DrawString(contacts.getAt(i).getSatName(), drawFont, new SolidBrush(Color.DarkGray), x, y); } else { brush = new SolidBrush(Color.FromArgb(contacts.getAt(i).getHash())); g.FillRectangle(brush, new Rectangle(x, y, satBoxhWidth, satBoxheight)); g.DrawString(contacts.getAt(i).getSatName(), drawFont, new SolidBrush(Color.Black), x, y); } } } System.Drawing.Pen stationPen; stationPen = new System.Drawing.Pen(Color.DarkGray, 1); g.DrawLine(stationPen, x_offset, 0, x_offset, imHeight); //Start Drawing Stations Names for (int i = 0; i < staNameList.Count(); i++) { int x1 = 0; int y1 = (i + 1) * satNameList.Count() * 20; int x2 = imWidth; int y2 = (i + 1) * satNameList.Count() * 20; g.DrawString(staNameList[i], drawFont, new SolidBrush(Color.Black), 5, y1 - ((satNameList.Count() / 2) * 20)); g.DrawLine(stationPen, x1, y1 + y_offset, x2, y2 + y_offset); } One_Sgp4.EpochTime time = new One_Sgp4.EpochTime(contacts.getStartTime()); g.DrawString(contacts.getStartTime().ToString(), drawFont, new SolidBrush(Color.Black), x_offset, 5); for (int i = x_offset; i < imWidth; i += 180) { g.DrawString(time.ToString(), drawFont, new SolidBrush(Color.Black), i, 5); g.DrawLine(stationPen, i, 0, i, imHeight); time.addTick(10 * 180); } //g.Dispose(); drawFont.Dispose(); brush.Dispose(); pen.Dispose(); dest.Save("Contacts.bmp"); return(dest); } else { int imWidth = 8640; int imHeight = 20; Image dest = new Bitmap(imWidth, imHeight); return(dest); } }
//! Calculate ContactWindows for satellite and groundstations /*! * \param Station to calcuate if satellite is in View * \param TimeDate start time * \param List<Sgp4Data> satellite position vector * \param string name of the satellite * \param double tick in witch time is increased by each step * \return List<contactWindow> */ public void calcContactWindows() { One_Sgp4.EpochTime starttime = new One_Sgp4.EpochTime(_time); bool visible = false; ContactWindow window = null; double minElevation = _station.getMinElevation(); for (int i = 0; i < _satPosData.Count(); i++) { double lsr = starttime.getLocalSiderealTime(_station.getLongitude()); Structs.point3D groundLocation = _station.getEci(lsr); Structs.point3D v = new Structs.point3D(); v.x = _satPosData[i].getX() - groundLocation.x; v.y = _satPosData[i].getY() - groundLocation.y; v.z = _satPosData[i].getZ() - groundLocation.z; double r_lat = _station.getLatitude() * Constants.toRadians; double sin_lat = Math.Sin(r_lat); double cos_lat = Math.Cos(r_lat); double sin_srt = Math.Sin(lsr); double cos_srt = Math.Cos(lsr); double rs = sin_lat * cos_srt * v.x + sin_lat * sin_srt * v.y - cos_lat * v.z; double re = -sin_srt * v.x + cos_srt * v.y; double rz = cos_lat * cos_srt * v.x + cos_lat * sin_srt * v.y + sin_lat * v.z; double range = Math.Sqrt(rs * rs + re * re + rz * rz); double elevation = Math.Asin(rz / range); double azimuth = Math.Atan(-re / rs); if (rs > 0.0) { azimuth += Constants.pi; } if (azimuth < 0.0) { azimuth += Constants.twoPi; } if (elevation >= minElevation) { if (visible == false) { window = new ContactWindow(_satName, _station.getName()); window.setStartTime(starttime); } TrackingData testTrack = new TrackingData(azimuth, elevation, range, starttime.ToString()); window.addTrackingData(testTrack); visible = true; } else { if (visible == true) { window.setStopTime(starttime); results.Add(window); } visible = false; } azimuth = azimuth * Constants.toDegrees; starttime.addTick(_tick); } }