From cad64e5bf43b58c92f1a56ce3df3abc96f6e82f1 Mon Sep 17 00:00:00 2001 From: Tim Schubert Date: Tue, 14 Jul 2020 10:56:09 +0200 Subject: [PATCH] Add waypoint generator --- utils/tle/import-tle.sh | 30 ++++++++++++++++++++ utils/tle/tle2wps.py | 61 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100755 utils/tle/import-tle.sh create mode 100755 utils/tle/tle2wps.py diff --git a/utils/tle/import-tle.sh b/utils/tle/import-tle.sh new file mode 100755 index 0000000..4162d9e --- /dev/null +++ b/utils/tle/import-tle.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +set -u +set -e + +search=$1 + +# Get the ids of sats matching the search term +if [ ! -f ids.txt ] +then + curl https://celestrak.com/pub/satcat.txt | grep "$search" | cut -b14-18 > ids.txt +fi + +# Download TLE data for each sat +while read id +do + if [ ! -f $id.txt ] + then + wget "https://celestrak.com/satcat/tle.php?CATNR=$id" -O $id.txt + fi + # 6000 s ~ 95 min ~ 1 orbital period +done < ids.txt + +while read id +do + if [ ! -f $id.waypoints ] + then + ./tle2wps.py $id.txt 2020 08 28 6000 > $id.waypoints + fi +done < ids.txt diff --git a/utils/tle/tle2wps.py b/utils/tle/tle2wps.py new file mode 100755 index 0000000..7c8cb35 --- /dev/null +++ b/utils/tle/tle2wps.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 + +""" +Creates a stream of waypoints using SGP4 and two-line element (TLE) information + +Up-to-date TLEs can be obtained from [Celestrak](https://celestrak.com/satcat/search.php) +""" + +import logging as log +import argparse + +from datetime import datetime +from skyfield.api import EarthSatellite, Time, load, utc + +log.basicConfig(level=log.DEBUG) + +""" +Class for exporting `ns3::Waypoint` in its own serialized format. + +See `ns3::Waypoint::operator <<` +""" +class Waypoint: + def __init__(self, time, x, y, z): + self.time = time + self.x = x + self.y = y + self.z = z + + def __repr__(self): + return("%fs $ %f:%f:%f" % (self.time, self.x, self.y, self.z)) + + +""" +Use Skyfield to generate the waypoints +""" +if __name__ == "__main__": + parser = argparse.ArgumentParser(description='Process some integers.') + parser.add_argument('tle', type=str, help='Two-line element data') + parser.add_argument('year', type=int, help='year to start at') + parser.add_argument('month', type=int, help='month to start at') + parser.add_argument('day', type=int, help='day to start at') + parser.add_argument('duration', type=int, help='duration in seconds') + args = parser.parse_args() + + ts = load.timescale(builtin=True) + sats = load.tle_file(args.tle) + log.info("Loaded %d satellites" % len(sats)) + + duration = args.duration + + for sat in sats: + log.info("Generating waypoints for %s" % sat.name) + # skyfield will automatically overflow the seconds and produce the next correct second + t_start = ts.utc(year=args.year, month=args.month, day=args.day) + for t in ts.utc(year=args.year, month=args.month, day=args.day, second=range(1, duration, 1)): + geocentric = sat.at(t) + t_rel = (t.tai - t_start.tai) * 10**5 + d = geocentric.itrf_xyz().m + wp = Waypoint(t_rel, d[0], d[1], d[2]) + print(wp) +