celestia-gnss/tle2ssc

126 lines
4.0 KiB
Plaintext
Raw Normal View History

2022-05-21 12:39:21 -06:00
#!/usr/bin/python3
# tle2ssc
# Convert a TLE into an .ssc file for Celestia
#
# Usage:
# tle2ssc [filename]
# Example:
# tle2ssc foo-tle.txt
2022-05-21 17:54:49 -06:00
import os
import math
2022-05-21 20:32:35 -06:00
from math import remainder
2022-05-21 13:51:34 -06:00
from datetime import datetime
2022-05-21 17:54:49 -06:00
from sgp4.api import Satrec, WGS72
2022-05-21 20:32:35 -06:00
from skyfield.api import EarthSatellite, load, wgs84
2022-05-21 17:54:49 -06:00
2022-05-21 19:04:08 -06:00
xpdotp = 1440.0 / (2.0 * math.pi)
# For now dev with just one Galileo satellite
satellite_name='GSAT0101'
satellite_number=37846
2022-05-21 17:54:49 -06:00
#satellites_url = 'http://celestrak.com/NORAD/elements/galileo.txt'
satellites_url = './extras/galileo-gnss/galileo.txt'
satellites = load.tle_file(satellites_url)
ts = load.timescale()
2022-05-21 19:04:08 -06:00
t = ts.now()
2022-05-21 17:54:49 -06:00
# 2022-05-20 02:17:30
2022-05-21 19:04:08 -06:00
#t = ts.utc(2022, 5, 20, 2, 17, 30)
2022-05-21 17:54:49 -06:00
by_number = {sat.model.satnum: sat for sat in satellites}
2022-05-21 19:04:08 -06:00
satellite = by_number[satellite_number]
2022-05-21 17:54:49 -06:00
2022-05-21 19:04:08 -06:00
satellite_radius=0.005
satellite_epoch=satellite.model.jdsatepoch
2022-05-21 17:54:49 -06:00
# The unique satellite NORAD catalog number given in the TLE file.
2022-05-21 19:04:08 -06:00
# Use one defined above.
#satellite_number=satellite.model.satnum
2022-05-21 17:54:49 -06:00
# Satellite classification, or else 'U' for “Unknown”
satellite_classification=satellite.model.classification
2022-05-21 19:04:08 -06:00
2022-05-21 17:54:49 -06:00
# International designator
satellite_intldesg=satellite.model.intldesg
2022-05-21 19:04:08 -06:00
2022-05-21 17:54:49 -06:00
# Full four-digit year of this element sets epoch moment.
satellite_epochyr=satellite.model.epochyr
2022-05-21 19:04:08 -06:00
2022-05-21 17:54:49 -06:00
# Fractional days into the year of the epoch moment.
satellite_epochdays=satellite.model.epochdays
2022-05-21 19:04:08 -06:00
2022-05-21 17:54:49 -06:00
# Julian date of the epoch (computed from epochyr and epochdays).
satellite_jdsatepoch=satellite.model.jdsatepoch
2022-05-21 19:04:08 -06:00
2022-05-21 17:54:49 -06:00
# First time derivative of the mean motion (ignored by SGP4).
satellite_ndot=satellite.model.ndot
2022-05-21 19:04:08 -06:00
2022-05-21 17:54:49 -06:00
# Second time derivative of the mean motion (ignored by SGP4).
satellite_nddot=satellite.model.nddot
2022-05-21 19:04:08 -06:00
2022-05-21 17:54:49 -06:00
# Ballistic drag coefficient B* in inverse earth radii.
satellite_bstar=satellite.model.bstar
2022-05-21 19:04:08 -06:00
2022-05-21 17:54:49 -06:00
# Ephemeris type (ignored by SGP4 as determination now automatic)
satellite_ephtype=satellite.model.ephtype
# Element number
satellite_elnum=satellite.model.elnum
2022-05-21 13:51:34 -06:00
2022-05-21 17:54:49 -06:00
# Inclination in radians. Convert radians to degrees.
satellite_inclination=math.degrees(satellite.model.inclo)
2022-05-21 19:04:08 -06:00
# Satellite Inclination and Obliquity are the same
2022-05-21 17:54:49 -06:00
satellite_obliquity=math.degrees(satellite.model.inclo)
2022-05-21 13:51:34 -06:00
2022-05-21 17:54:49 -06:00
# Right ascension of ascending node in radians. Convert to degrees.
satellite_ascending_node=math.degrees(satellite.model.nodeo)
satellite_equator_ascending_node=math.degrees(satellite.model.nodeo)
2022-05-21 13:51:34 -06:00
2022-05-21 17:54:49 -06:00
# Eccentricity.
satellite_eccentricity=satellite.model.ecco
2022-05-21 13:51:34 -06:00
2022-05-21 17:54:49 -06:00
# Argument of perigee in radians.
satellite_arg_of_pericenter=math.degrees(satellite.model.argpo)
2022-05-21 13:51:34 -06:00
2022-05-21 17:54:49 -06:00
# Mean anomaly in radians.
2022-05-21 20:32:35 -06:00
satellite_mean_anomaly=math.degrees(satellite.model.mo)
2022-05-21 17:54:49 -06:00
# Mean motion in radians per minute.
satellite_no_kozai=satellite.model.no_kozai
satellite_period=(1 / (satellite.model.no_kozai * xpdotp))
# Revolution number at epoch [Revs]
satellite_revnum=satellite.model.revnum
2022-05-21 20:32:35 -06:00
# Semi-Major Axis
2022-05-21 18:08:06 -06:00
satellite_semimajor_axis=pow((pow(satellite_period,2) * 75371000000000),0.33333333)
2022-05-21 17:54:49 -06:00
2022-05-21 20:32:35 -06:00
# Rotation Offset
satellite_rotation_offset=((satellite_arg_of_pericenter)+(satellite_mean_anomaly)+360*
((2451545-satellite_epochdays)/satellite_period-
round((2451545-satellite_epochdays)/satellite_period)))
# Output for .ssc file
2022-05-21 17:54:49 -06:00
print('"', satellite_name, '-', satellite_number, '" ','"Sol/Earth" {',sep="")
2022-05-21 14:30:57 -06:00
print(' Class "spacecraft"')
2022-05-21 20:32:35 -06:00
print(' # Mesh "foo.3ds" XXX')
2022-05-21 17:54:49 -06:00
print(' radius', satellite_radius)
2022-05-21 14:30:57 -06:00
print()
print(' EllipticalOrbit {')
2022-05-21 17:54:49 -06:00
print(' Epoch', satellite_epoch)
print(' Period', satellite_period)
2022-05-21 18:08:06 -06:00
print(' SemiMajorAxis', satellite_semimajor_axis)
2022-05-21 17:54:49 -06:00
print(' Eccentricity', satellite_eccentricity)
print(' Inclination', satellite_inclination)
print(' AscendingNode', satellite_ascending_node)
print(' ArgOfPericenter', satellite_arg_of_pericenter)
2022-05-21 20:32:35 -06:00
print(' MeanAnomaly', satellite_mean_anomaly)
2022-05-21 14:30:57 -06:00
print(' }')
2022-05-21 17:54:49 -06:00
print(' Obliquity', satellite_obliquity)
print(' EquatorAscendingNode', satellite_equator_ascending_node)
2022-05-21 20:32:35 -06:00
print(' RotationOffset', satellite_rotation_offset)
2022-05-21 14:30:57 -06:00
print(' # Orientation [ ]')
print('}')
2022-05-21 13:51:34 -06:00