KalmanEstimatorBuilder.java

  1. /* Copyright 2002-2019 CS Systèmes d'Information
  2.  * Licensed to CS Systèmes d'Information (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.NumericalPropagatorBuilder;
  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<NumericalPropagatorBuilder> propagatorBuilders;

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

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

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

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

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

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

  102.     /** Configure the estimated measurement parameters.
  103.      * <p>
  104.      * If this method is not called, no measurement parameters will be estimated.
  105.      * </p>
  106.      * @param estimatedMeasurementsParams The estimated measurements' parameters list.
  107.      * @return this object.
  108.      *
  109.      */
  110.     public KalmanEstimatorBuilder estimatedMeasurementsParameters(final ParameterDriversList estimatedMeasurementsParams) {
  111.         estimatedMeasurementsParameters = estimatedMeasurementsParams;
  112.         return this;
  113.     }

  114. }