//create satellite function private void CreateSatellite(string objID, string source, string fpath) { string sname = objID + "_" + source.Replace(' ', '_').Trim(); if (!stkRoot.CurrentScenario.Children.Contains(AgESTKObjectType.eSatellite, sname)) { //create new if non-existant stkRoot.CurrentScenario.Children.New(AgESTKObjectType.eSatellite, sname); } //handle to satellite IAgSatellite zsat = stkRoot.CurrentScenario.Children[sname] as IAgSatellite; zsat.SetPropagatorType(AgEVePropagatorType.ePropagatorSGP4); IAgVePropagatorSGP4 tleprop = zsat.Propagator as IAgVePropagatorSGP4; tleprop.Segments.RemoveAllSegs();//clear before adding new tleprop.CommonTasks.AddSegsFromFile(objID, fpath); tleprop.Propagate(); }
private void addSatelliteButton_Click(object sender, EventArgs e) { //Create vehicle (satellite) string satName = "TLE" + tleNumberTb.Text; AgSatellite satellite = null; if (CommonData.StkRoot.CurrentScenario.Children.Contains(AgESTKObjectType.eSatellite, satName)) { satellite = CommonData.StkRoot.GetObjectFromPath("Satellite/" + satName) as AgSatellite; } else { satellite = CommonData.StkRoot.CurrentScenario.Children.New(AgESTKObjectType.eSatellite, satName) as AgSatellite; //Using SPG4 propagator satellite.SetPropagatorType(AgEVePropagatorType.ePropagatorSGP4); IAgVePropagatorSGP4 propagator = satellite.Propagator as IAgVePropagatorSGP4; propagator.CommonTasks.AddSegsFromOnlineSource(tleNumberTb.Text); propagator.Propagate(); } //using Two Body propagator //satellite.SetPropagatorType(AgEVePropagatorType.ePropagatorTwoBody); //IAgVePropagatorTwoBody twoBodyPropagator = satellite.Propagator as IAgVePropagatorTwoBody; //twoBodyPropagator.Propagate(); //Add access constraints to object IAgAccessCnstrCondition lightingConstraint = null; if (!satellite.AccessConstraints.IsConstraintActive(AgEAccessConstraints.eCstrLighting)) { lightingConstraint = satellite.AccessConstraints.AddConstraint(AgEAccessConstraints.eCstrLighting) as IAgAccessCnstrCondition; } else { lightingConstraint = satellite.AccessConstraints.GetActiveConstraint(AgEAccessConstraints.eCstrLighting) as IAgAccessCnstrCondition; } lightingConstraint.Condition = AgECnstrLighting.eDirectSun; }
//create satellite function private void CreateSatellite(string objId, string source, string fpath) { IAgStkObject sat = null; try { string sname = objId + "_" + source.Replace(' ', '_').Trim(); //create new if non-existant or get handle sat = CreatorFunctions.GetCreateSatellite(sname); //handle to satellite IAgSatellite zsat = sat as IAgSatellite; //Erase old TLE data and replace it with new data from specified file zsat.SetPropagatorType(AgEVePropagatorType.ePropagatorSGP4); IAgVePropagatorSGP4 tleprop = zsat.Propagator as IAgVePropagatorSGP4; tleprop.Segments.RemoveAllSegs();//clear before adding new tleprop.CommonTasks.AddSegsFromFile(objId, fpath); tleprop.Propagate(); zsat.Graphics.Resolution.Orbit = 10; if (CoordSystem.SelectedIndex == 0) { zsat.VO.OrbitSystems.FixedByWindow.IsVisible = true; zsat.VO.OrbitSystems.InertialByWindow.IsVisible = false; string cmd = "VO */Satellite/" + sname + " ModelDetail Set ModelLabel 2000000000 MarkerLabel 2000000000"; try { CommonData.StkRoot.ExecuteCommand(cmd); } catch (Exception) { } } //Place into constellation IAgConstellation assets = null; if ((string)ConstType.SelectedItem == "Default Constellation") { IAgStkObject conste = CreatorFunctions.GetCreateConstellation("Assets"); assets = conste as IAgConstellation; } else if ((string)ConstType.SelectedItem == "Existing Constellation") { assets = (IAgConstellation)CommonData.StkRoot.GetObjectFromPath("Constellation/" + ExistingConst.Text); } else if ((string)ConstType.SelectedItem == "New Constellation") { IAgStkObject conste = CreatorFunctions.GetCreateConstellation(ConstName.Text.Replace(" ", "_")); assets = conste as IAgConstellation; } string objPath = "Satellite/" + sname; if (assets.Objects.IndexOf(objPath) == -1 && assets != null) { assets.Objects.Add(objPath); } } catch (Exception ex) { //Identify the satellite with an issue MessageBox.Show(ex.Message + "\n" + "SSC: " + objId); //unload satellite if possible so there is not an empty object in STK from an error //try //{ // sat.Unload(); //} //catch (Exception) //{ //} } }
private void Generate_Click(object sender, EventArgs e) { CommonData.StkRoot.ExecuteCommand("BatchGraphics * On"); IAgConstellation myConst; if ((string)ImportType.SelectedItem == "TLE/TCE") { string filepath = TCEFile.Text; IAgScenario scenario = (IAgScenario)CommonData.StkRoot.CurrentScenario; string startTime = scenario.StartTime; string stopTime = scenario.StopTime; string constellation = null; string cmd; try { IAgExecCmdResult result = CommonData.StkRoot.ExecuteCommand("DoesObjExist / */Constellation/Assets"); if ((string)ConstType.SelectedItem == "Default Constellation") { if (result[0] == "0") { IAgConstellation assets = (IAgConstellation)CommonData.StkRoot.CurrentScenario.Children.New(AgESTKObjectType.eConstellation, "Assets"); } constellation = "Assets"; } else if ((string)ConstType.SelectedItem == "Existing Constellation") { result = CommonData.StkRoot.ExecuteCommand("DoesObjExist / */Constellation/" + ExistingConst.Text); if (result[0] == "0") { IAgConstellation assets = (IAgConstellation)CommonData.StkRoot.CurrentScenario.Children.New(AgESTKObjectType.eConstellation, ExistingConst.Text); } constellation = ExistingConst.Text; } else if ((string)ConstType.SelectedItem == "New Constellation") { result = CommonData.StkRoot.ExecuteCommand("DoesObjExist / */Constellation/" + ConstName.Text); if (result[0] == "0") { IAgConstellation assets = (IAgConstellation)CommonData.StkRoot.CurrentScenario.Children.New(AgESTKObjectType.eConstellation, ConstName.Text); } constellation = ConstName.Text; } //must parse satellites into constellation because of bug associated with ImportTLEFile connect command //Get list of sats prior to import result = CommonData.StkRoot.ExecuteCommand("ShowNames * Class Satellite"); string[] prevSatArray = null; if (result[0] != "None") { prevSatArray = result[0].Split(null); } //Import TLE cmd = "ImportTLEFile * " + "\"" + filepath + "\"" + " AutoPropagate On TimeStep 30.0 StartStop " + "\"" + startTime + "\" " + "\"" + stopTime + "\""; CommonData.StkRoot.ExecuteCommand(cmd); myConst = CommonData.StkRoot.GetObjectFromPath("Constellation/" + constellation) as IAgConstellation; IAgSatellite sat; //Compare prev satellite list to new satellite list result = CommonData.StkRoot.ExecuteCommand("ShowNames * Class Satellite"); string[] newSatArray = null; if (result[0] != "None") { newSatArray = result[0].Split(null); } if (prevSatArray == null) { if (newSatArray != null) { foreach (var item in newSatArray) { if (item != "") { string newItem = item.Split('/').Last(); string objPath = "Satellite/" + newItem; myConst.Objects.Add(objPath); sat = CommonData.StkRoot.GetObjectFromPath(item.ToString()) as IAgSatellite; if (CoordSystem.SelectedIndex == 0) { sat.VO.OrbitSystems.FixedByWindow.IsVisible = true; sat.VO.OrbitSystems.InertialByWindow.IsVisible = false; } cmd = "VO */" + item.ToString() + " ModelDetail Set ModelLabel 2000000000 MarkerLabel 2000000000"; CommonData.StkRoot.ExecuteCommand(cmd); } } } } else { bool exists = false; foreach (var newSat in newSatArray) { if (newSat != "") { exists = false; foreach (var prevSat in prevSatArray) { if (prevSat == newSat) { exists = true; } } if (exists != true) { string newItem = newSat.Split('/').Last(); string objPath = "Satellite/" + newItem; myConst.Objects.Add(objPath); sat = CommonData.StkRoot.GetObjectFromPath(objPath) as IAgSatellite; if (CoordSystem.SelectedIndex == 0) { sat.VO.OrbitSystems.FixedByWindow.IsVisible = true; sat.VO.OrbitSystems.InertialByWindow.IsVisible = false; } cmd = "VO */" + objPath + " ModelDetail Set ModelLabel 2000000000 MarkerLabel 2000000000"; CommonData.StkRoot.ExecuteCommand(cmd); } } } } } catch (Exception) { MessageBox.Show("Could not load asset(s)"); } } else if ((string)ImportType.SelectedItem == "Orbital Elements") { int check = FieldCheck(); if (check == 0) { int errorNum = 0; try { errorNum = 1; IAgStkObject sat = CreatorFunctions.GetCreateSatellite(NameValue.Text); IAgSatellite mySat = sat as IAgSatellite; if (CoordSystem.SelectedIndex == 0) { mySat.VO.OrbitSystems.FixedByWindow.IsVisible = true; mySat.VO.OrbitSystems.InertialByWindow.IsVisible = false; string cmd = "VO */Satellite/" + NameValue.Text + " ModelDetail Set ModelLabel 2000000000 MarkerLabel 2000000000"; CommonData.StkRoot.ExecuteCommand(cmd); } ((IAgSatellite)mySat).SetPropagatorType(AgEVePropagatorType.ePropagatorJ2Perturbation); IAgOrbitStateClassical keplerian; keplerian = ((IAgOrbitStateClassical)((IAgVePropagatorJ2Perturbation)((IAgSatellite)mySat).Propagator).InitialState.Representation.ConvertTo(AgEOrbitStateType.eOrbitStateClassical)); keplerian.SizeShapeType = AgEClassicalSizeShape.eSizeShapeSemimajorAxis; ((IAgVePropagatorJ2Perturbation)((IAgSatellite)mySat).Propagator).InitialState.Representation.AssignClassical(AgECoordinateSystem.eCoordinateSystemICRF, Double.Parse(SMAValue.Text), Double.Parse(EccValue.Text), Double.Parse(IncValue.Text), Double.Parse(AoPValue.Text), Double.Parse(RAANValue.Text), Double.Parse(TAValue.Text)); ((IAgVePropagatorJ2Perturbation)((IAgSatellite)mySat).Propagator).Propagate(); IAgExecCmdResult result = CommonData.StkRoot.ExecuteCommand("DoesObjExist / */Constellation/Assets"); errorNum = 2; if ((string)ConstType.SelectedItem == "Default Constellation") { IAgStkObject conste = CreatorFunctions.GetCreateConstellation("Assets"); IAgConstellation assets = conste as IAgConstellation; string objPath = "Satellite/" + NameValue.Text; assets.Objects.Add(objPath); } else if ((string)ConstType.SelectedItem == "Existing Constellation") { IAgConstellation assets = (IAgConstellation)CommonData.StkRoot.GetObjectFromPath("Constellation/" + ExistingConst.Text); string objPath = "Satellite/" + NameValue.Text; assets.Objects.Add(objPath); } else if ((string)ConstType.SelectedItem == "New Constellation") { IAgConstellation assets = (IAgConstellation)CommonData.StkRoot.CurrentScenario.Children.New(AgESTKObjectType.eConstellation, ConstName.Text); string objPath = "Satellite/" + NameValue.Text; assets.Objects.Add(objPath); } } catch (Exception) { string errorMes = null; if (errorNum == 1) { errorMes = "Could not load satellite- Improper Orbital Elements"; } else if (errorNum == 2) { errorMes = "Could not add satellite to constellation"; } MessageBox.Show(errorMes); } } } else if ((string)ImportType.SelectedItem == "Satellite Database") { string sscString = null; string satName = null; int errorNum = 0; string errorSsc = null; string objPath = null; IAgSatellite mySat = null; IAgConstellation assets = null; IAgScenario scenario = CommonData.StkRoot.CurrentScenario as IAgScenario; string startTime = scenario.StartTime; string stopTime = scenario.StopTime; string cmd; int errorId = 0; CommonData.StkRoot.ExecuteCommand("BatchGraphics * On"); foreach (var item in _selectedSatList) { //Determine the proper satellite name based on catalog errorId = 5; int index = CommonData.SatCatItemList.IndexOf(CommonData.SatCatItemList.Where(p => p.Ssc == item).FirstOrDefault()); SatCatItem currentSat = CommonData.SatCatItemList[index]; if (currentSat.OtherName != "Unspecified") { string otherName = currentSat.OtherName.Replace(" ", "_"); otherName = Regex.Replace(otherName, @"[^0-9a-zA-Z_]+", ""); //CommonData.StkRoot.ExecuteCommand("Rename */" + objPath + " " + otherName); objPath = "Satellite/" + otherName; satName = otherName; } else if (currentSat.CommonName != "Unspecified") { string commonName = currentSat.CommonName.Replace(" ", "_"); commonName = Regex.Replace(commonName, @"[^0-9a-zA-Z_]+", ""); objPath = "Satellite/" + commonName; satName = commonName; } else { objPath = "Satellite/" + item; satName = item; } //SSCString = "SSCNumber " + item + " "; //cmd = "ImportTLEFile * " + "\"" + CommonData.SatDatabaseLocation + "\"" +SSCString+ "AutoPropagate On TimeStep 30.0 StartStop " + "\"" + startTime + "\" " + "\"" + stopTime + "\""; try { errorId = 1; //Create or get handle to satellite based on given name mySat = (IAgSatellite)CreatorFunctions.GetCreateSatellite(satName); //Erase old TLE data and replace it with new data from specified file mySat.SetPropagatorType(AgEVePropagatorType.ePropagatorSGP4); IAgVePropagatorSGP4 tleprop = mySat.Propagator as IAgVePropagatorSGP4; tleprop.Segments.RemoveAllSegs();//clear before adding new tleprop.CommonTasks.AddSegsFromFile(item, CommonData.Preferences.SatDatabaseLocation); tleprop.Propagate(); mySat.Graphics.Resolution.Orbit = 20; //Change trajectory representation to fixed if required. Inertial by default if (CoordSystem.SelectedIndex == 0) { mySat.VO.OrbitSystems.FixedByWindow.IsVisible = true; mySat.VO.OrbitSystems.InertialByWindow.IsVisible = false; string cmd1 = "VO */Satellite/" + satName + " ModelDetail Set ModelLabel 2000000000 MarkerLabel 2000000000"; CommonData.StkRoot.ExecuteCommand(cmd1); } else if (CoordSystem.SelectedIndex == 1) { mySat.VO.OrbitSystems.FixedByWindow.IsVisible = false; mySat.VO.OrbitSystems.InertialByWindow.IsVisible = true; string cmd1 = "VO */Satellite/" + satName + " ModelDetail Set ModelLabel 2000000000 MarkerLabel 2000000000"; CommonData.StkRoot.ExecuteCommand(cmd1); } //Get handle to constellation or create if necessary. Add satellite to constellation if ((string)ConstType.SelectedItem == "Default Constellation") { errorId = 2; assets = CreatorFunctions.GetCreateConstellation("Assets") as IAgConstellation; } else if ((string)ConstType.SelectedItem == "Existing Constellation") { errorId = 3; assets = CreatorFunctions.GetCreateConstellation(ExistingConst.Text) as IAgConstellation; } else if ((string)ConstType.SelectedItem == "New Constellation") { errorId = 4; assets = CreatorFunctions.GetCreateConstellation(ConstName.Text) as IAgConstellation; } if (!assets.Objects.Contains("Satellite/" + satName)) { objPath = "Satellite/" + satName; assets.Objects.Add(objPath); } errorId = 8; CreatorFunctions.ChangeSatColor(objPath, index); //Create sensor if applicable. Place sensor in appropiate constellation for sensors if (currentSat.Fov != 0 && SensorToggle.Checked) { try { errorId = 6; IAgStkObject assetsObject = assets as IAgStkObject; IAgStkObject sat = CommonData.StkRoot.GetObjectFromPath(objPath); IAgSensor sensor = CreatorFunctions.GetCreateSensor(sat, sat.InstanceName + "_Sensor") as IAgSensor; IAgStkObject sensorObject = sensor as IAgStkObject; sensor.CommonTasks.SetPatternSimpleConic(currentSat.Fov / 2, 1); sensor.VO.ProjectionType = AgESnVOProjectionType.eProjectionEarthIntersections; sensor.VO.PercentTranslucency = 70; errorId = 7; assets = CreatorFunctions.GetCreateConstellation(assetsObject.InstanceName + "_Sensors") as IAgConstellation; try { assets.Objects.AddObject(sensorObject); } catch (Exception) { //Likely already in the constellation } } catch (Exception) { } } } catch (Exception) { string errorIdString = null; if (errorId == 1) { errorIdString = "- Could not load from database"; } else if (errorId == 2) { errorIdString = "- Could not add to Default constellation"; } else if (errorId == 3) { errorIdString = "- Could not add to existing constellation"; } else if (errorId == 4) { errorIdString = "- Could not add to new constellation"; } else if (errorId == 5) { errorIdString = "- Could not change satellite name"; } else if (errorId == 6) { errorIdString = "- Could not load sensor or update sensor properties"; } else if (errorId == 7) { errorIdString = "- Could not add sensor to constellation"; } else if (errorId == 8) { errorIdString = "- Could not change satellite color"; } errorSsc = errorSsc + item + errorIdString + "\n\r"; errorNum++; } } if (errorNum != 0) { MessageBox.Show("Error loading the following satellites: \n\r" + errorSsc); } CommonData.StkRoot.ExecuteCommand("BatchGraphics * Off"); } else if ((string)ImportType.SelectedItem == "Ephemeris") { try { IAgConstellation assets = null; string constellation = null; if ((string)ConstType.SelectedItem == "Default Constellation") { IAgStkObject obj = CreatorFunctions.GetCreateConstellation("Assets"); assets = obj as IAgConstellation; constellation = "Assets"; } else if ((string)ConstType.SelectedItem == "Existing Constellation") { IAgStkObject obj = CreatorFunctions.GetCreateConstellation(ExistingConst.Text); assets = obj as IAgConstellation; constellation = ExistingConst.Text; } else if ((string)ConstType.SelectedItem == "New Constellation") { IAgStkObject obj = CreatorFunctions.GetCreateConstellation(ConstName.Text); assets = obj as IAgConstellation; constellation = ConstName.Text; } string filepath = TCEFile.Text; string[] separator1 = { "\\" }; string[] separator2 = { "." }; string fileName = filepath.Split(separator1, StringSplitOptions.None).Last(); string satName = fileName.Split(separator2, StringSplitOptions.None).First(); satName = Regex.Replace(satName, @"[^0-9a-zA-Z_]+", ""); IAgStkObject satObj = CreatorFunctions.GetCreateSatellite(satName); IAgSatellite sat = satObj as IAgSatellite; sat.SetPropagatorType(AgEVePropagatorType.ePropagatorStkExternal); IAgVePropagatorStkExternal prop = sat.Propagator as IAgVePropagatorStkExternal; prop.Filename = filepath; if (TimeSlip.Checked) { try { prop.Override = true; prop.EphemerisStartEpoch.SetExplicitTime(SlipTime.Text); } catch (Exception) { MessageBox.Show("Could not apply time slip"); } } prop.Propagate(); try { assets.Objects.AddObject(satObj); } catch (Exception) { MessageBox.Show("Could not add to constellation"); } if (CoordSystem.SelectedIndex == 0) { sat.VO.OrbitSystems.FixedByWindow.IsVisible = true; sat.VO.OrbitSystems.InertialByWindow.IsVisible = false; string cmd = "VO */Satellite/" + satName + " ModelDetail Set ModelLabel 2000000000 MarkerLabel 2000000000"; CommonData.StkRoot.ExecuteCommand(cmd); } } catch (Exception) { MessageBox.Show("Error loading ephemeris"); } } CommonData.StkRoot.ExecuteCommand("BatchGraphics * Off"); PopulateExistingConstellations(); }
//Satellite helpers public static void ChangeSatelliteInterval(IAgSatellite sat, string startTime, string stopTime, bool astgRun) { AgEVePropagatorType propType = sat.PropagatorType; //IAgVePropagator prop = sat.Propagator; switch (propType) { case AgEVePropagatorType.eUnknownPropagator: break; case AgEVePropagatorType.ePropagatorHPOP: IAgVePropagatorHPOP prop = sat.Propagator as IAgVePropagatorHPOP; prop.EphemerisInterval.SetExplicitInterval(startTime, stopTime); prop.Propagate(); break; case AgEVePropagatorType.ePropagatorJ2Perturbation: IAgVePropagatorJ2Perturbation prop1 = sat.Propagator as IAgVePropagatorJ2Perturbation; prop1.EphemerisInterval.SetExplicitInterval(startTime, stopTime); prop1.Propagate(); break; case AgEVePropagatorType.ePropagatorJ4Perturbation: IAgVePropagatorJ4Perturbation prop2 = sat.Propagator as IAgVePropagatorJ4Perturbation; prop2.EphemerisInterval.SetExplicitInterval(startTime, stopTime); prop2.Propagate(); break; case AgEVePropagatorType.ePropagatorLOP: IAgVePropagatorLOP prop3 = sat.Propagator as IAgVePropagatorLOP; prop3.EphemerisInterval.SetExplicitInterval(startTime, stopTime); prop3.Propagate(); break; case AgEVePropagatorType.ePropagatorSGP4: IAgVePropagatorSGP4 prop4 = sat.Propagator as IAgVePropagatorSGP4; prop4.EphemerisInterval.SetExplicitInterval(startTime, stopTime); prop4.Propagate(); break; case AgEVePropagatorType.ePropagatorSPICE: IAgVePropagatorSPICE prop5 = sat.Propagator as IAgVePropagatorSPICE; prop5.EphemerisInterval.SetExplicitInterval(startTime, stopTime); prop5.Propagate(); break; case AgEVePropagatorType.ePropagatorStkExternal: IAgVePropagatorStkExternal prop6 = sat.Propagator as IAgVePropagatorStkExternal; //prop6.EphemerisInterval.SetExplicitInterval(startTime, stopTime); break; case AgEVePropagatorType.ePropagatorTwoBody: IAgVePropagatorTwoBody prop7 = sat.Propagator as IAgVePropagatorTwoBody; prop7.EphemerisInterval.SetExplicitInterval(startTime, stopTime); prop7.Propagate(); break; case AgEVePropagatorType.ePropagatorUserExternal: break; case AgEVePropagatorType.ePropagatorGreatArc: IAgVePropagatorGreatArc prop8 = sat.Propagator as IAgVePropagatorGreatArc; prop8.EphemerisInterval.SetExplicitInterval(startTime, stopTime); prop8.Propagate(); break; case AgEVePropagatorType.ePropagatorBallistic: break; case AgEVePropagatorType.ePropagatorSimpleAscent: break; case AgEVePropagatorType.ePropagatorAstrogator: if (astgRun) { IAgVADriverMCS driver = sat.Propagator as IAgVADriverMCS; driver.RunMCS(); } break; case AgEVePropagatorType.ePropagatorRealtime: break; case AgEVePropagatorType.ePropagatorGPS: IAgVePropagatorGPS prop9 = sat.Propagator as IAgVePropagatorGPS; prop9.EphemerisInterval.SetExplicitInterval(startTime, stopTime); prop9.Propagate(); break; case AgEVePropagatorType.ePropagatorAviator: break; case AgEVePropagatorType.ePropagator11Param: IAgVePropagator11Param prop10 = sat.Propagator as IAgVePropagator11Param; prop10.EphemerisInterval.SetExplicitInterval(startTime, stopTime); prop10.Propagate(); break; case AgEVePropagatorType.ePropagatorSP3: IAgVePropagatorSP3 prop11 = sat.Propagator as IAgVePropagatorSP3; //prop11.EphemerisInterval.SetExplicitInterval(startTime, stopTime); break; default: break; } }
public static void CreateScenarioFromTle(ref AgStkObjectRoot root, double duration, ref InitialState initState, TLE currentTle) { root.NewScenario(currentTle.GetSatNumber() + "_Reentry"); DateTime startDate = currentTle.GetTleEpoch(); DateTime stopDate = startDate.AddDays(duration); IAgScenario scenario = root.CurrentScenario as IAgScenario; // Set scenario start and stop times scenario.SetTimePeriod(startDate.ToString("dd MMM yyyy hh:mm:ss.fff"), stopDate.ToString("dd MMM yyyy hh:mm:ss.fff")); // remove the terrain option root.ExecuteCommand("Terrain * TerrainServer UseTerrainForAnalysis No"); // create the SGP4 object from the TLE IAgSatellite decayingSat = (IAgSatellite)root.CurrentScenario.Children.New(AgESTKObjectType.eSatellite, currentTle.GetSatNumber()); decayingSat.SetPropagatorType(AgEVePropagatorType.ePropagatorSGP4); IAgVePropagatorSGP4 sgp4 = decayingSat.Propagator as IAgVePropagatorSGP4; sgp4.CommonTasks.AddSegsFromFile(currentTle.GetSatNumber(), currentTle.GetFilePath()); IAgVeGfxAttributesBasic att = decayingSat.Graphics.Attributes as IAgVeGfxAttributesBasic; att.Color = Color.Yellow; // Configure time period sgp4.EphemerisInterval.SetExplicitInterval(scenario.StartTime, scenario.StopTime); sgp4.Step = 60.0; // Propagate sgp4.Propagate(); // change the 3D model try { root.ExecuteCommand("VO */Satellite/" + currentTle.GetSatNumber() + " Model File \"C:\\Program Files\\AGI\\STK 11\\STKData\\VO\\Models\\Misc\\explosion.mdl\""); } catch (Exception) { } //// get the initial state from the TLE initState.Epoch = scenario.StartTime; IAgDataPrvTimeVar dpPos = ((IAgStkObject)decayingSat).DataProviders.GetDataPrvTimeVarFromPath("Cartesian Position//ICRF"); IAgDrResult resultPos = dpPos.Exec(scenario.StartTime, scenario.StartTime, 60.0); IAgDrDataSetCollection datasetsPos = resultPos.DataSets; if (resultPos.DataSets.Count > 0) { initState.CartesianPosX = datasetsPos[1].GetValues().GetValue(0).ToString(); initState.CartesianPosY = datasetsPos[2].GetValues().GetValue(0).ToString(); initState.CartesianPosZ = datasetsPos[3].GetValues().GetValue(0).ToString(); } IAgDataPrvTimeVar dpVel = ((IAgStkObject)decayingSat).DataProviders.GetDataPrvTimeVarFromPath("Cartesian Velocity//ICRF"); IAgDrResult resultVel = dpVel.Exec(scenario.StartTime, scenario.StartTime, 60.0); IAgDrDataSetCollection datasetsVel = resultVel.DataSets; if (resultVel.DataSets.Count > 0) { initState.CartesianVelX = datasetsVel[1].GetValues().GetValue(0).ToString(); initState.CartesianVelY = datasetsVel[2].GetValues().GetValue(0).ToString(); initState.CartesianVelZ = datasetsVel[3].GetValues().GetValue(0).ToString(); } // configure the 2D graphics root.ExecuteCommand("Graphics * BackgroundImage Show Off"); root.ExecuteCommand("MapDetails * LatLon Lon On 15"); root.ExecuteCommand("MapDetails * Map RWDB2_Islands State On Color green"); root.ExecuteCommand("MapDetails * Map RWDB2_International_Borders State On "); root.ExecuteCommand("MapDetails * Map RWDB2_Lakes State On"); try { root.ExecuteCommand("VO * Globe Show On File \"C:\\Program Files\\AGI\\STK 11\\STKData\\VO\\Globes\\Earth\\WhiteOnBlue.glb\""); } catch (Exception) { } // configure the 3D graphics root.ExecuteCommand("VO * GlobeDetails MapDetail Show On Map RWDB2_Coastlines ShowDetail On"); root.ExecuteCommand("VO * GlobeDetails MapDetail Show On Map RWDB2_Islands ShowDetail On DetailColor green"); root.ExecuteCommand("VO * GlobeDetails MapDetail Show On Map RWDB2_Lakes ShowDetail On DetailColor lightblue"); //dynamic uiApp = System.Runtime.InteropServices.Marshal.GetActiveObject("STK11.Application"); //try //{ // foreach (dynamic window in uiApp.Windows) // { // string windowCaption = (string)window.Caption; // if (windowCaption.Contains("2D")) // { // window.DockStyle = 3; // } // } //} //catch (Exception ex) //{ // string error = ex.Message; //} }
public static TLE CreateScenarioFromSatcat(ref AgStkObjectRoot root, double duration, ref InitialState initState, string satId) { root.NewScenario(satId + "_Reentry"); //DateTime startDate = currentTle.GetTleEpoch(); //DateTime stopDate = startDate.AddDays(duration); IAgScenario scenario = root.CurrentScenario as IAgScenario; // remove the terrain option root.ExecuteCommand("Terrain * TerrainServer UseTerrainForAnalysis No"); // import the satellite from the catalog root.ExecuteCommand("ImportFromDB * Satellite AGIServer Propagate On TimePeriod UseScenarioInterval SSCNumber " + satId + " \""); // get the satellite start time IAgStkObject satObj = root.CurrentScenario.Children[0]; IAgSatellite decayingSat = satObj as IAgSatellite; IAgVePropagatorSGP4 sgp4 = decayingSat.Propagator as IAgVePropagatorSGP4; //IAgCrdnEventSmartEpoch startEpoch = sgp4.EphemerisInterval.GetStartEpoch(); dynamic startEpoch = sgp4.Segments[0].SwitchTime; // Set scenario start and stop times DateTime startDate = STK.GetDateTimeFromStkTimeFormat(Convert.ToString(startEpoch)); DateTime stopDate = startDate.AddDays(duration); scenario.SetTimePeriod(startDate.ToString("dd MMM yyyy hh:mm:ss.fff"), stopDate.ToString("dd MMM yyyy hh:mm:ss.fff")); // get the TLE data back from STK TLE tle = new TLE(startDate, sgp4.Segments[0].SSCNum, Convert.ToString(sgp4.Segments[0].Inclination), Convert.ToString(sgp4.Segments[0].Eccentricity), Convert.ToString(sgp4.Segments[0].RevNumber), Convert.ToString(sgp4.Segments[0].MeanMotion)); IAgVeGfxAttributesBasic att = decayingSat.Graphics.Attributes as IAgVeGfxAttributesBasic; att.Color = Color.Yellow; // Configure time period sgp4.EphemerisInterval.SetExplicitInterval(scenario.StartTime, scenario.StopTime); sgp4.Step = 60.0; // change the 3D model try { root.ExecuteCommand("VO */Satellite/" + root.CurrentScenario.Children[0].InstanceName + " Model File \"C:\\Program Files\\AGI\\STK 11\\STKData\\VO\\Models\\Misc\\explosion.mdl\""); } catch (Exception) { } //// get the initial state from the TLE initState.Epoch = scenario.StartTime; IAgDataPrvTimeVar dpPos = ((IAgStkObject)decayingSat).DataProviders.GetDataPrvTimeVarFromPath("Cartesian Position//ICRF"); IAgDrResult resultPos = dpPos.Exec(scenario.StartTime, scenario.StartTime, 60.0); IAgDrDataSetCollection datasetsPos = resultPos.DataSets; if (resultPos.DataSets.Count > 0) { initState.CartesianPosX = datasetsPos[1].GetValues().GetValue(0).ToString(); initState.CartesianPosY = datasetsPos[2].GetValues().GetValue(0).ToString(); initState.CartesianPosZ = datasetsPos[3].GetValues().GetValue(0).ToString(); } IAgDataPrvTimeVar dpVel = ((IAgStkObject)decayingSat).DataProviders.GetDataPrvTimeVarFromPath("Cartesian Velocity//ICRF"); IAgDrResult resultVel = dpVel.Exec(scenario.StartTime, scenario.StartTime, 60.0); IAgDrDataSetCollection datasetsVel = resultVel.DataSets; if (resultVel.DataSets.Count > 0) { initState.CartesianVelX = datasetsVel[1].GetValues().GetValue(0).ToString(); initState.CartesianVelY = datasetsVel[2].GetValues().GetValue(0).ToString(); initState.CartesianVelZ = datasetsVel[3].GetValues().GetValue(0).ToString(); } // configure the 2D graphics root.ExecuteCommand("Graphics * BackgroundImage Show Off"); root.ExecuteCommand("MapDetails * LatLon Lon On 15"); root.ExecuteCommand("MapDetails * Map RWDB2_Islands State On Color green"); root.ExecuteCommand("MapDetails * Map RWDB2_International_Borders State On "); root.ExecuteCommand("MapDetails * Map RWDB2_Lakes State On"); try { root.ExecuteCommand("VO * Globe Show On File \"C:\\Program Files\\AGI\\STK 11\\STKData\\VO\\Globes\\Earth\\WhiteOnBlue.glb\""); } catch (Exception) { } // configure the 3D graphics root.ExecuteCommand("VO * GlobeDetails MapDetail Show On Map RWDB2_Coastlines ShowDetail On"); root.ExecuteCommand("VO * GlobeDetails MapDetail Show On Map RWDB2_Islands ShowDetail On DetailColor green"); root.ExecuteCommand("VO * GlobeDetails MapDetail Show On Map RWDB2_Lakes ShowDetail On DetailColor lightblue"); return(tle); }