forked from ArduPilot/MissionPlanner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCurrentState.cs
3938 lines (3171 loc) · 157 KB
/
CurrentState.cs
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
using log4net;
using MissionPlanner.ArduPilot;
using MissionPlanner.Attributes;
using MissionPlanner.Utilities;
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text;
namespace MissionPlanner
{
public class CurrentState : ICloneable, IDisposable
{
private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
[JsonIgnore] [IgnoreDataMember] public static ISpeech Speech;
// multipliers
public static float multiplierdist = 1;
public static string DistanceUnit = "";
public static float multiplierspeed = 1;
public static string SpeedUnit = "";
public static float multiplieralt = 1;
public static string AltUnit = "";
private PointLatLngAlt _homelocation = new PointLatLngAlt();
private static PointLatLngAlt _plannedhomelocation = new PointLatLngAlt();
private static PointLatLngAlt _trackerloc = new PointLatLngAlt();
public static int rateattitudebackup;
public static int ratepositionbackup;
public static int ratestatusbackup;
public static int ratesensorsbackup;
public static int ratercbackup;
public static int KIndexstatic = -1;
private float _airspeed;
private float _alt;
private float _alt_error;
private float _altasl;
private float _aspd_error;
private int _battery_remaining;
internal double _battery_voltage;
internal double _battery_voltage2;
private float _ch3percent = -1;
private float _climbrate;
private double _current;
private double _current2;
private float _groundcourse;
private float _groundspeed;
private DateTime _lastcurrent = DateTime.MinValue;
private DateTime _lastcurrent2 = DateTime.MinValue;
private float _localsnrdb;
private uint _mode = 99999;
private PointLatLngAlt _movingbase = new PointLatLngAlt();
private float _remotesnrdb;
private float _sonarrange;
private float _ter_alt;
private float _ter_curalt;
private float _verticalspeed;
private float _wpdist;
private float _yaw;
internal bool batterymonitoring = false;
// current firmware
public Firmwares firmware = Firmwares.ArduCopter2;
private bool gotwind;
// HIL
public int hilch1; // { get; set; }
public int hilch2; // { get; set; }
public int hilch3; // { get; set; }
public int hilch4; // { get; set; }
public int hilch5;
public int hilch6;
public int hilch7;
public int hilch8;
internal double imutime;
private DateTime lastalt = DateTime.MinValue;
public int lastautowp = -1;
private DateTime lastdata = DateTime.MinValue;
// for calc of sitl speedup
internal DateTime lastimutime = DateTime.MinValue;
private PointLatLngAlt lastpos = new PointLatLngAlt();
private DateTime lastremrssi = DateTime.Now;
private DateTime lastrssi = DateTime.Now;
private DateTime lastsecondcounter = DateTime.Now;
private DateTime lastupdate = DateTime.Now;
internal bool MONO;
private float oldalt;
private MAVState _parent;
[JsonIgnore]
[IgnoreDataMember]
public MAVState parent
{
get { return _parent; }
set
{
_parent = value;
if (parent != null)
if (parent.parent != null)
parent.parent.OnPacketReceived += Parent_OnPacketReceived;
}
}
// rc override
public short rcoverridech1; //{ get; set; }
public short rcoverridech10; // { get; set; }
public short rcoverridech11; //{ get; set; }
public short rcoverridech12; //{ get; set; }
public short rcoverridech13; // { get; set; }
public short rcoverridech14; // { get; set; }
public short rcoverridech15; // { get; set; }
public short rcoverridech16; // { get; set; }
public short rcoverridech17; // { get; set; }
public short rcoverridech18; // { get; set; }
public short rcoverridech2; // { get; set; }
public short rcoverridech3; //{ get; set; }
public short rcoverridech4; //{ get; set; }
public short rcoverridech5; // { get; set; }
public short rcoverridech6; // { get; set; }
public short rcoverridech7; // { get; set; }
public short rcoverridech8; // { get; set; }
public short rcoverridech9; //{ get; set; }
public Mavlink_Sensors sensors_enabled = new Mavlink_Sensors();
public Mavlink_Sensors sensors_health = new Mavlink_Sensors();
public Mavlink_Sensors sensors_present = new Mavlink_Sensors();
private bool useLocation;
/// <summary>
/// used for wind calc
/// </summary>
private double We_fgo;
/// <summary>
/// used in wind calc
/// </summary>
private double Wn_fgo;
static CurrentState()
{
// set default telemrates
rateattitudebackup = 4;
ratepositionbackup = 2;
ratestatusbackup = 2;
ratesensorsbackup = 2;
ratercbackup = 2;
//Init dictionary for storing names for customfields
custom_field_names = new Dictionary<string, string>();
}
~CurrentState()
{
log.Info("CurrentState .dtor");
Dispose();
}
public void Dispose()
{
log.Info("CurrentState Dispose");
if (parent != null)
if (parent.parent != null)
parent.parent.OnPacketReceived -= Parent_OnPacketReceived;
}
public CurrentState()
{
ResetInternals();
var t = Type.GetType("Mono.Runtime");
MONO = t != null;
}
// propery name, Name Name starts with MAV_ will link to named_value_float messages
public static Dictionary<string, string> custom_field_names;
public float customfield0 { get; set; }
public float customfield1 { get; set; }
public float customfield2 { get; set; }
public float customfield3 { get; set; }
public float customfield4 { get; set; }
public float customfield5 { get; set; }
public float customfield6 { get; set; }
public float customfield7 { get; set; }
public float customfield8 { get; set; }
public float customfield9 { get; set; }
// orientation - rads
[DisplayText("Roll (deg)")]
[GroupText("Attitude")]
public float roll { get; set; }
[GroupText("Attitude")]
[DisplayText("Pitch (deg)")]
public float pitch { get; set; }
[GroupText("Attitude")]
[DisplayText("Yaw (deg)")]
public float yaw
{
get => _yaw;
set
{
if (value < 0)
_yaw = value + 360;
else
_yaw = value;
}
}
[GroupText("Attitude")]
[DisplayText("SSA (deg)")]
public float SSA { get; set; }
[GroupText("Attitude")]
[DisplayText("AOA (deg)")]
public float AOA { get; set; }
[GroupText("Position")]
[DisplayText("GroundCourse (deg)")]
public float groundcourse
{
get => _groundcourse;
set
{
if (value < 0)
_groundcourse = value + 360;
else
_groundcourse = value;
}
}
// position
[DisplayText("Latitude (dd)")]
[GroupText("Position")]
public double lat { get; set; }
[GroupText("Position")]
[DisplayText("Longitude (dd)")]
public double lng { get; set; }
[GroupText("Position")]
[DisplayText("Altitude (alt)")]
public float alt
{
get => (_alt - altoffsethome) * multiplieralt;
set
{
// check update rate, and ensure time hasnt gone backwards
_alt = value;
if ((datetime - lastalt).TotalSeconds >= 0.2 && oldalt != alt || lastalt > datetime)
{
climbrate = (alt - oldalt) / (float)(datetime - lastalt).TotalSeconds;
verticalspeed = (alt - oldalt) / (float)(datetime - lastalt).TotalSeconds;
if (float.IsInfinity(_verticalspeed))
_verticalspeed = 0;
lastalt = datetime;
oldalt = alt;
}
}
}
[GroupText("Position")]
[DisplayText("Altitude (dist)")]
public float altasl
{
get => _altasl * multiplieralt;
set => _altasl = value;
}
[GroupText("Position")]
[DisplayText("Horizon Dist (dist)")]
public float horizondist => (float)(3570 * Math.Sqrt(alt)) * multiplierdist;
[GroupText("Position")]
[DisplayText("Velocity X (ms)")]
public double vx { get; set; }
[DisplayText("Velocity Y (ms)")]
[GroupText("Position")]
public double vy { get; set; }
[DisplayText("Velocity Z (ms)")]
[GroupText("Position")]
public double vz { get; set; }
[GroupText("Position")] public double vlen => Math.Sqrt(Math.Pow(vx, 2) + Math.Pow(vy, 2) + Math.Pow(vz, 2));
[GroupText("Position")]
[DisplayText("Alt Home Offset (dist)")]
public float altoffsethome { get; set; }
[GroupText("Position")]
[DisplayText("Gps Status")]
public float gpsstatus { get; set; }
[DisplayText("Gps HDOP")]
[GroupText("Position")]
public float gpshdop { get; set; }
[DisplayText("Sat Count")]
[GroupText("Position")]
public float satcount { get; set; }
[DisplayText("Horizontal Accuracy")]
[GroupText("Position")]
public float gpsh_acc { get; private set; }
[DisplayText("Vertical Accuracy")]
[GroupText("Position")]
public float gpsv_acc { get; private set; }
[DisplayText("Velocity Accuracy")]
[GroupText("Position")]
public float gpsvel_acc { get; private set; }
[DisplayText("Heading Accuracy")]
[GroupText("Position")]
public float gpshdg_acc { get; private set; }
[DisplayText("GPS Yaw (deg)")]
[GroupText("Position")]
public float gpsyaw { get; private set; }
[DisplayText("Latitude2 (dd)")]
[GroupText("Position")]
public double lat2 { get; set; }
[DisplayText("Longitude2 (dd)")]
[GroupText("Position")]
public double lng2 { get; set; }
[DisplayText("Altitude2 (dist)")]
[GroupText("Position")]
public float altasl2 { get; set; }
[DisplayText("Gps Status2")]
[GroupText("Position")]
public float gpsstatus2 { get; set; }
[DisplayText("Gps HDOP2")]
[GroupText("Position")]
public float gpshdop2 { get; set; }
[DisplayText("Sat Count2")]
[GroupText("Position")]
public float satcount2 { get; set; }
[GroupText("Position")]
public float groundspeed2 { get; set; }
[DisplayText("GroundCourse2 (deg)")]
[GroupText("Position")]
public float groundcourse2 { get; set; }
[DisplayText("Sat Count Blend")]
[GroupText("Position")]
public float satcountB => satcount + satcount2;
[GroupText("Position")]
public DateTime gpstime { get; set; }
public float altd1000 => alt / 1000 % 10;
public float altd100 => alt / 100 % 10;
// speeds
[DisplayText("AirSpeed (speed)")]
public float airspeed
{
get => _airspeed * multiplierspeed;
set => _airspeed = value;
}
[DisplayText("Airspeed Target (speed)")]
public float targetairspeed { get; private set; }
public bool lowairspeed { get; set; }
[DisplayText("Airspeed Ratio")]
public float asratio { get; set; }
[GroupText("Position")]
[DisplayText("GroundSpeed (speed)")]
public float groundspeed
{
get => _groundspeed * multiplierspeed;
set => _groundspeed = value;
}
// accel
[DisplayText("Accel X")]
[GroupText("Sensor")]
public float ax { get; set; }
[DisplayText("Accel Y")]
[GroupText("Sensor")]
public float ay { get; set; }
[DisplayText("Accel Z")]
[GroupText("Sensor")]
public float az { get; set; }
[DisplayText("Accel Strength")]
[GroupText("Sensor")]
public float accelsq => (float)Math.Sqrt(Math.Pow(ax, 2) + Math.Pow(ay, 2) + Math.Pow(az, 2)) / 1000.0f;
// gyro
[DisplayText("Gyro X")]
[GroupText("Sensor")]
public float gx { get; set; }
[DisplayText("Gyro Y")]
[GroupText("Sensor")]
public float gy { get; set; }
[DisplayText("Gyro Z")]
[GroupText("Sensor")]
public float gz { get; set; }
[DisplayText("Gyro Strength")]
[GroupText("Sensor")]
public float gyrosq => (float)Math.Sqrt(Math.Pow(gx, 2) + Math.Pow(gy, 2) + Math.Pow(gz, 2));
// mag
[DisplayText("Mag X")]
[GroupText("Sensor")]
public float mx { get; set; }
[DisplayText("Mag Y")]
[GroupText("Sensor")]
public float my { get; set; }
[DisplayText("Mag Z")]
[GroupText("Sensor")]
public float mz { get; set; }
[DisplayText("Mag Field")]
[GroupText("Sensor")]
public float magfield => (float)Math.Sqrt(Math.Pow(mx, 2) + Math.Pow(my, 2) + Math.Pow(mz, 2));
// accel2
[DisplayText("Accel2 X")]
[GroupText("Sensor")]
public float ax2 { get; set; }
[DisplayText("Accel2 Y")]
[GroupText("Sensor")]
public float ay2 { get; set; }
[DisplayText("Accel2 Z")]
[GroupText("Sensor")]
public float az2 { get; set; }
[DisplayText("Accel2 Strength")]
[GroupText("Sensor")]
public float accelsq2 => (float)Math.Sqrt(Math.Pow(ax2, 2) + Math.Pow(ay2, 2) + Math.Pow(az2, 2)) / 1000.0f;
// gyro2
[DisplayText("Gyro2 X")]
[GroupText("Sensor")]
public float gx2 { get; set; }
[DisplayText("Gyro2 Y")]
[GroupText("Sensor")]
public float gy2 { get; set; }
[DisplayText("Gyro2 Z")]
[GroupText("Sensor")]
public float gz2 { get; set; }
[DisplayText("Gyro2 Strength")]
[GroupText("Sensor")]
public float gyrosq2 => (float)Math.Sqrt(Math.Pow(gx2, 2) + Math.Pow(gy2, 2) + Math.Pow(gz2, 2));
// mag2
[DisplayText("Mag2 X")]
[GroupText("Sensor")]
public float mx2 { get; set; }
[DisplayText("Mag2 Y")]
[GroupText("Sensor")]
public float my2 { get; set; }
[DisplayText("Mag2 Z")]
[GroupText("Sensor")]
public float mz2 { get; set; }
[DisplayText("Mag2 Field")]
[GroupText("Sensor")]
public float magfield2 => (float)Math.Sqrt(Math.Pow(mx2, 2) + Math.Pow(my2, 2) + Math.Pow(mz2, 2));
// accel3
[DisplayText("Accel3 X")]
[GroupText("Sensor")]
public float ax3 { get; set; }
[DisplayText("Accel3 Y")]
[GroupText("Sensor")]
public float ay3 { get; set; }
[DisplayText("Accel3 Z")]
[GroupText("Sensor")]
public float az3 { get; set; }
[DisplayText("Accel3 Strength")]
[GroupText("Sensor")]
public float accelsq3 => (float)Math.Sqrt(Math.Pow(ax3, 2) + Math.Pow(ay3, 2) + Math.Pow(az3, 2)) / 1000.0f;
// gyro3
[DisplayText("Gyro3 X")]
[GroupText("Sensor")]
public float gx3 { get; set; }
[DisplayText("Gyro3 Y")]
[GroupText("Sensor")]
public float gy3 { get; set; }
[DisplayText("Gyro3 Z")]
[GroupText("Sensor")]
public float gz3 { get; set; }
[DisplayText("Gyro3 Strength")]
[GroupText("Sensor")]
public float gyrosq3 => (float)Math.Sqrt(Math.Pow(gx3, 2) + Math.Pow(gy3, 2) + Math.Pow(gz3, 2));
// mag3
[DisplayText("Mag3 X")]
[GroupText("Sensor")]
public float mx3 { get; set; }
[DisplayText("Mag3 Y")]
[GroupText("Sensor")]
public float my3 { get; set; }
[DisplayText("Mag3 Z")]
[GroupText("Sensor")]
public float mz3 { get; set; }
[DisplayText("Mag3 Field")]
[GroupText("Sensor")]
public float magfield3 => (float)Math.Sqrt(Math.Pow(mx3, 2) + Math.Pow(my3, 2) + Math.Pow(mz3, 2));
// hygrometer
[DisplayText("hygrotemp (cdegC)")]
[GroupText("Sensor")]
public short hygrotemp { get; set; }
[DisplayText("hygrohumi (c%)")]
[GroupText("Sensor")]
public ushort hygrohumi { get; set; }
[GroupText("Sensor")]
public byte hygro_id { get; set; }
//radio
[GroupText("RadioIn")] public float ch1in { get; set; }
[GroupText("RadioIn")] public float ch2in { get; set; }
[GroupText("RadioIn")] public float ch3in { get; set; }
[GroupText("RadioIn")] public float ch4in { get; set; }
[GroupText("RadioIn")] public float ch5in { get; set; }
[GroupText("RadioIn")] public float ch6in { get; set; }
[GroupText("RadioIn")] public float ch7in { get; set; }
[GroupText("RadioIn")] public float ch8in { get; set; }
[GroupText("RadioIn")] public float ch9in { get; set; }
[GroupText("RadioIn")] public float ch10in { get; set; }
[GroupText("RadioIn")] public float ch11in { get; set; }
[GroupText("RadioIn")] public float ch12in { get; set; }
[GroupText("RadioIn")] public float ch13in { get; set; }
[GroupText("RadioIn")] public float ch14in { get; set; }
[GroupText("RadioIn")] public float ch15in { get; set; }
[GroupText("RadioIn")] public float ch16in { get; set; }
// motors
[GroupText("RadioOut")] public float ch1out { get; set; }
[GroupText("RadioOut")] public float ch2out { get; set; }
[GroupText("RadioOut")] public float ch3out { get; set; }
[GroupText("RadioOut")] public float ch4out { get; set; }
[GroupText("RadioOut")] public float ch5out { get; set; }
[GroupText("RadioOut")] public float ch6out { get; set; }
[GroupText("RadioOut")] public float ch7out { get; set; }
[GroupText("RadioOut")] public float ch8out { get; set; }
[GroupText("RadioOut")] public float ch9out { get; set; }
[GroupText("RadioOut")] public float ch10out { get; set; }
[GroupText("RadioOut")] public float ch11out { get; set; }
[GroupText("RadioOut")] public float ch12out { get; set; }
[GroupText("RadioOut")] public float ch13out { get; set; }
[GroupText("RadioOut")] public float ch14out { get; set; }
[GroupText("RadioOut")] public float ch15out { get; set; }
[GroupText("RadioOut")] public float ch16out { get; set; }
[GroupText("ESC")] public float esc1_volt { get; set; }
[GroupText("ESC")] public float esc1_curr { get; set; }
[GroupText("ESC")] public float esc1_rpm { get; set; }
[GroupText("ESC")] public float esc1_temp { get; set; }
[GroupText("ESC")] public float esc2_volt { get; set; }
[GroupText("ESC")] public float esc2_curr { get; set; }
[GroupText("ESC")] public float esc2_rpm { get; set; }
[GroupText("ESC")] public float esc2_temp { get; set; }
[GroupText("ESC")] public float esc3_volt { get; set; }
[GroupText("ESC")] public float esc3_curr { get; set; }
[GroupText("ESC")] public float esc3_rpm { get; set; }
[GroupText("ESC")] public float esc3_temp { get; set; }
[GroupText("ESC")] public float esc4_volt { get; set; }
[GroupText("ESC")] public float esc4_curr { get; set; }
[GroupText("ESC")] public float esc4_rpm { get; set; }
[GroupText("ESC")] public float esc4_temp { get; set; }
[GroupText("ESC")] public float esc5_volt { get; set; }
[GroupText("ESC")] public float esc5_curr { get; set; }
[GroupText("ESC")] public float esc5_rpm { get; set; }
[GroupText("ESC")] public float esc5_temp { get; set; }
[GroupText("ESC")] public float esc6_volt { get; set; }
[GroupText("ESC")] public float esc6_curr { get; set; }
[GroupText("ESC")] public float esc6_rpm { get; set; }
[GroupText("ESC")] public float esc6_temp { get; set; }
[GroupText("ESC")] public float esc7_volt { get; set; }
[GroupText("ESC")] public float esc7_curr { get; set; }
[GroupText("ESC")] public float esc7_rpm { get; set; }
[GroupText("ESC")] public float esc7_temp { get; set; }
[GroupText("ESC")] public float esc8_volt { get; set; }
[GroupText("ESC")] public float esc8_curr { get; set; }
[GroupText("ESC")] public float esc8_rpm { get; set; }
[GroupText("ESC")] public float esc8_temp { get; set; }
public float ch3percent
{
get
{
if (_ch3percent != -1)
return _ch3percent;
try
{
if (parent != null && parent.parent.MAV.param.ContainsKey("RC3_MIN") &&
parent.parent.MAV.param.ContainsKey("RC3_MAX"))
return
(int)
((ch3out - parent.parent.MAV.param["RC3_MIN"].Value) /
(parent.parent.MAV.param["RC3_MAX"].Value - parent.parent.MAV.param["RC3_MIN"].Value) *
100);
if (ch3out == 0)
return 0;
return (int)((ch3out - 1100) / (1900 - 1100) * 100);
}
catch
{
return 0;
}
}
set => _ch3percent = value;
}
[DisplayText("Failsafe")] public bool failsafe { get; set; }
[DisplayText("RX Rssi")] public int rxrssi { get; set; }
public float crit_AOA
{
get
{
try
{
if (parent.parent.MAV.param.ContainsKey("AOA_CRIT"))
return
(int)
parent.parent.MAV.param["AOA_CRIT"].Value;
return 25;
}
catch
{
return 0;
}
}
set { }
}
public bool lowgroundspeed { get; set; }
[DisplayText("Vertical Speed (speed)")]
public float verticalspeed
{
get
{
if (float.IsNaN(_verticalspeed)) _verticalspeed = 0;
return _verticalspeed * multiplierspeed;
}
set => _verticalspeed = _verticalspeed * 0.4f + value * 0.6f;
}
[DisplayText("Vertical Speed (fpm)")] public double verticalspeed_fpm => vz * -3.28084 * 60;
[DisplayText("Glide Ratio")]
public double glide_ratio
{
get
{
var hor = Math.Sqrt(vx * vx + vy * vy);
return hor / vz;
}
}
//nav state
[GroupText("NAV")]
[DisplayText("Roll Target (deg)")]
public float nav_roll { get; set; }
[GroupText("NAV")]
[DisplayText("Pitch Target (deg)")]
public float nav_pitch { get; set; }
[GroupText("NAV")]
[DisplayText("Bearing Target (deg)")]
public float nav_bearing { get; set; }
[GroupText("NAV")]
[DisplayText("Bearing Target (deg)")]
public float target_bearing { get; set; }
[GroupText("NAV")]
[DisplayText("Dist to WP (dist)")]
public float wp_dist
{
get => _wpdist * multiplierdist;
set => _wpdist = value;
}
[GroupText("NAV")]
[DisplayText("Altitude Error (dist)")]
public float alt_error
{
get => _alt_error * multiplieralt;
set
{
if (_alt_error == value) return;
_alt_error = value;
targetalt = targetalt * 0.5f + (float)Math.Round(alt + alt_error, 0) * 0.5f;
}
}
[GroupText("NAV")]
[DisplayText("Bearing Error (deg)")]
public float ber_error
{
get => target_bearing - yaw;
set { }
}
[GroupText("NAV")]
[DisplayText("Airspeed Error (speed)")]
public float aspd_error
{
get => _aspd_error * multiplierspeed;
set
{
if (_aspd_error == value) return;
_aspd_error = value;
targetairspeed = targetairspeed * 0.5f + (float)Math.Round(airspeed + aspd_error, 0) * 0.5f;
}
}
[GroupText("NAV")]
[DisplayText("Xtrack Error (m)")]
public float xtrack_error { get; set; }
[GroupText("NAV")]
[DisplayText("WP No")]
public float wpno { get; set; }
[GroupText("NAV")]
[DisplayText("Mode")]
public string mode { get; set; }
[DisplayText("ClimbRate (speed)")]
public float climbrate
{
get => _climbrate * multiplierspeed;
set => _climbrate = value;
}
/// <summary>
/// time over target in seconds
/// </summary>
[DisplayText("Time over Target (sec)")]
[GroupText("NAV")]
public int tot
{
get
{
if (_groundspeed <= 0) return 0;
return (int)(_wpdist / _groundspeed);
}
}
[DisplayText("Time over Home (sec)")]
[GroupText("NAV")]
public int toh
{
get
{
if (_groundspeed <= 0) return 0;
return (int)(DistToHome / groundspeed);
}
}
[DisplayText("Dist Traveled (dist)")] public float distTraveled { get; set; }
[DisplayText("Time in Air (sec)")] public float timeSinceArmInAir { get; set; }
[DisplayText("Time in Air (sec)")] public float timeInAir { get; set; }
//Time in Air converted to min.sec format for easier reading
[DisplayText("Time in Air (min.sec)")]
public float timeInAirMinSec => (int)(timeInAir / 60) + timeInAir % 60 / 100;
// calced turn rate
[DisplayText("Turn Rate (speed)")]
public float turnrate
{
get
{
if (_groundspeed <= 1) return 0;
return (float)(roll * 9.80665 / groundspeed);
}
}
//https://en.wikipedia.org/wiki/Load_factor_(aeronautics)
[DisplayText("Turn Gs (load)")] public float turng => (float)(1 / Math.Cos(MathHelper.deg2rad * roll));
// turn radius
[DisplayText("Turn Radius (dist)")]
public float radius
{
get
{
if (_groundspeed <= 1) return 0;
return (float)(groundspeed * groundspeed / (9.80665 * Math.Tan(roll * MathHelper.deg2rad)));
}
}
public float QNH
{
get
{
var pressure = press_abs;
var alt_m = altasl;
var gndtemp = 15f;
var C_TO_KELVIN = 273.15f;
var temp = gndtemp + C_TO_KELVIN; // kelvin
var scaling = (float)Math.Exp(Math.Log(1.0 - alt_m / (153.8462 * temp)) / 0.190259);
var base_pressure = pressure / scaling;
return base_pressure;
}
}
[DisplayText("Wind Direction (Deg)")] public float wind_dir { get; set; }
[DisplayText("Wind Velocity (speed)")] public float wind_vel { get; set; }
public float targetaltd100 => targetalt / 100 % 10;
[GroupText("NAV")]
public float targetalt { get; private set; }
[JsonIgnore] [IgnoreDataMember]
public List<(DateTime time, string message)> messages { get; set; } = new List<(DateTime, string)>();
/// <summary>
/// a message that originates from the mav
/// </summary>
public string message
{
get { return messages.LastOrDefault().message; }
}
/// <summary>
/// a message that originates from within the gcs
/// </summary>
public string messageHigh
{
get { if (DateTime.Now > _messageHighTime.AddSeconds(10)) return ""; return _messagehigh.TrimUnPrintable(); }
set
{
if(value == null || value == "")
return;
// check against get
if (messageHigh == value)
return;
log.Info("messageHigh " + value);
_messageHighTime = DateTime.Now;
_messagehigh = value;
messageHighSeverity = MAVLink.MAV_SEVERITY.EMERGENCY;
}
}
string _messagehigh = "";
DateTime _messageHighTime;
public MAVLink.MAV_SEVERITY messageHighSeverity { get; set; }
//battery
[GroupText("Battery")]
[DisplayText("Bat Voltage (V)")]
public double battery_voltage
{
get => _battery_voltage;
set
{
if (_battery_voltage == 0) _battery_voltage = value;
_battery_voltage = value * 0.4f + _battery_voltage * 0.6f;
}
}
[GroupText("Battery")]
[DisplayText("Bat Voltage (V)")]
public double battery_voltage3 { get; set; }
[GroupText("Battery")]
[DisplayText("Bat Voltage (V)")]
public double battery_voltage4 { get; set; }
[GroupText("Battery")]
[DisplayText("Bat Voltage (V)")]
public double battery_voltage5 { get; set; }