STK OBJECT MODEL TUTORIAL Follow the instructions in the accompanying tutorial (a PDF file) to enter the following code into your Visual Studio project. NOTE: Code fragments are tabbed in such a way that the indentation should be correct when you copy them into your project. When copying a line, be sure to select the entire line, starting from the left margin of the page. * ------------------------------------------------------------- * * SECTION: Add the Core of the STK Object Model to your Project * * ------------------------------------------------------------- * 1) Add the following using statements to the beginning of Form1.cs: using AGI.STKObjects; using AGI.STKUtil; using AGI.STKObjects.Astrogator; 2) Add these declarations to the beginning of the Form1 class definition: private AGI.STKObjects.AgStkObjectRoot root; private AGI.STKObjects.Astrogator.IAgVADriverMCS driver; 3) In the Form1 class constructor, after the InitializeComponent() method, add: root = new AGI.STKObjects.AgStkObjectRoot(); 4) In the Form1 dispose method, immediately before the call to base.Dispose(), add: System.Runtime.InteropServices.Marshal.ReleaseComObject(root); root = null; * ------------------------------ * * SECTION: Create a New Scenario * * ------------------------------ * 1) Create a scenario named "AstrogatorTutorial" public void NewScenario() { try { button1.Enabled = false; // first close any existing scenario root.CloseScenario(); root.NewScenario("AstrogatorTutorial"); // Reset the units to the STK defaults IAgUnitPrefsDimCollection dimensions = root.UnitPreferences; dimensions.ResetUnits(); // Set the date unit, acquire an interface to the scenario and use // it to set the time period and epoch dimensions.SetCurrentUnit("DateFormat", "UTCG"); IAgScenario scene= (IAgScenario)root.CurrentScenario; scene.StartTime = "1 Jul 2009 00:00:00.00"; scene.StopTime = "1 Jul 2009 04:00:00.00"; scene.Epoch = "1 Jul 2009 00:00:00.00"; button2.Enabled = true; } catch(Exception e) { MessageBox.Show(e.Message); } } 2) Add to Click event procedure for New Scenario button: NewScenario(); * ------------------------------------------- * * SECTION: Create an Astrogator Satellite * * ------------------------------------------- * 1) Create a satellite named "Satellite1" and get an interface to the Astrogator propagator public void NewSatellite() { try { button2.Enabled = false; //Create a new satellite object IAgSatellite sat1 = root.CurrentScenario.Children.New(AgESTKObjectType.eSatellite, "Satellite1") as IAgSatellite; //Set the propagator to Astrogator sat1.SetPropagatorType(AgEVePropagatorType.ePropagatorAstrogator); //get the Driver for the Propagator driver = sat1.Propagator as IAgVADriverMCS; //Clear all segments from the MCS driver.MainSequence.RemoveAll(); button3.Enabled = true; } catch (Exception e) { MessageBox.Show(e.Message); } } 2) Add to Click event procedure for New Satellite button: NewSatellite(); * ------------------------------------------- * * SECTION: Configure the Initial State * * ------------------------------------------- * 1) Create an initial state segment and configure it public void InitialState() { try { //disable the Initial State Button button3.Enabled = false; IAgVAMCSInitialState initState = driver.MainSequence.Insert( AgEVASegmentType.eVASegmentTypeInitialState, "Inner Orbit", "-") as IAgVAMCSInitialState; initState.SetElementType(AgEVAElementType.eVAElementTypeKeplerian); IAgVAElementKeplerian kep = initState.Element as IAgVAElementKeplerian; kep.PeriapsisRadiusSize = 6700; kep.ArgOfPeriapsis = 0; kep.Eccentricity = 0; kep.Inclination = 0; kep.RAAN = 0; kep.TrueAnomaly = 0; //Enable the Parking Orbit button button4.Enabled = true; } catch (Exception e) { MessageBox.Show(e.Message); } } 2) Add to Click event procedure for Initial State button: InitialState(); * ------------------------------------------- * * SECTION: Configure the Parking Orbit * * ------------------------------------------- * 1) Add a propagate segment to the MCS for the parking orbit. public void ParkingOrbit() { try { button4.Enabled = false; IAgVAMCSPropagate propagate = driver.MainSequence.Insert( AgEVASegmentType.eVASegmentTypePropagate, "Propagate", "-") as IAgVAMCSPropagate; propagate.PropagatorName = "Earth Point Mass"; ((IAgVAMCSSegment)propagate).Properties.Color = Color.Blue; ((IAgVAStoppingCondition)propagate.StoppingConditions["Duration"].Properties).Trip = 7200; button5.Enabled = true; } catch (Exception e) { MessageBox.Show(e.Message); } } 2) Add to Click event procedure for Parking Orbit button: ParkingOrbit(); * ------------------------------------------- * * SECTION: Configure the Target Sequence * * for the First Maneuver * * ------------------------------------------- * 1) Create a target sequence that will find the magnitude of the first maneuver in the transfer public void FirstTargetSequence() { try { button5.Enabled = false; IAgVAMCSTargetSequence ts = driver.MainSequence.Insert( AgEVASegmentType.eVASegmentTypeTargetSequence, "Start Transfer", "-") as IAgVAMCSTargetSequence; IAgVAMCSManeuver dv1 = ts.Segments.Insert( AgEVASegmentType.eVASegmentTypeManeuver, "DV1", "-") as IAgVAMCSManeuver; dv1.SetManeuverType(AgEVAManeuverType.eVAManeuverTypeImpulsive); IAgVAManeuverImpulsive impulsive = dv1.Maneuver as IAgVAManeuverImpulsive; impulsive.SetAttitudeControlType(AgEVAAttitudeControl.eVAAttitudeControlThrustVector); IAgVAAttitudeControlImpulsiveThrustVector thrustVector = impulsive.AttitudeControl as IAgVAAttitudeControlImpulsiveThrustVector; thrustVector.ThrustAxesName = "Satellite/Satellite1 VNC(Earth)"; dv1.EnableControlParameter(AgEVAControlManeuver.eVAControlManeuverImpulsiveCartesianX); ((IAgVAMCSSegment)dv1).Results.Add("Keplerian Elems/Radius of Apoapsis"); IAgVAProfileDifferentialCorrector dc = ts.Profiles["Differential Corrector"] as IAgVAProfileDifferentialCorrector; IAgVADCControl xControlParam = dc.ControlParameters.GetControlByPaths("DV1", "ImpulsiveMnvr.Cartesian.X"); xControlParam.Enable = true; xControlParam.MaxStep = 0.3; IAgVADCResult roaResult = dc.Results.GetResultByPaths("DV1", "Radius Of Apoapsis"); roaResult.Enable = true; roaResult.DesiredValue = 42238; roaResult.Tolerance = 0.1; dc.MaxIterations = 50; ts.Action = AgEVATargetSeqAction.eVATargetSeqActionRunActiveProfiles; button6.Enabled = true; } catch (Exception e) { MessageBox.Show(e.Message); } } 2) Add to Click event procedure for First Target Sequence button: FirstTargetSequence(); * ------------------------------------------- * * SECTION: Configure the Transfer Orbit * * ------------------------------------------- * 1) Insert a propagate segment for the half ellipse from perigee to apogee in the transfer. public void TransferOrbit() { try { button6.Enabled = false; IAgVAMCSPropagate transferEllipse = driver.MainSequence.Insert( AgEVASegmentType.eVASegmentTypePropagate, "Transfer Ellipse", "-") as IAgVAMCSPropagate; ((IAgVAMCSSegment)transferEllipse).Properties.Color = Color.Red; transferEllipse.PropagatorName = "Earth Point Mass"; transferEllipse.StoppingConditions.Add("Apoapsis"); transferEllipse.StoppingConditions.Remove("Duration"); button7.Enabled = true; } catch (Exception e) { MessageBox.Show(e.Message); } } 2) Add to Click event procedure for Transfer Orbit button: TransferOrbit(); * ------------------------------------------- * * SECTION: Configure the Target Sequence * * for the Second Maneuver * * ------------------------------------------- * 1) Insert the target sequence that will solve for the maneuver to circularize the final orbit public void SecondTargetSequence() { try { button7.Enabled = false; IAgVAMCSTargetSequence ts = driver.MainSequence.Insert( AgEVASegmentType.eVASegmentTypeTargetSequence, "Finish Transfer", "-") as IAgVAMCSTargetSequence; IAgVAMCSManeuver dv2 = ts.Segments.Insert( AgEVASegmentType.eVASegmentTypeManeuver, "DV2", "-") as IAgVAMCSManeuver; dv2.SetManeuverType(AgEVAManeuverType.eVAManeuverTypeImpulsive); IAgVAManeuverImpulsive impulsive = dv2.Maneuver as IAgVAManeuverImpulsive; impulsive.SetAttitudeControlType(AgEVAAttitudeControl.eVAAttitudeControlThrustVector); IAgVAAttitudeControlImpulsiveThrustVector thrustVector = impulsive.AttitudeControl as IAgVAAttitudeControlImpulsiveThrustVector; thrustVector.ThrustAxesName = "Satellite/Satellite1 VNC(Earth)"; dv2.EnableControlParameter(AgEVAControlManeuver.eVAControlManeuverImpulsiveCartesianX); ((IAgVAMCSSegment)dv2).Results.Add("Keplerian Elems/Eccentricity"); IAgVAProfileDifferentialCorrector dc = ts.Profiles["Differential Corrector"] as IAgVAProfileDifferentialCorrector; IAgVADCControl xControlParam = dc.ControlParameters.GetControlByPaths("DV2", "ImpulsiveMnvr.Cartesian.X"); xControlParam.Enable = true; xControlParam.MaxStep = 0.3; IAgVADCResult eccResult = dc.Results.GetResultByPaths("DV2", "Eccentricity"); eccResult.Enable = true; eccResult.DesiredValue = 0; eccResult.Tolerance = 0.001; dc.Mode = AgEVAProfileMode.eVAProfileModeIterate; ts.Action = AgEVATargetSeqAction.eVATargetSeqActionRunActiveProfiles; button8.Enabled = true; } catch (Exception e) { MessageBox.Show(e.Message); } } 2) Add to Click event procedure for Second Target Sequence button: SecondTargetSequence(); * ------------------------------------------- * * SECTION: Configure the Final Orbit * * ------------------------------------------- * 1) Propagate the satellite for 1 day after the transfer public void FinalOrbit() { try { button8.Enabled = false; IAgVAMCSPropagate outerOrbit = driver.MainSequence.Insert( AgEVASegmentType.eVASegmentTypePropagate, "Outer Orbit", "-") as IAgVAMCSPropagate; ((IAgVAMCSSegment)outerOrbit).Properties.Color = Color.Green; outerOrbit.PropagatorName = "Earth Point Mass"; ((IAgVAStoppingCondition)outerOrbit.StoppingConditions["Duration"].Properties).Trip = 86400; button9.Enabled = true; } catch (Exception e) { MessageBox.Show(e.Message); } } 2) Add to Click event procedure for Final Orbit button: FinalOrbit(); * ------------------------------------------- * * SECTION: Run the MCS * * ------------------------------------------- * 1) Run the MCS and apply the targeted values of the maneuvers to the segments. public void RunMCS() { try { driver.RunMCS(); IAgVAMCSTargetSequence startTransfer = driver.MainSequence["Start Transfer"] as IAgVAMCSTargetSequence; IAgVAMCSTargetSequence finishTransfer = driver.MainSequence["Finish Transfer"] as IAgVAMCSTargetSequence; IAgVAProfileDifferentialCorrector startDC = startTransfer.Profiles["Differential Corrector"] as IAgVAProfileDifferentialCorrector; Console.WriteLine(startDC.ControlParameters.GetControlByPaths("DV1", "ImpulsiveMnvr.Cartesian.X").FinalValue); IAgVAProfileDifferentialCorrector finishDC = finishTransfer.Profiles["Differential Corrector"] as IAgVAProfileDifferentialCorrector; Console.WriteLine(finishDC.ControlParameters.GetControlByPaths("DV2", "ImpulsiveMnvr.Cartesian.X").FinalValue); Array dvComponents = new Array[3]; IAgVAMCSManeuver dv1 = startTransfer.Segments["DV1"] as IAgVAMCSManeuver; IAgVAManeuverImpulsive dv1Impulsive = dv1.Maneuver as IAgVAManeuverImpulsive; IAgVAAttitudeControlImpulsiveThrustVector dv1ThrustVector = dv1Impulsive.AttitudeControl as IAgVAAttitudeControlImpulsiveThrustVector; dvComponents = dv1ThrustVector.QueryCartesian(); Console.WriteLine(dvComponents.GetValue(0).ToString()); startTransfer.ApplyProfiles(); dvComponents = dv1ThrustVector.QueryCartesian(); Console.WriteLine(dvComponents.GetValue(0).ToString()); IAgVAMCSManeuver dv2 = finishTransfer.Segments["DV2"] as IAgVAMCSManeuver; IAgVAManeuverImpulsive dv2Impulsive = dv2.Maneuver as IAgVAManeuverImpulsive; IAgVAAttitudeControlImpulsiveThrustVector dv2ThrustVector = dv2Impulsive.AttitudeControl as IAgVAAttitudeControlImpulsiveThrustVector; dvComponents = dv2ThrustVector.QueryCartesian(); Console.WriteLine(dvComponents.GetValue(0).ToString()); finishTransfer.ApplyProfiles(); dvComponents = dv2ThrustVector.QueryCartesian(); Console.WriteLine(dvComponents.GetValue(0).ToString()); } catch (Exception e) { MessageBox.Show(e.Message); } } 2) Add to Click event procedure for Run MCS button: RunMCS();