View Javadoc
1   /*
2    * Copyright (C) 2019 Alberto Irurueta Carro (alberto@irurueta.com)
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *         http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package com.irurueta.navigation.inertial;
17  
18  import com.irurueta.algebra.Matrix;
19  import com.irurueta.algebra.WrongSizeException;
20  
21  /**
22   * Initializes the tightly coupled INS/GNSS extended Kalman filter error covariance
23   * matrix.
24   * This implementation is based on the equations defined in "Principles of GNSS, Inertial, and Multisensor
25   * Integrated Navigation Systems, Second Edition" and on the companion software available at:
26   * <a href="https://github.com/ymjdz/MATLAB-Codes/blob/master/Initialize_TC_P_matrix.m">
27   *     https://github.com/ymjdz/MATLAB-Codes/blob/master/Initialize_TC_P_matrix.m
28   * </a>
29   */
30  public class INSTightlyCoupledKalmanInitializer {
31  
32      /**
33       * Number of parameters of the Kalman filter.
34       */
35      public static final int NUM_PARAMS = 17;
36  
37      /**
38       * Constructor.
39       * Prevents instantiation of helper class.
40       */
41      private INSTightlyCoupledKalmanInitializer() {
42      }
43  
44      /**
45       * Initializes INS/GNS tightly coupled Kalman filter error covariance matrix.
46       *
47       * @param config Kalman filter configuration.
48       * @param result instance where resulting initialized error covariance matrix
49       *               will be stored. Matrix must be 17x17, otherwise it will be resized.
50       */
51      @SuppressWarnings("DuplicatedCode")
52      public static void initialize(final INSTightlyCoupledKalmanInitializerConfig config, final Matrix result) {
53          if (result.getRows() != NUM_PARAMS || result.getColumns() != NUM_PARAMS) {
54              try {
55                  result.resize(NUM_PARAMS, NUM_PARAMS);
56              } catch (final WrongSizeException ignore) {
57                  // never happens
58              }
59          }
60  
61          final var initAttUnc = config.getInitialAttitudeUncertainty();
62          final var initVelUnc = config.getInitialVelocityUncertainty();
63          final var initPosUnc = config.getInitialPositionUncertainty();
64          final var initBaUnc = config.getInitialAccelerationBiasUncertainty();
65          final var initBgUnc = config.getInitialGyroscopeBiasUncertainty();
66          final var initClockOffset = config.getInitialClockOffsetUncertainty();
67          final var initClockDrift = config.getInitialClockDriftUncertainty();
68  
69          final var initAttUnc2 = initAttUnc * initAttUnc;
70          final var initVelUnc2 = initVelUnc * initVelUnc;
71          final var initPosUnc2 = initPosUnc * initPosUnc;
72          final var initBaUnc2 = initBaUnc * initBaUnc;
73          final var initBgUnc2 = initBgUnc * initBgUnc;
74          final var initClockOffset2 = initClockOffset * initClockOffset;
75          final var initClockDrift2 = initClockDrift * initClockDrift;
76  
77          result.initialize(0.0);
78  
79          for (var i = 0; i < 3; i++) {
80              result.setElementAt(i, i, initAttUnc2);
81          }
82          for (var i = 3; i < 6; i++) {
83              result.setElementAt(i, i, initVelUnc2);
84          }
85          for (var i = 6; i < 9; i++) {
86              result.setElementAt(i, i, initPosUnc2);
87          }
88          for (var i = 9; i < 12; i++) {
89              result.setElementAt(i, i, initBaUnc2);
90          }
91          for (var i = 12; i < 15; i++) {
92              result.setElementAt(i, i, initBgUnc2);
93          }
94          result.setElementAt(15, 15, initClockOffset2);
95          result.setElementAt(16, 16, initClockDrift2);
96      }
97  
98      /**
99       * Initializes INS/GNS tightly coupled Kalman filter error covariance matrix.
100      *
101      * @param config Kalman filter configuration.
102      * @return initialized error covariance matrix.
103      */
104     public static Matrix initialize(final INSTightlyCoupledKalmanInitializerConfig config) {
105         Matrix result = null;
106         try {
107             result = new Matrix(NUM_PARAMS, NUM_PARAMS);
108             initialize(config, result);
109         } catch (final WrongSizeException ignore) {
110             // never happens
111         }
112 
113         return result;
114     }
115 }