Skip to content

Commit

Permalink
cancel rotation if negative elevation requested
Browse files Browse the repository at this point in the history
This can happen if TLE is stale.
  • Loading branch information
dernasherbrezon committed Sep 4, 2024
1 parent 52d2df3 commit f195065
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/main/java/ru/r2cloud/satellite/RotatorService.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ public void run() {
throw new RuntimeException("observation stopped");
}
Position currentPosition = predict.getSatellitePosition(current, groundStation, tlePropagator);
if (currentPosition.getElevation() < 0.0) {
LOG.info("[{}] negative elevation requested. most likely stale or invalid tle. cancelling rotation", req.getId());
throw new RuntimeException("negative elevation");
}
if (previousPosition != null) {
double tolerance = config.getTolerance();
double azimuthDelta = Math.abs(currentPosition.getAzimuth() - previousPosition.getAzimuth());
Expand Down
28 changes: 25 additions & 3 deletions src/test/java/ru/r2cloud/satellite/RotatorServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,24 @@ public class RotatorServiceTest {
private int serverPort;
private CollectingRequestHandler requestHandler;

@Test
public void testStaleTle() throws Exception {
ObservationRequest req = createRequest();
req.getTle().getRaw()[1] = "1 53376U 22096G 24125.30500733 .01222779 97906-3 12443-2 0 9998";
req.getTle().getRaw()[2] = "2 53376 97.3733 46.7756 0008493 160.3534 199.8078 16.11052950 97692";
req.setStartTimeMillis(1725198038000L);
req.setEndTimeMillis(1725199038000L);
int times = (int) ((req.getEndTimeMillis() - req.getStartTimeMillis()) / 70000);
service = new RotatorService(createValidConfig(), predict, new ScheduleFixedTimesTheadPoolFactory(times), new SteppingClock(req.getStartTimeMillis(), 70000));
service.start();
try {
assertNotNull(service.schedule(req, 1725198028000L, null));
} catch (RuntimeException e) {
assertEquals("negative elevation", e.getMessage());
}
assertPositions("expected/rotctrld-requests-stale-tle.txt", requestHandler.getRequests());
}

@Test
public void testRotctrldDuringPeriodOfUnavailability() {
SequentialRequestHandler handler = new SequentialRequestHandler(new SimpleRequestHandler("test\n"), new SimpleRequestHandler("RPRT 0\n"), new SimpleRequestHandler("RPRT 1\n"), new SimpleRequestHandler("test\n"), new SimpleRequestHandler("RPRT 0\n"));
Expand Down Expand Up @@ -114,14 +132,18 @@ public void testSuccess() throws Exception {
service = new RotatorService(createValidConfig(), predict, new ScheduleFixedTimesTheadPoolFactory(times), new SteppingClock(req.getStartTimeMillis(), 1000));
service.start();
assertNotNull(service.schedule(req, req.getStartTimeMillis(), null));
try (BufferedReader r = new BufferedReader(new InputStreamReader(RotatorService.class.getClassLoader().getResourceAsStream("expected/rotctrld-requests.txt"), StandardCharsets.UTF_8))) {
assertPositions("expected/rotctrld-requests.txt", requestHandler.getRequests());
}

private static void assertPositions(String expectedFile, List<String> requests) throws Exception {
try (BufferedReader r = new BufferedReader(new InputStreamReader(RotatorServiceTest.class.getClassLoader().getResourceAsStream(expectedFile), StandardCharsets.UTF_8))) {
String curLine = null;
int i = 0;
while ((curLine = r.readLine()) != null) {
assertPosition(curLine, requestHandler.getRequests().get(i));
assertPosition(curLine, requests.get(i));
i++;
}
assertEquals(i, requestHandler.getRequests().size());
assertEquals(i, requests.size());
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/test/resources/expected/rotctrld-requests-stale-tle.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
\set_pos 352.91692294756064 64.98025517525099
\set_pos 349.69881272805304 58.18332105196653
\set_pos 347.6137812645207 51.250694544049225
\set_pos 346.1633530169924 44.21286500405056
\set_pos 345.10232199719513 37.08555430799149
\set_pos 344.29620634607767 29.87814935460905
\set_pos 343.66475425736485 22.596968294139533
\set_pos 343.15656291222 15.246690670925322
\set_pos 342.7364638181337 7.831040504760989
\set_pos 342.37865424271996 0.3531322367814761

0 comments on commit f195065

Please sign in to comment.