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