KalmanEstimatorBuilder.java

  1. /* Copyright 2002-2024 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.EphemerisPropagatorBuilder;
  25. import org.orekit.propagation.conversion.PropagatorBuilder;
  26. import org.orekit.utils.ParameterDriversList;

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

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

  35.     /** Builders for propagators. */
  36.     private List<PropagatorBuilder> propagatorBuilders;

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

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

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

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

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

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

  77.     /** Add a propagation configuration.
  78.      * <p>
  79.      * This method must be called once for each propagator to managed with the
  80.      * {@link KalmanEstimator Kalman estimator}. The propagators order in the
  81.      * Kalman filter will be the call order.
  82.      * </p>
  83.      * <p>
  84.      * The {@code provider} should return a matrix with dimensions and ordering
  85.      * consistent with the {@code builder} configuration. The first 6 rows/columns
  86.      * correspond to the 6 orbital parameters. 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.      *                 This parameter can be equal to {@code null} if the input builder is
  96.      *                 an {@link EphemerisPropagatorBuilder}. Indeed, for ephemeris based estimation
  97.      *                 only measurement parameters are estimated. Therefore, the covariance related
  98.      *                 to dynamical parameters can be null.
  99.      * @return this object.
  100.      * @see CovarianceMatrixProvider#getProcessNoiseMatrix(org.orekit.propagation.SpacecraftState,
  101.      * org.orekit.propagation.SpacecraftState) getProcessNoiseMatrix(previous, current)
  102.      */
  103.     public KalmanEstimatorBuilder addPropagationConfiguration(final PropagatorBuilder builder,
  104.                                                               final CovarianceMatrixProvider provider) {
  105.         propagatorBuilders.add(builder);
  106.         processNoiseMatricesProviders.add(provider);
  107.         return this;
  108.     }

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

  124. }