Commit 91f1133d authored by Jeroen Vreeken's avatar Jeroen Vreeken
Browse files

Improved sat tracker which takes pass into account.

parent 9288e273
......@@ -53,6 +53,8 @@
#include "log.h"
#define TIME_OFFSET 2
#define EL_HORIZON -1.0
#define NEXTPASS_RANGE_T (3600 * 24)
char *command_host = "localhost";
int command_port = CONSOLE_COMMAND_PORT;
......@@ -69,6 +71,114 @@ char tle_str[139] =
struct location *location;
struct predict *predict = NULL;
static bool passknown = false;
static double az_aos = 0;
static time_t t_los;
void nextpass(struct predict *predict)
{
time_t t, tnow = time(NULL);
double JD;
struct ln_date date;
int i;
double prev_az, az, el;
bool aos = false, los = false;
bool cross_west = false, cross_east = false;
int t_west_1 = 0, t_east_1 = 0, t_west_2 = 0, t_east_2 = 0;
for (i = TIME_OFFSET; i < NEXTPASS_RANGE_T; i++) {
t = tnow + i;
ln_get_date_from_timet(&t, &date);
JD = ln_get_julian_day(&date);
predict_calc_azel(predict, JD, &az, &el);
az -= 180.0;
if (el >= EL_HORIZON && !aos) {
log_send(LOG_T_INFO,
"Next pass starts in %d seconds, az=%f", i, az);
printf(
"Next pass starts in %d seconds, az=%f\n", i, az);
aos = true;
prev_az = az;
az_aos = az;
}
if (el < EL_HORIZON && aos) {
log_send(LOG_T_INFO,
"Next pass ends in %d seconds", i);
printf(
"Next pass ends in %d seconds\n", i);
los = true;
t_los = tnow + i;
break;
}
if (aos && !los) {
printf("az: %f\n", az);
/* this is a pass */
if (az < -90.0 && prev_az > 90.0) {
/* crossed north */
prev_az -= 360.0;
}
if (az > 90.0 && prev_az < -90.0) {
/* crossed north */
prev_az += 360.0;
}
if (az <= 90.0 && prev_az > 90.0)
cross_west = true;
if (az >= -90.0 && prev_az < -90.0)
cross_east = true;
if (cross_east) {
t_west_2++;
} else {
t_west_1++;
}
if (cross_west) {
t_east_2++;
} else {
t_east_1++;
}
}
}
log_send(LOG_T_INFO,
"cross_west: %d, cross_east: %d, t_w_1: %d, t_w_2: %d, t_e_1: %d, t_e_2: %d",
cross_west, cross_east, t_west_1, t_west_2, t_east_1, t_east_2);
printf(
"cross_west: %d, cross_east: %d, t_w_1: %d, t_w_2: %d, t_e_1: %d, t_e_2: %d\n",
cross_west, cross_east, t_west_1, t_west_2, t_east_1, t_east_2);
if (t_west_1 >= t_west_2 &&
t_west_1 >= t_east_1 &&
t_west_1 >= t_east_2) {
/* if we begin with start az we might go through east late */
if (az_aos < -90) {
az_aos += 360;
}
} else if (t_west_2 >= t_west_1 &&
t_west_2 >= t_east_1 &&
t_west_2 >= t_east_2) {
/* if we begin with start az we go through east in wrong way first */
az_aos += 360;
} else if (t_east_1 >= t_west_1 &&
t_east_1 >= t_west_2 &&
t_east_1 >= t_east_2) {
/* if we begin with start az we might go through west late */
if (az_aos > 90) {
az_aos -= 360;
}
} else {
az_aos -= 360;
}
if (az_aos > 270.0)
az_aos = 270.0;
if (az_aos < -270.0)
az_aos = -270.0;
printf("new az_aos: %f\n", az_aos);
passknown = true;
}
bool set_tle(char newtle[139])
{
double lat, lon, alt;
......@@ -88,6 +198,7 @@ bool set_tle(char newtle[139])
if (predict)
predict_free(predict);
predict = predict_create(tle_str, lat, lon, alt);
nextpass(predict);
log_send(LOG_T_INFO, "Switching to new TLE");
......@@ -236,13 +347,15 @@ int main(int argc, char **argv)
cmd_srv = command_server_create(cmd_port, 0, 100);
if (!cmd_srv) {
printf("Could not open listen port for commands\n");
return -1;
} else {
command_server_handler_set(cmd_srv, handle_cmd);
}
stat_srv = status_server_create(stat_port, 0, 100);
if (!cmd_srv) {
if (!stat_srv) {
printf("Could not open listen port for status\n");
return -1;
}
weather = weather_create("Dwingeloo");
......@@ -274,6 +387,38 @@ int main(int argc, char **argv)
predict_calc_azel(predict, JD, &az, &el);
/* predict has an az range from 0 to 360 with 0 being South.
Dwingeloo has an az range from -270 to 270 with 0 being South
*/
az -= 180.0;
if (el < EL_HORIZON) {
if (!passknown)
nextpass(predict);
/* large step? */
if (fabs(az_aos - az) > 180.0) {
printf("Preset to aos position %f -> %f\n", az, az_aos);
az += copysign(360.0, az_aos);
}
} else {
/* check if we might have to compensate 360
degrees to prevent large az steps
*/
printf("fabs(%f - %f): %f\n", last_az,az,fabs(last_az- az));
if (az > 90.0 || az < -90.0) {
/* large step? */
if (fabs(last_az - az) > 200.0) {
printf("Swapping AZ\n");
az += copysign(360.0, last_az);
}
}
passknown = false;
}
if (t > t_los)
passknown = false;
if (refraction_enable) {
/* Get current weather */
temperature = weather_get_temperature(weather);
......@@ -284,11 +429,6 @@ int main(int argc, char **argv)
el += alt_adj;
}
/* libnova has an az range from 0 to 360 with 0 being South.
Dwingeloo has an az range from -270 to 270 with 0 being South
*/
az -= 180.0;
if (dt_model_enable) {
double daz, del;
......@@ -299,18 +439,7 @@ int main(int argc, char **argv)
el += del;
}
/* check if we might have compensate 360 degrees to
prevent large az steps
*/
printf("fabs(%f - %f): %f\n", last_az,az,fabs(last_az- az));
if (az > 90.0 || az < -90.0) {
/* large step? */
if (fabs(last_az - az) > 200.0) {
printf("Swapping AZ\n");
az += copysign(360.0, last_az);
}
}
if (!switch_cmd && fabs(last_az - az) > 180.0) {
if (!switch_cmd && fabs(last_az - az) > 90.0) {
if (switch_enabled)
log_send(LOG_T_WARNING,
"Disabling tracker to prevent large azimuth jump");
......@@ -319,6 +448,10 @@ int main(int argc, char **argv)
last_az = az;
/* Temporary limit on elevation */
if (el < 0.0)
el = 0.0;
printf("Setpoint: %d %f %f %f\n",
(unsigned int)t, JD, az, el);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment