1 /*
2 * Copyright (C) 2018 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;
17
18 import com.irurueta.algebra.Matrix;
19 import com.irurueta.geometry.Point;
20
21 /**
22 * Contains a located ranging reading associated to a given radio source (e.g. Wi-Fi access point or
23 * bluetooth beacon), indicating the distance to such access point.
24 *
25 * @param <S> a {@link RadioSource} type.
26 * @param <P> a {@link Point} type.
27 */
28 public class RangingReadingLocated<S extends RadioSource, P extends Point<?>> extends RangingReading<S>
29 implements ReadingLocated<P> {
30
31 /**
32 * Position where Wi-Fi reading was made.
33 */
34 private P position;
35
36 /**
37 * Covariance of inhomogeneous coordinates of current position
38 * (if available).
39 */
40 private Matrix positionCovariance;
41
42 /**
43 * Constructor.
44 *
45 * @param source radio source associated to this reading.
46 * @param distance distance in meters to the radio source.
47 * @param position position where reading was made.
48 * @throws IllegalArgumentException if radio source data is null, distance is negative
49 * or position is null.
50 */
51 public RangingReadingLocated(final S source, final double distance, final P position) {
52 super(source, distance);
53
54 if (position == null) {
55 throw new IllegalArgumentException();
56 }
57
58 this.position = position;
59 }
60
61 /**
62 * Constructor.
63 *
64 * @param source radio source associated to this reading.
65 * @param distance distance in meters to the radio source.
66 * @param position position where reading was made.
67 * @param numAttemptedMeasurements number of attempted measurements used in the RTT exchange.
68 * @param numSuccessfulMeasurements number of successful measurements used to calculate the
69 * distance and standard deviation.
70 * @throws IllegalArgumentException if radio source data is null, distance is negative,
71 * position is null, number of attempted measures is less than 1 or number of successful
72 * measures is negative.
73 */
74 public RangingReadingLocated(
75 final S source, final double distance, final P position, final int numAttemptedMeasurements,
76 final int numSuccessfulMeasurements) {
77 super(source, distance, numAttemptedMeasurements, numSuccessfulMeasurements);
78
79 if (position == null) {
80 throw new IllegalArgumentException();
81 }
82
83 this.position = position;
84 }
85
86 /**
87 * Constructor.
88 *
89 * @param source radio source associated to this reading.
90 * @param distance distance in meters to the radio source.
91 * @param position position where reading was made.
92 * @param distanceStandardDeviation standard deviation of distance, if available.
93 * @throws IllegalArgumentException if radio source data is null, distance is negative,
94 * position is null or standard deviation is zero or negative.
95 */
96 public RangingReadingLocated(
97 final S source, final double distance, final P position, final Double distanceStandardDeviation) {
98 super(source, distance, distanceStandardDeviation);
99
100 if (position == null) {
101 throw new IllegalArgumentException();
102 }
103
104 this.position = position;
105 }
106
107 /**
108 * Constructor.
109 *
110 * @param source radio source associated to this reading.
111 * @param distance distance in meters to the radio source.
112 * @param position position where reading was made.
113 * @param distanceStandardDeviation standard deviation of distance, if available.
114 * @param numAttemptedMeasurements number of attempted measurements used in the RTT exchange.
115 * @param numSuccessfulMeasurements number of successful measurements used to calculate the
116 * distance and standard deviation.
117 * @throws IllegalArgumentException if radio source data is null, distance is negative,
118 * position is null or standard deviation is zero or negative, number of attempted
119 * measures is less than 1 or number of successful measures is negative.
120 */
121 public RangingReadingLocated(
122 final S source, final double distance, final P position, final Double distanceStandardDeviation,
123 final int numAttemptedMeasurements, final int numSuccessfulMeasurements) {
124 super(source, distance, distanceStandardDeviation, numAttemptedMeasurements, numSuccessfulMeasurements);
125
126 if (position == null) {
127 throw new IllegalArgumentException();
128 }
129
130 this.position = position;
131 }
132
133 /**
134 * Constructor.
135 *
136 * @param source radio source associated to this reading.
137 * @param distance distance in meters to the radio source.
138 * @param position position where reading was made.
139 * @param positionCovariance covariance of inhomogeneous coordinates of
140 * current position (if available).
141 * @throws IllegalArgumentException if radio source data is null, distance is negative,
142 * position is null or position covariance has wrong size.
143 */
144 public RangingReadingLocated(
145 final S source, final double distance, final P position, final Matrix positionCovariance) {
146 this(source, distance, position);
147
148 if (positionCovariance != null) {
149 final var dims = position.getDimensions();
150 if (positionCovariance.getRows() != dims || positionCovariance.getColumns() != dims) {
151 throw new IllegalArgumentException();
152 }
153 }
154 this.positionCovariance = positionCovariance;
155 }
156
157 /**
158 * Constructor.
159 *
160 * @param source radio source associated to this reading.
161 * @param distance distance in meters to the radio source.
162 * @param position position where reading was made.
163 * @param positionCovariance covariance of inhomogeneous coordinates of
164 * current position (if available).
165 * @param numAttemptedMeasurements number of attempted measurements used in the RTT exchange.
166 * @param numSuccessfulMeasurements number of successful measurements used to calculate the
167 * distance and standard deviation.
168 * @throws IllegalArgumentException if radio source data is null, distance is negative,
169 * position is null, position covariance has wrong size, number of attempted
170 * measures is less than 1 or number of successful measures is negative.
171 */
172 public RangingReadingLocated(
173 final S source, final double distance, final P position, final Matrix positionCovariance,
174 final int numAttemptedMeasurements, final int numSuccessfulMeasurements) {
175 super(source, distance, numAttemptedMeasurements, numSuccessfulMeasurements);
176
177 if (position == null) {
178 throw new IllegalArgumentException();
179 }
180
181 if (positionCovariance != null) {
182 final var dims = position.getDimensions();
183 if (positionCovariance.getRows() != dims || positionCovariance.getColumns() != dims) {
184 throw new IllegalArgumentException();
185 }
186 }
187
188 this.position = position;
189 this.positionCovariance = positionCovariance;
190 }
191
192 /**
193 * Constructor.
194 *
195 * @param source radio source associated to this reading.
196 * @param distance distance in meters to the radio source.
197 * @param position position where reading was made.
198 * @param distanceStandardDeviation standard deviation of distance, if available.
199 * @param positionCovariance covariance of inhomogeneous coordinates of
200 * current position (if available).
201 * @throws IllegalArgumentException if radio source data is null, distance is negative,
202 * position is null or standard deviation is zero or negative.
203 */
204 public RangingReadingLocated(
205 final S source, final double distance, final P position, final Double distanceStandardDeviation,
206 final Matrix positionCovariance) {
207 this(source, distance, position, distanceStandardDeviation);
208
209 if (positionCovariance != null) {
210 final var dims = position.getDimensions();
211 if (positionCovariance.getRows() != dims || positionCovariance.getColumns() != dims) {
212 throw new IllegalArgumentException();
213 }
214 }
215 this.positionCovariance = positionCovariance;
216 }
217
218 /**
219 * Constructor.
220 *
221 * @param source radio source associated to this reading.
222 * @param distance distance in meters to the radio source.
223 * @param position position where reading was made.
224 * @param distanceStandardDeviation standard deviation of distance, if available.
225 * @param positionCovariance covariance of inhomogeneous coordinates of
226 * current position (if available).
227 * @param numAttemptedMeasurements number of attempted measurements used in the RTT exchange.
228 * @param numSuccessfulMeasurements number of successful measurements used to calculate the
229 * distance and standard deviation.
230 * @throws IllegalArgumentException if radio source data is null, distance is negative,
231 * position is null, distance standard deviation is zero or negative, position
232 * covariance has wrong size, number of attempted measures is less than 1 or
233 * number of successful measures is negative.
234 */
235 public RangingReadingLocated(
236 final S source, final double distance, final P position, final Double distanceStandardDeviation,
237 final Matrix positionCovariance, final int numAttemptedMeasurements, final int numSuccessfulMeasurements) {
238 super(source, distance, distanceStandardDeviation, numAttemptedMeasurements, numSuccessfulMeasurements);
239
240 if (position == null) {
241 throw new IllegalArgumentException();
242 }
243
244 if (positionCovariance != null) {
245 final var dims = position.getDimensions();
246 if (positionCovariance.getRows() != dims || positionCovariance.getColumns() != dims) {
247 throw new IllegalArgumentException();
248 }
249 }
250
251 this.position = position;
252 this.positionCovariance = positionCovariance;
253 }
254
255 /**
256 * Empty constructor.
257 */
258 protected RangingReadingLocated() {
259 super();
260 }
261
262 /**
263 * Gets position where reading was made.
264 *
265 * @return position where reading was made.
266 */
267 public P getPosition() {
268 return position;
269 }
270
271 /**
272 * Gets covariance of inhomogeneous coordinates of current position (if available).
273 *
274 * @return covariance of position or null.
275 */
276 public Matrix getPositionCovariance() {
277 return positionCovariance;
278 }
279 }