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.indoor.position;
17  
18  import com.irurueta.geometry.Point3D;
19  import com.irurueta.navigation.LockedException;
20  import com.irurueta.navigation.indoor.RadioSource;
21  import com.irurueta.navigation.indoor.RadioSourceLocated;
22  import com.irurueta.navigation.indoor.RangingAndRssiFingerprint;
23  import com.irurueta.navigation.indoor.RangingAndRssiReading;
24  import com.irurueta.navigation.lateration.MSACRobustLateration3DSolver;
25  import com.irurueta.numerical.robust.RobustEstimatorMethod;
26  
27  import java.util.List;
28  
29  /**
30   * Robustly estimates 3D position using located radio sources and their
31   * ranging+RSSI readings at unknown locations and using MSAC algorithm to discard
32   * outliers.
33   * This kind of estimator can be used to robustly determine the 3D position of a given
34   * device by getting ranging+RSSI readings at an unknown location of different radio
35   * sources whose 3D locations are known.
36   */
37  public class MSACRobustRangingAndRssiPositionEstimator3D extends RobustRangingAndRssiPositionEstimator3D {
38  
39      /**
40       * Constructor.
41       */
42      public MSACRobustRangingAndRssiPositionEstimator3D() {
43          super();
44          init();
45      }
46  
47      /**
48       * Constructor.
49       *
50       * @param sources located radio sources used for lateration.
51       * @throws IllegalArgumentException if provided sources is null or the number of
52       *                                  provided sources is less than the required minimum.
53       */
54      public MSACRobustRangingAndRssiPositionEstimator3D(final List<? extends RadioSourceLocated<Point3D>> sources) {
55          super();
56          init();
57          internalSetSources(sources);
58      }
59  
60      /**
61       * Constructor.
62       *
63       * @param fingerprint fingerprint containing ranging+RSSI readings at an unknown
64       *                    location for provided located radio sources.
65       * @throws IllegalArgumentException if provided fingerprint is null.
66       */
67      public MSACRobustRangingAndRssiPositionEstimator3D(
68              final RangingAndRssiFingerprint<? extends RadioSource, ? extends RangingAndRssiReading<?
69                      extends RadioSource>> fingerprint) {
70          super();
71          init();
72          internalSetFingerprint(fingerprint);
73      }
74  
75      /**
76       * Constructor
77       *
78       * @param sources     located radio sources used for lateration.
79       * @param fingerprint fingerprint containing ranging+RSSI readings at an unknown
80       *                    location for provided located radio sources.
81       * @throws IllegalArgumentException if either provided sources or fingerprint is null
82       *                                  or the number of provided sources is less than the required minimum.
83       */
84      public MSACRobustRangingAndRssiPositionEstimator3D(
85              final List<? extends RadioSourceLocated<Point3D>> sources,
86              final RangingAndRssiFingerprint<? extends RadioSource, ? extends RangingAndRssiReading<?
87                      extends RadioSource>> fingerprint) {
88          super();
89          init();
90          internalSetSources(sources);
91          internalSetFingerprint(fingerprint);
92      }
93  
94      /**
95       * Constructor.
96       *
97       * @param listener listener in charge of handling events.
98       */
99      public MSACRobustRangingAndRssiPositionEstimator3D(
100             final RobustRangingAndRssiPositionEstimatorListener<Point3D> listener) {
101         super(listener);
102         init();
103     }
104 
105     /**
106      * Constructor.
107      *
108      * @param sources  located radio sources used for lateration.
109      * @param listener listener in charge of handling events.
110      * @throws IllegalArgumentException if provided sources is null or the number of
111      *                                  provided sources is less than the required minimum.
112      */
113     public MSACRobustRangingAndRssiPositionEstimator3D(
114             final List<? extends RadioSourceLocated<Point3D>> sources,
115             final RobustRangingAndRssiPositionEstimatorListener<Point3D> listener) {
116         super(listener);
117         init();
118         internalSetSources(sources);
119     }
120 
121     /**
122      * Constructor.
123      *
124      * @param fingerprint fingerprint containing ranging+RSSI readings at an unknown
125      *                    location for provided location radio sources.
126      * @param listener    listener in charge of handling events.
127      * @throws IllegalArgumentException if provided fingerprint is null.
128      */
129     public MSACRobustRangingAndRssiPositionEstimator3D(
130             final RangingAndRssiFingerprint<? extends RadioSource, ? extends RangingAndRssiReading<?
131                     extends RadioSource>> fingerprint,
132             final RobustRangingAndRssiPositionEstimatorListener<Point3D> listener) {
133         super(listener);
134         init();
135         internalSetFingerprint(fingerprint);
136     }
137 
138     /**
139      * Constructor.
140      *
141      * @param sources     located radio sources used for lateration.
142      * @param fingerprint fingerprint containing ranging+RSSI readings at an unknown
143      *                    location for provided located radio sources.
144      * @param listener    listener in charge of handling events.
145      */
146     public MSACRobustRangingAndRssiPositionEstimator3D(
147             final List<? extends RadioSourceLocated<Point3D>> sources,
148             final RangingAndRssiFingerprint<? extends RadioSource, ? extends RangingAndRssiReading<?
149                     extends RadioSource>> fingerprint,
150             final RobustRangingAndRssiPositionEstimatorListener<Point3D> listener) {
151         super(listener);
152         init();
153         internalSetSources(sources);
154         internalSetFingerprint(fingerprint);
155     }
156 
157     /**
158      * Gets threshold to determine whether samples are inliers or not when testing possible solutions.
159      * The threshold refers to the amount of error on distance between estimated position and distances
160      * provided for each sample.
161      *
162      * @return threshold to determine whether samples are inliers or not.
163      */
164     public double getThreshold() {
165         return ((MSACRobustLateration3DSolver) laterationSolver).getThreshold();
166     }
167 
168     /**
169      * Sets threshold to determine whether samples are inliers or not when testing possible solutions.
170      * The threshold refers to the amount of error on distance between estimated position and distances
171      * provided for each sample.
172      *
173      * @param threshold threshold to determine whether samples are inliers or not.
174      * @throws IllegalArgumentException if provided value is equal or less than zero.
175      * @throws LockedException          if this solver is locked.
176      */
177     public void setThreshold(final double threshold) throws LockedException {
178         ((MSACRobustLateration3DSolver) laterationSolver).setThreshold(threshold);
179     }
180 
181     /**
182      * Returns method being used for robust estimation.
183      *
184      * @return method being used for robust estimation.
185      */
186     @Override
187     public RobustEstimatorMethod getMethod() {
188         return RobustEstimatorMethod.MSAC;
189     }
190 
191     /**
192      * Initializes robust lateration solver.
193      */
194     private void init() {
195         laterationSolver = new MSACRobustLateration3DSolver(trilaterationSolverListener);
196     }
197 }