# Analyze Access Between a Satellite Constellation and an Aircraft

This example shows how to model the trajectory of an aircraft and a Walker-Delta satellite constellation, and how to analyze and visualize the access between the aircraft and the satellite constellation.

### Define Mission Start Date and Duration

Specify a start date and duration for the mission.

```mission.StartDate = datetime(2021,1,1,12,0,0); mission.Duration = hours(2.5);```

### Define the Aircraft Trajectory

The aircraft trajectory begins at a latitude of 39.5 degrees, longitude of -75 degrees, and an altitude of 10000m, ending at a latitude of 45.9 degrees, longitude of -61.2 degrees, and an altitude of 10000m. The flight time is 2.5 hours. The trajectory is sampled every 10 seconds. Use the `geoTrajectory` object to define the trajectory.

```startLLA = [39.5 -75 10000]; endLLA = [45.9 -61.2 10000]; timeOfTravel = [0 2.5*3600]; % s sampleRate = 10; % s aircraft.trajectory = geoTrajectory([startLLA;endLLA], timeOfTravel, SampleRate=sampleRate);```

Plot the aircraft trajectory using `geoplot`.

```timeSamples = 0:10:9000; % s lla = lookupPose(aircraft.trajectory, timeSamples); geoplot(lla(:,1), lla(:,2), "b-"); geolimits([30 50], [-110 -50]);```

### Add the Aircraft to a New Satellite Scenario

Create a `satelliteScenario` object. The `satelliteScenario` object represents a mission scenario consisting of satellites, ground stations, platforms, and the interactions between them. The object also enables the visualization of trajectories and analysis results.

```mission.scenario = satelliteScenario(mission.StartDate, ... mission.StartDate + mission.Duration, 60);```

Launch a Satellite Scenario Viewer to visualize the mission.

`mission.viewer = satelliteScenarioViewer(mission.scenario);`

Add the aircraft to the scenario. To represent the aircraft trajectory in a satellite scenario, use the `Platform` object with the custom trajectory represented by the `geoTrajectory` object. Use the `platform` function to create the `Platform` object. Hide the aircraft trajectory and visualize its ground track. Add a 3-D model to visualize the aircraft. Set the camera target to the aircraft.

```aircraft.obj = platform(mission.scenario,aircraft.trajectory, Name="Aircraft"); aircraft.obj.MarkerColor = "green"; hide(aircraft.obj.Path); show(aircraft.obj.GroundTrack); aircraft.obj.Visual3DModel = "NarrowBodyAirliner.glb"; camtarget(mission.viewer, aircraft.obj);```

Click on the Home button in the Satellite Scenario Viewer to return the viewer to an Earth-centric view.

### Add a Walker-Delta Constellation to the Satellite Scenario

Add a Walker-Delta constellation to the scenario using the `walkerDelta` function. The change in true anomaly for equivalent satellites in neighboring planes is calculated as Phasing*360/totalSatellites. Argument of Latitude defines the starting point for distribution of satellites along the first orbital track.

```constellation.Radius = 7200000; % meters constellation.Inclination = 70; % deg constellation.TotalSatellites = 12; constellation.GeometryPlanes = 4; constellation.Phasing = 1; constellation.ArgLat = 15; % deg constellation.obj = walkerDelta(mission.scenario, ... constellation.Radius, ... constellation.Inclination, ... constellation.TotalSatellites, ... constellation.GeometryPlanes, ... constellation.Phasing, ... ArgumentOfLatitude=constellation.ArgLat, ... Name="Sat");```

### Add Sensors to the Constellation

Add a conical sensor to each satellite with a configurable half angle. Enable field of view visualization in the Satellite Scenario Viewer. To assist in visualization, the sensor is mounted 10m from the satellite, in the +z direction.

```sensor.HalfAngle = 35; % deg sensor.Names = constellation.obj.Name + " satellite"; sensor.obj = conicalSensor(constellation.obj, MaxViewAngle=sensor.HalfAngle*2, MountingLocation=[0 0 10], Name=sensor.Names); sensor.FOV.obj = fieldOfView(sensor.obj);```

### Configure the Constellation to Point at the Aircraft

Configure all the satellites in the constellation to point at the aircraft.

`pointAt(constellation.obj,aircraft.obj);`

