EskfMeasurementHandler.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.List;

  19. import org.hipparchus.exception.MathRuntimeException;
  20. import org.hipparchus.filtering.kalman.ProcessEstimate;
  21. import org.hipparchus.filtering.kalman.extended.ExtendedKalmanFilter;
  22. import org.orekit.errors.OrekitException;
  23. import org.orekit.estimation.measurements.ObservedMeasurement;
  24. import org.orekit.propagation.SpacecraftState;
  25. import org.orekit.propagation.sampling.OrekitStepHandler;
  26. import org.orekit.propagation.sampling.OrekitStepInterpolator;
  27. import org.orekit.time.AbsoluteDate;

  28. /** {@link org.orekit.propagation.sampling.OrekitStepHandler Step handler} picking up
  29.  * {@link ObservedMeasurement measurements} for the {@link SemiAnalyticalKalmanEstimator}.
  30.  * @author Julie Bayard
  31.  * @author Bryan Cazabonne
  32.  * @author Maxime Journot
  33.  * @since 11.1
  34.  */
  35. @Deprecated
  36. public class EskfMeasurementHandler implements OrekitStepHandler {

  37.     /** ESKF model. */
  38.     private final SemiAnalyticalKalmanModel model;

  39.     /** Extended Kalman Filter. */
  40.     private final ExtendedKalmanFilter<MeasurementDecorator> filter;

  41.     /** Underlying measurements. */
  42.     private final List<ObservedMeasurement<?>> observedMeasurements;

  43.     /** Index of the next measurement component in the model. */
  44.     private int index;

  45.     /** Reference date. */
  46.     private AbsoluteDate referenceDate;

  47.     /** Observer to retrieve current estimation info. */
  48.     private KalmanObserver observer;

  49.     /** Simple constructor.
  50.      * @param model semi-analytical kalman model
  51.      * @param filter kalman filter instance
  52.      * @param observedMeasurements list of observed measurements
  53.      * @param referenceDate reference date
  54.      */
  55.     public EskfMeasurementHandler(final SemiAnalyticalKalmanModel model,
  56.                                   final ExtendedKalmanFilter<MeasurementDecorator> filter,
  57.                                   final List<ObservedMeasurement<?>> observedMeasurements,
  58.                                   final AbsoluteDate referenceDate) {
  59.         this.model                = model;
  60.         this.filter               = filter;
  61.         this.observer             = model.getObserver();
  62.         this.observedMeasurements = observedMeasurements;
  63.         this.referenceDate        = referenceDate;
  64.     }

  65.     /** {@inheritDoc} */
  66.     @Override
  67.     public void init(final SpacecraftState s0, final AbsoluteDate t) {
  68.         this.index = 0;
  69.         // Initialize short periodic terms.
  70.         model.initializeShortPeriodicTerms(s0);
  71.         model.updateShortPeriods(s0);
  72.     }

  73.     /** {@inheritDoc} */
  74.     @Override
  75.     public void handleStep(final OrekitStepInterpolator interpolator) {

  76.         // Current date
  77.         final AbsoluteDate currentDate = interpolator.getCurrentState().getDate();

  78.         // Update the short period terms with the current MEAN state
  79.         model.updateShortPeriods(interpolator.getCurrentState());

  80.         // Process the measurements between previous step and current step
  81.         while (index < observedMeasurements.size() && observedMeasurements.get(index).getDate().compareTo(currentDate) < 0) {

  82.             try {

  83.                 // Update the norminal state with the interpolated parameters
  84.                 model.updateNominalSpacecraftState(interpolator.getInterpolatedState(observedMeasurements.get(index).getDate()));

  85.                 // Process the current observation
  86.                 final ProcessEstimate estimate = filter.estimationStep(KalmanEstimatorUtil.decorate(observedMeasurements.get(index), referenceDate));

  87.                 // Finalize the estimation
  88.                 model.finalizeEstimation(observedMeasurements.get(index), estimate);

  89.                 // Call the observer if the user add one
  90.                 if (observer != null) {
  91.                     observer.evaluationPerformed(model);
  92.                 }

  93.             } catch (MathRuntimeException mrte) {
  94.                 throw new OrekitException(mrte);
  95.             }

  96.             // Increment the measurement index
  97.             index += 1;

  98.         }

  99.         // Reset the initial state of the propagator
  100.         model.finalizeOperationsObservationGrid();

  101.     }

  102. }