1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package com.irurueta.navigation.gnss;
17
18 import com.irurueta.geometry.InhomogeneousPoint3D;
19 import com.irurueta.geometry.Point3D;
20 import com.irurueta.navigation.frames.ECEFPosition;
21 import com.irurueta.navigation.frames.ECEFVelocity;
22 import com.irurueta.units.Distance;
23 import com.irurueta.units.DistanceConverter;
24 import com.irurueta.units.DistanceUnit;
25 import com.irurueta.units.Speed;
26 import com.irurueta.units.SpeedConverter;
27 import com.irurueta.units.SpeedUnit;
28
29 import java.io.Serializable;
30 import java.util.Objects;
31
32
33
34
35 public class GNSSMeasurement implements Serializable, Cloneable {
36
37
38
39
40 private double pseudoRange;
41
42
43
44
45 private double pseudoRate;
46
47
48
49
50 private double x;
51
52
53
54
55 private double y;
56
57
58
59
60 private double z;
61
62
63
64
65 private double vx;
66
67
68
69
70 private double vy;
71
72
73
74
75 private double vz;
76
77
78
79
80 public GNSSMeasurement() {
81 }
82
83
84
85
86
87
88
89
90
91
92
93
94
95 public GNSSMeasurement(final double pseudoRange, final double pseudoRate,
96 final double x, final double y, final double z,
97 final double vx, final double vy, final double vz) {
98 setPseudoRange(pseudoRange);
99 setPseudoRate(pseudoRate);
100 setPositionCoordinates(x, y, z);
101 setVelocityCoordinates(vx, vy, vz);
102 }
103
104
105
106
107
108
109
110
111
112
113
114
115
116 public GNSSMeasurement(final Distance pseudoRange, final Speed pseudoRate,
117 final Distance x, final Distance y, final Distance z,
118 final Speed vx, final Speed vy, final Speed vz) {
119 setPseudoRangeDistance(pseudoRange);
120 setPseudoRateSpeed(pseudoRate);
121 setPositionCoordinates(x, y, z);
122 setVelocityCoordinates(vx, vy, vz);
123 }
124
125
126
127
128
129
130
131
132
133
134
135 public GNSSMeasurement(final Distance pseudoRange, final Speed pseudoRate, final Point3D position,
136 final Speed vx, final Speed vy, final Speed vz) {
137 setPseudoRangeDistance(pseudoRange);
138 setPseudoRateSpeed(pseudoRate);
139 setPosition(position);
140 setVelocityCoordinates(vx, vy, vz);
141 }
142
143
144
145
146
147
148
149
150
151 public GNSSMeasurement(final double pseudoRange, final double pseudoRate, final ECEFPosition position,
152 final ECEFVelocity velocity) {
153 setPseudoRange(pseudoRange);
154 setPseudoRate(pseudoRate);
155 setEcefPosition(position);
156 setEcefVelocity(velocity);
157 }
158
159
160
161
162
163
164
165
166 public GNSSMeasurement(final double pseudoRange, final double pseudoRate,
167 final ECEFPositionAndVelocity positionAndVelocity) {
168 setPseudoRange(pseudoRange);
169 setPseudoRate(pseudoRate);
170 setPositionAndVelocity(positionAndVelocity);
171 }
172
173
174
175
176
177
178
179
180
181 public GNSSMeasurement(final Distance pseudoRange, final Speed pseudoRate, final ECEFPosition position,
182 final ECEFVelocity velocity) {
183 setPseudoRangeDistance(pseudoRange);
184 setPseudoRateSpeed(pseudoRate);
185 setEcefPosition(position);
186 setEcefVelocity(velocity);
187 }
188
189
190
191
192
193
194
195
196 public GNSSMeasurement(final Distance pseudoRange, final Speed pseudoRate,
197 final ECEFPositionAndVelocity positionAndVelocity) {
198 setPseudoRangeDistance(pseudoRange);
199 setPseudoRateSpeed(pseudoRate);
200 setPositionAndVelocity(positionAndVelocity);
201 }
202
203
204
205
206
207
208 public GNSSMeasurement(final GNSSMeasurement input) {
209 copyFrom(input);
210 }
211
212
213
214
215
216
217 public double getPseudoRange() {
218 return pseudoRange;
219 }
220
221
222
223
224
225
226 public void setPseudoRange(final double pseudoRange) {
227 this.pseudoRange = pseudoRange;
228 }
229
230
231
232
233
234
235 public void getPseudoRangeDistance(final Distance result) {
236 result.setValue(pseudoRange);
237 result.setUnit(DistanceUnit.METER);
238 }
239
240
241
242
243
244
245 public Distance getPseudoRangeDistance() {
246 return new Distance(pseudoRange, DistanceUnit.METER);
247 }
248
249
250
251
252
253
254 public void setPseudoRangeDistance(final Distance pseudoRange) {
255 this.pseudoRange = DistanceConverter.convert(pseudoRange.getValue().doubleValue(), pseudoRange.getUnit(),
256 DistanceUnit.METER);
257 }
258
259
260
261
262
263
264 public double getPseudoRate() {
265 return pseudoRate;
266 }
267
268
269
270
271
272
273 public void setPseudoRate(final double pseudoRate) {
274 this.pseudoRate = pseudoRate;
275 }
276
277
278
279
280
281
282 public void getPseudoRateSpeed(final Speed result) {
283 result.setValue(pseudoRate);
284 result.setUnit(SpeedUnit.METERS_PER_SECOND);
285 }
286
287
288
289
290
291
292 public Speed getPseudoRateSpeed() {
293 return new Speed(pseudoRate, SpeedUnit.METERS_PER_SECOND);
294 }
295
296
297
298
299
300
301 public void setPseudoRateSpeed(final Speed pseudoRate) {
302 this.pseudoRate = SpeedConverter.convert(pseudoRate.getValue().doubleValue(), pseudoRate.getUnit(),
303 SpeedUnit.METERS_PER_SECOND);
304 }
305
306
307
308
309
310
311 public double getX() {
312 return x;
313 }
314
315
316
317
318
319
320 public void setX(final double x) {
321 this.x = x;
322 }
323
324
325
326
327
328
329
330 public void getDistanceX(final Distance result) {
331 result.setValue(x);
332 result.setUnit(DistanceUnit.METER);
333 }
334
335
336
337
338
339
340 public Distance getDistanceX() {
341 return new Distance(x, DistanceUnit.METER);
342 }
343
344
345
346
347
348
349 public void setDistanceX(final Distance x) {
350 this.x = DistanceConverter.convert(x.getValue().doubleValue(), x.getUnit(), DistanceUnit.METER);
351 }
352
353
354
355
356
357
358 public double getY() {
359 return y;
360 }
361
362
363
364
365
366
367 public void setY(final double y) {
368 this.y = y;
369 }
370
371
372
373
374
375
376
377 public void getDistanceY(final Distance result) {
378 result.setValue(y);
379 result.setUnit(DistanceUnit.METER);
380 }
381
382
383
384
385
386
387 public Distance getDistanceY() {
388 return new Distance(y, DistanceUnit.METER);
389 }
390
391
392
393
394
395
396 public void setDistanceY(final Distance y) {
397 this.y = DistanceConverter.convert(y.getValue().doubleValue(), y.getUnit(), DistanceUnit.METER);
398 }
399
400
401
402
403
404
405 public double getZ() {
406 return z;
407 }
408
409
410
411
412
413
414 public void setZ(final double z) {
415 this.z = z;
416 }
417
418
419
420
421
422
423
424 public void getDistanceZ(final Distance result) {
425 result.setValue(z);
426 result.setUnit(DistanceUnit.METER);
427 }
428
429
430
431
432
433
434 public Distance getDistanceZ() {
435 return new Distance(z, DistanceUnit.METER);
436 }
437
438
439
440
441
442
443 public void setDistanceZ(final Distance z) {
444 this.z = DistanceConverter.convert(z.getValue().doubleValue(), z.getUnit(), DistanceUnit.METER);
445 }
446
447
448
449
450
451
452
453
454 public void setPositionCoordinates(final double x, final double y, final double z) {
455 this.x = x;
456 this.y = y;
457 this.z = z;
458 }
459
460
461
462
463
464
465
466
467 public void setPositionCoordinates(final Distance x, final Distance y, final Distance z) {
468 setDistanceX(x);
469 setDistanceY(y);
470 setDistanceZ(z);
471 }
472
473
474
475
476
477
478 public void getPosition(final Point3D result) {
479 result.setInhomogeneousCoordinates(x, y, z);
480 }
481
482
483
484
485
486
487 public Point3D getPosition() {
488 return new InhomogeneousPoint3D(x, y, z);
489 }
490
491
492
493
494
495
496 public void setPosition(final Point3D position) {
497 x = position.getInhomX();
498 y = position.getInhomY();
499 z = position.getInhomZ();
500 }
501
502
503
504
505
506
507 public void getEcefPosition(final ECEFPosition result) {
508 result.setCoordinates(x, y, z);
509 }
510
511
512
513
514
515
516 public ECEFPosition getEcefPosition() {
517 return new ECEFPosition(x, y, z);
518 }
519
520
521
522
523
524
525 public void setEcefPosition(final ECEFPosition ecefPosition) {
526 x = ecefPosition.getX();
527 y = ecefPosition.getY();
528 z = ecefPosition.getZ();
529 }
530
531
532
533
534
535
536 public double getVx() {
537 return vx;
538 }
539
540
541
542
543
544
545 public void setVx(final double vx) {
546 this.vx = vx;
547 }
548
549
550
551
552
553
554
555 public void getSpeedX(final Speed result) {
556 result.setValue(vx);
557 result.setUnit(SpeedUnit.METERS_PER_SECOND);
558 }
559
560
561
562
563
564
565 public Speed getSpeedX() {
566 return new Speed(vx, SpeedUnit.METERS_PER_SECOND);
567 }
568
569
570
571
572
573
574 public void setSpeedX(final Speed speedX) {
575 vx = SpeedConverter.convert(speedX.getValue().doubleValue(), speedX.getUnit(), SpeedUnit.METERS_PER_SECOND);
576 }
577
578
579
580
581
582
583 public double getVy() {
584 return vy;
585 }
586
587
588
589
590
591
592 public void setVy(final double vy) {
593 this.vy = vy;
594 }
595
596
597
598
599
600
601
602 public void getSpeedY(final Speed result) {
603 result.setValue(vy);
604 result.setUnit(SpeedUnit.METERS_PER_SECOND);
605 }
606
607
608
609
610
611
612 public Speed getSpeedY() {
613 return new Speed(vy, SpeedUnit.METERS_PER_SECOND);
614 }
615
616
617
618
619
620
621 public void setSpeedY(final Speed speedY) {
622 vy = SpeedConverter.convert(speedY.getValue().doubleValue(), speedY.getUnit(), SpeedUnit.METERS_PER_SECOND);
623 }
624
625
626
627
628
629
630 public double getVz() {
631 return vz;
632 }
633
634
635
636
637
638
639 public void setVz(final double vz) {
640 this.vz = vz;
641 }
642
643
644
645
646
647
648 public void getSpeedZ(final Speed result) {
649 result.setValue(vz);
650 result.setUnit(SpeedUnit.METERS_PER_SECOND);
651 }
652
653
654
655
656
657
658 public Speed getSpeedZ() {
659 return new Speed(vz, SpeedUnit.METERS_PER_SECOND);
660 }
661
662
663
664
665
666
667 public void setSpeedZ(final Speed speedZ) {
668 vz = SpeedConverter.convert(speedZ.getValue().doubleValue(), speedZ.getUnit(), SpeedUnit.METERS_PER_SECOND);
669 }
670
671
672
673
674
675
676
677
678 public void setVelocityCoordinates(final double vx, final double vy, final double vz) {
679 this.vx = vx;
680 this.vy = vy;
681 this.vz = vz;
682 }
683
684
685
686
687
688
689
690
691 public void setVelocityCoordinates(final Speed speedX, final Speed speedY, final Speed speedZ) {
692 setSpeedX(speedX);
693 setSpeedY(speedY);
694 setSpeedZ(speedZ);
695 }
696
697
698
699
700
701
702 public void getEcefVelocity(final ECEFVelocity result) {
703 result.setCoordinates(vx, vy, vz);
704 }
705
706
707
708
709
710
711 public ECEFVelocity getEcefVelocity() {
712 return new ECEFVelocity(vx, vy, vz);
713 }
714
715
716
717
718
719
720 public void setEcefVelocity(final ECEFVelocity ecefVelocity) {
721 vx = ecefVelocity.getVx();
722 vy = ecefVelocity.getVy();
723 vz = ecefVelocity.getVz();
724 }
725
726
727
728
729
730
731 public void getPositionAndVelocity(final ECEFPositionAndVelocity result) {
732 result.setPositionCoordinates(x, y, z);
733 result.setVelocityCoordinates(vx, vy, vz);
734 }
735
736
737
738
739
740
741 public ECEFPositionAndVelocity getPositionAndVelocity() {
742 return new ECEFPositionAndVelocity(x, y, z, vx, vy, vz);
743 }
744
745
746
747
748
749
750 public void setPositionAndVelocity(final ECEFPositionAndVelocity positionAndVelocity) {
751 x = positionAndVelocity.getX();
752 y = positionAndVelocity.getY();
753 z = positionAndVelocity.getZ();
754
755 vx = positionAndVelocity.getVx();
756 vy = positionAndVelocity.getVy();
757 vz = positionAndVelocity.getVz();
758 }
759
760
761
762
763
764
765 public void copyTo(final GNSSMeasurement output) {
766 output.pseudoRange = pseudoRange;
767 output.pseudoRate = pseudoRate;
768
769 output.x = x;
770 output.y = y;
771 output.z = z;
772
773 output.vx = vx;
774 output.vy = vy;
775 output.vz = vz;
776 }
777
778
779
780
781
782
783 public void copyFrom(final GNSSMeasurement input) {
784 pseudoRange = input.pseudoRange;
785 pseudoRate = input.pseudoRate;
786
787 x = input.x;
788 y = input.y;
789 z = input.z;
790
791 vx = input.vx;
792 vy = input.vy;
793 vz = input.vz;
794 }
795
796
797
798
799
800
801
802 @Override
803 public int hashCode() {
804 return Objects.hash(pseudoRange, pseudoRate, x, y, z, vx, vy, vz);
805 }
806
807
808
809
810
811
812
813
814 @Override
815 public boolean equals(final Object obj) {
816 if (obj == this) {
817 return true;
818 }
819 if (obj == null || getClass() != obj.getClass()) {
820 return false;
821 }
822
823 final var other = (GNSSMeasurement) obj;
824 return equals(other);
825 }
826
827
828
829
830
831
832
833 public boolean equals(final GNSSMeasurement other) {
834 return equals(other, 0.0);
835 }
836
837
838
839
840
841
842
843
844
845
846 public boolean equals(final GNSSMeasurement other, final double threshold) {
847 if (other == null) {
848 return false;
849 }
850
851 return Math.abs(pseudoRange - other.pseudoRange) <= threshold
852 && Math.abs(pseudoRate - other.pseudoRate) <= threshold
853 && Math.abs(x - other.x) <= threshold
854 && Math.abs(y - other.y) <= threshold
855 && Math.abs(z - other.z) <= threshold
856 && Math.abs(vx - other.vx) <= threshold
857 && Math.abs(vy - other.vy) <= threshold
858 && Math.abs(vz - other.vz) <= threshold;
859 }
860
861
862
863
864
865
866
867 @Override
868 protected Object clone() throws CloneNotSupportedException {
869 final var result = (GNSSMeasurement) super.clone();
870 copyTo(result);
871 return result;
872 }
873 }