Hello everyone. Im trying to calculate TCA and MissDistance with TLE. I get an error in the code I wrote:
java: Main.ClosestApproachDetector is not abstract and does not override abstract method getMaxCheckInterval() in org.orekit.propagation.events.EventDetector
and here is the code:
import org.example.InitializeOrekit;
import org.hipparchus.geometry.euclidean.threed.Vector3D;
import org.orekit.bodies.OneAxisEllipsoid;
import org.orekit.data.DataProvidersManager;
import org.orekit.data.ZipJarCrawler;
import org.orekit.errors.OrekitException;
import org.orekit.frames.Frame;
import org.orekit.frames.FramesFactory;
import org.orekit.propagation.SpacecraftState;
import org.orekit.propagation.analytical.tle.TLE;
import org.orekit.propagation.analytical.tle.TLEPropagator;
import org.orekit.propagation.events.EventDetector;
import org.orekit.propagation.events.EventsLogger;
import org.orekit.propagation.events.handlers.EventHandler;
import org.orekit.propagation.events.handlers.StopOnEvent;
import org.orekit.time.AbsoluteDate;
import org.orekit.time.TimeScalesFactory;
import org.orekit.utils.Constants;
import java.io.File;
import java.util.List;
public class Main {
public static void main(String args) {
try {
// Load Orekit data
InitializeOrekit.init();
// TLE data for two satellites
String line1_1 = "1 25544U 98067A 20359.54976495 .00000564 00000-0 18836-4 0 9993";
String line2_1 = "2 25544 51.6431 110.3336 0001414 284.9646 143.1121 15.48941089253832";
String line1_2 = "1 40958U 15058F 20359.54947222 .00000224 00000-0 77805-5 0 9995";
String line2_2 = "2 40958 99.0533 161.6354 0013262 280.7981 79.1920 14.62143262436882";
// Create TLE objects
TLE tle1 = new TLE(line1_1, line2_1);
TLE tle2 = new TLE(line1_2, line2_2);
// Propagators
TLEPropagator propagator1 = TLEPropagator.selectExtrapolator(tle1);
TLEPropagator propagator2 = TLEPropagator.selectExtrapolator(tle2);
// Initial date
AbsoluteDate initialDate = new AbsoluteDate(2020, 12, 24, 12, 0, 0.000, TimeScalesFactory.getUTC());
AbsoluteDate finalDate = initialDate.shiftedBy(86400.0); // Propagate for one day
// Event detector for TCA
EventsLogger logger = new EventsLogger();
EventDetector detector = new ClosestApproachDetector(propagator2);
propagator1.addEventDetector(logger.monitorDetector(detector));
// Propagate
propagator1.propagate(initialDate, finalDate);
// Get TCA events
List<EventsLogger.LoggedEvent> events = logger.getLoggedEvents();
if (!events.isEmpty()) {
AbsoluteDate tcaDate = events.get(0).getState().getDate();
System.out.println("TCA Date: " + tcaDate);
// Calculate MissDistance
SpacecraftState state1 = propagator1.propagate(tcaDate);
SpacecraftState state2 = propagator2.propagate(tcaDate);
double missDistance = Vector3D.distance(state1.getPVCoordinates().getPosition(),
state2.getPVCoordinates().getPosition());
System.out.println("MissDistance at TCA: " + missDistance + " meters");
} else {
System.out.println("No TCA detected within the propagation period.");
}
} catch (Exception e) {
e.printStackTrace();
}
}
// Custom event detector for closest approach
private static class ClosestApproachDetector implements EventDetector {
private final TLEPropagator targetPropagator;
public ClosestApproachDetector(TLEPropagator targetPropagator) {
this.targetPropagator = targetPropagator;
}
@Override
public double g(SpacecraftState state) throws OrekitException {
SpacecraftState targetState = targetPropagator.propagate(state.getDate());
return Vector3D.distance(state.getPVCoordinates().getPosition(),
targetState.getPVCoordinates().getPosition());
}
@Override
public double getThreshold() {
return 1.0; // Threshold for event detection
}
@Override
public int getMaxIterationCount() {
return 100;
}
@Override
public double getMaxCheckInterval() {
return 600.0; // Check interval in seconds
}
@Override
public EventHandler getHandler() {
return new StopOnEvent();
}
}
}