//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); }
public List <Waypoint> RasterSearchWaypointGenerator( string areaTargetPath, string heading, double speed, double altitude, double turnRadius, SwathWidthType swathType, double swathParameter) { List <Waypoint> waypoints = new List <Waypoint>(); IAgStkObject areaTarget = root.GetObjectFromPath(areaTargetPath); IAgAreaTarget areaTargetObj = (IAgAreaTarget)areaTarget; bool areaTargetElActive = areaTarget.AccessConstraints.IsConstraintActive(AgEAccessConstraints.eCstrElevationAngle); double restoreAngle = 0; if (!areaTargetElActive) { IAgAccessCnstrAngle elevationMin = areaTarget.AccessConstraints.AddConstraint(AgEAccessConstraints.eCstrElevationAngle) as IAgAccessCnstrAngle; root.UnitPreferences["Angle"].SetCurrentUnit("deg"); elevationMin.Angle = 90; } else { IAgAccessCnstrAngle elevationMin = areaTarget.AccessConstraints.GetActiveConstraint(AgEAccessConstraints.eCstrElevationAngle) as IAgAccessCnstrAngle; root.UnitPreferences["Angle"].SetCurrentUnit("deg"); restoreAngle = (double)elevationMin.Angle; elevationMin.Angle = 90; } double minLat = 90; double maxLat = -90; double minLon = 180; double maxLon = -180; root.UnitPreferences["Angle"].SetCurrentUnit("deg"); switch (areaTargetObj.AreaType) { case AgEAreaType.eEllipse: IAgDataProviderGroup boundingProvider = areaTarget.DataProviders["Bounding Rectangle"] as IAgDataProviderGroup; IAgDataPrvFixed dpElements = boundingProvider.Group["Corner Points"] as IAgDataPrvFixed; IAgDrResult atDataPrvResult = dpElements.Exec(); Array atLats = atDataPrvResult.DataSets.GetDataSetByName("Geodetic-Lat").GetValues(); Array atLons = atDataPrvResult.DataSets.GetDataSetByName("Geodetic-Lon").GetValues(); foreach (object item in atLats) { if ((double)item > maxLat) { maxLat = (double)item; } if ((double)item < minLat) { minLat = (double)item; } } foreach (object item in atLons) { if ((double)item > maxLon) { maxLon = (double)item; } if ((double)item < minLon) { minLon = (double)item; } } break; case AgEAreaType.ePattern: IAgAreaTypePatternCollection boundary = areaTargetObj.AreaTypeData as IAgAreaTypePatternCollection; foreach (IAgAreaTypePattern item in boundary) { if ((double)item.Lat > maxLat) { maxLat = (double)item.Lat; } if ((double)item.Lat < minLat) { minLat = (double)item.Lat; } if ((double)item.Lon > maxLon) { maxLon = (double)item.Lon; } if ((double)item.Lon < minLon) { minLon = (double)item.Lon; } } break; default: break; } double deltaLat = maxLat - minLat; double deltaLon = maxLon - minLon; IAgExecCmdResult cmdResult; switch (heading) { case "NorthSouth": cmdResult = root.ExecuteCommand("MeasureSurfaceDistance * " + minLat + " " + minLon + " " + minLat + " " + maxLon); break; case "EastWest": cmdResult = root.ExecuteCommand("MeasureSurfaceDistance * " + minLat + " " + minLon + " " + maxLat + " " + minLon); break; default: cmdResult = root.ExecuteCommand("MeasureSurfaceDistance * " + minLat + " " + minLon + " " + maxLat + " " + minLon); break; } double regionWidth = double.Parse(cmdResult[0]); int numPasses = DetermineNumPasses(swathType, swathParameter, altitude, regionWidth, null); if (numPasses < 1) { MessageBox.Show("No Passes. Try Adjusting Swath Width Parameters"); return(waypoints); } root.BeginUpdate(); string gvName = uniqueName("gridTester", AgESTKObjectType.eGroundVehicle); IAgGroundVehicle groundVehicle = root.CurrentScenario.Children.New(AgESTKObjectType.eGroundVehicle, gvName) as IAgGroundVehicle; groundVehicle.Graphics.SetAttributesType(AgEVeGfxAttributes.eAttributesBasic); IAgVeGfxAttributesBasic gvGfx = groundVehicle.Graphics.Attributes as IAgVeGfxAttributesBasic; gvGfx.Inherit = false; gvGfx.IsVisible = false; IAgVePropagatorGreatArc route = groundVehicle.Route as IAgVePropagatorGreatArc; //route.ArcGranularity = 51.333; route.SetAltitudeRefType(AgEVeAltitudeRef.eWayPtAltRefWGS84); route.Method = AgEVeWayPtCompMethod.eDetermineTimeAccFromVel; Waypoint waypoint1 = new Waypoint(); Waypoint waypoint2 = new Waypoint(); bool headEast = true; double loopMin; double loopMax; double gridAngleStep; switch (heading) { case "NorthSouth": loopMin = minLon; loopMax = maxLon; gridAngleStep = (maxLon - minLon) / numPasses; break; case "EastWest": loopMin = minLat; loopMax = maxLat; gridAngleStep = (maxLat - minLat) / numPasses; break; default: loopMin = minLat; loopMax = maxLat; gridAngleStep = .95 * (maxLat - minLat) / numPasses; break; } for (double eval = loopMin; eval <= loopMax; eval += gridAngleStep) { route.Waypoints.RemoveAll(); IAgVeWaypointsElement thisWaypoint1; IAgVeWaypointsElement thisWaypoint2; switch (heading) { case "NorthSouth": thisWaypoint1 = route.Waypoints.Add(); thisWaypoint1.Latitude = minLat - gridAngleStep; thisWaypoint1.Longitude = eval; thisWaypoint1.Altitude = 0; thisWaypoint2 = route.Waypoints.Add(); thisWaypoint2.Latitude = maxLat + gridAngleStep; thisWaypoint2.Longitude = eval; thisWaypoint2.Altitude = 0; break; case "EastWest": default: thisWaypoint1 = route.Waypoints.Add(); thisWaypoint1.Latitude = eval; thisWaypoint1.Longitude = minLon - gridAngleStep; thisWaypoint1.Altitude = 0; thisWaypoint2 = route.Waypoints.Add(); thisWaypoint2.Latitude = eval; thisWaypoint2.Longitude = maxLon + gridAngleStep; thisWaypoint2.Altitude = 0; break; } route.Propagate(); IAgStkAccess access = areaTarget.GetAccessToObject((IAgStkObject)groundVehicle); access.ComputeAccess(); IAgDataPrvInterval dpAccess = access.DataProviders["Access Data"] as IAgDataPrvInterval; IAgScenario scen = root.CurrentScenario as IAgScenario; IAgDrResult result = dpAccess.Exec(scen.StartTime, scen.StopTime); if (result.DataSets.Count > 0) { Array startTimes = result.DataSets.GetDataSetByName("Start Time").GetValues(); Array stopTimes = result.DataSets.GetDataSetByName("Stop Time").GetValues(); string startTime = (string)startTimes.GetValue(0); string stopTime = (string)stopTimes.GetValue(stopTimes.GetLength(0) - 1); IAgDataProviderGroup dpLLA = ((IAgStkObject)groundVehicle).DataProviders["LLA State"] as IAgDataProviderGroup; IAgDataPrvTimeVar dpElements = dpLLA.Group["Fixed"] as IAgDataPrvTimeVar; IAgDrResult DataPrvResult = dpElements.ExecSingle(startTime); Array Lats = DataPrvResult.DataSets.GetDataSetByName("Lat").GetValues(); Array Lons = DataPrvResult.DataSets.GetDataSetByName("Lon").GetValues(); waypoint1 = new Waypoint(); waypoint1.Latitude = (double)Lats.GetValue(0); waypoint1.Longitude = (double)Lons.GetValue(0); waypoint1.Altitude = altitude; waypoint1.SurfaceAltitude = 0; waypoint1.Speed = speed; waypoint1.TurnRadius = turnRadius; IAgDataProviderGroup dpLLA1 = ((IAgStkObject)groundVehicle).DataProviders["LLA State"] as IAgDataProviderGroup; IAgDataPrvTimeVar dpElements1 = dpLLA1.Group["Fixed"] as IAgDataPrvTimeVar; IAgDrResult DataPrvResult1 = dpElements1.ExecSingle(stopTime); Array Lats1 = DataPrvResult1.DataSets.GetDataSetByName("Lat").GetValues(); Array Lons1 = DataPrvResult1.DataSets.GetDataSetByName("Lon").GetValues(); waypoint2 = new Waypoint(); waypoint2.Latitude = (double)Lats1.GetValue(0); waypoint2.Longitude = (double)Lons1.GetValue(0); waypoint2.Altitude = altitude; waypoint2.SurfaceAltitude = 0; waypoint2.Speed = speed; waypoint2.TurnRadius = turnRadius; if (headEast) { waypoints.Add(waypoint1); waypoints.Add(waypoint2); } else { waypoints.Add(waypoint2); waypoints.Add(waypoint1); } headEast = !headEast; } access.RemoveAccess(); } ((IAgStkObject)groundVehicle).Unload(); if (!areaTargetElActive) { areaTarget.AccessConstraints.RemoveConstraint(AgEAccessConstraints.eCstrElevationAngle); } else { IAgAccessCnstrAngle elevationMin = areaTarget.AccessConstraints.GetActiveConstraint(AgEAccessConstraints.eCstrElevationAngle) as IAgAccessCnstrAngle; root.UnitPreferences["Angle"].SetCurrentUnit("deg"); elevationMin.Angle = restoreAngle; } root.EndUpdate(); root.UnitPreferences.ResetUnits(); return(waypoints); }
//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 void EstimateProbability() { StkAssistant.SetAnalysisIntervalFromTCA(this.Primary.EpochISOYMD); string primaryPath = Primary.BaselineObjectPath; string primaryType = Primary.BaselineObjectType; string primaryName = primaryPath.Substring(primaryPath.LastIndexOf("/") + 1); string secondaryPath = Secondary.BaselineObjectPath; string secondaryName = secondaryPath.Substring(secondaryPath.LastIndexOf("/") + 1); string catName = "CAT_" + primaryName; int counter = 0; while (StkAssistant.Root.CurrentScenario.Children.Contains(AgESTKObjectType.eAdvCat, catName)) { catName = "CAT_" + primaryName + "_" + (++counter).ToString(); } IAgStkObject cat = StkAssistant.Root.CurrentScenario.Children.New(AgESTKObjectType.eAdvCat, catName); string cmdResult; StkAssistant.TryConnect("Save / " + primaryPath, out cmdResult); StkAssistant.TryConnect("Save / " + secondaryPath, out cmdResult); StkAssistant.TryConnect("ACAT */AdvCAT/" + catName + " TimePeriod \"" + StkAssistant.Scenario.StartTime + "\" \"" + StkAssistant.Scenario.StopTime + "\"", out cmdResult); StkAssistant.TryConnect("ACAT */AdvCAT/" + catName + " Primary Add \"" + primaryName + ".sa\" Cov", out cmdResult); StkAssistant.TryConnect("ACAT */AdvCAT/" + catName + " Secondary Add \"" + secondaryName + ".sa\" Cov", out cmdResult); StkAssistant.TryConnect("ACAT */AdvCAT/" + catName + " Compute ShowProgress On", out cmdResult); StkAssistant.TryConnect("VO */AdvCAT/" + catName + " AdvCATAttributes ShowSecondary On ShowAllSecondary On", out cmdResult); //StkAssistant.TryConnect("ReportCreate */AdvCAT/" + catName + " Type Display Style \"Close Approach By Min Range\"", out cmdResult); StkAssistant.TryConnect("ACATEvents_RM */AdvCAT/" + catName, out cmdResult); string catTCA; if (!cmdResult.Equals("No events found.")) { catTCA = cmdResult.Split(',')[5]; IAgStkObject catObject = StkAssistant.Root.GetObjectFromPath("*/AdvCAT/" + catName); IAgDataPrvInterval catDP = cat.DataProviders["Events by Min Range"] as IAgDataPrvInterval; IAgDrResult catResult = catDP.Exec(StkAssistant.Scenario.StartTime, StkAssistant.Scenario.StopTime); double catMaxProb = (double)catResult.DataSets.GetDataSetByName("Max Collision Probability").GetValues().GetValue(0); double catSigmaDilution = (double)catResult.DataSets.GetDataSetByName("Sigma Dilution Threshold").GetValues().GetValue(0); if (Probability == 0) { Probability = catMaxProb; } if (SigmaDilution == 0) { SigmaDilution = Math.Round(catSigmaDilution, 3); } } cat.Unload(); }
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 PropagationResults PropagateAstrogatorSatellite(AgStkObjectRoot root, AgUiApplication app, InitialState state, TLE tle, Data satData, Uncertainty uncertainty, int runId, int nRuns, string propName) { PropagationResults propResults = new PropagationResults(); propResults.RunNumber = runId.ToString().PadLeft(3, '0'); IAgSatellite sat = root.CurrentScenario.Children.New(AgESTKObjectType.eSatellite, tle.GetSatNumber() + "Astrogator") as IAgSatellite; //Set the propagator to Astrogator sat.SetPropagatorType(AgEVePropagatorType.ePropagatorAstrogator); //get the Driver for the Propagator IAgVADriverMCS driver = sat.Propagator as IAgVADriverMCS; //Clear all segments from the MCS driver.MainSequence.RemoveAll(); //// Target Sequence //// IAgVAMCSTargetSequence ts = driver.MainSequence.Insert(AgEVASegmentType.eVASegmentTypeTargetSequence, "SetupState", "-") as IAgVAMCSTargetSequence; ts.Action = AgEVATargetSeqAction.eVATargetSeqActionRunActiveProfiles; // add the initial state segment in the target sequence IAgVAMCSInitialState initState = ts.Segments.Insert(AgEVASegmentType.eVASegmentTypeInitialState, "InitialState", "-") as IAgVAMCSInitialState; initState.OrbitEpoch = ((IAgScenario)root.CurrentScenario).StartTime; // define elements initState.SetElementType(AgEVAElementType.eVAElementTypeCartesian); IAgVAElementCartesian cart = initState.Element as IAgVAElementCartesian; cart.X = Convert.ToDouble(state.CartesianPosX); cart.Y = Convert.ToDouble(state.CartesianPosY); cart.Z = Convert.ToDouble(state.CartesianPosZ); cart.Vx = Convert.ToDouble(state.CartesianVelX); cart.Vy = Convert.ToDouble(state.CartesianVelY); cart.Vz = Convert.ToDouble(state.CartesianVelZ); // spacecraft parameters IAgVASpacecraftParameters spacecraftParameters = (IAgVASpacecraftParameters)initState.SpacecraftParameters; spacecraftParameters.DryMass = satData.Mass; spacecraftParameters.Cd = satData.Cd; spacecraftParameters.DragArea = satData.DragArea; spacecraftParameters.Cr = satData.Cr; spacecraftParameters.SolarRadiationPressureArea = satData.SunArea; spacecraftParameters.RadiationPressureArea = 1e-10; IAgVAFuelTank fuelTank = (IAgVAFuelTank)initState.FuelTank; fuelTank.FuelMass = 0; // enable the control parameter for the state variables initState.EnableControlParameter(AgEVAControlInitState.eVAControlInitStateCartesianX); initState.EnableControlParameter(AgEVAControlInitState.eVAControlInitStateCartesianY); initState.EnableControlParameter(AgEVAControlInitState.eVAControlInitStateCartesianZ); initState.EnableControlParameter(AgEVAControlInitState.eVAControlInitStateCartesianVx); initState.EnableControlParameter(AgEVAControlInitState.eVAControlInitStateCartesianVy); initState.EnableControlParameter(AgEVAControlInitState.eVAControlInitStateCartesianVz); // add the results ((IAgVAMCSSegment)initState).Results.Add("Relative Motion/InTrack"); IAgVAStateCalcRelMotion intrackRel = ((IAgVAMCSSegment)initState).Results[0] as IAgVAStateCalcRelMotion; intrackRel.ReferenceSelection = AgEVACalcObjectReference.eVACalcObjectReferenceSpecified; IAgLinkToObject link_1 = intrackRel.Reference as IAgLinkToObject; link_1.BindTo("Satellite/" + tle.GetSatNumber().ToString()); ((IAgVAMCSSegment)initState).Results.Add("Relative Motion/Radial"); IAgVAStateCalcRelMotion radialRel = ((IAgVAMCSSegment)initState).Results[1] as IAgVAStateCalcRelMotion; radialRel.ReferenceSelection = AgEVACalcObjectReference.eVACalcObjectReferenceSpecified; IAgLinkToObject link_2 = radialRel.Reference as IAgLinkToObject; link_2.BindTo("Satellite/" + tle.GetSatNumber().ToString()); ((IAgVAMCSSegment)initState).Results.Add("Relative Motion/CrossTrack"); IAgVAStateCalcRelMotion crosstrackRel = ((IAgVAMCSSegment)initState).Results[2] as IAgVAStateCalcRelMotion; crosstrackRel.ReferenceSelection = AgEVACalcObjectReference.eVACalcObjectReferenceSpecified; IAgLinkToObject link_3 = crosstrackRel.Reference as IAgLinkToObject; link_3.BindTo("Satellite/" + tle.GetSatNumber().ToString()); ((IAgVAMCSSegment)initState).Results.Add("Relative Motion/InTrackRate"); IAgVAStateCalcRelMotion intrackrateRel = ((IAgVAMCSSegment)initState).Results[3] as IAgVAStateCalcRelMotion; intrackrateRel.ReferenceSelection = AgEVACalcObjectReference.eVACalcObjectReferenceSpecified; IAgLinkToObject link_4 = intrackrateRel.Reference as IAgLinkToObject; link_4.BindTo("Satellite/" + tle.GetSatNumber().ToString()); ((IAgVAMCSSegment)initState).Results.Add("Relative Motion/RadialRate"); IAgVAStateCalcRelMotion radialrateRel = ((IAgVAMCSSegment)initState).Results[4] as IAgVAStateCalcRelMotion; radialrateRel.ReferenceSelection = AgEVACalcObjectReference.eVACalcObjectReferenceSpecified; IAgLinkToObject link_5 = radialrateRel.Reference as IAgLinkToObject; link_5.BindTo("Satellite/" + tle.GetSatNumber().ToString()); ((IAgVAMCSSegment)initState).Results.Add("Relative Motion/CrossTrackRate"); IAgVAStateCalcRelMotion crosstrackrateRel = ((IAgVAMCSSegment)initState).Results[5] as IAgVAStateCalcRelMotion; crosstrackrateRel.ReferenceSelection = AgEVACalcObjectReference.eVACalcObjectReferenceSpecified; IAgLinkToObject link_6 = crosstrackrateRel.Reference as IAgLinkToObject; link_6.BindTo("Satellite/" + tle.GetSatNumber().ToString()); /// differential corrector setup /// IAgVAProfileDifferentialCorrector dc = ts.Profiles["Differential Corrector"] as IAgVAProfileDifferentialCorrector; // control parameters IAgVADCControl xControlParam = dc.ControlParameters.GetControlByPaths("InitialState", "InitialState.Cartesian.X"); xControlParam.Enable = true; xControlParam.MaxStep = 1; xControlParam.Perturbation = 0.1; IAgVADCControl yControlParam = dc.ControlParameters.GetControlByPaths("InitialState", "InitialState.Cartesian.Y"); yControlParam.Enable = true; yControlParam.MaxStep = 1; yControlParam.Perturbation = 0.1; IAgVADCControl zControlParam = dc.ControlParameters.GetControlByPaths("InitialState", "InitialState.Cartesian.Z"); zControlParam.Enable = true; zControlParam.MaxStep = 1; zControlParam.Perturbation = 0.1; IAgVADCControl vxControlParam = dc.ControlParameters.GetControlByPaths("InitialState", "InitialState.Cartesian.Vx"); vxControlParam.Enable = true; vxControlParam.MaxStep = 0.001; vxControlParam.Perturbation = 1e-04; IAgVADCControl vyControlParam = dc.ControlParameters.GetControlByPaths("InitialState", "InitialState.Cartesian.Vy"); vyControlParam.Enable = true; vyControlParam.MaxStep = 0.001; vyControlParam.Perturbation = 1e-04; IAgVADCControl vzControlParam = dc.ControlParameters.GetControlByPaths("InitialState", "InitialState.Cartesian.Vz"); vzControlParam.Enable = true; vzControlParam.MaxStep = 0.001; vzControlParam.Perturbation = 1e-04; // results double[] deviations = uncertainty.GetRandomDeviation(); IAgVADCResult intrackResult = dc.Results.GetResultByPaths("InitialState", "InTrack"); intrackResult.Enable = true; intrackResult.DesiredValue = deviations[0]; intrackResult.Tolerance = 0.01; IAgVADCResult radialResult = dc.Results.GetResultByPaths("InitialState", "Radial"); radialResult.Enable = true; radialResult.DesiredValue = deviations[1]; radialResult.Tolerance = 0.01; IAgVADCResult crosstrackResult = dc.Results.GetResultByPaths("InitialState", "CrossTrack"); crosstrackResult.Enable = true; crosstrackResult.DesiredValue = deviations[2]; crosstrackResult.Tolerance = 0.01; IAgVADCResult intrackRateResult = dc.Results.GetResultByPaths("InitialState", "InTrackRate"); intrackRateResult.Enable = true; intrackRateResult.DesiredValue = deviations[3] / 1000; intrackRateResult.Tolerance = 0.001; IAgVADCResult radialRateResult = dc.Results.GetResultByPaths("InitialState", "RadialRate"); radialRateResult.Enable = true; radialRateResult.DesiredValue = deviations[4] / 1000; radialRateResult.Tolerance = 0.001; IAgVADCResult crosstrackRateResult = dc.Results.GetResultByPaths("InitialState", "CrossTrackRate"); crosstrackRateResult.Enable = true; crosstrackRateResult.DesiredValue = deviations[5] / 1000; crosstrackRateResult.Tolerance = 0.001; /// Propagator /// IAgVAMCSPropagate propagate = driver.MainSequence.Insert(AgEVASegmentType.eVASegmentTypePropagate, "ToGround", "-") as IAgVAMCSPropagate; ((IAgVAMCSSegment)propagate).Properties.Color = Color.Red; //propagate.PropagatorName = "CustomProp"; propagate.PropagatorName = propName; // add an Epoch stopping condition IAgVAStoppingConditionCollection propStoppingConditions = propagate.StoppingConditions as IAgVAStoppingConditionCollection; IAgVAStoppingConditionElement epochElement = propStoppingConditions.Add("Epoch"); IAgVAStoppingCondition epoch = (IAgVAStoppingCondition)epochElement.Properties; epoch.Trip = ((IAgScenario)root.CurrentScenario).StopTime; // add an Altitude stopping condition IAgVAStoppingConditionElement altitudeElement = propStoppingConditions.Add("Altitude"); IAgVAStoppingCondition altitude = (IAgVAStoppingCondition)altitudeElement.Properties; altitude.Trip = 0; // remove the original stopping condition propagate.StoppingConditions.Remove("Duration"); // run the MCS driver.RunMCS(); driver.ClearDWCGraphics(); // get the stop time IAgDataPrvInterval dp = ((IAgStkObject)sat).DataProviders.GetDataPrvIntervalFromPath("Astrogator MCS Ephemeris Segments") as IAgDataPrvInterval; IAgDrResult result = dp.Exec(((IAgScenario)root.CurrentScenario).StartTime, ((IAgScenario)root.CurrentScenario).StopTime); string satStopTime = result.DataSets[3].GetValues().GetValue(1).ToString(); if (satStopTime.Equals((Convert.ToString(((IAgScenario)root.CurrentScenario).StopTime)))) { // the satellite does not decay (it is propagated until the scenario stop time) propResults.IsDecayed = false; } else { propResults.IsDecayed = true; propResults.ImpactEpoch = satStopTime; // remove the millisecond part satStopTime = satStopTime.Split('.')[0]; //ask for LLA data at stop time IAgDataPrvTimeVar dpInfo = ((IAgStkObject)sat).DataProviders.GetDataPrvInfoFromPath("LLA State//Fixed") as IAgDataPrvTimeVar; IAgDrResult resInfo = dpInfo.ExecSingle(satStopTime); string lat = resInfo.DataSets[1].GetValues().GetValue(0).ToString(); string lon = resInfo.DataSets[2].GetValues().GetValue(0).ToString(); string alt = resInfo.DataSets[3].GetValues().GetValue(0).ToString(); propResults.ImpactLat = lat; propResults.ImpactLon = lon; propResults.ImpactAlt = alt; // create a target object IAgTarget target = root.CurrentScenario.Children.New(AgESTKObjectType.eTarget, "Target" + (runId).ToString().PadLeft(3, '0')) as IAgTarget; target.Graphics.Color = Color.Red; target.Graphics.LabelVisible = false; IAgPosition pos = target.Position; pos.AssignGeodetic(lat, lon, 0); // create and display the time event IAgCrdnProvider provider = root.CurrentScenario.Children["Target" + (runId).ToString().PadLeft(3, '0')].Vgt; IAgCrdnEventEpoch eventEpoch = provider.Events.Factory.CreateEventEpoch(runId.ToString().PadLeft(3, '0') + "_Impact", "Impact Epoch") as IAgCrdnEventEpoch; eventEpoch.Epoch = satStopTime; try { root.ExecuteCommand("Timeline * TimeComponent Add ContentView \"Scenario Availability\" \"Target/Target" + (runId).ToString().PadLeft(3, '0') + " " + runId.ToString().PadLeft(3, '0') + "_Impact Time Instant\""); } catch (Exception) { } root.ExecuteCommand("Timeline * Refresh"); // create a unique ephemeris file for each Astrogator run DateTime now = DateTime.Now; string satEphemerisPath = Directory.GetCurrentDirectory() + "\\Ephemeris\\Reentry_run_" + (runId).ToString().PadLeft(3, '0') + ".e"; root.ExecuteCommand("ExportDataFile */Satellite/" + tle.GetSatNumber() + "Astrogator Ephemeris \"" + satEphemerisPath + "\" Type STK CoordSys ICRF CentralBody Earth InterpBoundaries Include"); propResults.EphemerisFilePath = satEphemerisPath; // unload Astrogator satellite root.CurrentScenario.Children[tle.GetSatNumber() + "Astrogator"].Unload(); if (runId == nRuns) { // remove the TLE sat // root.CurrentScenario.Children[tle.GetSatNumber()].Unload(); } } try { AGI.Ui.Core.IAgUiWindowsCollection windows = app.Windows; foreach (dynamic window in app.Windows) { string windowCaption = (string)window.Caption; if (windowCaption.Contains("Setup")) { window.Close(); } } } catch (Exception ex) { } return(propResults); }