celestia-gnss/tle2ssc

120 lines
3.7 KiB
Python
Executable File
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#!/usr/bin/python3
# tle2ssc
# Convert a TLE into an .ssc file for Celestia
#
# Usage:
# tle2ssc [filename]
# Example:
# tle2ssc foo-tle.txt
import os
import skyfield
import math
from datetime import datetime
from skyfield.api import EarthSatellite, load, wgs84
from sgp4.api import Satrec, WGS72
xpdotp = 1440.0 / (2.0 * math.pi)
# For now dev with just one Galileo satellite
satellite_name='GSAT0101'
satellite_number=37846
#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()
t = ts.now()
# 2022-05-20 02:17:30
#t = ts.utc(2022, 5, 20, 2, 17, 30)
by_number = {sat.model.satnum: sat for sat in satellites}
satellite = by_number[satellite_number]
satellite_radius=0.005
satellite_epoch=satellite.model.jdsatepoch
# The unique satellite NORAD catalog number given in the TLE file.
# Use one defined above.
#satellite_number=satellite.model.satnum
# Satellite classification, or else 'U' for “Unknown”
satellite_classification=satellite.model.classification
# International designator
satellite_intldesg=satellite.model.intldesg
# Full four-digit year of this element sets epoch moment.
satellite_epochyr=satellite.model.epochyr
# Fractional days into the year of the epoch moment.
satellite_epochdays=satellite.model.epochdays
# Julian date of the epoch (computed from epochyr and epochdays).
satellite_jdsatepoch=satellite.model.jdsatepoch
# First time derivative of the mean motion (ignored by SGP4).
satellite_ndot=satellite.model.ndot
# Second time derivative of the mean motion (ignored by SGP4).
satellite_nddot=satellite.model.nddot
# Ballistic drag coefficient B* in inverse earth radii.
satellite_bstar=satellite.model.bstar
# Ephemeris type (ignored by SGP4 as determination now automatic)
satellite_ephtype=satellite.model.ephtype
# Element number
satellite_elnum=satellite.model.elnum
# Inclination in radians. Convert radians to degrees.
satellite_inclination=math.degrees(satellite.model.inclo)
# Satellite Inclination and Obliquity are the same
satellite_obliquity=math.degrees(satellite.model.inclo)
# 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)
# Eccentricity.
satellite_eccentricity=satellite.model.ecco
# Argument of perigee in radians.
satellite_arg_of_pericenter=math.degrees(satellite.model.argpo)
# Mean anomaly in radians.
satellite_mean_anomoly=math.degrees(satellite.model.mo)
# 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
# SemiMajor Axis
satellite_semimajor_axis=pow((pow(satellite_period,2) * 75371000000000),0.33333333)
print('"', satellite_name, '-', satellite_number, '" ','"Sol/Earth" {',sep="")
print(' Class "spacecraft"')
print(' # Mesh "foo.3ds XXX"')
print(' radius', satellite_radius)
print()
print(' EllipticalOrbit {')
print(' Epoch', satellite_epoch)
print(' Period', satellite_period)
print(' SemiMajorAxis', satellite_semimajor_axis)
print(' Eccentricity', satellite_eccentricity)
print(' Inclination', satellite_inclination)
print(' AscendingNode', satellite_ascending_node)
print(' ArgOfPericenter', satellite_arg_of_pericenter)
print(' MeanAnomaly', satellite_mean_anomoly)
print(' }')
print(' Obliquity', satellite_obliquity)
print(' EquatorAscendingNode', satellite_equator_ascending_node)
print(' RotationOffset 312.7348 XXX')
print(' # Orientation [ ]')
print('}')