Skip to content

Commit

Permalink
better handling stale tle
Browse files Browse the repository at this point in the history
orekit can throw exception and crash application on startup
  • Loading branch information
dernasherbrezon committed Jul 21, 2024
1 parent 468e977 commit 0120e6b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/main/java/ru/r2cloud/predict/MaxElevationHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public class MaxElevationHandler implements EventHandler<ElevationExtremumDetector> {

private AbsoluteDate date;
private double maxElevation;
private final double maxElevation;

public MaxElevationHandler(double maxElevation) {
this.maxElevation = maxElevation;
Expand Down
32 changes: 24 additions & 8 deletions src/main/java/ru/r2cloud/predict/PredictOreKit.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,12 @@ private static List<SatPass> calculateFixedDirectional(AntennaConfiguration ante
EventsLogger logger = new EventsLogger();
tlePropagator.clearEventsDetectors();
tlePropagator.addEventDetector(logger.monitorDetector(detector));
tlePropagator.propagate(initialDate, new AbsoluteDate(initialDate, PREDICT_INTERVAL_SECONDS));
try {
tlePropagator.propagate(initialDate, new AbsoluteDate(initialDate, PREDICT_INTERVAL_SECONDS));
} catch (Exception e) {
LOG.error("unable to calculate schedule for {} date: {}", tlePropagator.getTLE().getSatelliteNumber(), initialDate, e);
return Collections.emptyList();
}
return convert(initialDate, logger.getLoggedEvents());
}

Expand Down Expand Up @@ -180,12 +185,13 @@ public Action eventOccurred(SpacecraftState s, ElevationExtremumDetector detecto
long initialMillis = initialDate.toDate(TimeScalesFactory.getUTC()).getTime();
for (AbsoluteDate curMax : max) {
SatPass cur = findStartEnd(tlePropagator, baseStationFrame, curMax, antenna);
if (cur != null) {
if (cur.getStartMillis() < initialMillis) {
cur.setStart(initialDate);
}
result.add(cur);
if (cur == null) {
continue;
}
if (cur.getStartMillis() < initialMillis) {
cur.setStart(initialDate);
}
result.add(cur);
}
return result;
}
Expand All @@ -195,7 +201,12 @@ private static SatPass calculateNextOmnidirectional(AntennaConfiguration antenna
ElevationExtremumDetector maxDetector = new ElevationExtremumDetector(600, 1, baseStationFrame).withMaxIter(48 * 60).withHandler(maxElevationHandler);
tlePropagator.clearEventsDetectors();
tlePropagator.addEventDetector(new EventSlopeFilter<EventDetector>(maxDetector, FilterType.TRIGGER_ONLY_DECREASING_EVENTS));
tlePropagator.propagate(initialDate, new AbsoluteDate(initialDate, PREDICT_INTERVAL_SECONDS));
try {
tlePropagator.propagate(initialDate, new AbsoluteDate(initialDate, PREDICT_INTERVAL_SECONDS));
} catch (Exception e) {
LOG.error("unable to calculate next observation. Most likely TLE is stale", e);
return null;
}
if (maxElevationHandler.getDate() == null) {
return null;
}
Expand All @@ -210,7 +221,12 @@ private static SatPass findStartEnd(TLEPropagator tlePropagator, TopocentricFram
tlePropagator.addEventDetector(boundsDetector);
// 60 mins before and 60 mins later
AbsoluteDate startDate = maxElevationTime.shiftedBy(-60 * 60.0);
tlePropagator.propagate(startDate, maxElevationTime.shiftedBy(60 * 60.0));
try {
tlePropagator.propagate(startDate, maxElevationTime.shiftedBy(60 * 60.0));
} catch (Exception e) {
LOG.error("unable to calculate start/end times. Most likely TLE is stale", e);
return null;
}

if (minElevationHandler.getStart() == null || minElevationHandler.getEnd() == null) {
return null;
Expand Down
28 changes: 28 additions & 0 deletions src/test/java/ru/r2cloud/satellite/PredictOreKitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import java.text.SimpleDateFormat;
import java.util.Date;
Expand Down Expand Up @@ -77,6 +78,30 @@ public void testFixedDirectionalAntenna() throws Exception {
assertPosition("00:29:32", "00:31:55", schedule.get(3));
}

@Test
public void testStaleTle() throws Exception {
config.setProperty("locaiton.lat", "51.82");
config.setProperty("locaiton.lon", "-0.05");
antenna.setMinElevation(2);
antenna.setGuaranteedElevation(10);
List<SatPass> result = predict.calculateSchedule(antenna, getDate("21-07-2024 14:07:37"), createPropagatorForStaleTle());
assertTrue(result.isEmpty());
assertNull(predict.calculateNext(antenna, getDate("21-07-2024 20:06:37"), createPropagatorForStaleTle()));
}

// it looks like Orekit has some state,
// calling new propagator with different dates
// cause different exceptions
@Test
public void testStaleTle2() throws Exception {
config.setProperty("locaiton.lat", "51.82");
config.setProperty("locaiton.lon", "-0.05");
antenna.setMinElevation(2);
antenna.setGuaranteedElevation(10);
predict.calculateSchedule(antenna, getDate("21-07-2024 00:06:37"), createPropagatorForStaleTle());
assertNull(predict.calculateNext(antenna, getDate("21-07-2024 20:06:37"), createPropagatorForStaleTle()));
}

private static Date getDate(String str) throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
sdf.setTimeZone(TimeZone.getTimeZone("Europe/London"));
Expand Down Expand Up @@ -105,4 +130,7 @@ public void start() throws Exception {
noaa15 = TLEPropagator.selectExtrapolator(new org.orekit.propagation.analytical.tle.TLE("1 25338U 98030A 17271.51297398 .00000037 00000-0 34305-4 0 9992", "2 25338 98.7817 282.6269 0009465 266.6019 93.4077 14.25818111 7720"));
}

private static TLEPropagator createPropagatorForStaleTle() {
return TLEPropagator.selectExtrapolator(new org.orekit.propagation.analytical.tle.TLE("1 53377U 22096H 24154.02726409 .00833254 34873-3 13426-2 0 9991", "2 53377 97.3798 75.4551 0009283 160.8570 199.3061 16.03510163102082"));
}
}

0 comments on commit 0120e6b

Please sign in to comment.