GroundFieldOfViewDetector Not Detecting Events

I’m having some trouble getting the GroundFieldOfViewDetector class to work as I would expect it to, and I’m wondering if someone has an idea why. I’m essentially using one the tutorial cases where I can use an ElevationDetector successfully to identify when a minimum elevation is crossed, but when I keep everything the same except for the event detector, it stops detecting new events.

My setup code is here:

        EventsLogger logger = new EventsLogger();

        // Orekit Example Satellite Definition
        Vector3D position = new Vector3D(-6142438.668, 3492467.560, -25767.25680);
        Vector3D velocity = new Vector3D(505.8479685, 942.7809215, 7435.922231);
        AbsoluteDate initialDate = new AbsoluteDate(2004, 01, 01, 23, 30, 0.0, TimeScalesFactory.getUTC());
        TimeStampedPVCoordinates state = new TimeStampedPVCoordinates(initialDate, position, velocity);
        Frame inertialFrame = FramesFactory.getEME2000();

        // Creating the propagator
        double mu = 3.986004415e+14;
        Orbit initialOrbit = new KeplerianOrbit(state, inertialFrame, initialDate, mu);
        Propagator prop = new KeplerianPropagator(initialOrbit);

        // Creating a Fake Sensor
        double longitude = FastMath.toRadians(45.);
        double latitude = FastMath.toRadians(25.);
        double altitude = 0.;
        GeodeticPoint station1 = new GeodeticPoint(latitude, longitude, altitude);

        // Creating the Topocentric Frame for the Sensor
        Frame earthFrame = FramesFactory.getITRF(IERSConventions.IERS_2010, true);
        BodyShape earth = new OneAxisEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS,
                Constants.WGS84_EARTH_FLATTENING,
                earthFrame);
        TopocentricFrame sta1Frame = new TopocentricFrame(earth, station1, "station1");

I follow that up with this implementation of the event detector:

        // Creating the field of view detector
        FieldOfView fov = new CircularFieldOfView(Vector3D.PLUS_K, 80.0, 0.0);
        GroundFieldOfViewDetector sta1Visi = new GroundFieldOfViewDetector(sta1Frame, fov)
                .withHandler((s,d,increasing)->{
                    return Action.CONTINUE;
                });

Followed up by the propagation and logging:

        prop.addEventDetector(logger.monitorDetector(sta1Visi));

        SpacecraftState finalState = prop.propagate(new AbsoluteDate(initialDate, 86400.0));
        List<LoggedEvent> events = logger.getLoggedEvents();

        for (LoggedEvent event : events) {
            String enterExit = event.isIncreasing() ? "ENTERED" : "EXITED";
            System.out.println("EVENT: " + event.getDate().toString() + "  " + enterExit);
        }

        System.out.println(" Final state : " + finalState.getDate().durationFrom(initialDate));

This produces the message in the last line relating to the propagation time but nothing that includes entry/exit events. When I replace the EventDetector with a ElevationDetector, then it detects events with no trouble. The detector code that I used is this:

        // Creating a min elevation detector
        double maxcheck = 60.0;
        double threshold = 0.001;
        double elevation = FastMath.toRadians(5.);
        EventDetector sta1Visi = new ElevationDetector(maxcheck, threshold,
                sta1Frame)
                .withConstantElevation(elevation)
                .withHandler((s, detector, increasing) -> {
                    return Action.CONTINUE;
                });

Any ideas why one works and the other doesn’t?

I guess you should convert 80 from degrees to radians. Here your fov covers the whole sphere, so there are no entry/exit to detect.

Excellent suggestion! That was the issue… I’m glad it was something simple. Thanks luc!

That said, if the satellite begins in the field of view, is there any way to trigger an event at the start of propagation to indicate it was already in coverage? Or would that just be a check I need to make before propagating?

Events are not forcefully triggered at start, in fact they are even prevented to be triggered at the very beginning of a propagation. The rationale is that a frequent use case is to have some propagation run until an event triggers that stops it, and then another propagation is started right after, so by construction it starts at the event. In this case, the event should not be triggered, because first we already have handled it and second we would end up stuck at the event with an infinite loop of zero duration propagation runs.

For events that correspond to inside/outside or start/end semantics, you can check if your propagation begins in the inside region by checking the sign of the g function of the event detector. Beware the relationship between plus/minus and inside/outside may be different from one event detector to another one, you have to check the documentation, or the code, or ask on the forum. For GroundFieldOfViewDetector the g function is negative when the satellite is visible. For ElevationDetector the g function is positive when the satellite is visible.

Perfect, thank you for the clarification!