-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathanalyzervehicle.h
1310 lines (1165 loc) · 47.3 KB
/
analyzervehicle.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifndef _ANALYZER_VEHICLE
#define _ANALYZER_VEHICLE
#include <stdint.h>
#include <map>
#pragma GCC diagnostic push
#if defined(__GNUC__) && __GNUC__ >= 9
#pragma GCC diagnostic ignored "-Waddress-of-packed-member"
#endif
#pragma GCC diagnostic ignored "-Wpedantic"
#include "mavlink_c_library/ardupilotmega/mavlink.h"
#include "mavlink_c_library/common/mavlink.h"
#pragma GCC diagnostic pop
#include "analyzer_util.h"
#include "Vector3f.h"
namespace AnalyzerVehicle {
/// @brief Abstraction of a vehicle attitude.
class Attitude {
public:
float roll() const { return _att[0]; };
float pitch() const { return _att[1]; };
float yaw() const { return _att[2]; };
uint64_t roll_modtime() const {
return get_att_modtime(0);
}
uint64_t pitch_modtime() const {
return get_att_modtime(1);
}
uint64_t yaw_modtime() const {
return get_att_modtime(2);
}
void set_roll(uint64_t T, float roll) {
_set_att_attrib(0, T, roll);
}
void set_pitch(uint64_t T, float pitch) {
_set_att_attrib(1, T, pitch);
}
void set_yaw(uint64_t T, float yaw) {
_set_att_attrib(2, T, yaw);
}
private:
// all in degrees:
float _att[3];
uint64_t _att_modtime[3];
void _set_att_attrib(uint8_t offset, uint64_t T, float value) {
_att[offset] = value;
_att_modtime[offset] = T;
}
uint64_t get_att_modtime(uint8_t offset) const {
return _att_modtime[offset];
}
};
/// @brief Abstraction of a vehicle attitude rates.
class AttitudeRate {
public:
// all in degrees/second:
float roll() const { return _att[0]; };
float pitch() const { return _att[1]; };
float yaw() const { return _att[2]; };
uint64_t roll_modtime() const {
return get_att_modtime(0);
}
uint64_t pitch_modtime() const {
return get_att_modtime(1);
}
uint64_t yaw_modtime() const {
return get_att_modtime(2);
}
void set_roll(uint64_t T, float roll) {
_set_att_attrib(0, T, roll);
}
void set_pitch(uint64_t T, float pitch) {
_set_att_attrib(1, T, pitch);
}
void set_yaw(uint64_t T, float yaw) {
_set_att_attrib(2, T, yaw);
}
private:
// all in degrees:
float _att[3];
uint64_t _att_modtime[3];
void _set_att_attrib(uint8_t offset, uint64_t T, float value) {
_att[offset] = value;
_att_modtime[offset] = T;
}
uint64_t get_att_modtime(uint8_t offset) const {
return _att_modtime[offset];
}
};
/// @brief Abstraction of a vehicle altitude.
class Altitude {
public:
void set_alt(uint64_t T, double alt) {
_alt = alt;
_alt_modtime = T;
}
double alt() const {
return _alt;
}
uint64_t alt_modtime() const {
return _alt_modtime;
}
private:
double _alt;
uint64_t _alt_modtime;
};
/// @brief Altitude according to some sensor or algorithm.
class AltitudeEstimate {
public:
AltitudeEstimate(const std::string name) :
_name(name)
{ }
AltitudeEstimate() :
_name(NULL),
_altitude({})
{ }
const std::string name() { return _name; }
const Altitude altitude() { return _altitude; }
void set_alt(uint64_t T, float alt) { _altitude.set_alt(T, alt); }
float alt() { return _altitude.alt(); }
private:
const std::string _name;
Altitude _altitude = { };
};
/// @brief Abstraction of a vehicle global position (2D).
class Position {
public:
void set_lat(uint64_t T, double lat) {
_lat = lat;
_lat_modtime = T;
}
double lat() const { return _lat; };
uint64_t lat_modtime() const { return _lat_modtime; };
void set_lon(uint64_t T, double lon) {
_lon = lon;
_lon_modtime = T;
}
double lon() const { return _lon; };
uint64_t lon_modtime() const { return _lon_modtime; };
// double distance_to(Position otherpos);
double horizontal_distance_to(Position otherpos) const;
bool is_zero_zero() {
return (is_zero(lat()) && is_zero(lon()));
}
private:
double _lat;
double _lon;
uint64_t _lat_modtime;
uint64_t _lon_modtime;
};
/// @brief Abstraction of a vehicle velocity.
class Velocity {
public:
bool is_0d() {
return ! is_equal(_velocity_scalar, -1.0f);
}
bool is_2d() {
if (is_0d()) {
return false;
}
if (_is_2d_scalar) {
return true;
}
return is_equal(_velocity[2], -1.0f);
}
bool is_3d() {
if (is_0d()) {
return false;
}
if (is_2d()) {
return false;
}
return true;
}
double size_2d() {
return sqrt(_velocity[0]*_velocity[0] + _velocity[1] * _velocity[1]);;
}
double size() {
if (is_0d()) {
return _velocity_scalar;
}
if (is_3d()) {
// this is the 3D case
return _velocity.len();
}
// this is the 2D case
return size_2d();
}
void set_x(uint64_t T, double x) {
_have_components = true;
_velocity[0] = x;
_velocity_modtime = T;
}
void set_y(uint64_t T, double y) {
_have_components = true;
_velocity[1] = y;
_velocity_modtime = T;
}
void set_z(uint64_t T, double z) {
_have_components = true;
_velocity[2] = z;
_velocity_modtime = T;
}
void set_scalar(uint64_t T, double scalar) {
_velocity_scalar = scalar;
_velocity_modtime = T;
}
uint64_t velocity_modtime() {
return _velocity_modtime;
}
void set_is2D_scalar(const bool value) {
_is_2d_scalar = value;
}
bool is2D_scalar() {
return _is_2d_scalar;
}
private:
// only one of these two should be set:
Vector3f _velocity = { };
double _velocity_scalar = -1;
bool _have_components = false;
uint64_t _velocity_modtime = 0;
bool _is_2d_scalar = false;
};
/// @brief State information for a base Extended Kalman Filter.
class EKF {
public:
void set_variance(uint64_t T, std::string name, double value) {
_variances[name] = value;
_variances_T[name] = T;
}
uint64_t variance_T(std::string name) const;
void set_flags(uint64_t T, uint16_t flags) {
_flags = flags;
_flags_T = T;
}
uint16_t flags() const {
return _flags;
}
uint64_t flags_T() const {
return _flags_T;
}
std::map<const std::string, double> variances() {
return _variances;
}
private:
std::map<const std::string, double> _variances;
std::map<const std::string, uint64_t> _variances_T;
uint16_t _flags = 0;
uint64_t _flags_T = 0;
};
/// @brief State information for a second-edition Extended Kalman Filter.
class NKF : public EKF {
public:
private:
};
/// @brief State information for a third-edition Extended Kalman Filter.
class XKF : public NKF {
public:
private:
};
// class AV_PosNED {
// public:
// uint16_t N;
// uint16_t E;
// uint16_t D;
// };
/// @brief Attitude according to some sensor or algorithm.
class AttitudeEstimate {
public:
AttitudeEstimate(const std::string name) :
_name(name)
{ }
AttitudeEstimate() :
_name(NULL),
_attitude({})
{ }
const std::string name() { return _name; }
const Attitude attitude() { return _attitude; }
void set_roll(uint64_t T, double roll) { _attitude.set_roll(T, roll); }
void set_pitch(uint64_t T, double pitch) { _attitude.set_pitch(T, pitch); }
void set_yaw(uint64_t T, double yaw) { _attitude.set_yaw(T, yaw); }
double roll() { return _attitude.roll(); }
double pitch() { return _attitude.pitch(); }
double yaw() { return _attitude.yaw(); }
private:
const std::string _name;
Attitude _attitude;
};
/// @brief Position according to some sensor or algorithm.
class PositionEstimate {
public:
PositionEstimate(const std::string name) :
_name(name)
{ }
PositionEstimate() :
_name(NULL),
_position({})
{ }
const std::string name() { return _name; }
const Position position() { return _position; }
void set_lat(uint64_t T, double lat) { _position.set_lat(T, lat); }
void set_lon(uint64_t T, double lon) { _position.set_lon(T, lon); }
double lat() { return _position.lat(); }
double lon() { return _position.lon(); }
private:
const std::string _name;
Position _position = { };
};
/// @brief Velocity according to some sensor or algorithm.
class VelocityEstimate {
public:
VelocityEstimate(const std::string name) :
_name(name)
{ }
VelocityEstimate() :
_name(NULL),
_velocity({})
{ }
const std::string name() { return _name; }
Velocity &velocity() { return _velocity; }
private:
const std::string _name;
Velocity _velocity = { };
};
/// @brief Information on a vehicle battery.
class Battery {
public:
float _remaining = 0; // percent
uint64_t _remaining_modtime = 0;
// uint32_t _capacity; // mAh
// uint64_t _capacity_modtime = 0;
bool _failsafe_event = 0;
uint64_t _failsafe_event_T = 0;
};
/// @brief Information about the Navigation Controller's output.
class AV_Nav {
public:
void set_desroll(uint64_t T, float roll) {
_des[0] = roll;
_modtimes[0] = T;
}
float desroll() const { return _des[0]; }
void set_despitch(uint64_t T, float pitch) {
_des[1] = pitch;
_modtimes[1] = T;
}
float despitch() const { return _des[1]; }
void set_desyaw(uint64_t T, float yaw) {
_des[2] = yaw;
_modtimes[2] = T;
}
float desyaw() const { return _des[2]; }
private:
float _des[3];
uint64_t _modtimes[3];
};
/// @brief A source of magnetic field information.
class Compass {
public:
Compass(const std::string name) :
_name(name)
{ }
const std::string name() const { return _name; }
Vector3f &field() { return _field; }
uint64_t field_T() { // most recent timestamp of all components
return _field_T;
}
void set_field_T(uint64_t field_T) { _field_T = field_T; }
private:
const std::string _name; // do we really want this?!
Vector3f _field = { };
uint64_t _field_T = 0;
};
/// @brief A source of GPS information (typically output from a GPS device).
class GPSInfo {
public:
GPSInfo(std::string name) { _name = name; }
const std::string name() { return _name; }
uint8_t fix_type() { return _fix_type; }
void set_fix_type(uint8_t fix_type) { _fix_type = fix_type; }
double hdop() { return _hdop; }
void set_hdop(double hdop) { _hdop = hdop; }
double sacc() { return _sacc; }
void set_sacc(double sacc) { _sacc = sacc; }
uint8_t satellites() { return _satellites_visible; }
void set_satellites(uint8_t satellites) { _satellites_visible = satellites; }
private:
std::string _name;
double _hdop = 0;
double _sacc = 0;
uint8_t _satellites_visible = 0;
uint8_t _fix_type = 0;
};
/* may need to factor and subclass this for non-APM-on-PixHawk: */
/// @brief Information about the AutoPilot.
class AutoPilot {
public:
typedef enum {
UNKNOWN,
PX4V2,
} AutoPilotHardware;
uint16_t overruns() { return _overruns; }
uint16_t overruns_T() { return _overruns_T; }
void set_overruns(uint64_t T, uint16_t);
uint16_t loopcount() { return _loopcount; }
void set_loopcount(uint64_t T, uint16_t);
uint64_t slices_max_T() { return _slices_max_T; }
uint16_t slices_max() { return _slices_max; }
void set_slices_max(uint64_t T, uint16_t);
uint16_t slices_min() { return _slices_min; }
void set_slices_min(uint64_t T, uint16_t);
uint16_t slices_avg() { return _slices_avg; }
void set_slices_avg(uint64_t T, uint16_t);
uint16_t slices_stddev() { return _slices_stddev; }
void set_slices_stddev(uint64_t T, uint16_t);
double vcc() { return _vcc; }
uint64_t vcc_T() { return _vcc_T; }
void set_vcc(uint64_t T, double);
void set_hardware(const AutoPilotHardware hw) { _hardware = hw; }
AutoPilotHardware hardware() const { return _hardware; }
private:
uint16_t _overruns;
uint64_t _overruns_T = 0;
uint16_t _loopcount;
uint64_t _loopcount_T = 0;
uint16_t _slices_max;
uint64_t _slices_max_T = 0;
uint16_t _slices_min;
uint64_t _slices_min_T = 0;
uint16_t _slices_avg;
uint64_t _slices_avg_T = 0;
uint16_t _slices_stddev;
uint64_t _slices_stddev_T = 0;
double _vcc;
uint64_t _vcc_T = 0;
AutoPilotHardware _hardware = UNKNOWN;
};
/// @brief Accelerometer and gyroscope information from onboard IMUs.
class IMU {
public:
IMU(const std::string name, uint64_t &T) :
_name(name),
_T(T)
{ }
const std::string name() const { return _name; }
uint64_t T() const { return _T; };
Vector3f &acc() { return _acc; }
Vector3f &gyr() { return _gyr; }
/// @brief Retrieve average of gyroscopes by sample count.
/// @param count number of samples to average over.
/// @param[out] ret the returned average.
/// @return True if the average could be found.
bool gyr_avg(const uint16_t count, Vector3f &ret) const;
/// @brief Retrieve average of gyroscopes by time
/// @param T Highest timestamp to use (microseconds, typically _vehicle->T())
/// @param T_delta Time span over which to take average (microseconds).
/// @param[out] ret The returned average.
/// @return True if the average could be found.
bool gyr_avg(uint64_t T, uint64_t T_delta, Vector3f &ret) const;
uint64_t acc_T() { // most recent timestamp of all components
return _acc_T;
}
uint64_t gyr_T() { // most recent timestamp of all components
return _gyr_T;
}
void set_acc_T(uint64_t acc_T) { _acc_T = acc_T; }
void set_gyr(uint64_t T, Vector3f values);
void set_acc_clip_count(uint16_t count);
uint64_t last_acc_clip_time() const;
bool acc_is_clipping() const;
private:
const std::string _name; // do we really want this?!
uint64_t &_T;
Vector3f _acc = { };
Vector3f _gyr = { };
uint64_t _acc_T = 0;
uint64_t _gyr_T = 0;
static const uint16_t _gyr_hist_max = 1000;
struct _timestamped_gyr_hist {
uint64_t T;
Vector3f gyr;
};
_timestamped_gyr_hist _gyr_hist[_gyr_hist_max] = { };
uint16_t _gyr_seen = 0;
uint16_t _gyr_next = 0;
uint64_t _acc_clip_count_T;
uint16_t _acc_clip_count = 0;
};
/// @brief Base class from which all vehicles inherit.
class Base {
public:
Base() { }
virtual ~Base() { }
/// @brief Returns a short string describing the vehicle.
/// @return A short string describing the vehicle e.g. "Copter".
virtual const std::string typeString() const { return "Base"; }
/// @brief Time since autopilot boot (microseconds).
/// @return Time since autopilot boot (microseconds).
uint64_t time_since_boot() const {
return _time_since_boot;
}
/// @brief The timestamp at which the "time_since_boot()" timestamp was updated.
/// @details This timestamp may reflect time on a different system - for example, a MAVLink tlog often uses a Ground Control Station's concept of time.
/// @return Timestamp that the autopilot boot time was last changed.
uint64_t time_since_boot_T() const {
return _time_since_boot_T;
}
/// @brief Set the number of microseconds the autopilot has been booted.
/// @param time_since_boot Microseconds since autopilot boot.
void set_time_since_boot(const uint64_t time_since_boot) {
_time_since_boot = time_since_boot;
_time_since_boot_T = T();
}
/// @brief Evaluation of whether the vehicle is flying.
/// @return ``true`` if it is believed the vehicle is flying.
virtual bool is_flying() const { return false; }
/// @brief Vehicle arm status.
/// @return ``true`` if it believed the vehicle is armed.
virtual bool is_armed() const { return _armed; };
/// @brief Set the vehicle arm status.
/// @param value The new vehicle arm status.
virtual void set_armed(bool value) { _armed = value; };
/// @brief All the different vehicles we have specific tests for.
enum vehicletype_t {
invalid = 0,
copter = 17,
plane = 19,
rover = 27,
};
/// @brief Vehicle type forced status.
/// @detail Sometimes the vehicle type can not be determined from a log and must be forced.
/// @return ``true`` if the vehicle type has been forced.
bool vehicletype_is_forced() const { return _vehicletype_is_forced; }
/// @brief Indicates that the vehicle type has been forced.
/// @param value ``true`` if the vehicle type has been forced.
void set_vehicletype_is_forced(bool value) { _vehicletype_is_forced = value; }
/// @brief Vehicle type.
/// @detail Until the vehicle type is determined, this returns invalid. After the vehicle type is determined (e.g. from a log), this will return a specific value from the vehicletype_t enumeration indication the vehicle type.
/// @return The current vehicle type.
virtual vehicletype_t vehicletype() const {
return invalid;
}
/// @brief Change the vehicle from one type to another.
/// @detail A base vehicle is used to gather information until we determine what vehicle type we are actually analyzing. This call is used to switch to a more-specific vehicle type.
/// @param _vehicle Vehicle to change type of.
/// @newtype New vehicle type.
static void switch_vehicletype(Base *&_vehicle, vehicletype_t newtype);
/// @brief Set a variance value by name.
/// @param name Name of variance to set (e.g. "pos_horiz").
/// @param value New value of the variance.
void ekf_set_variance(const char *name, double value) {
_ekf.set_variance(T(), name, value);
}
/// @brief Variance modification time.
/// @param name Name of variance to retrieve modification time for.
/// @return timestamp Timestamp at which variance was last changed (microseconds).
uint64_t ekf_variance_T(std::string name) const {
return _ekf.variance_T(name);
}
/// @brief Set EKF status flags.
/// @param flags EKF self-assessment status flags.
void ekf_set_flags(uint16_t flags) {
_ekf.set_flags(T(), flags);
}
/// @brief EKF status flags.
/// @return EKF self-assessment status flags.
uint16_t ekf_flags() const {
return _ekf.flags();
}
/// @brief EKF status flags modification time.
/// @return timestamp Timestamp at which the EKF self-assessment flags were last changed (microseconds).
uint64_t ekf_flags_T() const {
return _ekf.flags_T();
}
/// @brief All EKF variances.
/// @return Returns all EKF variances as a map from name to value.
std::map<const std::string, double> ekf_variances() {
return _ekf.variances();
}
/// @brief Set a variance value by name.
/// @param name Name of variance to set (e.g. "pos_horiz").
/// @param value New value of the variance.
void nkf_set_variance(const char *name, double value) {
_nkf.set_variance(T(), name, value);
}
uint64_t nkf_variance_T(std::string name) const {
return _nkf.variance_T(name);
}
/// @brief Set NKF (EKFv2) status flags.
/// @param flags NKF (EKFv2 self-assessment status flags.
void nkf_set_flags(uint16_t flags) {
_nkf.set_flags(T(), flags);
}
/// @brief NKF status flags.
/// @return NKF self-assessment status flags.
uint16_t nkf_flags() const {
return _nkf.flags();
}
/// @brief NKF (EKF2) status flags modification time.
/// @return timestamp Timestamp at which the NKF self-assessment flags were last changed (microseconds).
uint64_t nkf_flags_T() const {
return _nkf.flags_T();
}
/// @brief All NKF (EKF2) variances.
/// @return Returns all NKF (EKF2) variances as a map from name to value.
std::map<const std::string, double> nkf_variances() {
return _nkf.variances();
}
/// @brief Set a variance value by name.
/// @param name Name of variance to set (e.g. "pos_horiz").
/// @param value New value of the variance.
void xkf_set_variance(const char *name, double value) {
_xkf.set_variance(T(), name, value);
}
uint64_t xkf_variance_T(std::string name) const {
return _xkf.variance_T(name);
}
/// @brief Set XKF (EKF3) status flags.
/// @param flags XKF (EKF3 self-assessment status flags.
void xkf_set_flags(uint16_t flags) {
_xkf.set_flags(T(), flags);
}
/// @brief XKF status flags.
/// @return XKF self-assessment status flags.
uint16_t xkf_flags() const {
return _xkf.flags();
}
/// @brief XKF (EKF3) status flags modification time.
/// @return timestamp Timestamp at which the XKF self-assessment flags were last changed (microseconds).
uint64_t xkf_flags_T() const {
return _xkf.flags_T();
}
/// @brief All XKF (EKF3) variances.
/// @return Returns all XKF (EKF3) variances as a map from name to value.
std::map<const std::string, double> xkf_variances() {
return _xkf.variances();
}
/// @brief Retrieve parameter value.
/// @param name Parameter value to retrieve.
/// @detail This function will abort if the parameter has not been seen and no default is known.
/// @return Parameter value from log or defaults.
float param(const std::string name) const;
/// @brief Retrieve parameter value.
/// @detail Returns parameter value ONLY from input, not from defaults.
/// @param name Parameter value to retrieve.
/// @param[out] ret Parameter value.
/// @return ``true`` if the parameter has been seen in the log.
bool param(const char *name, float &ret) const;
/// @brief Retrieve parameter value.
/// @detail Returns parameter value ONLY from input, not from defaults.
/// @param name Parameter value to retrieve.
/// @param[out] ret Parameter value.
/// @return ``true`` if the parameter has been seen in the log.
bool param(const std::string name, float &ret) const;
/// @brief Number of parameters seen.
/// @return Number of parameters seen in input.
uint16_t param_count() const { return _param.size(); };
/// @brief Parameter status.
/// @return ``true`` if the parameter has been seen in the log.
bool param_seen(const std::string name) const;
/// @brief Timestamp at which a parameter was last modified (microseconds).
/// @param name Parameter modification time to retrieve.
/// @return Parameter modification time (microseconds).
uint64_t param_T(const std::string name) const;
/// @brief Set a parameter.
/// @param name Parameter to set.
/// @param value New value of parameter.
void param_set(const char *name, const float value);
/// @brief Return the default value for a parameter.
/// @detail Default parameters are supplied so that some analysis can be done even in the absence of parameters in the logs.
/// @param name Parameter to retrieve default value for.
/// @param[out] ret Value of parameter.
/// @return ``true`` if a default was found for the parameters.
virtual bool param_default(const char *name, float &ret) const;
/// @brief Retrieve a parameter value.
/// @detail Returns the value last set for this parameter, or a default if it has not been set yet.
/// @param name Parameter to retrieve default value for.
/// @param[out] ret Value of parameter.
/// @return ``true`` if the parameter value was found.
bool param_with_defaults(const char *name, float &ret) const;
/// @brief Retrieves a parameter value and abort()s if it not found.
/// @detail Returns the value last set for this parameter, or a default if it has not been set yet.
/// @param name Parameter to retrieve default value for.
/// @return Value of parameter.
float require_param_with_defaults(const char *name) const;
/// @brief Set outputs for all servos.
/// @param ch1 current output for servo 1 (ppm).
/// @param ch2 current output for servo 2 (ppm).
/// @param ch3 current output for servo 3 (ppm).
/// @param ch4 current output for servo 4 (ppm).
/// @param ch5 current output for servo 5 (ppm).
/// @param ch6 current output for servo 6 (ppm).
/// @param ch7 current output for servo 7 (ppm).
/// @param ch8 current output for servo 8 (ppm).
void set_servo_output(uint16_t ch1, uint16_t ch2, uint16_t ch3, uint16_t ch4, uint16_t ch5, uint16_t ch6, uint16_t ch7, uint16_t ch8);
/// @brief Set outputs for single servo.
/// @param channel_number Servo to set value for.
/// @param value New value for servo output (ppm).
void set_servo_output(uint8_t channel_number, uint16_t value);
/// @brief Return current output for a specific servo.
/// @param channel_number Servo number.
/// @return Current servo output (ppm).
uint16_t servo_output(uint8_t channel_number) const {
return _servo_output[channel_number];
}
/// @brief Set timestamp distinguishing logging events.
/// @detail This may or may not be a real wall-clock time.
/// @param time_us New timestamp (microseconds).
void set_T(const uint64_t time_us);
/// @brief Current timestamp.
/// @return Current universe timestamp.
uint64_t T() { return _T; }
/// @brief Canonical vehicle attitude - roll.
/// @return Canonical attitude - roll (degrees).
float roll() const { return att().roll(); }
/// @brief Canonical vehicle attitude - pitch (degrees).
/// @return Canonical attitude - pitch.
float pitch() const { return att().pitch(); }
/// @brief Canonical vehicle attitude - yaw.
/// @return Canonical attitude - yaw (degrees).
float yaw() const { return att().yaw(); }
/// @brief Modification time - roll.
/// @return Timestamp roll was last modified (microseconds).
uint64_t roll_modtime() const { return att().roll_modtime(); }
/// @brief Modification time - pitch.
/// @return Timestamp pitch was last modified (microseconds).
uint64_t pitch_modtime() const { return att().pitch_modtime(); }
/// @brief Modification time - yaw.
/// @return Timestamp yaw was last modified (microseconds).
uint64_t yaw_modtime() const { return att().yaw_modtime(); }
/// @brief Set canonical vehicle atttiude - roll.
/// @param new Canonical attitude - roll (degrees).
void set_roll(float roll) { att().set_roll(T(), roll); }
/// @brief Set canonical vehicle atttiude - pitch.
/// @param new Canonical attitude - pitch (degrees).
void set_pitch(float roll) { att().set_pitch(T(), roll); }
/// @brief Set canonical vehicle atttiude - yaw.
/// @param new Canonical attitude - yaw (degrees).
void set_yaw(float roll) { att().set_yaw(T(), roll); }
/// @brief set Navigation Controller desired attitude - roll.
/// @param roll New desired attitude - roll.
void set_desroll(float roll) { _nav.set_desroll(T(), roll); };
/// @brief Set Navigation Controller desired attitude - pitch.
/// @param roll New desired attitude - pitch.
void set_despitch(float pitch) { _nav.set_despitch(T(), pitch); };
/// @brief Set Navigation Controller desired attitude - yaw.
/// @param roll New desired attitude - yaw.
void set_desyaw(float yaw) { _nav.set_desyaw(T(), yaw); };
/// @brief Navigation Controller desired attitude - roll.
float desroll() const { return nav().desroll(); }
/// @brief Navigation Controller desired attitude - pitch.
float despitch() const { return nav().despitch(); }
/// @brief Navigation Controller desired attitude - yaw.
float desyaw() const { return nav().desyaw(); }
/// @brief Set canonical vehicle altitude.
/// @param value New vehicle altitude.
void set_altitude(float value) {
alt().set_alt(T(), value);
}
/// @brief Canonical vehicle altitude.
/// @return The vehicle's canonical altitude.
float altitude() const { return alt().alt(); };
/// @brief Canonical vehicle altitude modification time.
/// @return Timestamp The canonical vehicle altitude was modified (microseconds).
uint64_t alt_modtime() const { return alt().alt_modtime(); }
/// @brief Set vehicle canonical latitude.
/// @param lat New vehicle canonical latitude.
void set_lat(double lat) { pos().set_lat(T(), lat); }
/// @brief Set vehicle canonical longitude.
/// @param lat New vehicle canonical latitude.
void set_lon(double lon) { pos().set_lon(T(), lon); }
// @brief Vehicle canonical latitude.
// @return Vehicle's canonical latitude.
double lat() { return pos().lat(); }
// @brief Vehicle canonical longitude.
// @return Vehicle's canonical longitude.
double lon() { return pos().lon(); }
/// @brief Retrieve named position estimate.
/// @param name Name of position estimate to retrieve.
/// @return A position estimate.
PositionEstimate *position_estimate(const std::string name) {
if (_position_estimates.count(name) == 0) {
_position_estimates[name] = new PositionEstimate(name);
}
return _position_estimates[name];
};
/// @brief Retrieve named attitude estimate.
/// @param name Name of attitude estimate to retrieve.
/// @return An attitude estimate.
AttitudeEstimate *attitude_estimate(const std::string name) {
if (_attitude_estimates.count(name) == 0) {
_attitude_estimates[name] = new AttitudeEstimate(name);
}
return _attitude_estimates[name];
};
/// @brief Retrieve named altitude estimate.
/// @param name Name of altitude estimate to retrieve.
/// @return An altitude estimate.
AltitudeEstimate *altitude_estimate(const std::string name) {
if (_altitude_estimates.count(name) == 0) {
_altitude_estimates[name] = new AltitudeEstimate(name);
}
return _altitude_estimates[name];
};
/// @brief Retrieve named velocity estimate.
/// @param name Name of velocity estimate to retrieve.
/// @return A velocity estimate.
VelocityEstimate *velocity_estimate(const std::string name) {
if (_velocity_estimates.count(name) == 0) {
_velocity_estimates[name] = new VelocityEstimate(name);
}
return _velocity_estimates[name];
};
/// @brief Distance from canonical vehicle position to canonical origin.
/// @return Distance from origin, or -1 if we just don't know.
double distance_from_origin();
/// @brief Hardware diagnostics.
/// @return Map of sensor name to its boolean health.
std::map<const std::string, bool> sensors_health() {
return _sensors_health;
}
/// @brief Set the health status of a sensor by name.
/// @param name Name of sensor.
/// @param value New health value of sensor.
void sensor_set_healthy(std::string name, bool value) {
_sensors_health[name] = value;
}
/// @brief Subsystem health
/// @return Map of subsystem ID to its status
std::map<uint32_t, uint32_t> subsys_errors() {
return _subsys_error;
}
/// @brief Set an error flag value
/// @param subsys subsystem ID
/// @param code error code
void set_subsys_error_code(uint32_t subsys, uint32_t code) {
_subsys_error[subsys] = code;
}
/// @brief Indicate amount of flight battery remaining.
/// @param percent Percentage of charge remaining.
void set_battery_remaining(float percent) {
_battery._remaining = percent;
_battery._remaining_modtime = T();
}
/// @brief Amount of battery remaining.
/// @return Amount of battery remaining (percentage).
float battery_remaining() {
return _battery._remaining;
}
/// @brief Battery remaining modification time.
/// @return Timestamp when battery remaining was last modified (microseconds).
uint64_t battery_remaining_T() {
return _battery._remaining_modtime;
}
/// @brief Indicate a battery is in failsafe.
/// @param in_failsafe ``true`` if battery is in failsafe.
void set_battery_in_failsafe(bool in_failsafe) {
_battery._failsafe_event = in_failsafe;
_battery._failsafe_event_T = T();
}
/// @brief Battery failsafe status.
/// @return ``true`` if the battery is in failsafe.
bool battery_in_failsafe() {
return _battery._failsafe_event;
}
/// @brief Battery in failsafe modification time.
/// @return Timestamp when battery failsafe was last modified (microseconds).
uint64_t battery_in_failsafe_T() {
return _battery._failsafe_event_T;
}
/// @brief Attitude estimates.
/// @return Map of attitude estimate name to attitude estimate.
const std::map<const std::string, AttitudeEstimate*> &attitude_estimates() {
return _attitude_estimates;
}
/// @brief Altitude estimates.
/// @return Map of altitude estimate name to altitude estimate.
const std::map<const std::string, AltitudeEstimate*> &altitude_estimates() {
return _altitude_estimates;
}
/// @brief Position estimates.
/// @return Map of position estimate name to position estimate.
const std::map<const std::string, PositionEstimate*> &position_estimates() {
return _position_estimates;
}
/// @brief Velocity estimates.
/// @return Map of velocity estimate name to velocity estimate.
const std::map<const std::string, VelocityEstimate*> &velocity_estimates() {
return _velocity_estimates;
}
/// @brief Autopilot status information.