KalmanEstimator.java

  1. /* Copyright 2002-2022 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.ProcessEstimate;
  21. import org.hipparchus.filtering.kalman.extended.ExtendedKalmanFilter;
  22. import org.hipparchus.linear.MatrixDecomposer;
  23. import org.orekit.errors.OrekitException;
  24. import org.orekit.estimation.measurements.ObservedMeasurement;
  25. import org.orekit.propagation.Propagator;
  26. import org.orekit.propagation.conversion.OrbitDeterminationPropagatorBuilder;
  27. import org.orekit.propagation.numerical.NumericalPropagator;
  28. import org.orekit.propagation.semianalytical.dsst.DSSTPropagator;
  29. import org.orekit.time.AbsoluteDate;
  30. import org.orekit.utils.ParameterDriver;
  31. import org.orekit.utils.ParameterDriversList;


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

  65.     /** Reference date. */
  66.     private final AbsoluteDate referenceDate;

  67.     /** Kalman filter process model. */
  68.     private final AbstractKalmanModel processModel;

  69.     /** Filter. */
  70.     private final ExtendedKalmanFilter<MeasurementDecorator> filter;

  71.     /** Observer to retrieve current estimation info. */
  72.     private KalmanObserver observer;

  73.     /** Kalman filter estimator constructor (package private).
  74.      * @param decomposer decomposer to use for the correction phase
  75.      * @param propagatorBuilders propagators builders used to evaluate the orbit.
  76.      * @param processNoiseMatricesProviders providers for process noise matrices
  77.      * @param estimatedMeasurementParameters measurement parameters to estimate
  78.      * @param measurementProcessNoiseMatrix provider for measurement process noise matrix
  79.      * @since 10.3
  80.      */
  81.     KalmanEstimator(final MatrixDecomposer decomposer,
  82.                     final List<OrbitDeterminationPropagatorBuilder> propagatorBuilders,
  83.                     final List<CovarianceMatrixProvider> processNoiseMatricesProviders,
  84.                     final ParameterDriversList estimatedMeasurementParameters,
  85.                     final CovarianceMatrixProvider measurementProcessNoiseMatrix) {
  86.         super(propagatorBuilders);
  87.         this.referenceDate      = propagatorBuilders.get(0).getInitialOrbitDate();
  88.         this.observer           = null;

  89.         // Build the process model and measurement model
  90.         this.processModel = propagatorBuilders.get(0).buildKalmanModel(propagatorBuilders,
  91.                                                                        processNoiseMatricesProviders,
  92.                                                                        estimatedMeasurementParameters,
  93.                                                                        measurementProcessNoiseMatrix);

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

  95.     }

  96.     /** {@inheritDoc}. */
  97.     @Override
  98.     protected KalmanEstimation getKalmanEstimation() {
  99.         return processModel;
  100.     }

  101.     /** Set the observer.
  102.      * @param observer the observer
  103.      */
  104.     public void setObserver(final KalmanObserver observer) {
  105.         this.observer = observer;
  106.     }

  107.     /** Process a single measurement.
  108.      * <p>
  109.      * Update the filter with the new measurement by calling the estimate method.
  110.      * </p>
  111.      * @param observedMeasurement the measurement to process
  112.      * @return estimated propagators
  113.      */
  114.     public Propagator[] estimationStep(final ObservedMeasurement<?> observedMeasurement) {
  115.         try {
  116.             final ProcessEstimate estimate = filter.estimationStep(KalmanEstimatorUtil.decorate(observedMeasurement, referenceDate));
  117.             processModel.finalizeEstimation(observedMeasurement, estimate);
  118.             if (observer != null) {
  119.                 observer.evaluationPerformed(processModel);
  120.             }
  121.             return processModel.getEstimatedPropagators();
  122.         } catch (MathRuntimeException mrte) {
  123.             throw new OrekitException(mrte);
  124.         }
  125.     }

  126.     /** Process several measurements.
  127.      * @param observedMeasurements the measurements to process in <em>chronologically sorted</em> order
  128.      * @return estimated propagators
  129.      */
  130.     public Propagator[] processMeasurements(final Iterable<ObservedMeasurement<?>> observedMeasurements) {
  131.         Propagator[] propagators = null;
  132.         for (ObservedMeasurement<?> observedMeasurement : observedMeasurements) {
  133.             propagators = estimationStep(observedMeasurement);
  134.         }
  135.         return propagators;
  136.     }

  137. }