Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        //pulls data providers for the aircraft in ICRF frame
        public static List <Array> GetAttitudeData(IAgStkObject obj, double startTime, double timeStep)
        {
            List <Array>           attitudeData = new List <Array>();
            IAgScenario            scenario     = CommonData.StkRoot.CurrentScenario as IAgScenario;
            IAgDrDataSetCollection datasets     = null;

            if (CommonData.objectClass == "Aircraft")
            {
                IAgDataProviderGroup attitudeDP1 = obj.DataProviders["Body Axes Orientation:YPR 321"] as IAgDataProviderGroup;
                IAgDataPrvTimeVar    attitudeDP2 = attitudeDP1.Group["ICRF"] as IAgDataPrvTimeVar;
                IAgDrResult          result      = attitudeDP2.Exec(startTime, scenario.StopTime, timeStep);
                datasets = result.DataSets;
            }
            else if (CommonData.objectClass == "Satellite")
            {
                IAgDataProviderGroup attitudeDP1 = obj.DataProviders["Attitude YPR"] as IAgDataProviderGroup;
                IAgDataPrvTimeVar    attitudeDP2 = attitudeDP1.Group["Seq YPR"] as IAgDataPrvTimeVar;
                IAgDrResult          result      = attitudeDP2.Exec(startTime, scenario.StopTime, timeStep);
                datasets = result.DataSets;
            }

            for (int i = 0; i < datasets.Count; i++)
            {
                attitudeData.Add(datasets[i].GetValues());
            }

            return(attitudeData);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        public List <String> GetAvailableGroups(string stkObjectPath, string DataProviderName)
        {
            IAgStkObject stkObject = root.GetObjectFromPath(stkObjectPath);

            IAgDataProviderInfo dataProvider = stkObject.DataProviders[DataProviderName];

            List <String> groups = new List <string>();

            if (dataProvider.IsGroup())
            {
                IAgDataProviderGroup dpGroup     = dataProvider as IAgDataProviderGroup;
                IAgDataProviders     dpAvailable = dpGroup.Group;

                for (int i = 0; i < dpAvailable.Count; ++i)
                {
                    groups.Add(dpAvailable[i].Name);
                }
            }

            return(groups);
        }
Exemplo n.º 5
0
        //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);
        }
