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.RangingFingerprint;
23 import com.irurueta.navigation.indoor.RangingReading;
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 * RSSI readings at unknown locations and using MSAC algorithm to discard outliers.
32 * This kind of estimator can be used to robustly determine the 3D position of a given
33 * device by getting readings at an unknown location of different radio sources whose
34 * 3D locations are known.
35 */
36 public class MSACRobustRangingPositionEstimator3D extends RobustRangingPositionEstimator3D {
37
38 /**
39 * Constructor.
40 */
41 public MSACRobustRangingPositionEstimator3D() {
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 MSACRobustRangingPositionEstimator3D(final List<? extends RadioSourceLocated<Point3D>> 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 MSACRobustRangingPositionEstimator3D(
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 MSACRobustRangingPositionEstimator3D(
84 final List<? extends RadioSourceLocated<Point3D>> 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 MSACRobustRangingPositionEstimator3D(final RobustRangingPositionEstimatorListener<Point3D> 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 MSACRobustRangingPositionEstimator3D(
112 final List<? extends RadioSourceLocated<Point3D>> sources,
113 final RobustRangingPositionEstimatorListener<Point3D> 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 MSACRobustRangingPositionEstimator3D(
128 final RangingFingerprint<? extends RadioSource, ? extends RangingReading<?
129 extends RadioSource>> fingerprint,
130 final RobustRangingPositionEstimatorListener<Point3D> listener) {
131 super(listener);
132 init();
133 internalSetFingerprint(fingerprint);
134 }
135
136 /**
137 * Constructor.
138 *
139 * @param sources located radio sources used for lateration.
140 * @param fingerprint fingerprint containing ranging readings at an unknown
141 * location for provided located radio sources.
142 * @param listener listener in charge of handling events.
143 */
144 public MSACRobustRangingPositionEstimator3D(
145 final List<? extends RadioSourceLocated<Point3D>> sources,
146 final RangingFingerprint<? extends RadioSource, ? extends RangingReading<?
147 extends RadioSource>> fingerprint,
148 final RobustRangingPositionEstimatorListener<Point3D> listener) {
149 super(listener);
150 init();
151 internalSetSources(sources);
152 internalSetFingerprint(fingerprint);
153 }
154
155 /**
156 * Gets threshold to determine whether samples are inliers or not when testing possible solutions.
157 * The threshold refers to the amount of error on distance between estimated position and distances
158 * provided for each sample.
159 *
160 * @return threshold to determine whether samples are inliers or not.
161 */
162 public double getThreshold() {
163 return ((MSACRobustLateration3DSolver) laterationSolver).getThreshold();
164 }
165
166 /**
167 * Sets threshold to determine whether samples are inliers or not when testing possible solutions.
168 * The threshold refers to the amount of error on distance between estimated position and distances
169 * provided for each sample.
170 *
171 * @param threshold threshold to determine whether samples are inliers or not.
172 * @throws IllegalArgumentException if provided value is equal or less than zero.
173 * @throws LockedException if this solver is locked.
174 */
175 public void setThreshold(final double threshold) throws LockedException {
176 ((MSACRobustLateration3DSolver) laterationSolver).setThreshold(threshold);
177 }
178
179 /**
180 * Returns method being used for robust estimation.
181 *
182 * @return method being used for robust estimation.
183 */
184 @Override
185 public RobustEstimatorMethod getMethod() {
186 return RobustEstimatorMethod.MSAC;
187 }
188
189 /**
190 * Initializes robust lateration solver.
191 */
192 private void init() {
193 laterationSolver = new MSACRobustLateration3DSolver(trilaterationSolverListener);
194 }
195 }