public List <string> GetAvailableDataProviderElements( string stkObjectPath, string DataProviderName, string GroupName) { 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; } } } List <string> dataElements = new List <string>(); for (int i = 0; i < dataProvider.Elements.Count; ++i) { dataElements.Add(dataProvider.Elements[i].Name); } return(dataElements); }
public static double[] GetRICDifferenceAtTCA(string sat1Path, string sat2Path, string epochISOYMD) { IAgStkObject primary, secondary; try { primary = StkAssistant.Root.GetObjectFromPath(sat1Path); secondary = StkAssistant.Root.GetObjectFromPath(sat2Path); } catch { return(null); } IAgDataProviderInfo dpInfo = primary.DataProviders["RIC Coordinates"]; IAgDataProvider dataProvider = primary.DataProviders["RIC Coordinates"] as IAgDataProvider; dataProvider.PreData = secondary.Path.Replace(StkAssistant.Root.CurrentScenario.Path, ""); IAgDataPrvTimeVar dpTimeVarying = dataProvider as IAgDataPrvTimeVar; Array elements = new object[] { "Radial", "In-Track", "Cross-Track" }; IAgDrResult dpResult = dpTimeVarying.ExecSingleElements(epochISOYMD, elements); double[] ric = new double[3]; ric[0] = (double)dpResult.DataSets[0].GetValues().GetValue(0); ric[1] = (double)dpResult.DataSets[1].GetValues().GetValue(0); ric[2] = (double)dpResult.DataSets[2].GetValues().GetValue(0); return(ric); }
private static IAgDataPrvTimeVar GetClassicalElementsDP(string satPath) { IAgStkObject primary = Root.GetObjectFromPath(satPath); IAgDataProviderGroup classical = primary.DataProviders["Classical Elements"] as IAgDataProviderGroup; IAgDataProvider dataProvider = classical.Group["ICRF"] as IAgDataProvider; //Time varyign data is given as an array of time based values IAgDataPrvTimeVar dpTimeVarying = dataProvider as IAgDataPrvTimeVar; return(dpTimeVarying); }
//public STKDataProvider(IAgStkObject object0,string Name, bool needPreData) //{ // m_selectedObject = object0; // m_providerGroup = m_selectedObject.DataProviders["Cartesian Velocity"] as IAgDataProviderGroup; // IAgDataProvider CartVel_provider= (m_providerGroup.Group["J2000"] as IAgDataProvider); // ///Cast Appropiate Data Pro // IAgDataPrvTimeVar Velocity = CartVel_provider as IAgDataPrvTimeVar; // Array elem = new object[] { "x" }; // IAgDrResult Speed = Velocity.ExecElements("19 May 2019 22:00:00.000", "19 May 2019 22:10:00.000", 60, ref elem ); // m_dataSe = Speed.DataSets[0].GetValues(); // ///update_Dataset(26667, "Name", speed); // ///Console.WriteLine(CartVel_providers) //} public System.Array acquireDataset(string startTime, string stopTime, double timeStep) { IAgDataProvider provider = null; if (m_parent != m_superParent) { m_providerGroup = m_StkObj.DataProviders[m_superParent] as IAgDataProviderGroup; provider = (m_providerGroup.Group[m_parent] as IAgDataProvider); //m_parent } else if (m_parent == m_superParent) { provider = m_StkObj.DataProviders[m_parent] as IAgDataProvider; } ///Cast Appropiate Data Pro try { IAgDataPrvTimeVar Velocity = provider as IAgDataPrvTimeVar; Array elem = new object[] { m_DP2 }; IAgDrResult result = Velocity.ExecElements(startTime, stopTime, timeStep, ref elem); m_dataArray = result.DataSets[0].GetValues(); } catch { IAgDataPrvInterval Velocity = provider as IAgDataPrvInterval; if (Velocity != null) { Array elem = new object[] { m_DP2 }; IAgDrResult result = Velocity.ExecElements(startTime, stopTime, ref elem); m_dataArray = result.DataSets[0].GetValues(); } else { m_Error = true; } } return(m_dataArray); }
//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 MergeEphemeris(IAgStkObject[] objectArray, string outputFilePath) { Dictionary <double, IAgStkObject> ephems = new Dictionary <double, IAgStkObject>(); Root.UnitPreferences.SetCurrentUnit("DateFormat", "EpSec"); foreach (IAgStkObject stkObject in objectArray) { if (stkObject is IAgSatellite && (stkObject as IAgSatellite).PropagatorType == AgEVePropagatorType.ePropagatorStkExternal) { IAgVePropagatorStkExternal exProp = (stkObject as IAgSatellite).Propagator as IAgVePropagatorStkExternal; if (!ephems.ContainsKey(double.Parse(exProp.StartTime.ToString()))) { ephems.Add(double.Parse(exProp.StartTime.ToString()), stkObject); } } } List <KeyValuePair <double, IAgStkObject> > testing = ephems.OrderBy(i => i.Key).ToList(); List <string> ephemLines = new List <string>(); for (int i = 0; i < testing.Count(); i++) { IAgDataProviderGroup dp = (IAgDataProviderGroup)testing[i].Value.DataProviders["Cartesian Position"]; IAgDataProvider dpICRF = (IAgDataProvider)dp.Group["ICRF"]; IAgDataPrvTimeVar dpTimeVarying = (IAgDataPrvTimeVar)dpICRF; string stopTime = i < (testing.Count() - 1) ? testing[i + 1].Key.ToString() : ((testing[i].Value as IAgSatellite).Propagator as IAgVePropagatorStkExternal).StopTime.ToString(); string startTime = testing[i].Key.ToString(); IAgDrResult results = dpTimeVarying.ExecNativeTimes(startTime, stopTime); Array times = results.DataSets.GetDataSetByName("Time").GetValues(); Array xs = results.DataSets.GetDataSetByName("x").GetValues(); Array ys = results.DataSets.GetDataSetByName("y").GetValues(); Array zs = results.DataSets.GetDataSetByName("z").GetValues(); dp = (IAgDataProviderGroup)testing[i].Value.DataProviders["Cartesian Velocity"]; dpICRF = (IAgDataProvider)dp.Group["ICRF"]; dpTimeVarying = (IAgDataPrvTimeVar)dpICRF; results = dpTimeVarying.ExecNativeTimes(startTime, stopTime); Array xds = results.DataSets.GetDataSetByName("x").GetValues(); Array yds = results.DataSets.GetDataSetByName("y").GetValues(); Array zds = results.DataSets.GetDataSetByName("z").GetValues(); for (int j = 0; j < (times.Length - 2); j++) { ephemLines.Add(string.Format("{0} {1} {2} {3} {4} {5} {6}", times.GetValue(j), xs.GetValue(j), ys.GetValue(j), zs.GetValue(j), xds.GetValue(j), yds.GetValue(j), zds.GetValue(j))); } //MessageBox.Show("stored values"); } int count = ephemLines.Count; ephemLines.Insert(0, "stk.v.10.0"); ephemLines.Insert(1, "BEGIN Ephemeris"); ephemLines.Insert(2, "NumberOfEphemerisPoints " + count); ephemLines.Insert(3, "InterpolationMethod Lagrange"); ephemLines.Insert(4, "InterpolationOrder 5"); ephemLines.Insert(5, "ScenarioEpoch " + Root.ConversionUtility.ConvertDate(Root.UnitPreferences.GetCurrentUnitAbbrv("DateFormat"), "UTCG", (Root.CurrentScenario as IAgScenario).Epoch.ToString())); ephemLines.Insert(6, "CentralBody Earth"); ephemLines.Insert(7, "CoordinateSystem ICRF"); ephemLines.Insert(8, "DistanceUnit Meters"); ephemLines.Insert(9, "EphemerisTimePosVel"); ephemLines.Add("END Ephemeris"); File.WriteAllLines(outputFilePath, ephemLines.ToArray()); }
public static RICResults GetRICDifferenceOverTime(string sat1Path, string sat2Path, string epochISOYMD) { IAgDate tca = StkAssistant.Root.ConversionUtility.NewDate("ISO-YMD", epochISOYMD); IAgStkObject primary, secondary; try { primary = StkAssistant.Root.GetObjectFromPath(sat1Path); secondary = StkAssistant.Root.GetObjectFromPath(sat2Path); } catch { return(new RICResults()); } double period1 = StkAssistant.GetSatellitePeriod(primary.Path, epochISOYMD); double period2 = StkAssistant.GetSatellitePeriod(secondary.Path, epochISOYMD); double period = (period1 + period2) / 2; IAgDataProviderInfo dpInfo = primary.DataProviders["RIC Coordinates"]; IAgDataProvider dataProvider = primary.DataProviders["RIC Coordinates"] as IAgDataProvider; dataProvider.PreData = secondary.Path.Replace(StkAssistant.Root.CurrentScenario.Path, ""); IAgDataPrvTimeVar dpTimeVarying = dataProvider as IAgDataPrvTimeVar; Array elements = new object[] { "Time", "Radial", "In-Track", "Cross-Track", "Range" }; IAgDrResult dpResult = dpTimeVarying.ExecElements( tca.Subtract("sec", .5 * period).Format("ISO-YMD"), tca.Add("sec", .5 * period).Format("ISO-YMD"), 10, elements); RICResults ricResults = new RICResults(); foreach (IAgDrDataSet dataset in dpResult.DataSets) { if (dataset.ElementName.Equals("Time")) { List <string> times = new List <string>(); foreach (object item in dataset.GetValues()) { times.Add(item.ToString()); } ricResults.Times = times.ToArray(); } else { List <double> values = new List <double>(); foreach (object item in dataset.GetValues()) { values.Add((double)item); } switch (dataset.ElementName) { case "Radial": ricResults.R = values.ToArray(); break; case "In-Track": ricResults.I = values.ToArray(); break; case "Cross-Track": ricResults.C = values.ToArray(); break; case "Range": ricResults.Range = values.ToArray(); break; default: break; } } } return(ricResults); }