Commit 5f3aa23c authored by Jeroen Vreeken's avatar Jeroen Vreeken
Browse files

prevent large moves

parent f829ab49
...@@ -359,6 +359,11 @@ int main(int argc, char **argv) ...@@ -359,6 +359,11 @@ int main(int argc, char **argv)
az * 2 * M_PI / 360.0, t); az * 2 * M_PI / 360.0, t);
setpoint_command_setpoint_time(sp_command_el, setpoint_command_setpoint_time(sp_command_el,
el * 2 * M_PI / 360.0, t); el * 2 * M_PI / 360.0, t);
} else {
/* not enabled, send idle just in case we were
still moving */
setpoint_command_speed(sp_command_az, 0.0);
setpoint_command_speed(sp_command_el, 0.0);
} }
} }
......
...@@ -67,7 +67,7 @@ char tle_str[139] = ...@@ -67,7 +67,7 @@ char tle_str[139] =
struct location *location; struct location *location;
struct predict *predict = NULL; struct predict *predict = NULL;
void set_tle(void) bool set_tle(char newtle[139])
{ {
double lat, lon, alt; double lat, lon, alt;
...@@ -76,14 +76,18 @@ void set_tle(void) ...@@ -76,14 +76,18 @@ void set_tle(void)
alt = location_get_altitude(location); alt = location_get_altitude(location);
printf("Using lat: %f, lon: %f, alt: %f\n", lat, lon, alt); printf("Using lat: %f, lon: %f, alt: %f\n", lat, lon, alt);
if (predict_tle_check(tle_str)) { if (predict_tle_check(newtle)) {
printf("Invallid TLE\n"); printf("Invallid TLE\n");
return; return false;
} }
strcpy(tle_str, newtle);
if (predict) if (predict)
predict_free(predict); predict_free(predict);
predict = predict_create(tle_str, lat, lon, alt); predict = predict_create(tle_str, lat, lon, alt);
return true;
} }
...@@ -91,6 +95,7 @@ void set_tle(void) ...@@ -91,6 +95,7 @@ void set_tle(void)
bool refraction_enable = false; bool refraction_enable = false;
bool dt_model_enable = false; bool dt_model_enable = false;
bool switch_enabled = false; bool switch_enabled = false;
bool switch_cmd = false;
struct compensation_switch { struct compensation_switch {
char *name; char *name;
...@@ -203,14 +208,20 @@ void handle_cmd(struct cmd_client *cmd) ...@@ -203,14 +208,20 @@ void handle_cmd(struct cmd_client *cmd)
printf("found switch %s\n", name); printf("found switch %s\n", name);
if (val[0] == '1') { if (val[0] == '1') {
*compensation_switches[i].value = true; *compensation_switches[i].value = true;
if (!strcmp(name, "enabled")) {
switch_cmd = true;
}
} else { } else {
*compensation_switches[i].value = false; *compensation_switches[i].value = false;
} }
} }
} }
if (!strcmp(name, "tle")) { if (!strcmp(name, "tle")) {
strcpy(tle_str, val); char newtle[139];
set_tle();
strcpy(newtle, val);
if (!set_tle(newtle))
switch_enabled = false;
} }
} }
} }
...@@ -328,7 +339,7 @@ int main(int argc, char **argv) ...@@ -328,7 +339,7 @@ int main(int argc, char **argv)
alt = location_get_altitude(location); alt = location_get_altitude(location);
printf("Using lat: %f, lon: %f, alt: %f\n", lat, lon, alt); printf("Using lat: %f, lon: %f, alt: %f\n", lat, lon, alt);
set_tle(); set_tle(tle_str);
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
...@@ -415,18 +426,17 @@ int main(int argc, char **argv) ...@@ -415,18 +426,17 @@ int main(int argc, char **argv)
/* check if we might have compensate 360 degrees to /* check if we might have compensate 360 degrees to
prevent large az steps prevent large az steps
*/ */
printf("fabs(%f - %f): %f\n", last_az,az,fabs(last_az- az));
if (az > 90.0 || az < -90.0) { if (az > 90.0 || az < -90.0) {
/* If the sat is very low, /* large step? */
don't bother swapping */ if (fabs(last_az - az) > 200.0) {
printf("fabs(%f - %f): %f\n", last_az,az,fabs(last_az- az)); printf("Swapping AZ\n");
if (el > -20.0) { az += copysign(360.0, last_az);
/* 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) {
switch_enabled = false;
}
last_az = az; last_az = az;
...@@ -444,6 +454,7 @@ int main(int argc, char **argv) ...@@ -444,6 +454,7 @@ int main(int argc, char **argv)
setpoint_command_speed(sp_command_az, 0.0); setpoint_command_speed(sp_command_az, 0.0);
setpoint_command_speed(sp_command_el, 0.0); setpoint_command_speed(sp_command_el, 0.0);
} }
switch_cmd = false;
} }
FD_ZERO(&fdset_rx); FD_ZERO(&fdset_rx);
......
...@@ -354,6 +354,11 @@ int main(int argc, char **argv) ...@@ -354,6 +354,11 @@ int main(int argc, char **argv)
az * 2 * M_PI / 360.0, t); az * 2 * M_PI / 360.0, t);
setpoint_command_setpoint_time(sp_command_el, setpoint_command_setpoint_time(sp_command_el,
el * 2 * M_PI / 360.0, t); el * 2 * M_PI / 360.0, t);
} else {
/* not enabled, send idle just in case we were
still moving */
setpoint_command_speed(sp_command_az, 0.0);
setpoint_command_speed(sp_command_el, 0.0);
} }
} }
......
Supports Markdown
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