public void set_ManeuverParams(object MnvrObj, string name, double value) { IAgVAMCSManeuver thisMnvr = MnvrObj as IAgVAMCSManeuver; if (thisMnvr.ManeuverType == AgEVAManeuverType.eVAManeuverTypeImpulsive) { IAgVAManeuverImpulsive ImpMnvr = thisMnvr.Maneuver as IAgVAManeuverImpulsive; #region Type: Thrust Vector if (ImpMnvr.AttitudeControlType == AgEVAAttitudeControl.eVAAttitudeControlThrustVector) { IAgVAAttitudeControlImpulsiveThrustVector thisImpMnvr = ImpMnvr.AttitudeControl as IAgVAAttitudeControlImpulsiveThrustVector; IAgPosition DV_vectorObj = (thisImpMnvr.DeltaVVector as IAgPosition); Cartesian_Object DV_Vector = new Cartesian_Object(); DV_vectorObj.QueryCartesian(out DV_Vector.X, out DV_Vector.Y, out DV_Vector.Z); if (name == "Del-V (X: Velocity)") { DV_Vector.X = value; } else if (name == "Del-V (Y: Normal)") { DV_Vector.Y = value; } else if (name == "Del-V (Z: Co-Normal)") { DV_Vector.Z = value; } } #endregion #region Type: Along Velocity Vector else if (ImpMnvr.AttitudeControlType == AgEVAAttitudeControl.eVAAttitudeControlVelocityVector) { IAgVAAttitudeControlImpulsiveVelocityVector thisImpMnvr = ImpMnvr.AttitudeControl as IAgVAAttitudeControlImpulsiveVelocityVector; if (name == "Del-V Magnitude") { thisImpMnvr.DeltaVMagnitude = value; } } #endregion #region Type: Anti-Velocity Vector else if (ImpMnvr.AttitudeControlType == AgEVAAttitudeControl.eVAAttitudeControlAntiVelocityVector) { IAgVAAttitudeControlImpulsiveVelocityVector thisImpMnvr = ImpMnvr.AttitudeControl as IAgVAAttitudeControlImpulsiveVelocityVector; if (name == "Del-V Magnitude") { thisImpMnvr.DeltaVMagnitude = value; } } #endregion #region Type: Attitude else if (ImpMnvr.AttitudeControlType == AgEVAAttitudeControl.eVAAttitudeControlAttitude) { IAgVAAttitudeControlImpulsiveAttitude thisImpMnvr = ImpMnvr.AttitudeControl as IAgVAAttitudeControlImpulsiveAttitude; if (name == "Del-V Magnitude") { thisImpMnvr.DeltaVMagnitude = value; } EulerAng_Object MnvrEulAngs = new EulerAng_Object(); IAgOrientationEulerAngles angles = (IAgOrientationEulerAngles)thisImpMnvr.Orientation.ConvertTo(AgEOrientationType.eEulerAngles); MnvrEulAngs.Sequence = angles.Sequence; MnvrEulAngs.Phi_1 = double.Parse(angles.A.ToString(), System.Globalization.CultureInfo.InvariantCulture); MnvrEulAngs.Theta_2 = double.Parse(angles.A.ToString(), System.Globalization.CultureInfo.InvariantCulture); MnvrEulAngs.Psi_3 = double.Parse(angles.A.ToString(), System.Globalization.CultureInfo.InvariantCulture); //DeltaVParams.Add("Euler Angle Sequence", double.Parse(MnvrEulAngs.Sequence.ToString(), System.Globalization.CultureInfo.InvariantCulture)); l_unit.Add(units.u_Null); if (name == "Euler Angle 1 (Phi)") { MnvrEulAngs.Phi_1 = value; } else if (name == "Euler Angle 2 (Theta)") { MnvrEulAngs.Theta_2 = value; } else if (name == "Euler Angle 3 (Psi)") { MnvrEulAngs.Psi_3 = value; } } ; #endregion } }
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); }
//Impulsive public void get_ManeuverParams(IAgVAMCSSegment MnvrSegment, int depth, List <string> localParent) { depth++; IAgVAMCSManeuver thisMnvr = MnvrSegment as IAgVAMCSManeuver; #region List Header l_SegObj.Add(null); l_unit.Add(""); l_depth.Add(depth); l_isQuantity.Add(false); l_implemClass.Add(implem_Classes.NULL); #endregion if (thisMnvr.ManeuverType == AgEVAManeuverType.eVAManeuverTypeImpulsive) { IAgVAManeuverImpulsive ImpMnvr = thisMnvr.Maneuver as IAgVAManeuverImpulsive; #region Type: Thrust Vector if (ImpMnvr.AttitudeControlType == AgEVAAttitudeControl.eVAAttitudeControlThrustVector) { IAgVAAttitudeControlImpulsiveThrustVector thisImpMnvr = ImpMnvr.AttitudeControl as IAgVAAttitudeControlImpulsiveThrustVector; l_Names.Add("Impulsive: Thrust vector"); //Header name l_Values.Add(double.PositiveInfinity); l_types.Add(thisImpMnvr.ThrustAxesName); l_localParents.Add(localParent); IAgPosition DV_vectorObj = (thisImpMnvr.DeltaVVector as IAgPosition); Cartesian_Object DV_Vector = new Cartesian_Object(); DV_vectorObj.QueryCartesian(out DV_Vector.X, out DV_Vector.Y, out DV_Vector.Z); DeltaVParams.Add("Del-V (X: Velocity)", DV_Vector.X); l_unit.Add(units.u_Velocity); DeltaVParams.Add("Del-V (Y: Normal)", DV_Vector.Y); l_unit.Add(units.u_Velocity); DeltaVParams.Add("Del-V (Z: Co-Normal)", DV_Vector.Z); l_unit.Add(units.u_Velocity); update_Lists(DeltaVParams, depth, thisMnvr, implem_Classes.Astg_Mnvr_DV, localParent); } #endregion #region Type: Along Velocity Vector else if (ImpMnvr.AttitudeControlType == AgEVAAttitudeControl.eVAAttitudeControlVelocityVector) { IAgVAAttitudeControlImpulsiveVelocityVector thisImpMnvr = ImpMnvr.AttitudeControl as IAgVAAttitudeControlImpulsiveVelocityVector; l_Names.Add("Impulsive: Along Velocity Vector"); //Header name l_Values.Add(double.PositiveInfinity); l_types.Add(" "); l_localParents.Add(localParent); DeltaVParams.Add("Del-V Magnitude", thisImpMnvr.DeltaVMagnitude); l_unit.Add(units.u_Velocity); update_Lists(DeltaVParams, depth, thisMnvr, implem_Classes.Astg_Mnvr_DV, localParent); } #endregion #region Type: Anti-Velocity Vector else if (ImpMnvr.AttitudeControlType == AgEVAAttitudeControl.eVAAttitudeControlAntiVelocityVector) { IAgVAAttitudeControlImpulsiveVelocityVector thisImpMnvr = ImpMnvr.AttitudeControl as IAgVAAttitudeControlImpulsiveVelocityVector; l_Names.Add("Impulsive: Anti-Velocity Vector"); //Header name l_Values.Add(double.PositiveInfinity); l_types.Add(" "); l_localParents.Add(localParent); DeltaVParams.Add("Del-V Magnitude", thisImpMnvr.DeltaVMagnitude); l_unit.Add(units.u_Velocity); update_Lists(DeltaVParams, depth, thisMnvr, implem_Classes.Astg_Mnvr_DV, localParent); } #endregion #region Type: Attitude else if (ImpMnvr.AttitudeControlType == AgEVAAttitudeControl.eVAAttitudeControlAttitude) { IAgVAAttitudeControlImpulsiveAttitude thisImpMnvr = ImpMnvr.AttitudeControl as IAgVAAttitudeControlImpulsiveAttitude; l_Names.Add("Impulsive: Attitude"); //Header name l_Values.Add(double.PositiveInfinity); l_types.Add(thisImpMnvr.RefAxesName); l_localParents.Add(localParent); DeltaVParams.Add("Del-V Magnitude", thisImpMnvr.DeltaVMagnitude); l_unit.Add(units.u_Velocity); EulerAng_Object MnvrEulAngs = new EulerAng_Object(); IAgOrientationEulerAngles angles = (IAgOrientationEulerAngles)thisImpMnvr.Orientation.ConvertTo(AgEOrientationType.eEulerAngles); MnvrEulAngs.Sequence = angles.Sequence; MnvrEulAngs.Phi_1 = double.Parse(angles.A.ToString(), System.Globalization.CultureInfo.InvariantCulture); MnvrEulAngs.Theta_2 = double.Parse(angles.A.ToString(), System.Globalization.CultureInfo.InvariantCulture); MnvrEulAngs.Psi_3 = double.Parse(angles.A.ToString(), System.Globalization.CultureInfo.InvariantCulture); //DeltaVParams.Add("Euler Angle Sequence", double.Parse(MnvrEulAngs.Sequence.ToString(), System.Globalization.CultureInfo.InvariantCulture)); l_unit.Add(units.u_Null); DeltaVParams.Add("Euler Angle 1 (Phi)", MnvrEulAngs.Phi_1); l_unit.Add(units.u_Angle); DeltaVParams.Add("Euler Angle 2 (Theta)", MnvrEulAngs.Theta_2); l_unit.Add(units.u_Angle); DeltaVParams.Add("Euler Angle 3 (Psi)", MnvrEulAngs.Psi_3); l_unit.Add(units.u_Angle); update_Lists(DeltaVParams, depth, thisMnvr, implem_Classes.Astg_Mnvr_DV, localParent); } ; #endregion } }