KalmanEstimatorBuilder.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.ArrayList;
  19. import java.util.List;

  20. import org.hipparchus.linear.MatrixDecomposer;
  21. import org.hipparchus.linear.QRDecomposer;
  22. import org.orekit.errors.OrekitException;
  23. import org.orekit.errors.OrekitMessages;
  24. import org.orekit.propagation.conversion.OrbitDeterminationPropagatorBuilder;
  25. import org.orekit.utils.ParameterDriversList;

  26. /** Builder for a Kalman filter estimator.
  27.  * @author Romain Gerbaud
  28.  * @author Maxime Journot
  29.  * @since 9.2
  30.  */
  31. public class KalmanEstimatorBuilder {

  32.     /** Decomposer to use for the correction phase. */
  33.     private MatrixDecomposer decomposer;

  34.     /** Builders for propagators. */
  35.     private List<OrbitDeterminationPropagatorBuilder> propagatorBuilders;

  36.     /** Estimated measurements parameters. */
  37.     private ParameterDriversList estimatedMeasurementsParameters;

  38.     /** Process noise matrices providers. */
  39.     private List<CovarianceMatrixProvider> processNoiseMatricesProviders;

  40.     /** Process noise matrix provider for measurement parameters. */
  41.     private CovarianceMatrixProvider measurementProcessNoiseMatrix;

  42.     /** Default constructor.
  43.      *  Set an extended Kalman filter, with linearized covariance prediction.
  44.      */
  45.     public KalmanEstimatorBuilder() {
  46.         this.decomposer                      = new QRDecomposer(1.0e-15);
  47.         this.propagatorBuilders              = new ArrayList<>();
  48.         this.estimatedMeasurementsParameters = new ParameterDriversList();
  49.         this.processNoiseMatricesProviders   = new ArrayList<>();
  50.         this.measurementProcessNoiseMatrix   = null;
  51.     }

  52.     /** Construct a {@link KalmanEstimator} from the data in this builder.
  53.      * <p>
  54.      * Before this method is called, {@link #addPropagationConfiguration(OrbitDeterminationPropagatorBuilder,
  55.      * CovarianceMatrixProvider) addPropagationConfiguration()} must have been called
  56.      * at least once, otherwise configuration is incomplete and an exception will be raised.
  57.      * </p>
  58.      * @return a new {@link KalmanEstimator}.
  59.      */
  60.     public KalmanEstimator build() {
  61.         final int n = propagatorBuilders.size();
  62.         if (n == 0) {
  63.             throw new OrekitException(OrekitMessages.NO_PROPAGATOR_CONFIGURED);
  64.         }
  65.         return new KalmanEstimator(decomposer, propagatorBuilders, processNoiseMatricesProviders,
  66.                                    estimatedMeasurementsParameters, measurementProcessNoiseMatrix);
  67.     }

  68.     /** Configure the matrix decomposer.
  69.      * @param matrixDecomposer decomposer to use for the correction phase
  70.      * @return this object.
  71.      */
  72.     public KalmanEstimatorBuilder decomposer(final MatrixDecomposer matrixDecomposer) {
  73.         decomposer = matrixDecomposer;
  74.         return this;
  75.     }

  76.     /** Add a propagation configuration.
  77.      * <p>
  78.      * This method must be called once for each propagator to managed with the
  79.      * {@link KalmanEstimator Kalman estimator}. The propagators order in the
  80.      * Kalman filter will be the call order.
  81.      * </p>
  82.      * <p>
  83.      * The {@code provider} should return a matrix with dimensions and ordering
  84.      * consistent with the {@code builder} configuration. The first 6 rows/columns
  85.      * correspond to the 6 orbital parameters which must all be present, regardless
  86.      * of the fact they are estimated or not. The remaining elements correspond
  87.      * to the subset of propagation parameters that are estimated, in the
  88.      * same order as propagatorBuilder.{@link
  89.      * org.orekit.propagation.conversion.PropagatorBuilder#getPropagationParametersDrivers()
  90.      * getPropagationParametersDrivers()}.{@link org.orekit.utils.ParameterDriversList#getDrivers()
  91.      * getDrivers()} (but filtering out the non selected drivers).
  92.      * </p>
  93.      * @param builder The propagator builder to use in the Kalman filter.
  94.      * @param provider The process noise matrices provider to use, consistent with the builder.
  95.      * @return this object.
  96.      * @see CovarianceMatrixProvider#getProcessNoiseMatrix(org.orekit.propagation.SpacecraftState,
  97.      * org.orekit.propagation.SpacecraftState) getProcessNoiseMatrix(previous, current)
  98.      */
  99.     public KalmanEstimatorBuilder addPropagationConfiguration(final OrbitDeterminationPropagatorBuilder builder,
  100.                                                               final CovarianceMatrixProvider provider) {
  101.         propagatorBuilders.add(builder);
  102.         processNoiseMatricesProviders.add(provider);
  103.         return this;
  104.     }

  105.     /** Configure the estimated measurement parameters.
  106.      * <p>
  107.      * If this method is not called, no measurement parameters will be estimated.
  108.      * </p>
  109.      * @param estimatedMeasurementsParams The estimated measurements' parameters list.
  110.      * @param provider covariance matrix provider for the estimated measurement parameters
  111.      * @return this object.
  112.      * @since 10.3
  113.      */
  114.     public KalmanEstimatorBuilder estimatedMeasurementsParameters(final ParameterDriversList estimatedMeasurementsParams,
  115.                                                                   final CovarianceMatrixProvider provider) {
  116.         estimatedMeasurementsParameters = estimatedMeasurementsParams;
  117.         measurementProcessNoiseMatrix   = provider;
  118.         return this;
  119.     }

  120. }