//pulls data providers for the aircraft in ICRF frame public static List <Array> GetAttitudeData(IAgStkObject obj, double startTime, double timeStep) { List <Array> attitudeData = new List <Array>(); IAgScenario scenario = CommonData.StkRoot.CurrentScenario as IAgScenario; IAgDrDataSetCollection datasets = null; if (CommonData.objectClass == "Aircraft") { IAgDataProviderGroup attitudeDP1 = obj.DataProviders["Body Axes Orientation:YPR 321"] as IAgDataProviderGroup; IAgDataPrvTimeVar attitudeDP2 = attitudeDP1.Group["ICRF"] as IAgDataPrvTimeVar; IAgDrResult result = attitudeDP2.Exec(startTime, scenario.StopTime, timeStep); datasets = result.DataSets; } else if (CommonData.objectClass == "Satellite") { IAgDataProviderGroup attitudeDP1 = obj.DataProviders["Attitude YPR"] as IAgDataProviderGroup; IAgDataPrvTimeVar attitudeDP2 = attitudeDP1.Group["Seq YPR"] as IAgDataPrvTimeVar; IAgDrResult result = attitudeDP2.Exec(startTime, scenario.StopTime, timeStep); datasets = result.DataSets; } for (int i = 0; i < datasets.Count; i++) { attitudeData.Add(datasets[i].GetValues()); } return(attitudeData); }
//Main Function private void Generate_Click(object sender, EventArgs e) { int check = FieldCheck(); if (check == 0) { RemoveProximityGeometry(); try { CommonData.StkRoot.UnitPreferences.SetCurrentUnit("Distance", "km"); CommonData.RunList.Clear(); CommonData.TargetName = TargetSat.Text; CommonData.ActorName = ActorSat.Text; //Set user bounds for safety double userMinRange = Double.Parse(SphericalMag.Text) / 1000; double userMinR = Double.Parse(RMag.Text) / 1000; double userMinI = Double.Parse(IMag.Text) / 1000; double userMinC = Double.Parse(CMag.Text) / 1000; IAgScenario scenario = CommonData.StkRoot.CurrentScenario as IAgScenario; IAgStkObject satObj = CommonData.StkRoot.GetObjectFromPath("Satellite/" + ActorSat.Text); IAgSatellite sat = satObj as IAgSatellite; //Get all maneuver end times for actor satellite IAgDataProviderGroup maneuverDpGroup = satObj.DataProviders["Astrogator Maneuver Ephemeris Block Final"] as IAgDataProviderGroup; IAgDataPrvTimeVar maneuverDp = maneuverDpGroup.Group["Cartesian Elems"] as IAgDataPrvTimeVar; IAgDrResult result = maneuverDp.Exec(scenario.StartTime, scenario.StopTime, 60); IAgDrDataSetCollection maneuverData = result.DataSets; //If there is maneuvers, run iterations for each maneuver. If no maneuvers then just pull closest RIC data for entire trajectory if (maneuverData.Count != 0) { CommonData.HasManeuvers = true; //Get maneuver numbers IAgDataPrvInterval summaryDp = satObj.DataProviders["Maneuver Summary"] as IAgDataPrvInterval; IAgDrResult summaryResult = summaryDp.Exec(scenario.StartTime, scenario.StopTime); Array maneuverNumbers = summaryResult.DataSets.GetDataSetByName("Maneuver Number").GetValues(); int maxManeuverNum = maneuverNumbers.Length; //Get handles to cartesian position and velocity to seed passive safety runs IAgDataProviderGroup cartPos = satObj.DataProviders["Cartesian Position"] as IAgDataProviderGroup; IAgDataPrvTimeVar cartPosDP = cartPos.Group["ICRF"] as IAgDataPrvTimeVar; IAgDataProviderGroup cartVel = satObj.DataProviders["Cartesian Velocity"] as IAgDataProviderGroup; IAgDataPrvTimeVar cartVelDP = cartVel.Group["ICRF"] as IAgDataPrvTimeVar; //Create passive safety satellite. Set to Astrogator and pull handles to initial state and propagate segments IAgStkObject passiveSatObj = CreatorFunctions.GetCreateSatellite("PassiveCheck"); IAgSatellite passiveSat = passiveSatObj as IAgSatellite; passiveSat.SetPropagatorType(AgEVePropagatorType.ePropagatorAstrogator); IAgVADriverMCS passiveDriver = passiveSat.Propagator as IAgVADriverMCS; IAgVAMCSInitialState intState = passiveDriver.MainSequence[0] as IAgVAMCSInitialState; IAgVAMCSPropagate prop = passiveDriver.MainSequence[1] as IAgVAMCSPropagate; IAgVAStoppingConditionElement sc1 = prop.StoppingConditions[0]; IAgVAStoppingCondition sc = sc1.Properties as IAgVAStoppingCondition; sc.Trip = PropTime.Text; AgVAElementCartesian element = intState.Element as AgVAElementCartesian; Array epoch; Array vx; Array vy; Array vz; Array x; Array y; Array z; String epochCur; DateTime dateCur; //Assign cartesian elements to PassiveCheck satellite from actor maneuver maneuver data. Run each iteration to see if resulting trajectory violates constraints for (int i = 0; i < maxManeuverNum; i++) { //Get maneuver time and offset in time by 0.25 sec to account for boundrary conditions around impulsive maneuvers epoch = maneuverData[0 + (i * 7)].GetValues(); epochCur = epoch.GetValue(0).ToString(); dateCur = DateTime.Parse(epochCur); dateCur = dateCur.AddMilliseconds(250); //dateCur = DateTime.ParseExact(epochCur, "dd MMM yyyy HH:mm:ss.fff", CultureInfo.InvariantCulture); epochCur = dateCur.ToString("dd MMM yyyy HH:mm:ss.fff"); //Get cartesian state vector for given time result = cartPosDP.ExecSingle(epochCur); x = result.DataSets.GetDataSetByName("x").GetValues(); y = result.DataSets.GetDataSetByName("y").GetValues(); z = result.DataSets.GetDataSetByName("z").GetValues(); result = cartVelDP.ExecSingle(epochCur); vx = result.DataSets.GetDataSetByName("x").GetValues(); vy = result.DataSets.GetDataSetByName("y").GetValues(); vz = result.DataSets.GetDataSetByName("z").GetValues(); //Create passive run output to be used in visualization PassiveRun run = new PassiveRun(); run.UserMinRange = Double.Parse(SphericalMag.Text) / 1000; run.UserMinR = Double.Parse(RMag.Text) / 1000; run.UserMinI = Double.Parse(IMag.Text) / 1000; run.UserMinC = Double.Parse(CMag.Text) / 1000; intState.OrbitEpoch = epochCur; element.Vx = Double.Parse(vx.GetValue(0).ToString()); element.Vy = Double.Parse(vy.GetValue(0).ToString()); element.Vz = Double.Parse(vz.GetValue(0).ToString()); element.X = Double.Parse(x.GetValue(0).ToString()); element.Y = Double.Parse(y.GetValue(0).ToString()); element.Z = Double.Parse(z.GetValue(0).ToString()); passiveDriver.RunMCS(); run.Vx = Double.Parse(vx.GetValue(0).ToString()); run.Vy = Double.Parse(vy.GetValue(0).ToString()); run.Vz = Double.Parse(vz.GetValue(0).ToString()); run.X = Double.Parse(x.GetValue(0).ToString()); run.Y = Double.Parse(y.GetValue(0).ToString()); run.Z = Double.Parse(z.GetValue(0).ToString()); run.PropTime = Double.Parse(PropTime.Text); //Pull closest point to target for each iteration and save to passive run output IAgDataProvider psatDp = passiveSatObj.DataProviders["RIC Coordinates"] as IAgDataProvider; psatDp.PreData = "Satellite/" + TargetSat.Text; IAgDataPrvTimeVar psatDpTimeVar = psatDp as IAgDataPrvTimeVar; IAgDrResult psatDp2 = psatDpTimeVar.Exec(scenario.StartTime, scenario.StopTime, Double.Parse(TimeStep.Text)); run.Range = psatDp2.DataSets.GetDataSetByName("Range").GetValues(); run.Intrack = psatDp2.DataSets.GetDataSetByName("In-Track").GetValues(); run.Crosstrack = psatDp2.DataSets.GetDataSetByName("Cross-Track").GetValues(); run.Radial = psatDp2.DataSets.GetDataSetByName("Radial").GetValues(); run.MinRange = MathFunctions.ArrayMin(run.Range); run.MinIntrack = MathFunctions.ArrayMinAbs(run.Intrack); run.MinCrosstrack = MathFunctions.ArrayMinAbs(run.Crosstrack); run.MinRadial = MathFunctions.ArrayMinAbs(run.Radial); //run.ManeuverTime = epoch.GetValue(0).ToString(); run.ManeuverTime = epochCur; //spherical if (radioButton1.Checked) { run.IsSpherical = true; if (run.MinRange < userMinRange) { run.Safe = false; } else { run.Safe = true; } } //independent axis else { run.IsSpherical = false; if (Math.Abs(run.MinIntrack) < userMinI && Math.Abs(run.MinRadial) < userMinR && Math.Abs(run.MinCrosstrack) < userMinC) { bool tripped = false; for (int j = 0; j < run.Range.Length; j++) { if (Math.Abs(Double.Parse(run.Intrack.GetValue(j).ToString())) < userMinI && Math.Abs(Double.Parse(run.Radial.GetValue(j).ToString())) < userMinR && Math.Abs(Double.Parse(run.Crosstrack.GetValue(j).ToString())) < userMinC) { run.Safe = false; tripped = true; break; } } if (!tripped) { run.Safe = true; } } else { run.Safe = true; } } CommonData.RunList.Add(run); } } else { CommonData.HasManeuvers = false; PassiveRun run = new PassiveRun(); IAgDataProvider satDp = satObj.DataProviders["RIC Coordinates"] as IAgDataProvider; satDp.PreData = "Satellite/" + TargetSat.Text; IAgDataPrvTimeVar satDpTimeVar = satDp as IAgDataPrvTimeVar; IAgDrResult satDp2 = satDpTimeVar.Exec(scenario.StartTime, scenario.StopTime, Double.Parse(TimeStep.Text)); run.Range = satDp2.DataSets.GetDataSetByName("Range").GetValues(); run.Intrack = satDp2.DataSets.GetDataSetByName("In-Track").GetValues(); run.Crosstrack = satDp2.DataSets.GetDataSetByName("Cross-Track").GetValues(); run.Radial = satDp2.DataSets.GetDataSetByName("Radial").GetValues(); run.MinRange = MathFunctions.ArrayMin(run.Range); run.MinIntrack = MathFunctions.ArrayMinAbs(run.Intrack); run.MinCrosstrack = MathFunctions.ArrayMinAbs(run.Crosstrack); run.MinRadial = MathFunctions.ArrayMinAbs(run.Radial); run.ManeuverTime = "N/A"; //spherical if (radioButton1.Checked) { run.IsSpherical = true; if (run.MinRange < userMinRange) { run.Safe = false; } else { run.Safe = true; } } //independent axis else { run.IsSpherical = false; if (Math.Abs(run.MinIntrack) < userMinI && Math.Abs(run.MinRadial) < userMinR && Math.Abs(run.MinCrosstrack) < userMinC) { bool tripped = false; for (int j = 0; j < run.Range.Length; j++) { if (Math.Abs(Double.Parse(run.Intrack.GetValue(j).ToString())) < userMinI && Math.Abs(Double.Parse(run.Radial.GetValue(j).ToString())) < userMinR && Math.Abs(Double.Parse(run.Crosstrack.GetValue(j).ToString())) < userMinC) { run.Safe = false; tripped = true; break; } } if (!tripped) { run.Safe = true; } } else { run.Safe = true; } } CommonData.RunList.Add(run); } CommonData.BeenRun = true; } catch (Exception) { MessageBox.Show("Passive Safety Check Failed"); } } }
public Array GetDataProviders(string stkObjectPath, string DataProviderName, string GroupName, string ElementName) { string startTime = scen.StartTime.ToString(); string stopTime = scen.StopTime.ToString(); double stepSize = 60; IAgStkObject stkObject = root.GetObjectFromPath(stkObjectPath); IAgDataProviderInfo dpInfo = stkObject.DataProviders[DataProviderName]; IAgDataProvider dataProvider = stkObject.DataProviders[DataProviderName] as IAgDataProvider; if (dpInfo.IsGroup()) { IAgDataProviderGroup dpGroup = dpInfo as IAgDataProviderGroup; IAgDataProviders dpAvailable = dpGroup.Group; for (int i = 0; i < dpAvailable.Count; ++i) { if (dpAvailable[i].Name == GroupName) { dataProvider = dpAvailable[i] as IAgDataProvider; break; } } } IAgDrResult dpResult = null; switch (dpInfo.Type) { case AgEDataProviderType.eDrFixed: //Fixed data doesnt change over time IAgDataPrvFixed dpFixed = dataProvider as IAgDataPrvFixed; dpResult = dpFixed.Exec(); break; case AgEDataProviderType.eDrIntvl: //Interval data is given as a list of intervals with start, stop and duration IAgDataPrvInterval dpInterval = dataProvider as IAgDataPrvInterval; //Must provide analysis start and stop time dpResult = dpInterval.Exec(startTime, stopTime); break; case AgEDataProviderType.eDrTimeVar: //Time varyign data is given as an array of time based values IAgDataPrvTimeVar dpTimeVarying = dataProvider as IAgDataPrvTimeVar; //Must provide analysis start and stop time plus an evaluation step size dpResult = dpTimeVarying.Exec(startTime, stopTime, stepSize); break; default: break; } Array dataValues = null; IAgDrDataSetCollection datasets = dpResult.DataSets; if (datasets.Count > 0) { IAgDrDataSet thisDataset = datasets.GetDataSetByName(ElementName); dataValues = thisDataset.GetValues(); } return(dataValues); }
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); }