Exemplo n.º 6
0
        public List <Waypoint> BoundingParallelTrackWaypointGenerator(
            string areaTargetPath, double speed, double altitude, double turnRadius, SwathWidthType swathType, double swathParameter)
        {
            List <Waypoint> waypoints = new List <Waypoint>();

            IAgStkObject         areaTarget       = root.GetObjectFromPath(areaTargetPath);
            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();

            IAgExecCmdResult cmdResult = root.ExecuteCommand("MeasureSurfaceDistance * " +
                                                             atLats.GetValue(0).ToString() + " " + atLons.GetValue(0).ToString()
                                                             + " " + atLats.GetValue(1).ToString() + " " + atLons.GetValue(1).ToString());

            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);
            }

            double topStepLat    = (((double)atLats.GetValue(1) - (double)atLats.GetValue(0)) / (double)numPasses);
            double bottomStepLat = (((double)atLats.GetValue(2) - (double)atLats.GetValue(3)) / (double)numPasses);
            double topStepLon    = (((double)atLons.GetValue(1) - (double)atLons.GetValue(0)) / (double)numPasses);
            double bottomStepLon = (((double)atLons.GetValue(2) - (double)atLons.GetValue(3)) / (double)numPasses);

            double topLat0    = (double)atLats.GetValue(0);
            double topLon0    = (double)atLons.GetValue(0);
            double bottomLat0 = (double)atLats.GetValue(3);
            double bottomLon0 = (double)atLons.GetValue(3);

            Waypoint waypoint = new Waypoint();

            for (int i = 0; i <= numPasses; ++i)
            {
                int test = i % 2;

                double latTopEnroute = topLat0 + (double)i * topStepLat;
                double lonTopEnroute = topLon0 + (double)i * topStepLon;

                double latBottomEnroute = bottomLat0 + (double)i * bottomStepLat;
                double lonBottomEnroute = bottomLon0 + (double)i * bottomStepLon;


                if (test == 0)
                {
                    waypoint                 = new Waypoint();
                    waypoint.Latitude        = latTopEnroute;
                    waypoint.Longitude       = lonTopEnroute;
                    waypoint.Altitude        = altitude;
                    waypoint.SurfaceAltitude = 0;
                    waypoint.Speed           = speed;
                    waypoint.TurnRadius      = turnRadius;
                    waypoints.Add(waypoint);

                    waypoint            = new Waypoint();
                    waypoint.Latitude   = latBottomEnroute;
                    waypoint.Longitude  = lonBottomEnroute;
                    waypoint.Altitude   = altitude;
                    waypoint.Speed      = speed;
                    waypoint.TurnRadius = turnRadius;
                    waypoints.Add(waypoint);
                }
                else
                {
                    waypoint                 = new Waypoint();
                    waypoint.Latitude        = latBottomEnroute;
                    waypoint.Longitude       = lonBottomEnroute;
                    waypoint.Altitude        = altitude;
                    waypoint.SurfaceAltitude = 0;
                    waypoint.Speed           = speed;
                    waypoint.TurnRadius      = turnRadius;
                    waypoints.Add(waypoint);

                    waypoint            = new Waypoint();
                    waypoint.Latitude   = latTopEnroute;
                    waypoint.Longitude  = lonTopEnroute;
                    waypoint.Altitude   = altitude;
                    waypoint.Speed      = speed;
                    waypoint.TurnRadius = turnRadius;
                    waypoints.Add(waypoint);
                }
            }

            return(waypoints);
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        public List <Waypoint> ExpandingSquareWaypointGenerator(
            string areaTargetPath, 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;

            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;
            double swathWidth;
            double gridAngleStep;

            if (swathType != SwathWidthType.NumberOfPasses)
            {
                swathWidth    = DetermineSwathWidth(swathType, swathParameter, altitude);
                gridAngleStep = swathWidth / 111000; // degrees longitude...ish
            }
            else
            {
                gridAngleStep = (((maxLat - minLat) + (maxLon - minLon)) / 2) / swathParameter;
            }

            double initialLat, initialLon;

            initialLat = maxLat - ((maxLat - minLat) / 2);
            initialLon = maxLon - ((maxLon - minLon) / 2);
            //IAgPosition centroid = (areaTarget as IAgAreaTarget).Position;

            //object centroidLat;
            //object centroidLon;
            //double centroidAlt;
            //centroid.QueryPlanetodetic(out centroidLat, out centroidLon, out centroidAlt);
            //initialLat = (double)centroidLat ;
            //initialLon = (double)centroidLon  ;

            Waypoint waypointInit = new Waypoint();

            waypointInit.Latitude        = (double)initialLat;
            waypointInit.Longitude       = (double)initialLon;
            waypointInit.Altitude        = altitude;
            waypointInit.SurfaceAltitude = 0;
            waypointInit.Speed           = speed;
            waypointInit.TurnRadius      = turnRadius;

            waypoints.Add(waypointInit);
            bool     keepCircling = true;
            Waypoint waypoint1, waypoint2, waypoint3, waypoint4;
            double   multiplier = 1;

            while (keepCircling)
            {
                waypoint1                 = new Waypoint();
                waypoint1.Latitude        = waypoints[waypoints.Count - 1].Latitude + multiplier * gridAngleStep;
                waypoint1.Longitude       = waypoints[waypoints.Count - 1].Longitude;
                waypoint1.Altitude        = altitude;
                waypoint1.SurfaceAltitude = 0;
                waypoint1.Speed           = speed;
                waypoint1.TurnRadius      = turnRadius;
                waypoints.Add(waypoint1);

                waypoint2                 = new Waypoint();
                waypoint2.Latitude        = waypoints[waypoints.Count - 1].Latitude;
                waypoint2.Longitude       = waypoints[waypoints.Count - 1].Longitude + multiplier * gridAngleStep;
                waypoint2.Altitude        = altitude;
                waypoint2.SurfaceAltitude = 0;
                waypoint2.Speed           = speed;
                waypoint2.TurnRadius      = turnRadius;
                waypoints.Add(waypoint2);
                multiplier += 1.0;

                waypoint3                 = new Waypoint();
                waypoint3.Latitude        = waypoints[waypoints.Count - 1].Latitude - multiplier * gridAngleStep;
                waypoint3.Longitude       = waypoints[waypoints.Count - 1].Longitude;
                waypoint3.Altitude        = altitude;
                waypoint3.SurfaceAltitude = 0;
                waypoint3.Speed           = speed;
                waypoint3.TurnRadius      = turnRadius;
                waypoints.Add(waypoint3);

                waypoint4                 = new Waypoint();
                waypoint4.Latitude        = waypoints[waypoints.Count - 1].Latitude;
                waypoint4.Longitude       = waypoints[waypoints.Count - 1].Longitude - multiplier * gridAngleStep;
                waypoint4.Altitude        = altitude;
                waypoint4.SurfaceAltitude = 0;
                waypoint4.Speed           = speed;
                waypoint4.TurnRadius      = turnRadius;
                waypoints.Add(waypoint4);
                multiplier += 1.0;

                if ((waypoint4.Latitude > maxLat & waypoint4.Longitude > maxLon) ||
                    (waypoint4.Latitude < minLat & waypoint4.Longitude < minLon))
                {
                    keepCircling = false;
                }
            }

            return(waypoints);
        }
Exemplo n.º 9
0
        //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");
                }
            }
        }
Exemplo n.º 10
0
        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");
                }
            }
        }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
0
        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());
        }