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.Point2D;
19  import com.irurueta.navigation.indoor.RadioSource;
20  import com.irurueta.navigation.indoor.RadioSourceLocated;
21  import com.irurueta.navigation.indoor.RangingAndRssiFingerprint;
22  import com.irurueta.navigation.indoor.RangingAndRssiReading;
23  
24  import java.util.List;
25  
26  /**
27   * Robustly estimates 2D position, using RSSI readings first to obtain an initial coarse
28   * position estimation, and then ranging readings to refine such estimation.
29   */
30  public class SequentialRobustRangingAndRssiPositionEstimator2D extends
31          SequentialRobustRangingAndRssiPositionEstimator<Point2D> {
32  
33      /**
34       * Constructor.
35       */
36      public SequentialRobustRangingAndRssiPositionEstimator2D() {
37          super();
38          rangingPreliminarySubsetSize = rssiPreliminarySubsetSize = getMinRequiredSources();
39      }
40  
41      /**
42       * Constructor.
43       *
44       * @param sources located radio sources used for lateration.
45       * @throws IllegalArgumentException if provided sources is null or the number of
46       *                                  provided sources is less than the required minimum.
47       */
48      public SequentialRobustRangingAndRssiPositionEstimator2D(
49              final List<? extends RadioSourceLocated<Point2D>> sources) {
50          super(sources);
51          rangingPreliminarySubsetSize = rssiPreliminarySubsetSize = getMinRequiredSources();
52      }
53  
54      /**
55       * Constructor.
56       *
57       * @param fingerprint fingerprint containing RSSI readings at an unknown location
58       *                    for provided located radio sources.
59       * @throws IllegalArgumentException if provided fingerprint is null.
60       */
61      public SequentialRobustRangingAndRssiPositionEstimator2D(
62              final RangingAndRssiFingerprint<? extends RadioSource, ? extends RangingAndRssiReading<?
63                      extends RadioSource>> fingerprint) {
64          super(fingerprint);
65          rangingPreliminarySubsetSize = rssiPreliminarySubsetSize = getMinRequiredSources();
66      }
67  
68      /**
69       * Constructor.
70       *
71       * @param sources     located radio sources used for lateration.
72       * @param fingerprint fingerprint containing RSSI readings at an unknown location
73       *                    for provided located radio sources.
74       * @throws IllegalArgumentException if either provided sources or fingerprint is null
75       *                                  or the number of provided sources is less than the required minimum.
76       */
77      public SequentialRobustRangingAndRssiPositionEstimator2D(
78              final List<? extends RadioSourceLocated<Point2D>> sources,
79              final RangingAndRssiFingerprint<? extends RadioSource, ? extends RangingAndRssiReading<?
80                      extends RadioSource>> fingerprint) {
81          super(sources, fingerprint);
82          rangingPreliminarySubsetSize = rssiPreliminarySubsetSize = getMinRequiredSources();
83      }
84  
85      /**
86       * Constructor.
87       *
88       * @param listener listener in charge of handling events.
89       */
90      public SequentialRobustRangingAndRssiPositionEstimator2D(
91              final SequentialRobustRangingAndRssiPositionEstimatorListener<Point2D> listener) {
92          super(listener);
93          rangingPreliminarySubsetSize = rssiPreliminarySubsetSize = getMinRequiredSources();
94      }
95  
96      /**
97       * Constructor.
98       *
99       * @param sources  located radio sources used for lateration.
100      * @param listener listener in charge of handling events.
101      * @throws IllegalArgumentException if provided sources is null or the number of
102      *                                  provided sources is less than the required minimum.
103      */
104     public SequentialRobustRangingAndRssiPositionEstimator2D(
105             final List<? extends RadioSourceLocated<Point2D>> sources,
106             final SequentialRobustRangingAndRssiPositionEstimatorListener<Point2D> listener) {
107         super(sources, listener);
108         rangingPreliminarySubsetSize = rssiPreliminarySubsetSize = getMinRequiredSources();
109     }
110 
111     /**
112      * Constructor.
113      *
114      * @param fingerprint fingerprint containing RSSI readings at an unknown location
115      *                    for provided located radio sources.
116      * @param listener    listener in charge of handling events.
117      * @throws IllegalArgumentException if provided fingerprint is null.
118      */
119     public SequentialRobustRangingAndRssiPositionEstimator2D(
120             final RangingAndRssiFingerprint<? extends RadioSource, ? extends RangingAndRssiReading<?
121                     extends RadioSource>> fingerprint,
122             final SequentialRobustRangingAndRssiPositionEstimatorListener<Point2D> listener) {
123         super(fingerprint, listener);
124         rangingPreliminarySubsetSize = rssiPreliminarySubsetSize = getMinRequiredSources();
125     }
126 
127     /**
128      * Constructor.
129      *
130      * @param sources     located radio sources used for lateration.
131      * @param fingerprint fingerprint containing RSSI readings at an unknown location
132      *                    for provided located radio sources.
133      * @param listener    listener in charge of handling events.
134      * @throws IllegalArgumentException if either provided sources or fingerprint is null
135      *                                  or the number of provided sources is less than the required minimum.
136      */
137     public SequentialRobustRangingAndRssiPositionEstimator2D(
138             final List<? extends RadioSourceLocated<Point2D>> sources,
139             final RangingAndRssiFingerprint<? extends RadioSource, ? extends RangingAndRssiReading<?
140                     extends RadioSource>> fingerprint,
141             final SequentialRobustRangingAndRssiPositionEstimatorListener<Point2D> listener) {
142         super(sources, fingerprint, listener);
143         rangingPreliminarySubsetSize = rssiPreliminarySubsetSize = getMinRequiredSources();
144     }
145 
146     /**
147      * Constructor.
148      *
149      * @param sourceQualityScores             quality scores corresponding to
150      *                                        each provided located radio source.
151      *                                        The larger the score value the better
152      *                                        the quality of the radio source.
153      * @param fingerprintReadingQualityScores quality scores corresponding to readings
154      *                                        within provided fingerprint. The larger
155      *                                        the score the better the quality of the
156      *                                        reading.
157      */
158     public SequentialRobustRangingAndRssiPositionEstimator2D(
159             final double[] sourceQualityScores, final double[] fingerprintReadingQualityScores) {
160         super(sourceQualityScores, fingerprintReadingQualityScores);
161         rangingPreliminarySubsetSize = rssiPreliminarySubsetSize = getMinRequiredSources();
162     }
163 
164     /**
165      * Constructor.
166      *
167      * @param sourceQualityScores             quality scores corresponding to
168      *                                        each provided located radio source.
169      *                                        The larger the score value the better
170      *                                        the quality of the radio source.
171      * @param fingerprintReadingQualityScores quality scores corresponding to readings
172      *                                        within provided fingerprint. The larger
173      *                                        the score the better the quality of the
174      *                                        reading.
175      * @param sources                         located radio sources used for
176      *                                        lateration.
177      * @throws IllegalArgumentException if provided sources is null or the number of
178      *                                  provided sources is less than the required minimum.
179      */
180     public SequentialRobustRangingAndRssiPositionEstimator2D(
181             final double[] sourceQualityScores, final double[] fingerprintReadingQualityScores,
182             final List<? extends RadioSourceLocated<Point2D>> sources) {
183         super(sourceQualityScores, fingerprintReadingQualityScores, sources);
184         rangingPreliminarySubsetSize = rssiPreliminarySubsetSize = getMinRequiredSources();
185     }
186 
187     /**
188      * Constructor.
189      *
190      * @param sourceQualityScores             quality scores corresponding to
191      *                                        each provided located radio source.
192      *                                        The larger the score value the better
193      *                                        the quality of the radio source.
194      * @param fingerprintReadingQualityScores quality scores corresponding to readings
195      *                                        within provided fingerprint. The larger
196      *                                        the score the better the quality of the
197      *                                        reading.
198      * @param fingerprint                     fingerprint containing RSSI readings at an
199      *                                        unknown location for provided located
200      *                                        radio sources.
201      * @throws IllegalArgumentException if provided fingerprint is null.
202      */
203     public SequentialRobustRangingAndRssiPositionEstimator2D(
204             final double[] sourceQualityScores, final double[] fingerprintReadingQualityScores,
205             final RangingAndRssiFingerprint<? extends RadioSource, ? extends RangingAndRssiReading<?
206                     extends RadioSource>> fingerprint) {
207         super(sourceQualityScores, fingerprintReadingQualityScores, fingerprint);
208         rangingPreliminarySubsetSize = rssiPreliminarySubsetSize = getMinRequiredSources();
209     }
210 
211     /**
212      * Constructor.
213      *
214      * @param sourceQualityScores             quality scores corresponding to
215      *                                        each provided located radio source.
216      *                                        The larger the score value the better
217      *                                        the quality of the radio source.
218      * @param fingerprintReadingQualityScores quality scores corresponding to readings
219      *                                        within provided fingerprint. The larger
220      *                                        the score the better the quality of the
221      *                                        reading.
222      * @param sources                         located radio sources used for
223      *                                        lateration.
224      * @param fingerprint                     fingerprint containing RSSI readings at an
225      *                                        unknown location for provided located
226      *                                        radio sources.
227      * @throws IllegalArgumentException if either provided sources or fingerprint is null
228      *                                  or the number of provided sources is less than the required minimum.
229      */
230     public SequentialRobustRangingAndRssiPositionEstimator2D(
231             final double[] sourceQualityScores, final double[] fingerprintReadingQualityScores,
232             final List<? extends RadioSourceLocated<Point2D>> sources,
233             final RangingAndRssiFingerprint<? extends RadioSource, ? extends RangingAndRssiReading<?
234                     extends RadioSource>> fingerprint) {
235         super(sourceQualityScores, fingerprintReadingQualityScores, sources, fingerprint);
236         rangingPreliminarySubsetSize = rssiPreliminarySubsetSize = getMinRequiredSources();
237     }
238 
239     /**
240      * Constructor.
241      *
242      * @param sourceQualityScores             quality scores corresponding to
243      *                                        each provided located radio source.
244      *                                        The larger the score value the better
245      *                                        the quality of the radio source.
246      * @param fingerprintReadingQualityScores quality scores corresponding to readings
247      *                                        within provided fingerprint. The larger
248      *                                        the score the better the quality of the
249      *                                        reading.
250      * @param listener                        listener in charge of handling events.
251      */
252     public SequentialRobustRangingAndRssiPositionEstimator2D(
253             final double[] sourceQualityScores, final double[] fingerprintReadingQualityScores,
254             final SequentialRobustRangingAndRssiPositionEstimatorListener<Point2D> listener) {
255         super(sourceQualityScores, fingerprintReadingQualityScores, listener);
256         rangingPreliminarySubsetSize = rssiPreliminarySubsetSize = getMinRequiredSources();
257     }
258 
259     /**
260      * Constructor.
261      *
262      * @param sourceQualityScores             quality scores corresponding to
263      *                                        each provided located radio source.
264      *                                        The larger the score value the better
265      *                                        the quality of the radio source.
266      * @param fingerprintReadingQualityScores quality scores corresponding to readings
267      *                                        within provided fingerprint. The larger
268      *                                        the score the better the quality of the
269      *                                        reading.
270      * @param sources                         located radio sources used for
271      *                                        lateration.
272      * @param listener                        listener in charge of handling events.
273      * @throws IllegalArgumentException if provided sources is null or the number of
274      *                                  provided sources is less than the required minimum.
275      */
276     public SequentialRobustRangingAndRssiPositionEstimator2D(
277             final double[] sourceQualityScores, final double[] fingerprintReadingQualityScores,
278             final List<? extends RadioSourceLocated<Point2D>> sources,
279             final SequentialRobustRangingAndRssiPositionEstimatorListener<Point2D> listener) {
280         super(sourceQualityScores, fingerprintReadingQualityScores, sources, listener);
281         rangingPreliminarySubsetSize = rssiPreliminarySubsetSize = getMinRequiredSources();
282     }
283 
284     /**
285      * Constructor.
286      *
287      * @param sourceQualityScores             quality scores corresponding to
288      *                                        each provided located radio source.
289      *                                        The larger the score value the better
290      *                                        the quality of the radio source.
291      * @param fingerprintReadingQualityScores quality scores corresponding to readings
292      *                                        within provided fingerprint. The larger
293      *                                        the score the better the quality of the
294      *                                        reading.
295      * @param fingerprint                     fingerprint containing RSSI readings at an
296      *                                        unknown location for provided located
297      *                                        radio sources.
298      * @param listener                        listener in charge of handling events.
299      * @throws IllegalArgumentException if provided fingerprint is null.
300      */
301     public SequentialRobustRangingAndRssiPositionEstimator2D(
302             final double[] sourceQualityScores, final double[] fingerprintReadingQualityScores,
303             final RangingAndRssiFingerprint<? extends RadioSource, ? extends RangingAndRssiReading<?
304                     extends RadioSource>> fingerprint,
305             final SequentialRobustRangingAndRssiPositionEstimatorListener<Point2D> listener) {
306         super(sourceQualityScores, fingerprintReadingQualityScores, fingerprint, listener);
307         rangingPreliminarySubsetSize = rssiPreliminarySubsetSize = getMinRequiredSources();
308     }
309 
310     /**
311      * Constructor.
312      *
313      * @param sourceQualityScores             quality scores corresponding to
314      *                                        each provided located radio source.
315      *                                        The larger the score value the better
316      *                                        the quality of the radio source.
317      * @param fingerprintReadingQualityScores quality scores corresponding to readings
318      *                                        within provided fingerprint. The larger
319      *                                        the score the better the quality of the
320      *                                        reading.
321      * @param sources                         located radio sources used for
322      *                                        lateration.
323      * @param fingerprint                     fingerprint containing RSSI readings at an
324      *                                        unknown location for provided located
325      *                                        radio sources.
326      * @param listener                        listener in charge of handling events.
327      * @throws IllegalArgumentException if either provided sources or fingerprint is null
328      *                                  or the number of provided sources is less than the required minimum.
329      */
330     public SequentialRobustRangingAndRssiPositionEstimator2D(
331             final double[] sourceQualityScores, final double[] fingerprintReadingQualityScores,
332             final List<? extends RadioSourceLocated<Point2D>> sources,
333             final RangingAndRssiFingerprint<? extends RadioSource, ? extends RangingAndRssiReading<?
334                     extends RadioSource>> fingerprint,
335             final SequentialRobustRangingAndRssiPositionEstimatorListener<Point2D> listener) {
336         super(sourceQualityScores, fingerprintReadingQualityScores, sources, fingerprint, listener);
337         rangingPreliminarySubsetSize = rssiPreliminarySubsetSize = getMinRequiredSources();
338     }
339 
340     /**
341      * Gets number of dimensions of provided and estimated points.
342      *
343      * @return number of dimensions of provided and estimated points.
344      */
345     @Override
346     public int getNumberOfDimensions() {
347         return Point2D.POINT2D_INHOMOGENEOUS_COORDINATES_LENGTH;
348     }
349 
350     /**
351      * Gets minimum required number of located radio sources to perform lateration.
352      *
353      * @return minimum required number of located radio sources to perform
354      * lateration.
355      */
356     @Override
357     public int getMinRequiredSources() {
358         return Point2D.POINT2D_HOMOGENEOUS_COORDINATES_LENGTH;
359     }
360 
361     /**
362      * Builds ranging and RSSI internal estimators.
363      */
364     @Override
365     protected void buildEstimators() {
366         rssiEstimator = RobustRssiPositionEstimator2D.create(rssiRobustMethod);
367         rangingEstimator = RobustRangingPositionEstimator2D.create(rangingRobustMethod);
368     }
369 }