mirror of
https://github.com/Lukas0025/YAGS.git
synced 2025-04-04 06:51:33 +01:00
Added support for auto plan
This commit is contained in:
parent
912b4b650d
commit
42e624a3d4
Binary file not shown.
Binary file not shown.
0
station/artefacts/.gitkeep
Normal file
0
station/artefacts/.gitkeep
Normal file
@ -1,10 +1,4 @@
|
||||
masterUrl = "http://10.0.3.41:8000"
|
||||
pullInterval = 10 # in sec
|
||||
apiKey = "7b105947-65d6-40ba-bb4c-50b95a3ec1c8"
|
||||
|
||||
# do not edit
|
||||
station = {
|
||||
"lat": 0,
|
||||
"lon": 0,
|
||||
"alt": 0 #KM
|
||||
}
|
||||
masterUrl = "http://10.0.0.8"
|
||||
pullInterval = 120 # in sec
|
||||
apiKey = "672bccda-6eb3-4cae-bcbf-ed398e9d3dd9"
|
||||
planInterval = 1200 # in sec
|
@ -4,16 +4,24 @@ import time
|
||||
from datetime import datetime, timedelta
|
||||
from recorder import recorder
|
||||
|
||||
import sys
|
||||
import traceback
|
||||
import planner
|
||||
|
||||
def onRecorded(info):
|
||||
pass
|
||||
|
||||
i = 0
|
||||
while True:
|
||||
try:
|
||||
puller.pull()
|
||||
if (i % config.pullInterval) == 0:
|
||||
puller.pull()
|
||||
|
||||
jobsDeltas = []
|
||||
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["end"] <= datetime.utcnow():
|
||||
puller.setFail(job["id"])
|
||||
@ -22,15 +30,21 @@ while True:
|
||||
# start record
|
||||
puller.setRecording(job["id"])
|
||||
|
||||
curRecorder = recorder(job)
|
||||
curRecorder = recorder(job, puller.location)
|
||||
curRecorder.start()
|
||||
|
||||
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:
|
||||
print("[ERROR] main script fail restarting")
|
||||
except Exception as inst:
|
||||
print(f"[ERROR] main script fail restarting - error {inst}")
|
||||
|
||||
|
||||
|
||||
|
||||
time.sleep(config.pullInterval)
|
||||
time.sleep(1)
|
50
station/planner.py
Normal file
50
station/planner.py
Normal 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"]
|
||||
)
|
@ -8,6 +8,7 @@ import os
|
||||
import pathlib
|
||||
|
||||
watingJobs = []
|
||||
location = {}
|
||||
|
||||
def getNewJobs():
|
||||
response = urlopen(config.masterUrl + "/api/observation/record?key=" + config.apiKey)
|
||||
@ -19,10 +20,23 @@ def getInfo():
|
||||
data_json = json.loads(response.read())
|
||||
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):
|
||||
r = requests.post(url=config.masterUrl + url, data=data, files=files)
|
||||
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):
|
||||
apiSend("/api/observation/fail", {"id": observation})
|
||||
|
||||
@ -71,12 +85,12 @@ def parseNewJobs(jobs):
|
||||
watingJobs.append(job)
|
||||
|
||||
def parseInfo(info):
|
||||
if "gps" in info:
|
||||
config.lat = info["gps"]["lat"]
|
||||
config.lon = info["gps"]["lon"]
|
||||
config.alt = info["gps"]["alt"] / 1000
|
||||
if "gps" in info["locator"]:
|
||||
location["lat"] = info["locator"]["gps"]["lat"]
|
||||
location["lon"] = info["locator"]["gps"]["lon"]
|
||||
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():
|
||||
#get station info
|
||||
|
0
station/records/.gitkeep
Normal file
0
station/records/.gitkeep
Normal file
@ -7,7 +7,7 @@
|
||||
|
||||
function tle($params) {
|
||||
// get all targets
|
||||
$targets = new \wsos\database\core\table(\DAL\targets::class);
|
||||
$targets = new \wsos\database\core\table(\DAL\target::class);
|
||||
|
||||
$updated = [];
|
||||
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 = explode("\n", $newTle);
|
||||
|
||||
if (count($newTle) == 3) { //tle loaded
|
||||
$locator["tle"]["line1"] = $newTle[1];
|
||||
$locator["tle"]["line2"] = $newTle[2];
|
||||
if (count($newTle) >= 3) { //tle loaded
|
||||
$locator["tle"]["line1"] = str_replace("\r", "", $newTle[1]);
|
||||
$locator["tle"]["line2"] = str_replace("\r", "", $newTle[2]);
|
||||
|
||||
$updated[] = ["name" => $target->name->get(), "norad" => $norad];
|
||||
|
@ -13,7 +13,7 @@
|
||||
//register API functions
|
||||
include_once(__DIR__ . "/observations.php");
|
||||
include_once(__DIR__ . "/stations.php");
|
||||
include_once(__DIR__ . "/cron.php");
|
||||
include_once(__DIR__ . "/crons.php");
|
||||
|
||||
//init API
|
||||
$api->serve($router->getArgs());
|
Loading…
x
Reference in New Issue
Block a user