Added support for auto plan

This commit is contained in:
Lukáš Plevač 2023-10-01 17:43:57 +02:00
parent 912b4b650d
commit 42e624a3d4
10 changed files with 101 additions and 29 deletions

View File

View File

@ -1,10 +1,4 @@
masterUrl = "http://10.0.3.41:8000" masterUrl = "http://10.0.0.8"
pullInterval = 10 # in sec pullInterval = 120 # in sec
apiKey = "7b105947-65d6-40ba-bb4c-50b95a3ec1c8" apiKey = "672bccda-6eb3-4cae-bcbf-ed398e9d3dd9"
planInterval = 1200 # in sec
# do not edit
station = {
"lat": 0,
"lon": 0,
"alt": 0 #KM
}

View File

@ -4,16 +4,24 @@ import time
from datetime import datetime, timedelta from datetime import datetime, timedelta
from recorder import recorder from recorder import recorder
import sys
import traceback
import planner
def onRecorded(info): def onRecorded(info):
pass pass
i = 0
while True: while True:
try: try:
puller.pull() if (i % config.pullInterval) == 0:
puller.pull()
jobsDeltas = []
for job in puller.watingJobs: for job in puller.watingJobs:
print(f"Job {job['target']['name']} starts at {job['start']}")
jobsDeltas.append((job["start"] - datetime.utcnow()).total_seconds())
if job["start"] <= datetime.utcnow() + timedelta(seconds=60): if job["start"] <= datetime.utcnow() + timedelta(seconds=60):
if job["end"] <= datetime.utcnow(): if job["end"] <= datetime.utcnow():
puller.setFail(job["id"]) puller.setFail(job["id"])
@ -22,15 +30,21 @@ while True:
# start record # start record
puller.setRecording(job["id"]) puller.setRecording(job["id"])
curRecorder = recorder(job) curRecorder = recorder(job, puller.location)
curRecorder.start() curRecorder.start()
puller.watingJobs.remove(job) puller.watingJobs.remove(job)
if (i % 10) == 0 and len(jobsDeltas):
print(f"Next job in {min(jobsDeltas)}s")
# ask for planeble satellites
if (i % config.planInterval) == 0:
planner.planAll(puller.location)
i += 1
except: except Exception as inst:
print("[ERROR] main script fail restarting") print(f"[ERROR] main script fail restarting - error {inst}")
time.sleep(1)
time.sleep(config.pullInterval)

50
station/planner.py Normal file
View File

@ -0,0 +1,50 @@
from pyorbital.orbital import Orbital
from datetime import datetime, timedelta
import time
import puller
def plan(lat, lon, alt, tle, transmitter, receiver, name, delta = timedelta(seconds=1800), predictH = 24, horizon = 0):
#prevent plan same obsevation
last = datetime.utcnow()
for ob in puller.watingJobs:
last = max(ob["start"], last)
orb = Orbital(name, line1=tle["line1"], line2=tle["line2"])
passes = orb.get_next_passes(
datetime.utcnow() + delta,
predictH,
lon,
lat,
alt,
tol = 0.001,
horizon = horizon
)
for ob in passes:
start = ob[0]
end = ob[1]
if start < last:
print(f"[INFO] alredy planed {name} at {start}")
continue
print(f"[INFO] planed {name} at {start}")
puller.plan(transmitter, receiver, start, end)
def planAll(location):
planeble = puller.getPlaneble()
for transmitter in planeble:
plan(
location["lat"],
location["lon"],
location["alt"],
transmitter["locator"]["tle"],
transmitter["transmitter"],
transmitter["receiver"],
transmitter["name"]
)

View File

@ -8,6 +8,7 @@ import os
import pathlib import pathlib
watingJobs = [] watingJobs = []
location = {}
def getNewJobs(): def getNewJobs():
response = urlopen(config.masterUrl + "/api/observation/record?key=" + config.apiKey) response = urlopen(config.masterUrl + "/api/observation/record?key=" + config.apiKey)
@ -19,10 +20,23 @@ def getInfo():
data_json = json.loads(response.read()) data_json = json.loads(response.read())
return data_json return data_json
def getPlaneble():
response = urlopen(config.masterUrl + "/api/station/autoPlanable?key=" + config.apiKey)
data_json = json.loads(response.read())
return data_json
def apiSend(url, data, files=None): def apiSend(url, data, files=None):
r = requests.post(url=config.masterUrl + url, data=data, files=files) r = requests.post(url=config.masterUrl + url, data=data, files=files)
return r.text return r.text
def plan(transmitter, receiver, start, end):
apiSend("/api/observation/plan", {
"transmitter": transmitter,
"receiver": receiver,
"start": start.strftime("%Y-%m-%dT%H:%M:%S"),
"end": end .strftime("%Y-%m-%dT%H:%M:%S")
})
def setFail(observation): def setFail(observation):
apiSend("/api/observation/fail", {"id": observation}) apiSend("/api/observation/fail", {"id": observation})
@ -71,12 +85,12 @@ def parseNewJobs(jobs):
watingJobs.append(job) watingJobs.append(job)
def parseInfo(info): def parseInfo(info):
if "gps" in info: if "gps" in info["locator"]:
config.lat = info["gps"]["lat"] location["lat"] = info["locator"]["gps"]["lat"]
config.lon = info["gps"]["lon"] location["lon"] = info["locator"]["gps"]["lon"]
config.alt = info["gps"]["alt"] / 1000 location["alt"] = info["locator"]["gps"]["alt"] / 1000
print(f"[INFO] loaded locator from YAGS server LAT: {config.lat}, LON: {config.lon}, ALT: {config.alt}") #print(f"[INFO] loaded locator from YAGS server LAT: {position["lat"]}, LON: {position["lon"]}, ALT: {position["alt"]}")
def pull(): def pull():
#get station info #get station info

0
station/records/.gitkeep Normal file
View File

View File

@ -7,7 +7,7 @@
function tle($params) { function tle($params) {
// get all targets // get all targets
$targets = new \wsos\database\core\table(\DAL\targets::class); $targets = new \wsos\database\core\table(\DAL\target::class);
$updated = []; $updated = [];
foreach ($targets->getAll()->values as $target) { foreach ($targets->getAll()->values as $target) {
@ -23,9 +23,9 @@
$newTle = file_get_contents("https://celestrak.org/NORAD/elements/gp.php?CATNR={$norad}&FORMAT=tle"); $newTle = file_get_contents("https://celestrak.org/NORAD/elements/gp.php?CATNR={$norad}&FORMAT=tle");
$newTle = explode("\n", $newTle); $newTle = explode("\n", $newTle);
if (count($newTle) == 3) { //tle loaded if (count($newTle) >= 3) { //tle loaded
$locator["tle"]["line1"] = $newTle[1]; $locator["tle"]["line1"] = str_replace("\r", "", $newTle[1]);
$locator["tle"]["line2"] = $newTle[2]; $locator["tle"]["line2"] = str_replace("\r", "", $newTle[2]);
$updated[] = ["name" => $target->name->get(), "norad" => $norad]; $updated[] = ["name" => $target->name->get(), "norad" => $norad];

View File

@ -13,7 +13,7 @@
//register API functions //register API functions
include_once(__DIR__ . "/observations.php"); include_once(__DIR__ . "/observations.php");
include_once(__DIR__ . "/stations.php"); include_once(__DIR__ . "/stations.php");
include_once(__DIR__ . "/cron.php"); include_once(__DIR__ . "/crons.php");
//init API //init API
$api->serve($router->getArgs()); $api->serve($router->getArgs());