KalmanEstimator.java

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

  18. import java.util.List;

  19. import org.hipparchus.exception.MathRuntimeException;
  20. import org.hipparchus.filtering.kalman.KalmanFilter;
  21. import org.hipparchus.filtering.kalman.ProcessEstimate;
  22. import org.hipparchus.filtering.kalman.extended.ExtendedKalmanFilter;
  23. import org.hipparchus.linear.MatrixDecomposer;
  24. import org.orekit.errors.OrekitException;
  25. import org.orekit.estimation.measurements.ObservedMeasurement;
  26. import org.orekit.propagation.Propagator;
  27. import org.orekit.propagation.analytical.BrouwerLyddanePropagator;
  28. import org.orekit.propagation.analytical.EcksteinHechlerPropagator;
  29. import org.orekit.propagation.analytical.Ephemeris;
  30. import org.orekit.propagation.analytical.KeplerianPropagator;
  31. import org.orekit.propagation.analytical.tle.TLEPropagator;
  32. import org.orekit.propagation.conversion.PropagatorBuilder;
  33. import org.orekit.propagation.numerical.NumericalPropagator;
  34. import org.orekit.propagation.semianalytical.dsst.DSSTPropagator;
  35. import org.orekit.utils.ParameterDriver;
  36. import org.orekit.utils.ParameterDriversList;


  37. /**
  38.  * Implementation of a Kalman filter to perform orbit determination.
  39.  * <p>
  40.  * The filter uses a {@link PropagatorBuilder} to initialize its reference trajectory.
  41.  * The Kalman estimator can be used with a {@link NumericalPropagator}, {@link TLEPropagator},
  42.  * {@link BrouwerLyddanePropagator}, {@link EcksteinHechlerPropagator}, {@link KeplerianPropagator},
  43.  * or {@link Ephemeris}.
  44.  * </p>
  45.  * <p>
  46.  * Kalman estimation using a {@link DSSTPropagator semi-analytical orbit propagator} must be done using
  47.  * the {@link SemiAnalyticalKalmanEstimator}.
  48.  * </p>
  49.  * <p>
  50.  * The estimated parameters are driven by {@link ParameterDriver} objects. They are of 3 different types:<ol>
  51.  *   <li><b>Orbital parameters</b>:The position and velocity of the spacecraft, or, more generally, its orbit.<br>
  52.  *       These parameters are retrieved from the reference trajectory propagator builder when the filter is initialized.</li>
  53.  *   <li><b>Propagation parameters</b>: Some parameters modelling physical processes (SRP or drag coefficients etc...).<br>
  54.  *       They are also retrieved from the propagator builder during the initialization phase.</li>
  55.  *   <li><b>Measurements parameters</b>: Parameters related to measurements (station biases, positions etc...).<br>
  56.  *       They are passed down to the filter in its constructor.</li>
  57.  * </ol>
  58.  * <p>
  59.  * The total number of estimated parameters is m, the size of the state vector.
  60.  * </p>
  61.  * <p>
  62.  * The Kalman filter implementation used is provided by the underlying mathematical library Hipparchus.
  63.  * All the variables seen by Hipparchus (states, covariances, measurement matrices...) are normalized
  64.  * using a specific scale for each estimated parameters or standard deviation noise for each measurement components.
  65.  * </p>
  66.  *
  67.  * <p>A {@link KalmanEstimator} object is built using the {@link KalmanEstimatorBuilder#build() build}
  68.  * method of a {@link KalmanEstimatorBuilder}.</p>
  69.  *
  70.  * @author Romain Gerbaud
  71.  * @author Maxime Journot
  72.  * @author Luc Maisonobe
  73.  * @since 9.2
  74.  */
  75. public class KalmanEstimator extends AbstractKalmanEstimator {

  76.     /** Kalman filter process model. */
  77.     private final KalmanModel processModel;

  78.     /** Filter. */
  79.     private final KalmanFilter<MeasurementDecorator> filter;

  80.     /** Kalman filter estimator constructor (package private).
  81.      * @param decomposer decomposer to use for the correction phase
  82.      * @param propagatorBuilders propagators builders used to evaluate the orbit.
  83.      * @param processNoiseMatricesProviders providers for process noise matrices
  84.      * @param estimatedMeasurementParameters measurement parameters to estimate
  85.      * @param measurementProcessNoiseMatrix provider for measurement process noise matrix
  86.      * @since 10.3
  87.      */
  88.     KalmanEstimator(final MatrixDecomposer decomposer,
  89.                     final List<PropagatorBuilder> propagatorBuilders,
  90.                     final List<CovarianceMatrixProvider> processNoiseMatricesProviders,
  91.                     final ParameterDriversList estimatedMeasurementParameters,
  92.                     final CovarianceMatrixProvider measurementProcessNoiseMatrix) {
  93.         super(decomposer, propagatorBuilders);

  94.         // Build the process model and measurement model
  95.         this.processModel = new KalmanModel(propagatorBuilders,
  96.                                             processNoiseMatricesProviders,
  97.                                             estimatedMeasurementParameters,
  98.                                             measurementProcessNoiseMatrix);

  99.         this.filter = new ExtendedKalmanFilter<>(decomposer, processModel, processModel.getEstimate());

  100.     }

  101.     /** {@inheritDoc}. */
  102.     @Override
  103.     protected KalmanEstimation getKalmanEstimation() {
  104.         return processModel;
  105.     }

  106.     /** {@inheritDoc}. */
  107.     @Override
  108.     protected KalmanFilter<MeasurementDecorator> getKalmanFilter() {
  109.         return filter;
  110.     }

  111.     /** {@inheritDoc}. */
  112.     @Override
  113.     protected double[] getScale() {
  114.         return processModel.getScale();
  115.     }

  116.     /** Process a single measurement.
  117.      * <p>
  118.      * Update the filter with the new measurement by calling the estimate method.
  119.      * </p>
  120.      * @param observedMeasurement the measurement to process
  121.      * @return estimated propagators
  122.      */
  123.     public Propagator[] estimationStep(final ObservedMeasurement<?> observedMeasurement) {
  124.         try {
  125.             final ProcessEstimate estimate = filter.estimationStep(KalmanEstimatorUtil.decorate(observedMeasurement, getReferenceDate()));
  126.             processModel.finalizeEstimation(observedMeasurement, estimate);
  127.             if (getObserver() != null) {
  128.                 getObserver().evaluationPerformed(processModel);
  129.             }
  130.             return processModel.getEstimatedPropagators();
  131.         } catch (MathRuntimeException mrte) {
  132.             throw new OrekitException(mrte);
  133.         }
  134.     }

  135.     /** Process several measurements.
  136.      * @param observedMeasurements the measurements to process in <em>chronologically sorted</em> order
  137.      * @return estimated propagators
  138.      */
  139.     public Propagator[] processMeasurements(final Iterable<ObservedMeasurement<?>> observedMeasurements) {
  140.         Propagator[] propagators = null;
  141.         for (ObservedMeasurement<?> observedMeasurement : observedMeasurements) {
  142.             propagators = estimationStep(observedMeasurement);
  143.         }
  144.         return propagators;
  145.     }

  146. }