public void Orbit_generation() { //load_orbit_file(); scenarioCheck(); var format = new NumberFormatInfo(); format.NegativeSign = "-"; format.NumberDecimalSeparator = "."; // planetodetic.Lat = Double.Parse(lat2[i], format); for (int i = 0; i < orbitmissioncount; i++) { //debug infomation/////// if (orbitdata[i].misnum == orbitdata[i].cod_id && orbitdata[i].used == 1 && orbitdata[i].efileused == false) { //generate the timeline file TL_file_generator(orbitdata[i].name, orbitdata[i].name); Console.Write("Misnum == cod_id\n"); Console.Write("Mission= " + orbitdata[i].name + "\n" + orbitdata[i].epoch + " " + orbitdata[i].epoch_time + " "); Console.Write(orbitdata[i].sma + " " + orbitdata[i].ecc + " " + orbitdata[i].inc + " " + orbitdata[i].raan + " " + orbitdata[i].aop + " " + orbitdata[i].ma + "\n"); string centerbodyname; if (orbitdata[i].centerbody == 1) { centerbodyname = "Earth"; } else if (orbitdata[i].centerbody == 2) { centerbodyname = "Moon"; } else { centerbodyname = "Earth"; } // AGI.STKObjects.IAgSatellite sat = (IAgSatellite)m_oApplication.CurrentScenario.Children.New(AGI.STKObjects.AgESTKObjectType.eSatellite, mission2[i]); //sat.SetPropagatorType(AGI.STKObjects.AgEVePropagatorType.ePropagatorTwoBody); try { //create a new sat with the cod orbit details; orbitdata[i].MisSat = (IAgSatellite)m_oApplication.CurrentScenario.Children.NewOnCentralBody(AGI.STKObjects.AgESTKObjectType.eSatellite, orbitdata[i].name, centerbodyname); //AGI.STKObjects.IAgSatellite sat = (IAgSatellite)m_oApplication.CurrentScenario.Children.NewOnCentralBody(AGI.STKObjects.AgESTKObjectType.eSatellite, orbitdata[i].name, centerbodyname); }catch { //sat already exists reset the scenario; this.m_oApplication.CloseScenario(); scenarioCheck(); Orbit_generation(); return; } //disable the leading ground track groundtrack_set(orbitdata[i].MisSat, groundtrack_displayed); //set the propagator type to HPOP orbitdata[i].MisSat.SetPropagatorType(AGI.STKObjects.AgEVePropagatorType.ePropagatorHPOP); //TODO update below code to use sat not hpop; AGI.STKObjects.IAgVePropagatorHPOP hpop = (AGI.STKObjects.IAgVePropagatorHPOP)orbitdata[i].MisSat.Propagator; IAgOrbitState orbit = hpop.InitialState.Representation; //create the string to hold the missions epoch date & time string cmb_epoch = orbitdata[i].epoch; cmb_epoch += " "; cmb_epoch += orbitdata[i].epoch_time; DateTime epochDT = Convert.ToDateTime(orbitdata[i].epoch); DateTime startDT = Convert.ToDateTime(orbitdata[i].start_date); DateTime endDT; if (orbitdata[i].endopt == 0) { endDT = startDT; endDT = endDT.AddDays((double)orbitdata[i].duration); orbitdata[i].end_time = orbitdata[i].start_time; } else { endDT = Convert.ToDateTime(orbitdata[i].end_date); } //hpop.ForceModel.EclipsingBodies.AssignEclipsingBody( centerbodyname); //check the centerbody of the provided orbit data; if (orbitdata[i].centerbody == 1) {// centerbody == EARTH Console.Write("centerbody2[i]) == 1 \n"); Console.Write("\n Centralbodyfile=" + hpop.ForceModel.CentralBodyGravity.File + "\n"); hpop.ForceModel.Drag.Use = false; hpop.ForceModel.SolarRadiationPressure.Use = false; } else if (orbitdata[i].centerbody == 2) {//CenterBody == Moon Console.Write("centerbody2[i]) == 2 \n"); hpop.ForceModel.Drag.Use = false; hpop.ForceModel.SolarRadiationPressure.Use = false; Console.Write("\n Centralbodyfile=" + hpop.ForceModel.CentralBodyGravity.File + "\n"); //change gravity file for HPOP use with the moon hpop.ForceModel.CentralBodyGravity.File = "STKData\\CentralBodies\\Moon\\LP100K.grv"; } //hpop.InitialState.Representation.Assign(orbit); Console.Write("set epochtime = " + epochDT.ToString("dd MMM yyyy ") + orbitdata[i].epoch_time + "\n"); //set the epoch date/time from the orbit bin file hpop.InitialState.Representation.Epoch = (epochDT.ToString("dd MMM yyyy ") + orbitdata[i].epoch_time); Console.Write("set start/stop times = " + (startDT.ToString("dd MMM yyyy ") + orbitdata[i].start_time) + " / " + startDT.AddDays(1).ToString("dd MMM yyyy ") + "\n"); //only proagate the orbit 1 day from the start date/time to get the required data to convert to a Fixed coordnate system hpop.EphemerisInterval.SetStartAndStopTimes((startDT.ToString("dd MMM yyyy ") + orbitdata[i].start_time), startDT.AddDays(1).ToString("dd MMM yyyy ")); //hpop.EphemerisInterval.SetStartAndStopTimes((startDT.ToString("dd MMM yyyy ") + orbitdata[i].start_time), (endDT.ToString("dd MMM yyyy ") + orbitdata[i].end_time)); hpop.InitialState.Representation.AssignClassical(AgECoordinateSystem.eCoordinateSystemJ2000, orbitdata[i].sma, orbitdata[i].ecc, orbitdata[i].inc, orbitdata[i].aop, orbitdata[i].raan, orbitdata[i].ma); hpop.Propagate(); //check if the orbit is earth centered and that the // orbit start date is different from the Mission model date if (orbitdata[i].centerbody == 1 && orbitdata[i].start_date != startdate) { Console.Write("Startdate != orbit_start date converting to Cartesian elements for fixed system" + "\n"); IAgStkObject sat = m_oApplication.CurrentScenario.Children[orbitdata[i].name]; // Get the satellite's ICRF cartesian position at 180 EpSec using the data provider interface IAgDataProviderGroup dpGroup = sat.DataProviders["Cartesian Position"] as IAgDataProviderGroup; Array elements = new object[] { "x", "y", "z" }; //***TODO*** find J2000 group instead of ICRF IAgDataPrvTimeVar dp = dpGroup.Group["ICRF"] as IAgDataPrvTimeVar; //get the elements at the start date/time of the orbit using in NPAS IAgDrResult dpResult = dp.ExecSingleElements(hpop.StartTime, ref elements); Console.Write("hpop.startTime=" + hpop.StartTime + "\n"); double xICRF = (double)dpResult.DataSets[0].GetValues().GetValue(0); double yICRF = (double)dpResult.DataSets[1].GetValues().GetValue(0); double zICRF = (double)dpResult.DataSets[2].GetValues().GetValue(0); // Get the satellite's ICRF cartesian velocity at 180 EpSec using the data provider interface dpGroup = sat.DataProviders["Cartesian Velocity"] as IAgDataProviderGroup; //***TODO*** find J2000 group instead of ICRF dp = dpGroup.Group["ICRF"] as IAgDataPrvTimeVar; //get the elements at the start date/time of the orbit using in NPAS dpResult = dp.ExecSingleElements(hpop.StartTime, ref elements); double xvelICRF = (double)dpResult.DataSets[0].GetValues().GetValue(0); double yvelICRF = (double)dpResult.DataSets[1].GetValues().GetValue(0); double zvelICRF = (double)dpResult.DataSets[2].GetValues().GetValue(0); Console.Write("J2000 cartesian vectors\n"); Console.Write("X=" + xICRF + " Y=" + yICRF + " Z=" + zICRF + "\n"); Console.Write("Xd=" + xvelICRF + " Yd=" + yvelICRF + " Zd=" + zvelICRF + "\n"); // Create a position vector using the ICRF coordinates IAgCrdnAxes axesICRF = sat.Vgt.WellKnownAxes.Earth.ICRF; IAgCartesian3Vector vectorICRF = m_oApplication.ConversionUtility.NewCartesian3Vector(); vectorICRF.Set(xICRF, yICRF, zICRF); // Create a velocity vector using the ICRF coordinates IAgCartesian3Vector vectorvelICRF = m_oApplication.ConversionUtility.NewCartesian3Vector(); vectorvelICRF.Set(xvelICRF, yvelICRF, zvelICRF); // Use the TransformWithRate method to transform ICRF to Fixed IAgCrdnAxes axesFixed = sat.Vgt.WellKnownAxes.Earth.Fixed; IAgCrdnAxesTransformWithRateResult result = axesICRF.TransformWithRate(hpop.StartTime, axesFixed, vectorICRF, vectorvelICRF); // Get the Fixed position and velocity coordinates double xFixed = result.Vector.X; double yFixed = result.Vector.Y; double zFixed = result.Vector.Z; double xvelFixed = result.Velocity.X; double yvelFixed = result.Velocity.Y; double zvelFixed = result.Velocity.Z; Console.Write("converted cartesian vectors" + "\n"); Console.Write("X=" + xFixed + " Y=" + yFixed + " Z=" + zFixed + "\n"); Console.Write("Xd=" + xvelFixed + " Yd=" + yvelFixed + " Zd=" + zvelFixed + "\n"); DateTime start, stop; start = Convert.ToDateTime(startdate); stop = Convert.ToDateTime(enddate); //set the epoch and start date/time to the selected scenario date/time hpop.InitialState.Representation.Epoch = (start.ToString("dd MMM yyyy ")); hpop.EphemerisInterval.SetStartAndStopTimes((start.ToString("dd MMM yyyy ")), (stop.ToString("dd MMM yyyy "))); hpop.InitialState.Representation.AssignCartesian(AgECoordinateSystem.eCoordinateSystemFixed, xFixed, yFixed, zFixed, xvelFixed, yvelFixed, zvelFixed); hpop.InitialState.Representation.Epoch = (start.ToString("dd MMM yyyy ")); hpop.EphemerisInterval.SetStartAndStopTimes((start.ToString("dd MMM yyyy ")), (stop.ToString("dd MMM yyyy "))); //propagate new orbit hpop.Propagate(); } orbitdata[i].Missensor = generate_sensor(orbitdata[i].name, "Stations"); orbitdata[i].MisChain = generate_chain(orbitdata[i].name, "Stations", orbitdata[i].name + "_sensor"); } else if (orbitdata[i].used == 1 && orbitdata[i].efileused == false) { //generate the missions timeline file inside the orignial cod mis name //don't generate multiple orbits on top of each other; TL_file_generator(orbitdata[i].name, missionindex[orbitdata[i].cod_id]); orbitdata[i].MisChain = null; Console.Write("Misnum != cod_id && orbitdata[i].used == 1 for " + orbitdata[i].name + "\n"); } else if (orbitdata[i].used == 1 && orbitdata[i].efileused == true) { TL_file_generator(orbitdata[i].name, missionindex[orbitdata[i].cod_id]); orbitdata[i].MisSat = (IAgSatellite)m_oApplication.CurrentScenario.Children.New(AGI.STKObjects.AgESTKObjectType.eSatellite, orbitdata[i].name); //disable the leading ground track groundtrack_set(orbitdata[i].MisSat, groundtrack_displayed); //set the propagator type to STK E file orbitdata[i].MisSat.SetPropagatorType(AGI.STKObjects.AgEVePropagatorType.ePropagatorStkExternal); AGI.STKObjects.IAgVePropagatorStkExternal EFileProp = (AGI.STKObjects.IAgVePropagatorStkExternal)orbitdata[i].MisSat.Propagator; //strip the file name from the entire director name; EFileProp.Filename = (Efile_directory + orbitdata[i].efilename.Split('/').Last().ToString()); //propagate the efile orbit EFileProp.Propagate(); //add new sensor to the current sat and change the sensor type to target orbitdata[i].Missensor = generate_sensor(orbitdata[i].name, "Stations"); //add a new chain for the current sat orbitdata[i].MisChain = generate_chain(orbitdata[i].name, "Stations", orbitdata[i].name + "_sensor"); } else { orbitdata[i].MisChain = null; Console.Write("Misnum != cod_id for " + orbitdata[i].name + "\n"); } } }
/* This code takes a set of Cartesian coordinates in a fixed frame and converts them into Keplerian orbital elements in an inertial frame * without using a satellite object (using conversion utility within STK Engine). The Keplerian elements you would like to return can be specified * by changing the enum values near the top of the Main function. */ static void Main(string[] args) { AgSTKXApplication app = new AgSTKXApplication(); app.NoGraphics = true; AgStkObjectRoot root = new AgStkObjectRoot(); // Here are some preliminary variables for the classical coordinate elements you would like to obtain SizeShapeTypes SizeShapeType = SizeShapeTypes.Altitude; AscNodeTypes AscNodeType = AscNodeTypes.RAAN; LocationTypes LocationType = LocationTypes.ArgumentOfLatitude; // Here we create a new AgOrbitState object IAgConversionUtility ConversionUtility = root.ConversionUtility; IAgOrbitState cartesianOrbit = ConversionUtility.NewOrbitStateOnEarth(); // Here is how you display and change the epoch Console.WriteLine("Epoch:"); cartesianOrbit.Epoch = "1 Jun 2003 17:00:00.000"; Console.WriteLine(cartesianOrbit.Epoch); // Here we assign whatever Cartesian coordinates we would like to in a fixed frame cartesianOrbit.AssignCartesian(AgECoordinateSystem.eCoordinateSystemFixed, 5598.42, -14988.6, 4.80738, 3.408, 1.27376, 2.60903); // Now we convert the orbit to a classical orbit state IAgOrbitStateClassical classicalOrbit = cartesianOrbit.ConvertTo(AgEOrbitStateType.eOrbitStateClassical) as IAgOrbitStateClassical; Console.WriteLine(classicalOrbit.CoordinateSystemType); // Prints out the first two classical orbit elements switch (SizeShapeType) { case SizeShapeTypes.Altitude: classicalOrbit.SizeShapeType = AgEClassicalSizeShape.eSizeShapeAltitude; IAgClassicalSizeShapeAltitude sizeShapeAltitude = classicalOrbit.SizeShape as IAgClassicalSizeShapeAltitude; Console.WriteLine("Apogee Altitude:"); Console.WriteLine(sizeShapeAltitude.ApogeeAltitude); Console.WriteLine("Perigee Altitude:"); Console.WriteLine(sizeShapeAltitude.PerigeeAltitude); break; case SizeShapeTypes.MeanMotion: classicalOrbit.SizeShapeType = AgEClassicalSizeShape.eSizeShapeMeanMotion; IAgClassicalSizeShapeMeanMotion sizeShapeMeanMotion = classicalOrbit.SizeShape as IAgClassicalSizeShapeMeanMotion; Console.WriteLine("Mean Motion:"); Console.WriteLine(sizeShapeMeanMotion.MeanMotion); Console.WriteLine("Eccentricity:"); Console.WriteLine(sizeShapeMeanMotion.Eccentricity); break; case SizeShapeTypes.Period: classicalOrbit.SizeShapeType = AgEClassicalSizeShape.eSizeShapePeriod; IAgClassicalSizeShapePeriod sizeShapePeriod = classicalOrbit.SizeShape as IAgClassicalSizeShapePeriod; Console.WriteLine("Period:"); Console.WriteLine(sizeShapePeriod.Period); Console.WriteLine("Eccentricity:"); Console.WriteLine(sizeShapePeriod.Eccentricity); break; case SizeShapeTypes.Radius: classicalOrbit.SizeShapeType = AgEClassicalSizeShape.eSizeShapeRadius; IAgClassicalSizeShapeRadius sizeShapeRadius = classicalOrbit.SizeShape as IAgClassicalSizeShapeRadius; Console.WriteLine("Apogee Radius:"); Console.WriteLine(sizeShapeRadius.ApogeeRadius); Console.WriteLine("Perigee Radius:"); Console.WriteLine(sizeShapeRadius.PerigeeRadius); break; case SizeShapeTypes.SemimajorAxis: classicalOrbit.SizeShapeType = AgEClassicalSizeShape.eSizeShapeSemimajorAxis; IAgClassicalSizeShapeSemimajorAxis sizeShapeSemimajorAxis = classicalOrbit.SizeShape as IAgClassicalSizeShapeSemimajorAxis; Console.WriteLine("Semimajor Axis:"); Console.WriteLine(sizeShapeSemimajorAxis.SemiMajorAxis); Console.WriteLine("Eccentricity:"); Console.WriteLine(sizeShapeSemimajorAxis.Eccentricity); break; } // Prints the inclination and argument of perigee IAgClassicalOrientation orientation = classicalOrbit.Orientation; Console.WriteLine("Inclination:"); Console.WriteLine(orientation.Inclination); Console.WriteLine("Argument of Perigee:"); Console.WriteLine(orientation.ArgOfPerigee); // This section prints the ascending node value Console.WriteLine("Ascending Node:"); switch (AscNodeType) { case AscNodeTypes.RAAN: orientation.AscNodeType = AgEOrientationAscNode.eAscNodeRAAN; IAgOrientationAscNodeRAAN ascNodeRAAN = orientation.AscNode as IAgOrientationAscNodeRAAN; Console.WriteLine(ascNodeRAAN.Value); break; case AscNodeTypes.LAN: orientation.AscNodeType = AgEOrientationAscNode.eAscNodeLAN; IAgOrientationAscNodeLAN ascNodeLAN = orientation.AscNode as IAgOrientationAscNodeLAN; Console.WriteLine(ascNodeLAN.Value); break; } // This section prints the location of the satellite along the orbit in terms of whatever you would like Console.WriteLine("Location:"); switch (LocationType) { case LocationTypes.ArgumentOfLatitude: classicalOrbit.LocationType = AgEClassicalLocation.eLocationArgumentOfLatitude; IAgClassicalLocationArgumentOfLatitude locationArgumentOfLatitude = classicalOrbit.Location as IAgClassicalLocationArgumentOfLatitude; Console.WriteLine(locationArgumentOfLatitude.Value); break; case LocationTypes.EccentricAnomaly: classicalOrbit.LocationType = AgEClassicalLocation.eLocationEccentricAnomaly; IAgClassicalLocationEccentricAnomaly locationSpecificEccentricAnomaly = classicalOrbit.Location as IAgClassicalLocationEccentricAnomaly; Console.WriteLine(locationSpecificEccentricAnomaly.Value); break; case LocationTypes.MeanAnomaly: classicalOrbit.LocationType = AgEClassicalLocation.eLocationMeanAnomaly; IAgClassicalLocationMeanAnomaly locationSpecificMeanAnomaly = classicalOrbit.Location as IAgClassicalLocationMeanAnomaly; Console.WriteLine(locationSpecificMeanAnomaly.Value); break; case LocationTypes.TimePastAN: classicalOrbit.LocationType = AgEClassicalLocation.eLocationTimePastAN; IAgClassicalLocationTimePastAN locationSpecificTimePastAN = classicalOrbit.Location as IAgClassicalLocationTimePastAN; Console.WriteLine(locationSpecificTimePastAN.Value); break; case LocationTypes.TimePastPerigee: classicalOrbit.LocationType = AgEClassicalLocation.eLocationTimePastPerigee; IAgClassicalLocationTimePastPerigee locationSpecificTimePastPerigee = classicalOrbit.Location as IAgClassicalLocationTimePastPerigee; Console.WriteLine(locationSpecificTimePastPerigee.Value); break; case LocationTypes.TrueAnomaly: classicalOrbit.LocationType = AgEClassicalLocation.eLocationTrueAnomaly; IAgClassicalLocationTrueAnomaly locationTrueAnomaly = classicalOrbit.Location as IAgClassicalLocationTrueAnomaly; Console.WriteLine(locationTrueAnomaly.Value); break; } Console.ReadLine(); }
//added selected TDRSs into the model private void add_tdrs(station_str passed) { IAgSatellite localtdrs; localtdrs = (IAgSatellite)m_oApplication.CurrentScenario.Children.New(AGI.STKObjects.AgESTKObjectType.eSatellite, passed.name); //AGI.STKObjects.IAgSatellite sat = (IAgSatellite)m_oApplication.CurrentScenario.Children.NewOnCentralBody(AGI.STKObjects.AgESTKObjectType.eSatellite, orbitdata[i].name, centerbodyname); //disable the leading ground track localtdrs.Graphics.PassData.GroundTrack.SetLeadDataType(AgELeadTrailData.eDataNone); //disable trailing ground track localtdrs.Graphics.PassData.GroundTrack.SetTrailDataType(AgELeadTrailData.eDataNone); localtdrs.VO.Pass.TrackData.PassData.GroundTrack.SetLeadDataType(AgELeadTrailData.eDataNone); localtdrs.VO.Pass.TrackData.PassData.GroundTrack.SetTrailDataType(AgELeadTrailData.eDataNone); localtdrs.VO.Pass.TrackData.PassData.Orbit.SetLeadDataType(AgELeadTrailData.eDataNone); localtdrs.VO.Pass.TrackData.PassData.Orbit.SetTrailDataType(AgELeadTrailData.eDataNone); //set the propagator type to HPOP localtdrs.SetPropagatorType(AGI.STKObjects.AgEVePropagatorType.ePropagatorJ2Perturbation); AGI.STKObjects.IAgVePropagatorJ2Perturbation hpop = (AGI.STKObjects.IAgVePropagatorJ2Perturbation)localtdrs.Propagator; IAgOrbitState orbit = hpop.InitialState.Representation; //create the string to hold the missions epoch date & time string cmb_epoch = startdate, cmb_end = enddate; cmb_epoch += " 00:00:00"; DateTime epochDT = Convert.ToDateTime(cmb_epoch); DateTime endepochDT = Convert.ToDateTime(cmb_end); //hpop.InitialState.Representation.Assign(orbit); Console.Write("epochtime = " + epochDT.ToString("dd MMM yyyy ") + "00:00:00" + "\n"); hpop.InitialState.Representation.Epoch = (epochDT.ToString("dd MMM yyyy ") + "00:00:00"); // hpop.InitialState.Representation.Assign(ia) //hpop.InitialState.Representation.AssignClassical(AgECoordinateSystem.eCoordinateSystemJ2000, orbitdata[i].sma, orbitdata[i].ecc, orbitdata[i].inc, orbitdata[i].aop, orbitdata[i].raan, orbitdata[i].ma); //hpop.Propagate(); IAgOrbitStateClassical classical = (IAgOrbitStateClassical)hpop.InitialState.Representation.ConvertTo(AgEOrbitStateType.eOrbitStateClassical); classical.CoordinateSystemType = AGI.STKUtil.AgECoordinateSystem.eCoordinateSystemJ2000; IAgCrdnEventIntervalSmartInterval interval = hpop.EphemerisInterval; interval.SetExplicitInterval((epochDT.ToString("dd MMM yyyy ") + "00:00:00"), (endepochDT.ToString("dd MMM yyyy ") + "00:00:00")); hpop.Step = 60; classical.LocationType = AgEClassicalLocation.eLocationTrueAnomaly; IAgClassicalLocationTrueAnomaly trueAnomaly = (IAgClassicalLocationTrueAnomaly)classical.Location; trueAnomaly.Value = 178.845262; classical.SizeShapeType = AgEClassicalSizeShape.eSizeShapePeriod; IAgClassicalSizeShapePeriod period = (IAgClassicalSizeShapePeriod)classical.SizeShape; period.Eccentricity = 0.0; period.Period = 86164.090540; classical.Orientation.ArgOfPerigee = 0.0; classical.Orientation.Inclination = 0.0; classical.Orientation.AscNodeType = AgEOrientationAscNode.eAscNodeLAN; IAgOrientationAscNodeLAN lan = (IAgOrientationAscNodeLAN)classical.Orientation.AscNode; lan.Value = (360 - passed.lon); hpop.InitialState.Representation.Assign(classical); hpop.Propagate(); }