UnscentedKalmanEstimatorBuilder.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.hipparchus.util.UnscentedTransformProvider;
  23. import org.orekit.errors.OrekitException;
  24. import org.orekit.errors.OrekitMessages;
  25. import org.orekit.propagation.conversion.NumericalPropagatorBuilder;
  26. import org.orekit.utils.ParameterDriversList;

  27. /** Builder for an Unscented Kalman filter estimator.
  28.  * @author GaĆ«tan Pierre
  29.  * @author Bryan Cazabonne
  30.  * @since 11.3
  31.  */
  32. public class UnscentedKalmanEstimatorBuilder {

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

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

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

  39.     /** Process noise matrix providers. */
  40.     private List<CovarianceMatrixProvider> processNoiseMatrixProviders;

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

  43.     /** Unscend transform provider. */
  44.     private UnscentedTransformProvider utProvider;

  45.     /** Default constructor.
  46.      *  Set an Unscented Kalman filter.
  47.      */
  48.     public UnscentedKalmanEstimatorBuilder() {
  49.         this.decomposer                      = new QRDecomposer(1.0e-15);
  50.         this.propagatorBuilders              = new ArrayList<>();
  51.         this.estimatedMeasurementsParameters = new ParameterDriversList();
  52.         this.processNoiseMatrixProviders     = new ArrayList<>();
  53.         this.measurementProcessNoiseMatrix   = null;
  54.         this.utProvider                      = null;
  55.     }

  56.     /** Construct a {@link UnscentedKalmanEstimator} from the data in this builder.
  57.      * <p>
  58.      * Before this method is called, {@link #addPropagationConfiguration(NumericalPropagatorBuilder,
  59.      * CovarianceMatrixProvider) addPropagationConfiguration()} must have been called
  60.      * at least once, otherwise configuration is incomplete and an exception will be raised.
  61.      * <p>
  62.      * In addition, the {@link #unscentedTransformProvider(UnscentedTransformProvider)
  63.      * unscentedTransformProvider()} must be called to configure the unscented transform
  64.      * provider use during the estimation process, otherwise configuration is
  65.      * incomplete and an exception will be raised.
  66.      * </p>
  67.      * @return a new {@link UnscentedKalmanEstimator}.
  68.      */
  69.     public UnscentedKalmanEstimator build() {
  70.         if (propagatorBuilders.size() == 0) {
  71.             throw new OrekitException(OrekitMessages.NO_PROPAGATOR_CONFIGURED);
  72.         }
  73.         if (utProvider == null) {
  74.             throw new OrekitException(OrekitMessages.NO_UNSCENTED_TRANSFORM_CONFIGURED);
  75.         }
  76.         return new UnscentedKalmanEstimator(decomposer, propagatorBuilders, processNoiseMatrixProviders,
  77.                                             estimatedMeasurementsParameters, measurementProcessNoiseMatrix,
  78.                                             utProvider);

  79.     }

  80.     /** Configure the matrix decomposer.
  81.      * @param matrixDecomposer decomposer to use for the correction phase
  82.      * @return this object.
  83.      */
  84.     public UnscentedKalmanEstimatorBuilder decomposer(final MatrixDecomposer matrixDecomposer) {
  85.         decomposer = matrixDecomposer;
  86.         return this;
  87.     }

  88.     /** Configure the unscented transform provider.
  89.      * @param transformProvider unscented transform to use for the prediction phase
  90.      * @return this object.
  91.      */
  92.     public UnscentedKalmanEstimatorBuilder unscentedTransformProvider(final UnscentedTransformProvider transformProvider) {
  93.         this.utProvider = transformProvider;
  94.         return this;
  95.     }

  96.     /** Add a propagation configuration.
  97.      * <p>
  98.      * This method must be called once for each propagator to managed with the
  99.      * {@link UnscentedKalmanEstimator unscented kalman estimatior}. The
  100.      * propagators order in the Kalman filter will be the call order.
  101.      * </p>
  102.      * <p>
  103.      * The {@code provider} should return a matrix with dimensions and ordering
  104.      * consistent with the {@code builder} configuration. The first 6 rows/columns
  105.      * correspond to the 6 orbital parameters which must all be present, regardless
  106.      * of the fact they are estimated or not. The remaining elements correspond
  107.      * to the subset of propagation parameters that are estimated, in the
  108.      * same order as propagatorBuilder.{@link
  109.      * org.orekit.propagation.conversion.PropagatorBuilder#getPropagationParametersDrivers()
  110.      * getPropagationParametersDrivers()}.{@link org.orekit.utils.ParameterDriversList#getDrivers()
  111.      * getDrivers()} (but filtering out the non selected drivers).
  112.      * </p>
  113.      * @param builder The propagator builder to use in the Kalman filter.
  114.      * @param provider The process noise matrices provider to use, consistent with the builder.
  115.      * @see CovarianceMatrixProvider#getProcessNoiseMatrix(org.orekit.propagation.SpacecraftState,
  116.      * org.orekit.propagation.SpacecraftState) getProcessNoiseMatrix(previous, current)
  117.      * @return this object.
  118.      */
  119.     public UnscentedKalmanEstimatorBuilder addPropagationConfiguration(final NumericalPropagatorBuilder builder,
  120.                                                                        final CovarianceMatrixProvider provider) {
  121.         propagatorBuilders.add(builder);
  122.         processNoiseMatrixProviders.add(provider);
  123.         return this;
  124.     }

  125.     /** Configure the estimated measurement parameters.
  126.      * <p>
  127.      * If this method is not called, no measurement parameters will be estimated.
  128.      * </p>
  129.      * @param estimatedMeasurementsParams The estimated measurements' parameters list.
  130.      * @param provider covariance matrix provider for the estimated measurement parameters
  131.      * @return this object.
  132.      */
  133.     public UnscentedKalmanEstimatorBuilder estimatedMeasurementsParameters(final ParameterDriversList estimatedMeasurementsParams,
  134.                                                                            final CovarianceMatrixProvider provider) {
  135.         estimatedMeasurementsParameters = estimatedMeasurementsParams;
  136.         measurementProcessNoiseMatrix   = provider;
  137.         return this;
  138.     }

  139. }