use `DateDetector` to retrieve the state of an orbit within a specific time sequence, but it is not working


I would like to use DateDetector to retrieve the state of an orbit within a specific time sequence, but it is not working as expected. The contents of the eventOccurred method are not being triggered. Here is my code for reference.

        final TLE tle = new TLE("1 48251U 21033D   24100.92177916  .00068874  00000+0  13229-2 0  9999", "2 48251  97.2783 177.1897 0013115 174.7574 185.3817 15.47627235164785");
        orbit = getOrbitByTLE(tle, OrekitContext.frame, 192);
        final TLEPropagator propagator = TLEPropagator.selectExtrapolator(tle);
        DateDetector dateDetector = new DateDetector(1, DateDetector.DEFAULT_THRESHOLD);
        for (int i = 0; i < dates.size(); i++) {
            AbsoluteDate absoluteDate = new AbsoluteDate(dates.get(i), TimeScalesFactory.getUTC());
        List<Orbit> orbits = new ArrayList<>();

        dateDetector.withHandler(new EventHandler<DateDetector>() {
            public Action eventOccurred(SpacecraftState s, DateDetector detector, boolean increasing) {
                return Action.CONTINUE;
        propagator.propagate(orbit.getDate(), new AbsoluteDate(dates.get(dates.size() - 1), TimeScalesFactory.getUTC()).shiftedBy(100));

Hello @Toonaiveckuu1,

Welcome to the forum !

dateDetector.withHandler(new EventHandler [...]

The withXXX methods used in the event detectors in Orekit always create a new object with the desired property.
In your case you do set up an event handler but you’re not saving the object in a variable used afterward. The correct code should be:

dateDetector = dateDetector.withHandler(new EventHandler [...]

Also, beware that the default maxCheck of DateDetector is 1E10 so the propagator will check the dates every 1E10 seconds. If your dates are closer than this some will be missed.
You can avoid this doing:

dateDetector = dateDetector.withMaxCheck(newValue);


1 Like

it`s work,thank you very much :grinning: :hugs:

1 Like