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

  28. /** Builder for an Unscented Kalman filter estimator.
  29.  * <p>
  30.  * The builder is generalized to accept any {@link PropagatorBuilder}.
  31.  * Howerver, it is absolutely not recommended to use a {@link DSSTPropagatorBuilder}.
  32.  * A specific {@link SemiAnalyticalUnscentedKalmanEstimatorBuilder semi-analytical
  33.  * unscented Kalman Filter} is implemented and shall be used.
  34.  * </p>
  35.  * @author GaĆ«tan Pierre
  36.  * @author Bryan Cazabonne
  37.  * @since 11.3
  38.  */
  39. public class UnscentedKalmanEstimatorBuilder {

  40.     /** Decomposer to use for the correction phase. */
  41.     private MatrixDecomposer decomposer;

  42.     /** Builders for propagators. */
  43.     private List<PropagatorBuilder> propagatorBuilders;

  44.     /** Estimated measurements parameters. */
  45.     private ParameterDriversList estimatedMeasurementsParameters;

  46.     /** Process noise matrix providers. */
  47.     private List<CovarianceMatrixProvider> processNoiseMatrixProviders;

  48.     /** Process noise matrix provider for measurement parameters. */
  49.     private CovarianceMatrixProvider measurementProcessNoiseMatrix;

  50.     /** Unscend transform provider. */
  51.     private UnscentedTransformProvider utProvider;

  52.     /** Default constructor.
  53.      *  Set an Unscented Kalman filter.
  54.      */
  55.     public UnscentedKalmanEstimatorBuilder() {
  56.         this.decomposer                      = new QRDecomposer(1.0e-15);
  57.         this.propagatorBuilders              = new ArrayList<>();
  58.         this.estimatedMeasurementsParameters = new ParameterDriversList();
  59.         this.processNoiseMatrixProviders     = new ArrayList<>();
  60.         this.measurementProcessNoiseMatrix   = null;
  61.         this.utProvider                      = null;
  62.     }

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

  86.     }

  87.     /** Configure the matrix decomposer.
  88.      * @param matrixDecomposer decomposer to use for the correction phase
  89.      * @return this object.
  90.      */
  91.     public UnscentedKalmanEstimatorBuilder decomposer(final MatrixDecomposer matrixDecomposer) {
  92.         decomposer = matrixDecomposer;
  93.         return this;
  94.     }

  95.     /** Configure the unscented transform provider.
  96.      * @param transformProvider unscented transform to use for the prediction phase
  97.      * @return this object.
  98.      */
  99.     public UnscentedKalmanEstimatorBuilder unscentedTransformProvider(final UnscentedTransformProvider transformProvider) {
  100.         this.utProvider = transformProvider;
  101.         return this;
  102.     }

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

  132.     /** Configure the estimated measurement parameters.
  133.      * <p>
  134.      * If this method is not called, no measurement parameters will be estimated.
  135.      * </p>
  136.      * @param estimatedMeasurementsParams The estimated measurements' parameters list.
  137.      * @param provider covariance matrix provider for the estimated measurement parameters
  138.      * @return this object.
  139.      */
  140.     public UnscentedKalmanEstimatorBuilder estimatedMeasurementsParameters(final ParameterDriversList estimatedMeasurementsParams,
  141.                                                                            final CovarianceMatrixProvider provider) {
  142.         estimatedMeasurementsParameters = estimatedMeasurementsParams;
  143.         measurementProcessNoiseMatrix   = provider;
  144.         return this;
  145.     }

  146. }