|
1 | 1 | from typing import Final |
2 | 2 |
|
3 | | -from skyfield.api import EarthSatellite, Topos, load |
| 3 | +from skyfield.api import EarthSatellite, Topos, load, Timescale, Time |
4 | 4 |
|
5 | 5 | SPEED_OF_LIGHT_METERS_PER_SECOND: Final[int] = 299_792_458 |
| 6 | +TRANSMISSION_FREQUENCY_HZ: Final[float] = 433_920_000 # Default frequency, UW-Orbital's 433.920 MHz band |
6 | 7 |
|
7 | 8 | """ |
8 | 9 | @brief Holds logic for calculating doppler shift from TLS and ground station coordinates |
9 | 10 | @details Since we're not actually getting TLE or interfacing with HackRF it's not hooked up to anything yet |
10 | 11 | """ |
11 | 12 |
|
12 | | - |
13 | | -def load_satellite(tle_line1: str, tle_line2: str, name: str = "UW_SAT") -> EarthSatellite: |
| 13 | +# Change: made function take in time as a parameter instead |
| 14 | +def load_satellite(tle_line1: str, tle_line2: str, timescale: Timescale, name: str = "UW_SAT") -> EarthSatellite: |
14 | 15 | """ |
15 | 16 | @brief Loads satellite from TLE lines |
16 | 17 | @param tle_line1: First line of TLE |
17 | 18 | @param tle_line2: Second line of TLE |
| 19 | + @param timescale: Time for which satellite position is being calculated |
18 | 20 | @param name: Optional satellite name |
19 | 21 | @returns EarthSatellite object |
20 | 22 | """ |
21 | | - return EarthSatellite(tle_line1, tle_line2, name, load.timescale()) |
22 | | - |
| 23 | + return EarthSatellite(tle_line1, tle_line2, name, timescale) |
23 | 24 |
|
| 25 | +# Change: made function take in time as a parameter |
24 | 26 | def calculate_relative_velocity( |
25 | | - satellite: EarthSatellite, observer_latitude_deg: float, observer_longitude_deg: float, observer_altitude_m: float |
| 27 | + satellite: EarthSatellite, observer_latitude_deg: float, observer_longitude_deg: float, observer_altitude_m: float, time_current: Time |
26 | 28 | ) -> float: |
27 | 29 | """ |
28 | 30 | @brief Computes relative velocity between satellite and observer |
29 | 31 | @param satellite: EarthSatellite object |
30 | 32 | @param observer_latitude_degree: Latitude of observer in degrees |
31 | 33 | @param observer_longitude_deg: Longitude of observer in degrees |
32 | 34 | @param observer_altitude_m: Altitude of observer in meters |
| 35 | + @param time_current: Time for which relative velocity is being calculated |
33 | 36 | @returns Relative radial velocity in m/s (positive is moving away) |
34 | 37 | """ |
35 | | - time_current = load.timescale().now() |
36 | 38 |
|
37 | 39 | observer = Topos( |
38 | 40 | latitude_degrees=observer_latitude_deg, |
@@ -71,22 +73,27 @@ def compute_doppler_shift(frequency_hz: float, relative_velocity_m_s: float) -> |
71 | 73 | ) |
72 | 74 |
|
73 | 75 |
|
| 76 | +# Change: made trans freq a constant in the file that is passed instead of a parameter to the function |
74 | 77 | def calculate_doppler( |
75 | 78 | tle_line1: str, |
76 | 79 | tle_line2: str, |
77 | 80 | observer_latitude_deg: float, |
78 | 81 | observer_longitude_deg: float, |
79 | 82 | observer_altitude_m: float, |
80 | | - transmission_frequency_hz: float = 433_920_000, # Default frequency, UW-Orbital's 433.920 MHz band |
| 83 | + timescale: Timescale, |
| 84 | + time_current: Time |
81 | 85 | ) -> float: |
82 | 86 | """ |
83 | 87 | @brief High-level function to compute Doppler shift |
84 | 88 | @param tle_line1: First line of TLE data |
85 | 89 | @param tle_line2: Second line of TLE data |
86 | | - @param observer_coords: Tuple of (latitude_deg, longitude_deg, altitude_m) |
87 | | - @param transmission_frequency_hz: Frequency of the satellite transmission in Hz |
| 90 | + @param observer_latitude_deg: Latitude of observer in degrees |
| 91 | + @param observer_longitude_deg: Longitude of observer in degrees |
| 92 | + @param observer_altitude_m: Altitude of observer in meters |
| 93 | + @param timescale: Time for which satellite position is being calculated |
| 94 | + @param time_current: Time for which Doppler shift is being calculated |
88 | 95 | @returns Doppler-shifted frequency in Hz |
89 | 96 | """ |
90 | | - sat = load_satellite(tle_line1, tle_line2) |
91 | | - rv = calculate_relative_velocity(sat, observer_latitude_deg, observer_longitude_deg, observer_altitude_m) |
92 | | - return compute_doppler_shift(transmission_frequency_hz, rv) |
| 97 | + sat = load_satellite(tle_line1, tle_line2, timescale) |
| 98 | + rv = calculate_relative_velocity(sat, observer_latitude_deg, observer_longitude_deg, observer_altitude_m, time_current) |
| 99 | + return compute_doppler_shift(TRANSMISSION_FREQUENCY_HZ, rv) |
0 commit comments