public void WaypointsToGreatArc(IAgAircraft aircraft, List <Waypoint> waypoints, bool useTakeoffLanding)
        {
            //Set propagator to GreatArc
            aircraft.SetRouteType(AgEVePropagatorType.ePropagatorGreatArc);
            IAgVePropagatorGreatArc route = aircraft.Route as IAgVePropagatorGreatArc;

            route.ArcGranularity = 51.333;

            //Set Ref type to WayPtAltRefMSL
            route.SetAltitudeRefType(AgEVeAltitudeRef.eWayPtAltRefMSL);
            route.Method = AgEVeWayPtCompMethod.eDetermineTimeAccFromVel;

            route.Waypoints.RemoveAll();

            if (useTakeoffLanding)
            {
                waypoints[0].Altitude = waypoints[0].SurfaceAltitude;
                waypoints[waypoints.Count - 1].Altitude = waypoints[waypoints.Count - 1].SurfaceAltitude;
            }

            foreach (Waypoint waypoint in waypoints)
            {
                IAgVeWaypointsElement thisWaypoint = route.Waypoints.Add();
                thisWaypoint.Latitude   = waypoint.Latitude;
                thisWaypoint.Longitude  = waypoint.Longitude;
                thisWaypoint.Altitude   = waypoint.Altitude;
                thisWaypoint.Speed      = waypoint.Speed;
                thisWaypoint.TurnRadius = waypoint.TurnRadius;
            }

            route.Propagate();
        }
        public void CheckFlightEndurance(IAgAircraft flight, string enduranceUnit, double enduranceValue)
        {
            if (enduranceUnit.Equals("mi") || enduranceUnit.Equals("km") || enduranceUnit.Equals("nm"))
            {
                root.UnitPreferences["Distance"].SetCurrentUnit(enduranceUnit);
            }
            else
            {
                root.UnitPreferences["Time"].SetCurrentUnit(enduranceUnit);
            }
            bool tooLong = true;

            root.BeginUpdate();
            while (tooLong)
            {
                IAgDataPrvTimeVar dpDistance = ((IAgStkObject)flight).DataProviders["Distance"] as IAgDataPrvTimeVar;
                string            evalTime   = (flight.Route as IAgVePropagatorGreatArc).StopTime.ToString();
                evalTime = evalTime.Substring(0, evalTime.IndexOf("."));

                IAgDrResult dpResult = dpDistance.ExecSingle(evalTime);

                Array distance = dpResult.DataSets.GetDataSetByName("Dist from start").GetValues();
                Array duration = dpResult.DataSets.GetDataSetByName("Time from start").GetValues();

                double distanceTraveled = (double)distance.GetValue(0);
                double timeTraveled     = (double)duration.GetValue(0);

                if (enduranceUnit.Equals("mi") || enduranceUnit.Equals("km") || enduranceUnit.Equals("nm"))
                {
                    if (distanceTraveled < enduranceValue)
                    {
                        tooLong = false;
                    }
                }
                else if (timeTraveled < enduranceValue)
                {
                    tooLong = false;
                }

                if (tooLong)
                {
                    IAgVePropagatorGreatArc route = (IAgVePropagatorGreatArc)flight.Route;
                    route.Waypoints.RemoveAt(route.Waypoints.Count - 2);
                    route.Propagate();
                }
            }
            root.UnitPreferences.ResetUnits();
            root.EndUpdate();
        }