### Determine the Satellite-to-Aircraft Access Intervals

Analyze the access intervals between the satellites in the constellation and the aircraft.

```accessAnalysis.obj = access(sensor.obj, aircraft.obj); accessAnalysis.Intervals = accessIntervals(accessAnalysis.obj); accessAnalysis.Intervals = sortrows(accessAnalysis.Intervals,"StartTime"); disp(accessAnalysis.Intervals)```
``` Source Target IntervalNumber StartTime EndTime Duration StartOrbit EndOrbit __________________ __________ ______________ ____________________ ____________________ ________ __________ ________ "Sat_4 satellite" "Aircraft" 1 01-Jan-2021 12:14:00 01-Jan-2021 12:27:00 780 1 1 "Sat_9 satellite" "Aircraft" 1 01-Jan-2021 12:19:00 01-Jan-2021 12:35:00 960 1 1 "Sat_6 satellite" "Aircraft" 1 01-Jan-2021 12:48:00 01-Jan-2021 13:04:00 960 1 1 "Sat_8 satellite" "Aircraft" 1 01-Jan-2021 12:55:00 01-Jan-2021 13:10:00 900 1 1 "Sat_5 satellite" "Aircraft" 1 01-Jan-2021 13:23:00 01-Jan-2021 13:39:00 960 1 1 "Sat_7 satellite" "Aircraft" 1 01-Jan-2021 13:32:00 01-Jan-2021 13:46:00 840 1 2 "Sat_4 satellite" "Aircraft" 2 01-Jan-2021 13:57:00 01-Jan-2021 14:14:00 1020 2 2 "Sat_12 satellite" "Aircraft" 1 01-Jan-2021 13:57:00 01-Jan-2021 13:59:00 120 2 2 "Sat_9 satellite" "Aircraft" 2 01-Jan-2021 14:09:00 01-Jan-2021 14:22:00 780 2 2 "Sat_11 satellite" "Aircraft" 1 01-Jan-2021 14:26:00 01-Jan-2021 14:30:00 240 2 2 ```

### Calculate System-Wide Access Percentage

Determine the system-wide access percentage, which is the percentage of time from the scenario start time to stop time when at least one satellite can access the aircraft.

Calculate the access status between the aircraft and each individual satellite over time using `accessStatus`. Each row of the output array corresponds to a satellite in the constellation. Each column corresponds to time steps in the scenario. A value of `True` indicates that the satellite can access the aircraft at that specific time sample. The second output of `accessStatus` contains the timesteps of the scenario.

`[accessAnalysis.Status, mission.TimeSteps] = accessStatus(accessAnalysis.obj);`

Use `any` to perform a logical `OR` on all rows corresponding to access of each satellite to the aircraft. This results in a single row vector of logicals, in which a given element is true if at least one satellite can access the aircraft at the corresponding time step for a duration of one scenario sample time (60 seconds). Use `stairs` to plot system-wide access status with respect to time.

```accessAnalysis.SystemWideAccessStatus = any(accessAnalysis.Status, 1); stairs(mission.TimeSteps, accessAnalysis.SystemWideAccessStatus); ylim([-.2, 1.2]); xlabel("Time"); ylabel("System-Wide Access Status"); yticks([0,1]);```

Count the number of elements in the vector whose value is `True`. Multiply this quantity by the sample time of 60 seconds to determine the total time in seconds when at least one satellite can access the aircraft.

`accessAnalysis.SystemWideAccessDuration = sum(accessAnalysis.SystemWideAccessStatus) * mission.scenario.SampleTime; % seconds`

Calculate the system-wide access percentage.

```accessAnalysis.SystemWideAccessPercentage = (accessAnalysis.SystemWideAccessDuration/seconds(mission.Duration))*100; disp("System Wide Access = " + accessAnalysis.SystemWideAccessPercentage + " %")```
```System Wide Access = 67.3333 % ```

### Animate the Satellite Scenario

Configure the Satellite Scenario Viewer to hide orbits and labels.

```hide(constellation.obj.Orbit); constellation.obj.ShowLabel = false; aircraft.obj.ShowLabel = false;```

Play the scenario.

```mission.viewer.PlaybackSpeedMultiplier = 200; play(mission.scenario);```