SignalTravelTimeAdjustableReceiver.java

/* Copyright 2022-2025 Romain Serra
 * Licensed to CS GROUP (CS) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * CS licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.orekit.estimation.measurements;

import org.hipparchus.geometry.euclidean.threed.Vector3D;
import org.orekit.frames.Frame;
import org.orekit.propagation.SpacecraftState;
import org.orekit.time.AbsoluteDate;
import org.orekit.utils.AbsolutePVCoordinates;
import org.orekit.utils.PVCoordinatesProvider;

/**
 * Class for computing signal time of flight with an adjustable receiver and fixed emitter's position.
 * @since 14.0
 * @author Romain Serra
 */
public class SignalTravelTimeAdjustableReceiver extends AbstractSignalTravelTime {

    /** Position/velocity provider of receiver. */
    private final PVCoordinatesProvider adjustableReceiverPVProvider;

    public SignalTravelTimeAdjustableReceiver(final PVCoordinatesProvider adjustableReceiverPVProvider) {
        this.adjustableReceiverPVProvider = adjustableReceiverPVProvider;
    }

    /**
     * Build instance from spacecraft state.
     * @param state spacecraft state
     * @return signal time computer
     */
    public static SignalTravelTimeAdjustableReceiver of(final SpacecraftState state) {
        return new SignalTravelTimeAdjustableReceiver(new AbsolutePVCoordinates(state.getFrame(), state.getPVCoordinates()));
    }

    /** Compute propagation delay on a link leg (typically downlink or uplink) without a guess.
     * @param emitterPosition fixed position of emitter
     * @param emissionDate emission date
     * @param frame inertial frame in which emitter is defined
     * @return <em>positive</em> delay between signal emission and signal reception dates
     */
    public double compute(final Vector3D emitterPosition, final AbsoluteDate emissionDate, final Frame frame) {
        final Vector3D receiverPosition = adjustableReceiverPVProvider.getPosition(emissionDate, frame);
        final double distance = receiverPosition.subtract(emitterPosition).getNorm();
        final AbsoluteDate approxReceptionDate = emissionDate.shiftedBy(distance * C_RECIPROCAL);
        return compute(emitterPosition, emissionDate, approxReceptionDate, frame);
    }

    /** Compute propagation delay on a link leg (typically downlink or uplink).
     * @param emitterPosition fixed position of emitter
     * @param emissionDate emission date
     * @param approxReceptionDate approximate reception date
     * @param frame inertial frame in which emitter is defined
     * @return <em>positive</em> delay between signal emission and signal reception dates
     */
    public double compute(final Vector3D emitterPosition, final AbsoluteDate emissionDate,
                          final AbsoluteDate approxReceptionDate, final Frame frame) {
        // initialize reception date search loop assuming the state is already correct
        final double offset = approxReceptionDate.durationFrom(emissionDate);

        return compute(adjustableReceiverPVProvider, offset, emitterPosition, approxReceptionDate, frame);
    }

    @Override
    protected double computeShift(final double offset, final double delay) {
        return delay - offset;
    }
}