Beispiel #3
0
        private void addLLAWaypointBtn_Click(object sender, EventArgs e)
        {
            IAgVePropagatorGreatArc greatArcPropagator = createAircraftFromWaypoints();
            double lat = Convert.ToDouble(latTb.Text);
            double lon = Convert.ToDouble(lonTb.Text);
            double alt = Convert.ToDouble(altTb.Text);

            IAgVeWaypointsElement waypoint2 = greatArcPropagator.Waypoints.Add();

            waypoint2.Latitude  = lat;
            waypoint2.Longitude = lon;
            waypoint2.Altitude  = alt;

            greatArcPropagator.Propagate();
        }
        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);
        }
        public void UpdateWaypoint(IAgStkObject greatArcVehicle,
                                   WaypointProperty waypointProp, double waypointParameter, string parameterUnit)
        {
            IAgVePropagatorGreatArc route = null;

            switch (parameterUnit)
            {
            case "mph":
                root.UnitPreferences.SetCurrentUnit("Distance", "mi");
                root.UnitPreferences.SetCurrentUnit("Time", "hr");
                break;

            case "km/sec":
                root.UnitPreferences.SetCurrentUnit("Distance", "km");
                root.UnitPreferences.SetCurrentUnit("Time", "sec");
                break;

            case "knots":
                root.UnitPreferences.SetCurrentUnit("Distance", "nm");
                root.UnitPreferences.SetCurrentUnit("Time", "hr");
                break;

            case "m":
                root.UnitPreferences.SetCurrentUnit("Distance", "m");
                break;

            case "km":
                root.UnitPreferences.SetCurrentUnit("Distance", "km");
                break;

            case "ft":
                root.UnitPreferences.SetCurrentUnit("Distance", "ft");
                break;

            case "deg":
                root.UnitPreferences.SetCurrentUnit("Angle", "deg");
                break;

            case "rad":
                root.UnitPreferences.SetCurrentUnit("Angle", "rad");
                break;

            default:
                break;
            }


            switch (greatArcVehicle.ClassType)
            {
            case AgESTKObjectType.eAircraft:
                if (((IAgAircraft)greatArcVehicle).RouteType == AgEVePropagatorType.ePropagatorGreatArc)
                {
                    route = ((IAgAircraft)greatArcVehicle).Route as IAgVePropagatorGreatArc;
                }
                break;

            case AgESTKObjectType.eGroundVehicle:
                if (((IAgGroundVehicle)greatArcVehicle).RouteType == AgEVePropagatorType.ePropagatorGreatArc)
                {
                    route = ((IAgGroundVehicle)greatArcVehicle).Route as IAgVePropagatorGreatArc;
                }

                break;

            case AgESTKObjectType.eShip:
                if (((IAgShip)greatArcVehicle).RouteType == AgEVePropagatorType.ePropagatorGreatArc)
                {
                    route = ((IAgShip)greatArcVehicle).Route as IAgVePropagatorGreatArc;
                }

                break;

            default:
                break;
            }

            if (route != null)
            {
                foreach (IAgVeWaypointsElement waypoint in route.Waypoints)
                {
                    switch (waypointProp)
                    {
                    case WaypointProperty.Speed:
                        waypoint.Speed = waypointParameter;
                        break;

                    case WaypointProperty.Altitude:
                        waypoint.Altitude = waypointParameter;
                        break;

                    case WaypointProperty.TurnRadius:
                        waypoint.TurnRadius = waypointParameter;
                        break;

                    case WaypointProperty.Latitude:
                        waypoint.Latitude = (double)waypoint.Latitude + waypointParameter;
                        break;

                    case WaypointProperty.Longitude:
                        waypoint.Longitude = (double)waypoint.Longitude + waypointParameter;
                        break;

                    default:
                        break;
                    }
                }
                route.Propagate();
                root.UnitPreferences.ResetUnits();
            }
        }
        private void AddRoute(MyWaypoint startPoint, MyWaypoint endPoint, string gvName)
        {
            List <MyWaypoint> routePoints = GetRoute(startPoint, endPoint);

            // create new GV and add the waypoints
            if (m_root.CurrentScenario.Children.Contains(AgESTKObjectType.eGroundVehicle, gvName))
            {
                MessageBox.Show(gvName + " already exists, please pick a different name");
            }
            else
            {
                if (routePoints != null && routePoints.Count > 0)
                {
                    double turnRadius  = 2.0;   // meter
                    double granularity = 1.1;   // meter

                    m_root.UnitPreferences.SetCurrentUnit("Distance", "m");

                    switch (speedUnitsComboBox.SelectedItem.ToString())
                    {
                    case "km/h":
                        //m_root.UnitPreferences.SetCurrentUnit("Distance", "km");
                        m_root.UnitPreferences.SetCurrentUnit("Time", "hr");
                        //turnRadius /= 1000.0;
                        //granularity /= 1000.0;
                        speedUnitMultiplier = 1000.0;
                        break;

                    case "mph":
                        //m_root.UnitPreferences.SetCurrentUnit("Distance", "mi");
                        m_root.UnitPreferences.SetCurrentUnit("Time", "hr");
                        //turnRadius /= 1609.44;
                        //granularity /= 1609.44;
                        speedUnitMultiplier = 1609.44;
                        break;

                    case "m/s":
                        //m_root.UnitPreferences.SetCurrentUnit("Distance", "m");
                        m_root.UnitPreferences.SetCurrentUnit("Time", "sec");
                        speedUnitMultiplier = 1.0;
                        break;
                    }

                    switch (altUnitsComboBox.SelectedItem.ToString())
                    {
                    case "m":
                        altUnitMultiplier = 1.0;
                        break;

                    case "km":
                        altUnitMultiplier = 1000.0;
                        break;

                    case "ft":
                        altUnitMultiplier = 0.3048;
                        break;
                    }


                    IAgStkObject     gvObject = m_root.CurrentScenario.Children.New(AgESTKObjectType.eGroundVehicle, gvName);
                    IAgGroundVehicle gv       = gvObject as IAgGroundVehicle;

                    gv.SetRouteType(AgEVePropagatorType.ePropagatorGreatArc);
                    IAgVePropagatorGreatArc prop = gv.Route as IAgVePropagatorGreatArc;

                    foreach (MyWaypoint thisPt in routePoints)
                    {
                        IAgVeWaypointsElement thisVeWaypoint = prop.Waypoints.Add();
                        thisVeWaypoint.Latitude   = thisPt.Latitude;
                        thisVeWaypoint.Longitude  = thisPt.Longitude;
                        thisVeWaypoint.Altitude   = thisPt.Altitude * altUnitMultiplier;
                        thisVeWaypoint.Speed      = Convert.ToDouble(speedTextBox.Text) * speedUnitMultiplier;
                        thisVeWaypoint.TurnRadius = turnRadius;
                    }

                    if (terrainCheckBox.Checked)
                    {
                        prop.SetAltitudeRefType(AgEVeAltitudeRef.eWayPtAltRefTerrain);
                        IAgVeWayPtAltitudeRefTerrain altRef = prop.AltitudeRef as IAgVeWayPtAltitudeRefTerrain;
                        altRef.Granularity  = granularity;
                        altRef.InterpMethod = AgEVeWayPtInterpMethod.eWayPtEllipsoidHeight;
                    }

                    prop.Propagate();
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// 新建一个SARSYS在当前sc文件中
        /// 需要建立最基础的系统
        /// 参数大多数有默认值
        /// </summary>
        public void newsarsys()
        {
            #region 写入信息
            AGI.STKX.IAgExecCmdResult resultmsg = rootapp.ExecuteCommand("SetDescription * long SARSYS");
            #endregion

            #region 设定单位、仿真时间
            // Reset the units to the STK defaults
            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");

            scene = (IAgScenario)root.CurrentScenario;
            scene.StartTime = simstarttime;
            scene.StopTime = simstoptime;
            scene.Epoch = simstarttime;

            // Set new preference for Temperature
            dimensions.SetCurrentUnit("Temperature", "degC");
            #endregion

            #region 放置发射站
            //SATELLITE #1: TDRS
            //Assign a two-body propagator to propagate it
            tdrs = (IAgSatellite)root.CurrentScenario.Children.New(AgESTKObjectType.
                eSatellite, "TDRS");
            tdrs.SetPropagatorType(AgEVePropagatorType.ePropagatorTwoBody);
            twobody = (IAgVePropagatorTwoBody)tdrs.Propagator;

            //Define the TDRS satellite's orbit using
            //classical (Keplerian) orbital elements
            classical = (IAgOrbitStateClassical)twobody.InitialState.Representation.ConvertTo(AgEOrbitStateType.eOrbitStateClassical);

            //Set J2000 as the coordinate system
            //and set the time period and time step
            classical.CoordinateSystemType = AgECoordinateSystem.eCoordinateSystemJ2000;
            twobody.EphemerisInterval.SetStartAndStopTimes(simstarttime, simstoptime);
            twobody.Step = 60;

            //定义半主轴长度,离心率
            //Use period and eccentricity to define the size
            //and shape of the orbit
            classical.SizeShapeType = AgEClassicalSizeShape.eSizeShapeSemimajorAxis;
            IAgClassicalSizeShapeSemimajorAxis semi = (IAgClassicalSizeShapeSemimajorAxis)classical.SizeShape;
            semi.SemiMajorAxis = 35860;
            semi.Eccentricity = 0.0;

            //定义轨道倾角,升交点赤经,近地点幅角
            //Use argument of perigee, inclination
            //and longitude of ascending node to
            //define the orientation of the orbit
            classical.Orientation.ArgOfPerigee = 15.0;
            classical.Orientation.Inclination = 40.0;
            classical.Orientation.AscNodeType = AgEOrientationAscNode.eAscNodeLAN;
            IAgOrientationAscNodeLAN lan = (IAgOrientationAscNodeLAN)classical.Orientation.AscNode;
            lan.Value = 259.999982;

            //定义真近点角(?)来定义初始位置
            //Use true anomaly to specify the position of
            //the satellite in orbit
            classical.LocationType = AgEClassicalLocation.eLocationTrueAnomaly;
            IAgClassicalLocationTrueAnomaly trueAnomaly = (IAgClassicalLocationTrueAnomaly)classical.Location;
            trueAnomaly.Value = 178.845262;

            //Assign the orbital elements to the TDRS
            //satellite's propagator and propagate the orbit
            twobody.InitialState.Representation.Assign(classical);
            twobody.Propagate();

            root.Rewind();

            #endregion

            #region 放置接收站
            cruise = (IAgAircraft)root.CurrentScenario.Children.New(AgESTKObjectType.eAircraft, "Cruise");
            cruise.SetRouteType(AgEVePropagatorType.ePropagatorGreatArc);
            greatArc = (IAgVePropagatorGreatArc)cruise.Route;
            greatArc.EphemerisInterval.SetStartAndStopTimes(simstarttime, simstoptime);
            greatArc.Method = AgEVeWayPtCompMethod.eDetermineTimeAccFromVel;

            ((IAgVOModelFile)cruise.VO.Model.ModelData).Filename = @"\STKData\VO\Models\Air\e-3a_sentry_awacs.mdl";
            cruise.VO.Offsets.Rotational.Enable = true;
            cruise.VO.Offsets.Rotational.X = 180;

            //Use the convenience method defined above
            //to add waypoints specifying the ship's route
            AddWaypoint(greatArc.Waypoints, -42.1, -121.5, 3.0, .15, 0.0);
            AddWaypoint(greatArc.Waypoints, 62.0, -56.6, 3.0, .15, 0.0);

            cruise.SetAttitudeType(AgEVeAttitude.eAttitudeStandard);
            IAgVeRouteAttitudeStandard attitude = (IAgVeRouteAttitudeStandard)cruise.Attitude;
            attitude.Basic.SetProfileType(AgEVeProfile.
                eProfileECFVelocityAlignmentWithRadialConstraint);
            cruise.Graphics.WaypointMarker.IsWaypointMarkersVisible = true;
            cruise.Graphics.WaypointMarker.IsTurnMarkersVisible = true;
            greatArc.Propagate();
            root.Rewind();

            #endregion

            #region 放置发射站雷达
            horizon = (IAgSensor)root.CurrentScenario.Children["TDRS"].Children.
                    New(AgESTKObjectType.eSensor, "Horizon");
            horizon.SetPatternType(AgESnPattern.eSnSimpleConic);
            IAgSnSimpleConicPattern simpleConic = (IAgSnSimpleConicPattern)horizon.Pattern;
            simpleConic.ConeAngle = 0.1;

            //Select a Fixed pointing type and the Az-El
            //orientation type, and set the elevation angle to
            //90 deg, so that the sensor points straight down
            //with reference to the satellite
            horizon.SetPointingType(AgESnPointing.eSnPtFixed);
            IAgSnPtFixed fixedPt = (IAgSnPtFixed)horizon.Pointing;
            IAgOrientationAzEl azEl = (IAgOrientationAzEl)fixedPt.Orientation.ConvertTo(AgEOrientationType.eAzEl);
            azEl.Elevation = 89.2;
            azEl.AboutBoresight = AgEAzElAboutBoresight.eAzElAboutBoresightRotate;
            fixedPt.Orientation.Assign(azEl);

            root.Rewind();

            #endregion
        }
Beispiel #8
0
        /// <summary>
        /// 新建一个SARSYS在当前sc文件中
        /// 需要建立最基础的系统
        /// 参数大多数有默认值
        /// </summary>
        public void newsarsys()
        {
            #region 写入信息
            AGI.STKX.IAgExecCmdResult resultmsg = rootapp.ExecuteCommand("SetDescription * long SARSYS");
            #endregion


            #region 设定单位、仿真时间
            // Reset the units to the STK defaults
            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");

            scene = (IAgScenario)root.CurrentScenario;
            scene.StartTime = simstarttime;
            scene.StopTime = simstoptime;
            scene.Epoch = simstarttime;

            //rootapp.ExecuteCommand("MapTracking * UTM");

            // Set new preference for Temperature
            dimensions.SetCurrentUnit("Temperature", "degC");
            #endregion

            #region 放置发射站
            //SATELLITE #1: TDRS
            //Assign a two-body propagator to propagate it
            tdrs = (IAgSatellite)root.CurrentScenario.Children.New(AgESTKObjectType.
                eSatellite, "TDRS");
            tdrs.SetPropagatorType(AgEVePropagatorType.ePropagatorTwoBody);
            twobody = (IAgVePropagatorTwoBody)tdrs.Propagator;

            //Define the TDRS satellite's orbit using
            //classical (Keplerian) orbital elements
            classical = (IAgOrbitStateClassical)twobody.InitialState.Representation.ConvertTo(AgEOrbitStateType.eOrbitStateClassical);

            //Set J2000 as the coordinate system
            //and set the time period and time step
            classical.CoordinateSystemType = AgECoordinateSystem.eCoordinateSystemJ2000;
            twobody.EphemerisInterval.SetStartAndStopTimes(simstarttime, simstoptime);
            twobody.Step = 60;

            //定义半主轴长度,离心率
            //Use period and eccentricity to define the size
            //and shape of the orbit
            classical.SizeShapeType = AgEClassicalSizeShape.eSizeShapeSemimajorAxis;
            IAgClassicalSizeShapeSemimajorAxis semi = (IAgClassicalSizeShapeSemimajorAxis)classical.SizeShape;
            semi.SemiMajorAxis = sasem;
            semi.Eccentricity = saecc;


            //定义轨道倾角,升交点赤经,近地点幅角
            //Use argument of perigee, inclination
            //and longitude of ascending node to
            //define the orientation of the orbit
            classical.Orientation.ArgOfPerigee = saaop;
            classical.Orientation.Inclination = sainc;
            classical.Orientation.AscNodeType = AgEOrientationAscNode.eAscNodeLAN;
            IAgOrientationAscNodeLAN lan = (IAgOrientationAscNodeLAN)classical.Orientation.AscNode;
            lan.Value = salan;

            //定义真近点角(?)来定义初始位置
            //Use true anomaly to specify the position of
            //the satellite in orbit
            classical.LocationType = AgEClassicalLocation.eLocationTrueAnomaly;
            IAgClassicalLocationTrueAnomaly trueAnomaly = (IAgClassicalLocationTrueAnomaly)classical.Location;
            trueAnomaly.Value = satra;


            //Assign the orbital elements to the TDRS
            //satellite's propagator and propagate the orbit	
            twobody.InitialState.Representation.Assign(classical);
            twobody.Propagate();

            root.Rewind();

            #endregion

            
            #region 放置接收站
            cruise = (IAgAircraft)root.CurrentScenario.Children.New(AgESTKObjectType.eAircraft, "Cruise");
            cruise.SetRouteType(AgEVePropagatorType.ePropagatorGreatArc);
            greatArc = (IAgVePropagatorGreatArc)cruise.Route;
            greatArc.EphemerisInterval.SetStartAndStopTimes(simstarttime, simstoptime);
            greatArc.Method = AgEVeWayPtCompMethod.eDetermineTimeAccFromVel;

            ((IAgVOModelFile)cruise.VO.Model.ModelData).Filename = @"\STKData\VO\Models\Air\rq-4a_globalhawk.mdl";
            cruise.VO.Offsets.Rotational.Enable = true;
            cruise.VO.Offsets.Rotational.X = 180;

            //Use the convenience method defined above
            //to add waypoints specifying the ship's route
            for (int ii = 0; ii < plwaypoints.Length; ii += 5)
            {
                AddWaypoint(greatArc.Waypoints, plwaypoints[ii], plwaypoints[ii + 1], plwaypoints[ii + 2], plwaypoints[ii + 3], plwaypoints[ii + 4]);
            }
              
            
            cruise.SetAttitudeType(AgEVeAttitude.eAttitudeStandard);
            IAgVeRouteAttitudeStandard attitude = (IAgVeRouteAttitudeStandard)cruise.Attitude;
            attitude.Basic.SetProfileType(AgEVeProfile.
                eProfileECFVelocityAlignmentWithRadialConstraint);
            cruise.Graphics.WaypointMarker.IsWaypointMarkersVisible = true;
            cruise.Graphics.WaypointMarker.IsTurnMarkersVisible = true;
            greatArc.Propagate();
            root.Rewind();


            #endregion

            #region 放置发射站雷达
            radar_t = (IAgSensor)root.CurrentScenario.Children["TDRS"].Children.New(AgESTKObjectType.eSensor, "radar_t");
            radar_t.SetPatternType(AgESnPattern.eSnSimpleConic);
            ((IAgSnSimpleConicPattern)radar_t.Pattern).ConeAngle = racoang;



            //Select a Fixed pointing type and the Az-El
            //orientation type, and set the elevation angle to
            //90 deg, so that the sensor points straight down
            //with reference to the satellite
            radar_t.SetPointingType(AgESnPointing.eSnPtFixed);
            IAgSnPtFixed fixedPt = (IAgSnPtFixed)radar_t.Pointing;
            IAgOrientationAzEl azEl = (IAgOrientationAzEl)fixedPt.Orientation.ConvertTo(AgEOrientationType.eAzEl);
            azEl.Elevation = raeleva;
            azEl.AboutBoresight = AgEAzElAboutBoresight.eAzElAboutBoresightRotate;
            fixedPt.Orientation.Assign(azEl);

            radar_t.Graphics.FillVisible = true;
            radar_t.VO.FillVisible = true;
            

            root.Rewind();


            #endregion


            #region 放置接收站雷达


            target = (IAgSensor)root.CurrentScenario.Children["TDRS"].Children.New(AgESTKObjectType.eSensor, "target");

            target.SetLocationType(AgESnLocation.eSnLocationCrdnPoint);
            IAgLocationCrdnPoint vgtPoint = target.LocationData as IAgLocationCrdnPoint;
            //vgtPoint.PointPath = "TDRS/radar_t BoresightIntersection(Terrain)";
            vgtPoint.PointPath = "Satellite/TDRS/Sensor/radar_t BoresightIntersection(Terrain)";
            target.SetPatternType(AgESnPattern.eSnSimpleConic);
            ((IAgSnSimpleConicPattern)target.Pattern).ConeAngle = 0.00001;
           
            

            IAgSnPtTargeted targetedSensor1 = target.CommonTasks.SetPointingTargetedTracking(
   AgETrackModeType.eTrackModeTranspond, AgEBoresightType.eBoresightRotate, "*/Aircraft/Cruise");


            target.SetPointingType(AgESnPointing.eSnPtTargeted);
            IAgSnPtTargeted rpt1 = (IAgSnPtTargeted)target.Pointing;
            rpt1.Boresight = AgESnPtTrgtBsightType.eSnPtTrgtBsightTracking;
            root.Rewind();
            rootapp.ExecuteCommand("Graphics */Satellite/TDRS/Sensor/target Show Off");


            /////////////////////////
            radar_r = (IAgSensor)root.CurrentScenario.Children["Cruise"].Children.New(AgESTKObjectType.eSensor, "radar_r");
            radar_r.SetPatternType(AgESnPattern.eSnSimpleConic);
            ((IAgSnSimpleConicPattern)radar_r.Pattern).ConeAngle = 3;
        

            IAgSnPtTargeted targetedSensor = radar_r.CommonTasks.SetPointingTargetedTracking(
    AgETrackModeType.eTrackModeTranspond, AgEBoresightType.eBoresightRotate, "*/Satellite/TDRS/Sensor/target");   

            
            radar_r.SetPointingType(AgESnPointing.eSnPtTargeted);
            IAgSnPtTargeted rpt = (IAgSnPtTargeted)radar_r.Pointing;
            rpt.Boresight = AgESnPtTrgtBsightType.eSnPtTrgtBsightTracking;
            

            root.Rewind();
            #endregion
        }
Beispiel #9
0
        //Satellite helpers
        public static void ChangeSatelliteInterval(IAgSatellite sat, string startTime, string stopTime, bool astgRun)
        {
            AgEVePropagatorType propType = sat.PropagatorType;

            //IAgVePropagator prop = sat.Propagator;

            switch (propType)
            {
            case AgEVePropagatorType.eUnknownPropagator:
                break;

            case AgEVePropagatorType.ePropagatorHPOP:
                IAgVePropagatorHPOP prop = sat.Propagator as IAgVePropagatorHPOP;
                prop.EphemerisInterval.SetExplicitInterval(startTime, stopTime);
                prop.Propagate();
                break;

            case AgEVePropagatorType.ePropagatorJ2Perturbation:
                IAgVePropagatorJ2Perturbation prop1 = sat.Propagator as IAgVePropagatorJ2Perturbation;
                prop1.EphemerisInterval.SetExplicitInterval(startTime, stopTime);
                prop1.Propagate();
                break;

            case AgEVePropagatorType.ePropagatorJ4Perturbation:
                IAgVePropagatorJ4Perturbation prop2 = sat.Propagator as IAgVePropagatorJ4Perturbation;
                prop2.EphemerisInterval.SetExplicitInterval(startTime, stopTime);
                prop2.Propagate();
                break;

            case AgEVePropagatorType.ePropagatorLOP:
                IAgVePropagatorLOP prop3 = sat.Propagator as IAgVePropagatorLOP;
                prop3.EphemerisInterval.SetExplicitInterval(startTime, stopTime);
                prop3.Propagate();
                break;

            case AgEVePropagatorType.ePropagatorSGP4:
                IAgVePropagatorSGP4 prop4 = sat.Propagator as IAgVePropagatorSGP4;
                prop4.EphemerisInterval.SetExplicitInterval(startTime, stopTime);
                prop4.Propagate();
                break;

            case AgEVePropagatorType.ePropagatorSPICE:
                IAgVePropagatorSPICE prop5 = sat.Propagator as IAgVePropagatorSPICE;
                prop5.EphemerisInterval.SetExplicitInterval(startTime, stopTime);
                prop5.Propagate();
                break;

            case AgEVePropagatorType.ePropagatorStkExternal:
                IAgVePropagatorStkExternal prop6 = sat.Propagator as IAgVePropagatorStkExternal;
                //prop6.EphemerisInterval.SetExplicitInterval(startTime, stopTime);
                break;

            case AgEVePropagatorType.ePropagatorTwoBody:
                IAgVePropagatorTwoBody prop7 = sat.Propagator as IAgVePropagatorTwoBody;
                prop7.EphemerisInterval.SetExplicitInterval(startTime, stopTime);
                prop7.Propagate();
                break;

            case AgEVePropagatorType.ePropagatorUserExternal:
                break;

            case AgEVePropagatorType.ePropagatorGreatArc:
                IAgVePropagatorGreatArc prop8 = sat.Propagator as IAgVePropagatorGreatArc;
                prop8.EphemerisInterval.SetExplicitInterval(startTime, stopTime);
                prop8.Propagate();
                break;

            case AgEVePropagatorType.ePropagatorBallistic:
                break;

            case AgEVePropagatorType.ePropagatorSimpleAscent:
                break;

            case AgEVePropagatorType.ePropagatorAstrogator:
                if (astgRun)
                {
                    IAgVADriverMCS driver = sat.Propagator as IAgVADriverMCS;
                    driver.RunMCS();
                }
                break;

            case AgEVePropagatorType.ePropagatorRealtime:
                break;

            case AgEVePropagatorType.ePropagatorGPS:
                IAgVePropagatorGPS prop9 = sat.Propagator as IAgVePropagatorGPS;
                prop9.EphemerisInterval.SetExplicitInterval(startTime, stopTime);
                prop9.Propagate();
                break;

            case AgEVePropagatorType.ePropagatorAviator:
                break;

            case AgEVePropagatorType.ePropagator11Param:
                IAgVePropagator11Param prop10 = sat.Propagator as IAgVePropagator11Param;
                prop10.EphemerisInterval.SetExplicitInterval(startTime, stopTime);
                prop10.Propagate();
                break;

            case AgEVePropagatorType.ePropagatorSP3:
                IAgVePropagatorSP3 prop11 = sat.Propagator as IAgVePropagatorSP3;
                //prop11.EphemerisInterval.SetExplicitInterval(startTime, stopTime);
                break;

            default:
                break;
            }
        }
Beispiel #10
0
        // old method

        /*    public List<MyWaypoint> CreateRoute(MyWaypoint startPoint, MyWaypoint endPoint)
         *  {
         *      // create route from waypointString
         *      RouteRequest routeRequest = new RouteRequest();
         *
         *      // Set the credentials using a valid Bing Maps key
         *      routeRequest.Credentials = new BingRouteService.Credentials();
         *      routeRequest.Credentials.ApplicationId = m_bingMapKey;
         *
         *      // tell them that we want points along the route
         *      routeRequest.Options = new RouteOptions();
         *      routeRequest.Options.RoutePathType = RoutePathType.Points;
         *
         *      //Parse user data to create array of waypoints
         *      BingRouteService.Waypoint[] waypoints = new BingRouteService.Waypoint[2];
         *
         *      BingRouteService.Waypoint point1 = new BingRouteService.Waypoint();
         *      BingRouteService.Location location1 = new BingRouteService.Location();
         *      location1.Latitude = startPoint.Latitude;
         *      location1.Longitude = startPoint.Longitude;
         *      point1.Location = location1;
         *      point1.Description = "Start";
         *      waypoints[0] = point1;
         *
         *      BingRouteService.Waypoint point2 = new BingRouteService.Waypoint();
         *      BingRouteService.Location location2 = new BingRouteService.Location();
         *      location2.Latitude = endPoint.Latitude;
         *      location2.Longitude = endPoint.Longitude;
         *      point2.Location = location2;
         *      point2.Description = "End";
         *      waypoints[1] = point2;
         *
         *      routeRequest.Waypoints = waypoints;
         *
         *      // Make the calculate route request
         *      RouteServiceClient routeService = new RouteServiceClient("BasicHttpBinding_IRouteService");
         *      RouteResponse routeResponse = routeService.CalculateRoute(routeRequest);
         *
         *      // pull out the lat/lon values
         *      List<MyWaypoint> returnPoints = new List<MyWaypoint>();
         *      if (routeResponse.Result.Legs.Length > 0)
         *      {
         *          //MessageBox.Show("Distance: " + routeResponse.Result.Summary.Distance.ToString()
         *          //    + " Time: " + routeResponse.Result.Summary.TimeInSeconds.ToString());
         *          foreach (BingRouteService.Location thisPt in routeResponse.Result.RoutePath.Points)
         *          {
         *              MyWaypoint thisPoint = new MyWaypoint();
         *
         *              thisPoint.Latitude = thisPt.Latitude;
         *              thisPoint.Longitude = thisPt.Longitude;
         *              //thisPoint.Altitude = GetAltitude(thisPoint.Latitude, thisPoint.Longitude);
         *              thisPoint.Altitude = 0.0;
         *
         *              returnPoints.Add(thisPoint);
         *          }
         *      }
         *
         *      return returnPoints;
         *  } */

        public void PopulateGvRoute(string gvName, List <Directions.MyWaypoint> routePoints,
                                    double speedValue, string speedUnits, bool useTerrain)
        {
            //MessageBox.Show($"Populate GvRoute method called! Name is {gvName}");// FOR DEBUGGING PURPOSES
            double turnRadius  = 15.0;  // meter
            double granularity = 100;   // meter

            switch (speedUnits)
            {
            case "km/h":
                m_root.UnitPreferences.SetCurrentUnit("Distance", "km");
                m_root.UnitPreferences.SetCurrentUnit("Time", "hr");
                turnRadius  /= 1000.0;
                granularity /= 1000.0;
                break;

            case "mph":
                m_root.UnitPreferences.SetCurrentUnit("Distance", "mi");
                m_root.UnitPreferences.SetCurrentUnit("Time", "hr");
                turnRadius  /= 1609.44;
                granularity /= 1609.44;
                break;

            case "m/s":
                m_root.UnitPreferences.SetCurrentUnit("Distance", "m");
                m_root.UnitPreferences.SetCurrentUnit("Time", "sec");
                break;
            }


            IAgStkObject     gvObject = m_root.CurrentScenario.Children.New(AgESTKObjectType.eGroundVehicle, gvName);
            IAgGroundVehicle gv       = gvObject as IAgGroundVehicle;

            gv.Graphics.WaypointMarker.IsWaypointMarkersVisible = false;
            //gv.Graphics.WaypointMarker.IsTurnMarkersVisible = false;
            IAgVOModel gvModel = gv.VO.Model;

            gvModel.ModelType = AgEModelType.eModelFile;
            IAgVOModelFile modelFile = gvModel.ModelData as IAgVOModelFile;

            if (File.Exists(installDir + @"Plugins\GreatArcPlugin\Model\mercslk.mdl"))
            {
                modelFile.Filename = installDir + @"Plugins\GreatArcPlugin\Model\mercslk.mdl";
            }

            gv.VO.Route.InheritTrackDataFrom2D = true;

            gv.SetRouteType(AgEVePropagatorType.ePropagatorGreatArc);
            IAgVePropagatorGreatArc prop = gv.Route as IAgVePropagatorGreatArc;

            foreach (Directions.MyWaypoint thisPt in routePoints)
            {
                IAgVeWaypointsElement thisVeWaypoint = prop.Waypoints.Add();
                thisVeWaypoint.Latitude  = thisPt.Latitude;
                thisVeWaypoint.Longitude = thisPt.Longitude;
                thisVeWaypoint.Altitude  = thisPt.Altitude;

                thisVeWaypoint.Speed      = speedValue;
                thisVeWaypoint.TurnRadius = turnRadius;
            }

            if (useTerrain)
            {
                prop.SetAltitudeRefType(AgEVeAltitudeRef.eWayPtAltRefTerrain);
                IAgVeWayPtAltitudeRefTerrain altRef = prop.AltitudeRef as IAgVeWayPtAltitudeRefTerrain;
                altRef.Granularity  = granularity;
                altRef.InterpMethod = AgEVeWayPtInterpMethod.eWayPtTerrainHeight;
            }

            prop.Propagate();
            //MessageBox.Show("GV route propagated!");// FOR DEBUGGING PURPOSES
        }
Beispiel #11
0
        private void createAircraft_Click(object sender, EventArgs e)
        {
            IAgVePropagatorGreatArc greatArcPropagator = createAircraftFromWaypoints();

            greatArcPropagator.Propagate();
        }