-
Notifications
You must be signed in to change notification settings - Fork 22
/
formgps.cpp
1432 lines (1182 loc) · 47.4 KB
/
formgps.cpp
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
#include "formgps.h"
#include "aogproperty.h"
#include <QColor>
#include <QRgb>
#include "qmlutil.h"
#include "glm.h"
#include "cpgn.h"
#include <QLocale>
#include <QLabel>
#include <QQuickWindow>
#include "qmlsettings.h"
extern QLabel *grnPixelsWindow;
extern QMLSettings qml_settings;
FormGPS::FormGPS(QWidget *parent) : QQmlApplicationEngine(parent)
{
connect_classes(); //make all the inter-class connections
qml_settings.setupKeys();
qml_settings.loadSettings(); //fetch everything from QSettings for QML to use
/* Temporary test data to see if drawing routines are working. */
/*
if ((QString)property_setVehicle_vehicleName == "Default Vehicle") {
//set up a default vehicle
//fieldColor = QColor(s.value("display/fieldColor", "#82781E").toString());
//sectionColor = QColor(s.value("display/sectionColor", "#32DCC8").toString());
property_setMenu_isCompassOn = true;
property_setMenu_isSpeedoOn = true;
//just for debugging I think, force sections to be set
property_setSection_position1 = -3.3528;
property_setSection_position2 = -2.2352;
property_setSection_position3 = -1.1176;
property_setSection_position4 = 0;
property_setSection_position5 = 1.1176;
property_setSection_position6 = 2.2352;
property_setSection_position7 = 3.3528;
property_setVehicle_numSections = 6;
property_setVehicle_toolWidth = 6.7056;
property_setTool_zones = QVector<int>( { 6,2,4,6,8,10,12,0,0 }); //2 rows per zone
property_setTool_numSectionsMulti = 12; //12 rows
property_setTool_sectionWidthMulti = .5588; //22" rows
property_setTool_isSectionsNotZones = true; //enable zones
if (property_setTool_isSectionsNotZones) {
tool.sectionCalcWidths();
} else {
tool.sectionCalcMulti();
}
property_setVehicle_wheelbase = 3.1496;
property_setVehicle_trackWidth = 2.286;
property_setVehicle_hitchLength = -2.54;
property_setTool_isToolTBT=true;
property_setVehicle_tankTrailingHitchLength = -3;
property_setTool_isToolTrailing = true;
property_setTool_toolTrailingHitchLength = -4.572;
property_setVehicle_minTurningRadius = 8;
property_setVehicle_maxSteerAngle = 30;
} else {
//reload our saved settings
vehicle_load(property_setVehicle_vehicleName);
}
*/
setupGui();
loadSettings();
//QML does this now
//LineUpIndividualSectionBtns();
/*
//hard wire this on for testing
isJobStarted = true;
//fileCreateField();
if (! FileOpenField((QString)property_setF_CurrentDir))
{
//set up default field to play in for debugging purposes
currentFieldDirectory = "TestField";
property_setF_CurrentDir = currentFieldDirectory;
pn.latStart = sim.latitude;
pn.lonStart = sim.longitude;
FileCreateField();
ABLine.refPoint1.easting = 0;
ABLine.refPoint1.easting = 0;
ABLine.abHeading = glm::toRadians(5.0f);
ABLine.SetABLineByHeading();
CABLines line;
line.origin = Vec2(0,0);
line.origin = Vec2(0,0);
line.heading = glm::toRadians(5.0f);
line.Name = "Test AB Line";
ABLine.lineArr.append( line );
FileSaveABLines();
CBoundaryList boundary;
boundary.isDriveThru = true;
boundary.fenceLine.append(Vec3(-100,0,0));
boundary.fenceLine.append(Vec3(-100,250,glm::toRadians((double)90)));
boundary.fenceLine.append(Vec3( 100,250,glm::toRadians((double)180)));
boundary.fenceLine.append(Vec3( 100,0,glm::toRadians((double)270)));
boundary.fenceLine.append(Vec3(-100,0,0));
boundary.CalculateFenceArea(0);
double delta = 0;
boundary.fenceLineEar.clear();
for (int i = 0; i < boundary.fenceLine.count(); i++)
{
if (i == 0)
{
boundary.fenceLineEar.append(Vec2(boundary.fenceLine[i].easting, boundary.fenceLine[i].northing));
continue;
}
delta += (boundary.fenceLine[i - 1].heading - boundary.fenceLine[i].heading);
if (fabs(delta) > 0.005)
{
boundary.fenceLineEar.append(Vec2(boundary.fenceLine[i].easting, boundary.fenceLine[i].northing));
delta = 0;
}
}
bnd.bndList.append(boundary);
fd.UpdateFieldBoundaryGUIAreas(bnd.bndList);
calculateMinMax();
FileSaveBoundary();
bnd.BuildTurnLines(fd);
bootstrap_field=true;
isJobStarted = true;
}
//ABLine.isABLineSet = true;
//ABLine.isBtnABLineOn = true;
*/
isJobStarted = false;
StartLoopbackServer();
simConnectSlots();
if ((bool)property_setMenu_isSimulatorOn == false) {
qDebug() << "Stopping simulator because it's off in settings.";
timerSim.stop();
}
}
FormGPS::~FormGPS()
{
/* clean up our dynamically-allocated
* objects.
*/
}
//This used to be part of oglBack_paint in the C# code, but
//because openGL rendering can potentially be in another thread here, it's
//broken out here. So the lookaheadPixels array has been populated already
//by the rendering routine.
void FormGPS::processSectionLookahead() {
//qDebug() << "frame time before doing section lookahead " << swFrame.elapsed();
lock.lockForWrite();
//qDebug() << "frame time after getting lock " << swFrame.elapsed();
if (property_displayShowBack)
grnPixelsWindow->setPixmap(QPixmap::fromImage(grnPix.mirrored()));
//determine where the tool is wrt to headland
if (bnd.isHeadlandOn) bnd.WhereAreToolCorners(tool);
//set the look ahead for hyd Lift in pixels per second
vehicle.hydLiftLookAheadDistanceLeft = tool.farLeftSpeed * vehicle.hydLiftLookAheadTime * 10;
vehicle.hydLiftLookAheadDistanceRight = tool.farRightSpeed * vehicle.hydLiftLookAheadTime * 10;
if (vehicle.hydLiftLookAheadDistanceLeft > 200) vehicle.hydLiftLookAheadDistanceLeft = 200;
if (vehicle.hydLiftLookAheadDistanceRight > 200) vehicle.hydLiftLookAheadDistanceRight = 200;
tool.lookAheadDistanceOnPixelsLeft = tool.farLeftSpeed * tool.lookAheadOnSetting * 10;
tool.lookAheadDistanceOnPixelsRight = tool.farRightSpeed * tool.lookAheadOnSetting * 10;
if (tool.lookAheadDistanceOnPixelsLeft > 200) tool.lookAheadDistanceOnPixelsLeft = 200;
if (tool.lookAheadDistanceOnPixelsRight > 200) tool.lookAheadDistanceOnPixelsRight = 200;
tool.lookAheadDistanceOffPixelsLeft = tool.farLeftSpeed * tool.lookAheadOffSetting * 10;
tool.lookAheadDistanceOffPixelsRight = tool.farRightSpeed * tool.lookAheadOffSetting * 10;
if (tool.lookAheadDistanceOffPixelsLeft > 160) tool.lookAheadDistanceOffPixelsLeft = 160;
if (tool.lookAheadDistanceOffPixelsRight > 160) tool.lookAheadDistanceOffPixelsRight = 160;
//determine if section is in boundary and headland using the section left/right positions
bool isLeftIn = true, isRightIn = true;
if (bnd.bndList.count() > 0)
{
for (int j = 0; j < tool.numOfSections; j++)
{
//only one first left point, the rest are all rights moved over to left
isLeftIn = j == 0 ? bnd.IsPointInsideFenceArea(tool.section[j].leftPoint) : isRightIn;
isRightIn = bnd.IsPointInsideFenceArea(tool.section[j].rightPoint);
if (tool.isSectionOffWhenOut)
{
//merge the two sides into in or out
if (isLeftIn || isRightIn) tool.section[j].isInBoundary = true;
else tool.section[j].isInBoundary = false;
}
else
{
//merge the two sides into in or out
if (!isLeftIn || !isRightIn) tool.section[j].isInBoundary = false;
else tool.section[j].isInBoundary = true;
}
}
}
//determine farthest ahead lookahead - is the height of the readpixel line
double rpHeight = 0;
double rpOnHeight = 0;
double rpToolHeight = 0;
//pick the larger side
if (vehicle.hydLiftLookAheadDistanceLeft > vehicle.hydLiftLookAheadDistanceRight) rpToolHeight = vehicle.hydLiftLookAheadDistanceLeft;
else rpToolHeight = vehicle.hydLiftLookAheadDistanceRight;
if (tool.lookAheadDistanceOnPixelsLeft > tool.lookAheadDistanceOnPixelsRight) rpOnHeight = tool.lookAheadDistanceOnPixelsLeft;
else rpOnHeight = tool.lookAheadDistanceOnPixelsRight;
isHeadlandClose = false;
//clamp the height after looking way ahead, this is for switching off super section only
rpOnHeight = fabs(rpOnHeight);
rpToolHeight = fabs(rpToolHeight);
//10 % min is required for overlap, otherwise it never would be on.
int pixLimit = (int)((double)(tool.section[0].rpSectionWidth * rpOnHeight) / (double)(5.0));
if ((rpOnHeight < rpToolHeight && bnd.isHeadlandOn && bnd.isSectionControlledByHeadland)) rpHeight = rpToolHeight + 2;
else rpHeight = rpOnHeight + 2;
if (rpHeight > 290) rpHeight = 290;
if (rpHeight < 8) rpHeight = 8;
//read the whole block of pixels up to max lookahead, one read only
//pixels are already read
//GL.ReadPixels(tool.rpXPosition, 0, tool.rpWidth, (int)rpHeight, OpenTK.Graphics.OpenGL.PixelFormat.Green, PixelType.UnsignedByte, grnPixels);
//Paint to context for troubleshooting
//oglBack.MakeCurrent();
//oglBack.SwapBuffers();
//determine if headland is in read pixel buffer left middle and right.
int start = 0, end = 0, tagged = 0, totalPixel = 0;
//slope of the look ahead line
double mOn = 0, mOff = 0;
//tram and hydraulics
if (tram.displayMode > 0 && tool.width > vehicle.trackWidth)
{
tram.controlByte = 0;
//1 pixels in is there a tram line?
if (tram.isOuter)
{
if (grnPixels[(int)(tram.halfWheelTrack * 10)].green == 245) tram.controlByte += 2;
if (grnPixels[tool.rpWidth - (int)(tram.halfWheelTrack * 10)].green == 245) tram.controlByte += 1;
}
else
{
if (grnPixels[tool.rpWidth / 2 - (int)(tram.halfWheelTrack * 10)].green == 245) tram.controlByte += 2;
if (grnPixels[tool.rpWidth / 2 + (int)(tram.halfWheelTrack * 10)].green == 245) tram.controlByte += 1;
}
}
//determine if in or out of headland, do hydraulics if on
if (bnd.isHeadlandOn)
{
//calculate the slope
double m = (vehicle.hydLiftLookAheadDistanceRight - vehicle.hydLiftLookAheadDistanceLeft) / tool.rpWidth;
int height = 1;
for (int pos = 0; pos < tool.rpWidth; pos++)
{
height = (int)(vehicle.hydLiftLookAheadDistanceLeft + (m * pos)) - 1;
for (int a = pos; a < height * tool.rpWidth; a += tool.rpWidth)
{
if (grnPixels[a].green == 250)
{
isHeadlandClose = true;
goto GetOutTool;
}
}
}
GetOutTool: //goto
//is the tool completely in the headland or not
bnd.isToolInHeadland = bnd.isToolOuterPointsInHeadland && !isHeadlandClose;
//set hydraulics based on tool in headland or not
bnd.SetHydPosition(autoBtnState, p_239, vehicle);
}
/////////////////////////////////////////// Section control ssssssssssssssssssssss
int endHeight = 1, startHeight = 1;
if (bnd.isHeadlandOn && bnd.isSectionControlledByHeadland) bnd.WhereAreToolLookOnPoints(vehicle, tool);
for (int j = 0; j < tool.numOfSections; j++)
{
//Off or too slow or going backwards
if (tool.sectionButtonState.get(j) == btnStates::Off || vehicle.avgSpeed < vehicle.slowSpeedCutoff || tool.section[j].speedPixels < 0)
{
tool.section[j].sectionOnRequest = false;
tool.section[j].sectionOffRequest = true;
// Manual on, force the section On
if (tool.sectionButtonState.get(j) == btnStates::On)
{
tool.section[j].sectionOnRequest = true;
tool.section[j].sectionOffRequest = false;
continue;
}
continue;
}
// Manual on, force the section On
if (tool.sectionButtonState.get(j) == btnStates::On)
{
tool.section[j].sectionOnRequest = true;
tool.section[j].sectionOffRequest = false;
continue;
}
//AutoSection - If any nowhere applied, send OnRequest, if its all green send an offRequest
tool.section[j].isSectionRequiredOn = false;
//calculate the slopes of the lines
mOn = (tool.lookAheadDistanceOnPixelsRight - tool.lookAheadDistanceOnPixelsLeft) / tool.rpWidth;
mOff = (tool.lookAheadDistanceOffPixelsRight - tool.lookAheadDistanceOffPixelsLeft) / tool.rpWidth;
start = tool.section[j].rpSectionPosition - tool.section[0].rpSectionPosition;
end = tool.section[j].rpSectionWidth - 1 + start;
if (end >= tool.rpWidth)
end = tool.rpWidth - 1;
totalPixel = 1;
tagged = 0;
for (int pos = start; pos <= end; pos++)
{
startHeight = (int)(tool.lookAheadDistanceOffPixelsLeft + (mOff * pos)) * tool.rpWidth + pos;
endHeight = (int)(tool.lookAheadDistanceOnPixelsLeft + (mOn * pos)) * tool.rpWidth + pos;
for (int a = startHeight; a <= endHeight; a += tool.rpWidth)
{
totalPixel++;
if (grnPixels[a].green == 0) tagged++;
}
}
//determine if meeting minimum coverage
tool.section[j].isSectionRequiredOn = ((tagged * 100) / totalPixel > (100 - tool.minCoverage));
//logic if in or out of boundaries or headland
if (bnd.bndList.count() > 0)
{
//if out of boundary, turn it off
if (!tool.section[j].isInBoundary)
{
tool.section[j].isSectionRequiredOn = false;
tool.section[j].sectionOffRequest = true;
tool.section[j].sectionOnRequest = false;
tool.section[j].sectionOffTimer = 0;
tool.section[j].sectionOnTimer = 0;
continue;
}
else
{
//is headland coming up
if (bnd.isHeadlandOn && bnd.isSectionControlledByHeadland)
{
bool isHeadlandInLookOn = false;
//is headline in off to on area
mOn = (tool.lookAheadDistanceOnPixelsRight - tool.lookAheadDistanceOnPixelsLeft) / tool.rpWidth;
mOff = (tool.lookAheadDistanceOffPixelsRight - tool.lookAheadDistanceOffPixelsLeft) / tool.rpWidth;
start = tool.section[j].rpSectionPosition - tool.section[0].rpSectionPosition;
end = tool.section[j].rpSectionWidth - 1 + start;
if (end >= tool.rpWidth)
end = tool.rpWidth - 1;
tagged = 0;
for (int pos = start; pos <= end; pos++)
{
startHeight = (int)(tool.lookAheadDistanceOffPixelsLeft + (mOff * pos)) * tool.rpWidth + pos;
endHeight = (int)(tool.lookAheadDistanceOnPixelsLeft + (mOn * pos)) * tool.rpWidth + pos;
for (int a = startHeight; a <= endHeight; a += tool.rpWidth)
{
if (a < 0)
mOn = 0;
if (grnPixels[a].green == 250)
{
isHeadlandInLookOn = true;
goto GetOutHdOn;
}
}
}
GetOutHdOn:
//determine if look ahead points are completely in headland
if (tool.section[j].isSectionRequiredOn && tool.section[j].isLookOnInHeadland && !isHeadlandInLookOn)
{
tool.section[j].isSectionRequiredOn = false;
tool.section[j].sectionOffRequest = true;
tool.section[j].sectionOnRequest = false;
}
if (tool.section[j].isSectionRequiredOn && !tool.section[j].isLookOnInHeadland && isHeadlandInLookOn)
{
tool.section[j].isSectionRequiredOn = true;
tool.section[j].sectionOffRequest = false;
tool.section[j].sectionOnRequest = true;
}
}
}
}
//global request to turn on section
tool.section[j].sectionOnRequest = tool.section[j].isSectionRequiredOn;
tool.section[j].sectionOffRequest = !tool.section[j].sectionOnRequest;
} // end of go thru all sections "for"
//Set all the on and off times based from on off section requests
for (int j = 0; j < tool.numOfSections; j++)
{
//SECTION timers
if (tool.section[j].sectionOnRequest)
tool.section[j].isSectionOn = true;
//turn off delay
if (tool.turnOffDelay > 0)
{
if (!tool.section[j].sectionOffRequest) tool.section[j].sectionOffTimer = (int)(gpsHz / 2.0 * tool.turnOffDelay);
if (tool.section[j].sectionOffTimer > 0) tool.section[j].sectionOffTimer--;
if (tool.section[j].sectionOffRequest && tool.section[j].sectionOffTimer == 0)
{
if (tool.section[j].isSectionOn) tool.section[j].isSectionOn = false;
}
}
else
{
if (tool.section[j].sectionOffRequest)
tool.section[j].isSectionOn = false;
}
//Mapping timers
if (tool.section[j].sectionOnRequest && !tool.section[j].isMappingOn && tool.section[j].mappingOnTimer == 0)
{
tool.section[j].mappingOnTimer = (int)(tool.lookAheadOnSetting * (gpsHz / 2) - 1);
}
else if (tool.section[j].sectionOnRequest && tool.section[j].isMappingOn && tool.section[j].mappingOffTimer > 1)
{
tool.section[j].mappingOffTimer = 0;
tool.section[j].mappingOnTimer = (int)(tool.lookAheadOnSetting * (gpsHz / 2) - 1);
}
if (tool.lookAheadOffSetting > 0)
{
if (tool.section[j].sectionOffRequest && tool.section[j].isMappingOn && tool.section[j].mappingOffTimer == 0)
{
tool.section[j].mappingOffTimer = (int)(tool.lookAheadOffSetting * (gpsHz / 2) + 4);
}
}
else if (tool.turnOffDelay > 0)
{
if (tool.section[j].sectionOffRequest && tool.section[j].isMappingOn && tool.section[j].mappingOffTimer == 0)
tool.section[j].mappingOffTimer = (int)(tool.turnOffDelay * gpsHz / 2);
}
else
{
tool.section[j].mappingOffTimer = 0;
}
//MAPPING - Not the making of triangle patches - only status - on or off
if (tool.section[j].sectionOnRequest)
{
tool.section[j].mappingOffTimer = 0;
if (tool.section[j].mappingOnTimer > 1)
tool.section[j].mappingOnTimer--;
else
{
tool.section[j].isMappingOn = true;
}
}
if (tool.section[j].sectionOffRequest)
{
tool.section[j].mappingOnTimer = 0;
if (tool.section[j].mappingOffTimer > 1)
tool.section[j].mappingOffTimer--;
else
{
tool.section[j].isMappingOn = false;
}
}
}
//Checks the workswitch or steerSwitch if required
if (ahrs.isAutoSteerAuto || mc.isRemoteWorkSystemOn)
mc.CheckWorkAndSteerSwitch(ahrs,isAutoSteerBtnOn);
// check if any sections have changed status
number = 0;
for (int j = 0; j < tool.numOfSections; j++)
{
if (tool.section[j].isMappingOn)
{
number |= 1ul << j;
}
}
//there has been a status change of section on/off
if (number != lastNumber)
{
int sectionOnOffZones = 0, patchingZones = 0;
//everything off
if (number == 0)
{
for (int j = 0; j < triStrip.count(); j++)
{
if (triStrip[j].isDrawing)
triStrip[j].TurnMappingOff(tool, fd);
}
}
else if (!tool.isMultiColoredSections)
{
//set the start and end positions from section points
for (int j = 0; j < tool.numOfSections; j++)
{
//skip till first mapping section
if (!tool.section[j].isMappingOn) continue;
//do we need more patches created
if (triStrip.count() < sectionOnOffZones + 1)
triStrip.append(CPatches());
//set this strip start edge to edge of this section
triStrip[sectionOnOffZones].newStartSectionNum = j;
while ((j + 1) < tool.numOfSections && tool.section[j + 1].isMappingOn)
{
j++;
}
//set the edge of this section to be end edge of strp
triStrip[sectionOnOffZones].newEndSectionNum = j;
sectionOnOffZones++;
}
//count current patch strips being made
for (int j = 0; j < triStrip.count(); j++)
{
if (triStrip[j].isDrawing) patchingZones++;
}
//tests for creating new strips or continuing
bool isOk = (patchingZones == sectionOnOffZones && sectionOnOffZones < 3);
if (isOk)
{
for (int j = 0; j < sectionOnOffZones; j++)
{
if (triStrip[j].newStartSectionNum > triStrip[j].currentEndSectionNum
|| triStrip[j].newEndSectionNum < triStrip[j].currentStartSectionNum)
isOk = false;
}
}
if (isOk)
{
for (int j = 0; j < sectionOnOffZones; j++)
{
if (triStrip[j].newStartSectionNum != triStrip[j].currentStartSectionNum
|| triStrip[j].newEndSectionNum != triStrip[j].currentEndSectionNum)
{
//if (tool.isSectionsNotZones)
{
triStrip[j].AddMappingPoint(tool,fd, 0);
}
triStrip[j].currentStartSectionNum = triStrip[j].newStartSectionNum;
triStrip[j].currentEndSectionNum = triStrip[j].newEndSectionNum;
triStrip[j].AddMappingPoint(tool,fd, 0);
}
}
}
else
{
//too complicated, just make new strips
for (int j = 0; j < triStrip.count(); j++)
{
if (triStrip[j].isDrawing)
triStrip[j].TurnMappingOff(tool, fd);
}
for (int j = 0; j < sectionOnOffZones; j++)
{
triStrip[j].currentStartSectionNum = triStrip[j].newStartSectionNum;
triStrip[j].currentEndSectionNum = triStrip[j].newEndSectionNum;
triStrip[j].TurnMappingOn(tool, 0);
}
}
}
else if (tool.isMultiColoredSections) //could be else only but this is more clear
{
//set the start and end positions from section points
for (int j = 0; j < tool.numOfSections; j++)
{
//do we need more patches created
if (triStrip.count() < sectionOnOffZones + 1)
triStrip.append(CPatches());
//set this strip start edge to edge of this section
triStrip[sectionOnOffZones].newStartSectionNum = j;
//set the edge of this section to be end edge of strp
triStrip[sectionOnOffZones].newEndSectionNum = j;
sectionOnOffZones++;
if (!tool.section[j].isMappingOn)
{
if (triStrip[j].isDrawing)
triStrip[j].TurnMappingOff(tool, fd);
}
else
{
triStrip[j].currentStartSectionNum = triStrip[j].newStartSectionNum;
triStrip[j].currentEndSectionNum = triStrip[j].newEndSectionNum;
triStrip[j].TurnMappingOn(tool,j);
}
}
}
lastNumber = number;
}
//send the byte out to section machines
BuildMachineByte();
//if a minute has elapsed save the field in case of crash and to be able to resume
if (minuteCounter > 30 && (uint)sentenceCounter < 20)
{
tmrWatchdog->stop();
//don't save if no gps
if (isJobStarted)
{
//auto save the field patches, contours accumulated so far
FileSaveSections();
FileSaveContour();
//NMEA log file
//TODO: if (isLogElevation) FileSaveElevation();
//ExportFieldAs_KML();
}
//if its the next day, calc sunrise sunset for next day
minuteCounter = 0;
//set saving flag off
isSavingFile = false;
//go see if data ready for draw and position updates
tmrWatchdog->start();
//calc overlap
//oglZoom.Refresh();
}
//stop the timer and calc how long it took to do calcs and draw
frameTimeRough = swFrame.elapsed();
//qDebug() << "frame time after finishing section lookahead " << frameTimeRough ;
if (frameTimeRough > 50) frameTimeRough = 50;
frameTime = frameTime * 0.90 + frameTimeRough * 0.1;
QObject *aog = qmlItem(qml_root, "aog");
aog->setProperty("frameTime", frameTime);
//TODO 5 hz sections
//if (bbCounter++ > 0)
// bbCounter = 0;
//draw the section control window off screen buffer
//if (bbCounter == 0)
//{
p_239.pgn[p_239.geoStop] = mc.isOutOfBounds ? 1 : 0;
SendPgnToLoop(p_239.pgn);
if (!tool.isSectionsNotZones)
SendPgnToLoop(p_229.pgn);
//}
lock.unlock();
//this is the end of the "frame". Now we wait for next NMEA sentence with a valid fix.
}
void FormGPS::tmrWatchdog_timeout()
{
//TODO: replace all this with individual timers for cleaner
if (! (bool)property_setMenu_isSimulatorOn && timerSim.isActive()) {
qDebug() << "Shutting down simulator.";
timerSim.stop();
} else if ( (bool)property_setMenu_isSimulatorOn && ! timerSim.isActive() ) {
qDebug() << "Starting up simulator.";
pn.latitude = sim.latitude;
pn.longitude = sim.longitude;
pn.headingTrue = 0;
timerSim.start(100); //fire simulator every 100 ms.
gpsHz = 10;
}
// This is done in QML
// if ((uint)sentenceCounter++ > 20)
// {
// //TODO: ShowNoGPSWarning();
// return;
// }
sentenceCounter += 1;
if (tenSecondCounter++ >= 40)
{
tenSecondCounter = 0;
tenSeconds++;
}
if (threeSecondCounter++ >= 12)
{
threeSecondCounter = 0;
threeSeconds++;
}
if (oneSecondCounter++ >= 4)
{
oneSecondCounter = 0;
oneSecond++;
}
if (oneHalfSecondCounter++ >= 2)
{
oneHalfSecondCounter = 0;
oneHalfSecond++;
}
if (oneFifthSecondCounter++ >= 0)
{
oneFifthSecondCounter = 0;
oneFifthSecond++;
}
////////////////////////////////////////////// 10 second ///////////////////////////////////////////////////////
//every 10 second update status
if (tenSeconds != 0)
{
//reset the counter
tenSeconds = 0;
if (isJobStarted)
{
if (isMetric)
{
/* TODO:
if (bnd.bndList.count() > 0)
{
lblFieldStatus.Text = "(" + fd.AreaBoundaryLessInnersHectares + " - "
+ fd.WorkedHectares + " = "
+ fd.WorkedAreaRemainHectares + ") "
+ fd.WorkedAreaRemainPercentage + " ("
+ fd.AreaBoundaryLessInnersHectares + " - "
+ fd.ActualAreaWorkedHectares + " = "
+ fd.ActualRemainHectares + ") "
+ fd.ActualOverlapPercent + " "
+ fd.TimeTillFinished + " "
+ fd.WorkRateHectares;
}
else
lblFieldStatus.Text =
fd.WorkedHectares + " *"
+ fd.ActualAreaWorkedHectares + " *"
+ fd.ActualOverlapPercent + " "
+ fd.WorkRateHectares;
*/
}
else //imperial
{
/* TODO:
if (bnd.bndList.count() > 0)
lblFieldStatus.Text = fd.AreaBoundaryLessInnersAcres + " - "
+ fd.WorkedAcres + " = "
+ fd.WorkedAreaRemainAcres + ") "
+ fd.WorkedAreaRemainPercentage + " ("
+ fd.AreaBoundaryLessInnersAcres + " - "
+ fd.ActualAreaWorkedAcres + " = "
+ fd.ActualRemainAcres + ") "
+ fd.ActualOverlapPercent + " "
+ fd.TimeTillFinished + " "
+ fd.WorkRateHectares;
else
lblFieldStatus.Text =
fd.WorkedAcres + " *"
+ fd.ActualAreaWorkedAcres + " *"
+ fd.ActualOverlapPercent + " "
+ fd.WorkRateAcres;
*/
}
//TODO: lblCurrentField.Text = displayFieldName;
if (curve.numCurveLineSelected > 0 && curve.isBtnCurveOn)
{
//TODO: lblGuidanceLine.Text = curve.curveArr[curve.numCurveLineSelected - 1].Name;
}
else if (ABLine.numABLineSelected > 0 && ABLine.isBtnABLineOn)
{
//TODO: lblGuidanceLine.Text = ABLine.lineArr[ABLine.numABLineSelected - 1].Name;
}
//TODO: else lblGuidanceLine.Text = "Guidance Line";
}
else
{
//TODO: lblFieldStatus.Text = string.Empty;
//TODO: lblCurrentField.Text = (tool.width * m2FtOrM).ToString("N2") + unitsFtM + " - " + vehicleFileName;
}
}
///////////////////////////////////////////////////////// 333333333333333 ////////////////////////////////////////
//every 3 second update status
if (displayUpdateThreeSecondCounter != threeSeconds)
{
//reset the counter
displayUpdateThreeSecondCounter = threeSeconds;
//check to make sure the grid is big enough
//worldGrid.checkZoomWorldGrid(pn.fix.northing, pn.fix.easting);
//hide the NAv panel in 6 secs
/* TODO:
if (panelNavigation.Visible)
{
if (navPanelCounter-- < 2) panelNavigation.Visible = false;
}
if (panelNavigation.Visible)
lblHz.Text = gpsHz.ToString("N1") + " ~ " + (frameTime.ToString("N1")) + " " + FixQuality;
lblFix.Text = FixQuality + pn.age.ToString("N1");
lblTime.Text = DateTime.Now.ToString("T");
*/
if (isJobStarted)
{
if (ABLine.isBtnABLineOn || curve.isBtnCurveOn)
{
/* TODO
if (!btnEditAB.Visible)
{
//btnMakeLinesFromBoundary.Visible = true;
btnEditAB.Visible = true;
//btnSnapToPivot.Visible = true;
cboxpRowWidth.Visible = true;
btnYouSkipEnable.Visible = true;
}
if (curve.numCurveLineSelected > 0 && curve.isBtnCurveOn)
{
lblGuidanceLine.Text = curve.curveArr[curve.numCurveLineSelected - 1].Name;
}
else if (ABLine.numABLineSelected > 0 && ABLine.isBtnABLineOn)
{
lblGuidanceLine.Text = ABLine.lineArr[ABLine.numABLineSelected - 1].Name;
}
else lblGuidanceLine.Text = gStr.gsNoGuidanceLines;
*/
}
/*TODO :else
{
if (btnEditAB.Visible)
{
//btnMakeLinesFromBoundary.Visible = false;
btnEditAB.Visible = false;
//btnSnapToPivot.Visible = false;
cboxpRowWidth.Visible = false;
btnYouSkipEnable.Visible = false;
}
}*/
}
//save nmea log file
//TODO: if (isLogNMEA) FileSaveNMEA();
//update button lines numbers
//TODO: UpdateGuidanceLineButtonNumbers();
}//end every 3 seconds
//every second update all status /////////////////////////// 1 1 1 1 1 1 ////////////////////////////
if (displayUpdateOneSecondCounter != oneSecond)
{
//reset the counter
displayUpdateOneSecondCounter = oneSecond;
//counter used for saving field in background
minuteCounter++;
tenMinuteCounter++;
if (isStanleyUsed)
{
if (curve.isBtnCurveOn || ABLine.isBtnABLineOn)
{
//TODO
//lblInty.Text = gyd.inty.ToString("N3");
}
}
else
{
if (curve.isBtnCurveOn)
{
//TODO
//lblInty.Text = curve.inty.ToString("N3");
}
else if (ABLine.isBtnABLineOn && !ct.isContourBtnOn)
{
//TODO
//lblInty.Text = ABLine.inty.ToString("N3");
}
else if (ct.isContourBtnOn) {}//TODO lblInty.Text = ct.inty.ToString("N3");
}
if (recPath.isDrivingRecordedPath) {} //TODO lblInty.Text = recPath.inty.ToString("N3");
//if (ABLine.isBtnABLineOn && !ct.isContourBtnOn)
//{
// btnEditAB.Text = ((int)(ABLine.moveDistance * 100)).ToString();
//}
//if (curve.isBtnCurveOn && !ct.isContourBtnOn)
//{
// btnEditAB.Text = ((int)(curve.moveDistance * 100)).ToString();
//}
//statusbar flash red undefined headland
//TODO: flash background alternately
/*
if (mc.isOutOfBounds && panelSim.BackColor == Color.Transparent
|| !mc.isOutOfBounds && panelSim.BackColor == Color.Tomato)
{
if (!mc.isOutOfBounds)
{
panelSim.BackColor = Color.Transparent;
}
else
{
panelSim.BackColor = Color.Tomato;
}
}*/
}