-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathheadlandManagement.lua
executable file
·2725 lines (2424 loc) · 132 KB
/
headlandManagement.lua
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
--
-- Headland Management for LS 22
--
-- Glowins Modschmiede
--
-- Todos:
-- X Contour: Speichern der Einstellungen
-- X Contour: Wahlweise Abschaltung des Front-Detectors
-- X Contour: Wahlweise Orientierung entlang der Feldgrenze oder entlang der Arbeitslinie
-- - Optionales Anhalten am Ende des Wendevorgangs bis Abschluss aller Sequenzen
-- - Fertigstellung des Ballenablade-Stopps
-- - Prüfen: Konfigurierbare 4-Tasten-Option
HeadlandManagement = {}
if HeadlandManagement.MOD_NAME == nil then HeadlandManagement.MOD_NAME = g_currentModName end
HeadlandManagement.MODSETTINGSDIR = g_currentModSettingsDirectory
source(g_currentModDirectory.."tools/gmsDebug.lua")
GMSDebug:init(HeadlandManagement.MOD_NAME, false)
GMSDebug:enableConsoleCommands("hlmDebug")
source(g_currentModDirectory.."gui/HeadlandManagementGui.lua")
g_gui:loadGui(g_currentModDirectory.."gui/HeadlandManagementGui.xml", "HeadlandManagementGui", HeadlandManagementGui:new())
HeadlandManagement.REDUCESPEED = 1
HeadlandManagement.STOPGPS = 2
HeadlandManagement.WAITTIME1 = 3
HeadlandManagement.CRABSTEERING = 4
HeadlandManagement.DIFFLOCK = 5
HeadlandManagement.RAISEIMPLEMENT1 = 6
HeadlandManagement.WAITONTRIGGER = 7
HeadlandManagement.RAISEIMPLEMENT2 = 8
HeadlandManagement.WAITTIME2 = 9
HeadlandManagement.TURNPLOW = 10
HeadlandManagement.STOPPTO = 11
HeadlandManagement.WAITTIME3 = 12
HeadlandManagement.MAXSTEP = 13
HeadlandManagement.GUIDANCE_RIGHT = -1
HeadlandManagement.GUIDANCE_LEFT = 1
HeadlandManagement.contourSharpness = 0.75
HeadlandManagement.contourSteeringSmoothness = 0.005
HeadlandManagement.contourParametersChanged = false
HeadlandManagement.debug = false
HeadlandManagement.showKeys = true
HeadlandManagement.BEEPSOUND = createSample("HLMBEEP")
loadSample(HeadlandManagement.BEEPSOUND, g_currentModDirectory.."sound/beep.ogg", false)
HeadlandManagement.sideInfo = SideNotification.new(nil, "dataS/menu/hud/hud_elements.png")
HeadlandManagement.guiIconOff = createImageOverlay(g_currentModDirectory.."gui/hlm_off.dds")
HeadlandManagement.guiIconField = createImageOverlay(g_currentModDirectory.."gui/hlm_field_normal.dds")
HeadlandManagement.guiIconFieldR = createImageOverlay(g_currentModDirectory.."gui/hlm_field_right.dds")
HeadlandManagement.guiIconFieldL = createImageOverlay(g_currentModDirectory.."gui/hlm_field_left.dds")
HeadlandManagement.guiIconFieldLR = createImageOverlay(g_currentModDirectory.."gui/hlm_field_leftright.dds")
HeadlandManagement.guiIconFieldA = createImageOverlay(g_currentModDirectory.."gui/hlm_field_auto_normal.dds")
HeadlandManagement.guiIconFieldAR = createImageOverlay(g_currentModDirectory.."gui/hlm_field_auto_right.dds")
HeadlandManagement.guiIconFieldAL = createImageOverlay(g_currentModDirectory.."gui/hlm_field_auto_left.dds")
HeadlandManagement.guiIconFieldALR = createImageOverlay(g_currentModDirectory.."gui/hlm_field_auto_leftright.dds")
HeadlandManagement.guiIconFieldW = createImageOverlay(g_currentModDirectory.."gui/hlm_field_working.dds")
HeadlandManagement.guiIconFieldWCG = createImageOverlay(g_currentModDirectory.."gui/hlm_field_cg_working.dds")
HeadlandManagement.guiIconFieldGS = createImageOverlay(g_currentModDirectory.."gui/hlm_field_gs.dds")
HeadlandManagement.guiIconFieldEV = createImageOverlay(g_currentModDirectory.."gui/hlm_field_ev.dds")
HeadlandManagement.guiIconFieldCGA = createImageOverlay(g_currentModDirectory.."gui/hlm_field_cg_auto_normal.dds")
HeadlandManagement.guiIconFieldCGAR = createImageOverlay(g_currentModDirectory.."gui/hlm_field_cg_auto_right.dds")
HeadlandManagement.guiIconFieldCGAL = createImageOverlay(g_currentModDirectory.."gui/hlm_field_cg_auto_left.dds")
HeadlandManagement.guiIconFieldCG = createImageOverlay(g_currentModDirectory.."gui/hlm_field_cg_normal.dds")
HeadlandManagement.guiIconFieldCGR = createImageOverlay(g_currentModDirectory.."gui/hlm_field_cg_right.dds")
HeadlandManagement.guiIconFieldCGL = createImageOverlay(g_currentModDirectory.."gui/hlm_field_cg_left.dds")
HeadlandManagement.guiIconHeadland = createImageOverlay(g_currentModDirectory.."gui/hlm_headland_normal.dds")
HeadlandManagement.guiIconHeadlandA = createImageOverlay(g_currentModDirectory.."gui/hlm_headland_auto_normal.dds")
HeadlandManagement.guiIconHeadlandW = createImageOverlay(g_currentModDirectory.."gui/hlm_headland_working.dds")
HeadlandManagement.guiIconHeadlandWCG = createImageOverlay(g_currentModDirectory.."gui/hlm_headland_cg_working.dds")
HeadlandManagement.guiIconHeadlandEV = createImageOverlay(g_currentModDirectory.."gui/hlm_headland_ev.dds")
HeadlandManagement.guiIconHeadlandCG = createImageOverlay(g_currentModDirectory.."gui/hlm_headland_cg_normal.dds")
HeadlandManagement.guiIconHeadlandACG = createImageOverlay(g_currentModDirectory.."gui/hlm_headland_cg_auto_normal.dds")
-- Filtered implements
HeadlandManagement.filterList = {}
HeadlandManagement.filterList[1] = "E-DriveLaner"
-- Killbits for supported published mods
HeadlandManagement.kbVCA = false
HeadlandManagement.kbGS = false
HeadlandManagement.kbSC = false
HeadlandManagement.kbEV = false
HeadlandManagement.kbECC = false
-- set configuration
function addHLMconfig(xmlFile, superfunc, baseXMLName, baseDir, customEnvironment, isMod, storeItem)
local configurations, defaultConfigurationIds = superfunc(xmlFile, baseXMLName, baseDir, customEnvironment, isMod, storeItem)
dbgprint("addHLMconfig : Kat: "..storeItem.categoryName.." / ".."Name: "..storeItem.xmlFilename, 2)
local category = storeItem.categoryName
if
( category == "TRACTORSS"
or category == "TRACTORSM"
or category == "TRACTORSL"
or category == "HARVESTERS"
or category == "FORAGEHARVESTERS"
or category == "BEETVEHICLES"
or category == "POTATOVEHICLES"
or category == "COTTONVEHICLES"
or category == "SPRAYERVEHICLES"
or category == "SLURRYVEHICLES"
or category == "SUGARCANEVEHICLES"
or category == "MOWERVEHICLES"
or category == "MISCVEHICLES"
or category == "GRAPEVEHICLES"
or category == "OLIVEVEHICLES"
-- Ifkos etc.
or category == "LSFM"
-- Hof Bergmann etc.
or category == "MINIAGRICULTUREEQUIPMENT"
or category == "FM_VEHICLES"
or category == "FENDTPACKCATEGORY"
or category == "FD_CASEPACKCATEGORY"
or category == "SDFCORE2"
or category == "SDFCORE3"
or category == "SDFCORE4"
or category == "SDFCORE4H"
or category == "SDFCORE4L"
or category == "SDFCORE4S"
or category == "SDFCORE5"
or category == "SDFCORE5A"
or category == "SDFCORE5AH"
or category == "SDFCORE5AL"
or category == "SDFCORE5AS"
or category == "SDFCORE5N"
or category == "SDFCORE5NH"
or category == "SDFCORE5NL"
or category == "SDFCORE5NS"
)
and configurations ~= nil
and xmlFile:hasProperty("vehicle.enterable")
and xmlFile:hasProperty("vehicle.motorized")
and xmlFile:hasProperty("vehicle.drivable")
then
configurations["HeadlandManagement"] = {
{name = g_i18n.modEnvironments[HeadlandManagement.MOD_NAME]:getText("text_HLM_notInstalled_short"), index = 1, isDefault = true, isSelectable = true, price = 0, dailyUpkeep = 0, desc = g_i18n.modEnvironments[HeadlandManagement.MOD_NAME]:getText("text_HLM_notInstalled")},
{name = g_i18n.modEnvironments[HeadlandManagement.MOD_NAME]:getText("text_HLM_installed_short"), index = 2, isDefault = false, isSelectable = true, price = 3000, dailyUpkeep = 0, desc = g_i18n.modEnvironments[HeadlandManagement.MOD_NAME]:getText("text_HLM_installed")}
}
dbgprint("addHLMconfig : Configuration HeadlandManagement added", 2)
dbgprint_r(configurations["HeadlandManagement"], 4)
end
return configurations, defaultConfigurationIds
end
-- Standards / Basics
function HeadlandManagement.prerequisitesPresent(specializations)
return true
end
function HeadlandManagement.initSpecialization()
dbgprint("initSpecialization : start", 2)
if g_configurationManager.configurations["HeadlandManagement"] == nil then
g_configurationManager:addConfigurationType("HeadlandManagement", g_i18n.modEnvironments[HeadlandManagement.MOD_NAME]:getText("text_HLM_configuration"), nil, nil, nil, nil, ConfigurationUtil.SELECTOR_MULTIOPTION)
end
StoreItemUtil.getConfigurationsFromXML = Utils.overwrittenFunction(StoreItemUtil.getConfigurationsFromXML, addHLMconfig)
dbgprint("initSpecialization : Configuration initialized", 1)
local schemaSavegame = Vehicle.xmlSchemaSavegame
dbgprint("initSpecialization: starting xmlSchemaSavegame registration process", 1)
local schemaKey = HeadlandManagement.MOD_NAME..".HeadlandManagement"
-- register new and old schema for backwarts compatibility reasons
for _, key in pairs({schemaKey,"HeadlandManagement"}) do
schemaSavegame:register(XMLValueType.BOOL, "vehicles.vehicle(?)."..key.."#configured", "HLM configured", false)
schemaSavegame:register(XMLValueType.BOOL, "vehicles.vehicle(?)."..key.."#isOn", "HLM is turned on", false)
schemaSavegame:register(XMLValueType.BOOL, "vehicles.vehicle(?)."..key.."#beep", "Audible alert", true)
schemaSavegame:register(XMLValueType.INT, "vehicles.vehicle(?)."..key.."#beepVol", "Audible alert volume", 5)
schemaSavegame:register(XMLValueType.FLOAT,"vehicles.vehicle(?)."..key.."#turnSpeed", "Speed in headlands", 5)
schemaSavegame:register(XMLValueType.BOOL, "vehicles.vehicle(?)."..key.."#useSpeedControl", "Change speed in headlands", true)
schemaSavegame:register(XMLValueType.BOOL, "vehicles.vehicle(?)."..key.."#useModSpeedControl", "use mod SpeedControl", false)
schemaSavegame:register(XMLValueType.BOOL, "vehicles.vehicle(?)."..key.."#useCrabSteering", "Change crab steering in headlands", true)
schemaSavegame:register(XMLValueType.BOOL, "vehicles.vehicle(?)."..key.."#useCrabSteeringTwoStep", "Changecrab steering over turn config", true)
schemaSavegame:register(XMLValueType.BOOL, "vehicles.vehicle(?)."..key.."#useRaiseImplementF", "Raise front attachements in headlands", true)
schemaSavegame:register(XMLValueType.BOOL, "vehicles.vehicle(?)."..key.."#useRaiseImplementB", "Raise back attahements in headlands", true)
schemaSavegame:register(XMLValueType.BOOL, "vehicles.vehicle(?)."..key.."#waitOnTrigger", "Raise back attachements when reaching position of front implement's raise", false)
schemaSavegame:register(XMLValueType.BOOL, "vehicles.vehicle(?)."..key.."#useStopPTOF", "Stop front PTO in headlands", true)
schemaSavegame:register(XMLValueType.BOOL, "vehicles.vehicle(?)."..key.."#useStopPTOB", "Stop back PTO in headlands", true)
schemaSavegame:register(XMLValueType.BOOL, "vehicles.vehicle(?)."..key.."#turnPlow", "Turn plow in headlands", true)
schemaSavegame:register(XMLValueType.BOOL, "vehicles.vehicle(?)."..key.."#centerPlow", "Center plow first in headlands", false)
schemaSavegame:register(XMLValueType.BOOL, "vehicles.vehicle(?)."..key.."#switchRidge", "Change ridgemarkers", true)
schemaSavegame:register(XMLValueType.BOOL, "vehicles.vehicle(?)."..key.."#useGPS", "Change GPS", true)
schemaSavegame:register(XMLValueType.INT, "vehicles.vehicle(?)."..key.."#gpsSetting", "GPS-Mode", 1)
schemaSavegame:register(XMLValueType.BOOL, "vehicles.vehicle(?)."..key.."#vcaDirSwitch", "Switch vca-turn", true)
schemaSavegame:register(XMLValueType.BOOL, "vehicles.vehicle(?)."..key.."#autoResume", "Auto resume field mode after turn", false)
schemaSavegame:register(XMLValueType.BOOL, "vehicles.vehicle(?)."..key.."#useGuidanceSteeringTrigger", "Use headland automatic of GS", false)
schemaSavegame:register(XMLValueType.BOOL, "vehicles.vehicle(?)."..key.."#useGuidanceSteeringOffset", "Use back trigger", false)
schemaSavegame:register(XMLValueType.BOOL, "vehicles.vehicle(?)."..key.."#useEVTrigger", "Use headland automatic of EV", false)
schemaSavegame:register(XMLValueType.BOOL, "vehicles.vehicle(?)."..key.."#useHLMTriggerF", "Use HLM trigger with front node", false)
schemaSavegame:register(XMLValueType.BOOL, "vehicles.vehicle(?)."..key.."#useHLMTriggerB", "Use HLM trigger with back node", false)
schemaSavegame:register(XMLValueType.INT, "vehicles.vehicle(?)."..key.."#headlandDistance", "Distance to headland", 9)
schemaSavegame:register(XMLValueType.BOOL, "vehicles.vehicle(?)."..key.."#useDiffLock", "Unlock diff locks in headland", true)
schemaSavegame:register(XMLValueType.INT, "vehicles.vehicle(?)."..key.."#contour", "Contour state", 0)
schemaSavegame:register(XMLValueType.BOOL, "vehicles.vehicle(?)."..key.."#contourMultiMode", "More than one row", false)
schemaSavegame:register(XMLValueType.BOOL, "vehicles.vehicle(?)."..key.."#contourNoSwap", "Swap guiding side", false)
schemaSavegame:register(XMLValueType.BOOL, "vehicles.vehicle(?)."..key.."#contourFrontActive", "Front sensor state", true)
schemaSavegame:register(XMLValueType.BOOL, "vehicles.vehicle(?)."..key.."#contourWidthAdaption", "Adapt width in headland mode", false)
schemaSavegame:register(XMLValueType.BOOL, "vehicles.vehicle(?)."..key.."#contourWidthMeasurement", "Automatic mode state", false)
schemaSavegame:register(XMLValueType.BOOL, "vehicles.vehicle(?)."..key.."#contourWidthManualMode", "Contour width is set manually", false)
schemaSavegame:register(XMLValueType.FLOAT, "vehicles.vehicle(?)."..key.."#contourWidthManualInput", "Manual input value", 3.0)
schemaSavegame:register(XMLValueType.FLOAT, "vehicles.vehicle(?)."..key.."#contourWidth", "Contour width", 0.0)
schemaSavegame:register(XMLValueType.INT, "vehicles.vehicle(?)."..key.."#contourTrack", "Actual track for counter", 0)
schemaSavegame:register(XMLValueType.BOOL, "vehicles.vehicle(?)."..key.."#contourShowLines", "Show contour lines", true)
schemaSavegame:register(XMLValueType.BOOL, "vehicles.vehicle(?)."..key.."#contourWorkedArea", "Contour on worked area or on field border", false)
dbgprint("initSpecialization: finished xmlSchemaSavegame registration process for schema "..key, 1)
end
dbgprint("initSpecialization: finished xmlSchemaSavegame registration process", 1)
end
function HeadlandManagement.registerEventListeners(vehicleType)
SpecializationUtil.registerEventListener(vehicleType, "onUpdate", HeadlandManagement)
SpecializationUtil.registerEventListener(vehicleType, "onUpdateTick", HeadlandManagement)
SpecializationUtil.registerEventListener(vehicleType, "onDraw", HeadlandManagement)
SpecializationUtil.registerEventListener(vehicleType, "onLoad", HeadlandManagement)
SpecializationUtil.registerEventListener(vehicleType, "onPostLoad", HeadlandManagement)
SpecializationUtil.registerEventListener(vehicleType, "saveToXMLFile", HeadlandManagement)
SpecializationUtil.registerEventListener(vehicleType, "onRegisterActionEvents", HeadlandManagement)
SpecializationUtil.registerEventListener(vehicleType, "onReadStream", HeadlandManagement)
SpecializationUtil.registerEventListener(vehicleType, "onWriteStream", HeadlandManagement)
SpecializationUtil.registerEventListener(vehicleType, "onReadUpdateStream", HeadlandManagement)
SpecializationUtil.registerEventListener(vehicleType, "onWriteUpdateStream", HeadlandManagement)
SpecializationUtil.registerEventListener(vehicleType, "onPostAttachImplement", HeadlandManagement)
SpecializationUtil.registerEventListener(vehicleType, "onPreDetachImplement", HeadlandManagement)
end
function HeadlandManagement.registerOverwrittenFunctions(vehicleType)
SpecializationUtil.registerOverwrittenFunction(vehicleType, "setSteeringInput", HeadlandManagement.setSteeringInput)
end
function HeadlandManagement:saveContourSettings()
local filename = HeadlandManagement.MODSETTINGSDIR.."contourSettings.xml"
local key = "contourSettings"
local saved = false
createFolder(HeadlandManagement.MODSETTINGSDIR)
local xmlFile = XMLFile.create("settingsXML", filename, key)
if xmlFile ~= nil then
dbgprint("saveSettings : key: "..tostring(key), 2)
xmlFile:setFloat(key..".contourSharpness", HeadlandManagement.contourSharpness)
xmlFile:setFloat(key..".contourSteeringSmoothness", HeadlandManagement.contourSteeringSmoothness)
xmlFile:save()
xmlFile:delete()
dbgprint("saveSettings : saving data finished", 2)
saved = true
end
return saved
end
function HeadlandManagement:loadContourSettings()
local loaded = false
local filename = HeadlandManagement.MODSETTINGSDIR.."contourSettings.xml"
local key = "contourSettings"
local xmlFile = XMLFile.loadIfExists("settingsXML", filename, key)
if xmlFile ~= nil then
dbgprint("loadSettings : spec: "..tostring(spec), 2)
HeadlandManagement.contourSharpness = xmlFile:getFloat(key..".contourSharpness") or HeadlandManagement.contourSharpness
HeadlandManagement.contourSteeringSmoothness = xmlFile:getFloat(key..".contourSteeringSmoothness") or HeadlandManagement.contourSteeringSmoothness
HeadlandManagement.contourSharpness = math.floor(HeadlandManagement.contourSharpness * 10000)/10000
HeadlandManagement.contourSteeringSmoothness = math.floor(HeadlandManagement.contourSteeringSmoothness * 10000)/10000
xmlFile:delete()
dbgprint("loadSettings : loading data finished", 2)
loaded = true
end
return loaded
end
function HeadlandManagement:onLoad(savegame)
dbgprint("onLoad", 2)
HeadlandManagement.isDedi = g_server ~= nil and g_currentMission.connectedToDedicatedServer
-- Make Specialization easier accessible
self.spec_HeadlandManagement = self["spec_"..HeadlandManagement.MOD_NAME..".HeadlandManagement"]
local spec = self.spec_HeadlandManagement
spec.dirtyFlag = self:getNextDirtyFlag()
spec.exists = false -- Headland Management is configured into vehicle
spec.isOn = false -- Headland Management is switched on
spec.timer = 0 -- Timer for waiting actions
spec.beep = true -- Beep on or off
spec.beepVol = 3 -- Initial beep volume setting
spec.normSpeed = 20 -- working speed on field
spec.turnSpeed = 5 -- working speed on headland
spec.actStep = 0 -- actual step in process chain
spec.isActive = false -- Headland Management in headland mode (active) or field mode (inactive)
spec.action = {} -- switches for process chain
spec.action[0] =false
spec.useSpeedControl = true -- change working speed on headland
spec.useHLMTriggerF = false -- use vehicle's front node as trigger
spec.useHLMTriggerB = false -- use vehicle's back node as trigger
spec.headlandDistance = 9 -- headland width (distance to field border) -- needs config settings
spec.headlandF = false -- front node over headland?
spec.headlandB = false -- back node over headland?
spec.lastHeadlandF = false -- was front node already over headland?
spec.lastHeadlandB = false -- was back node already over headland?
spec.useRaiseImplementF = true -- raise front implements in headland mode
spec.useRaiseImplementB = true -- raise back implements in headland mode
spec.implementStatusTable = {} -- table of implement's state (lowered on field?)
spec.implementPTOTable = {} -- table of implement's pto state on field
spec.useStopPTOF = true -- stop front pto in headland mode
spec.useStopPTOB = true -- stop back pto in headland mode
spec.stopEmptyBaler = false -- stop auto-emptying of balers in headland
spec.waitTime = 0 -- time to wait for animations to finish
spec.waitOnTrigger = false -- wait until vehicle has moved to trigger point before raising back implements
spec.useTurnPlow = true -- turn plow in headland mode
spec.useCenterPlow = true -- turn plow in two steps
spec.plowRotationMaxNew = nil -- plow state while turning
spec.vehicleLength = 0 -- calculated vehicle's length
spec.vehicleWidth = 0 -- vehicle's width
spec.maxTurningRadius = 0 -- vehicle's turn radius
spec.autoOverride = false -- temporary override of headland automatic
spec.useRidgeMarker = true -- switch ridge markers in headland mode
spec.ridgeMarkerState = 0 -- state of ridge markers on field
spec.crabSteeringFound = false -- vehicle has crab steering feature
spec.useCrabSteering = true -- change crab steering in headland mode
spec.useCrabSteeringTwoStep = true -- change crab steering to AI driver position in headland mode
spec.useGPS = true -- control gps in headland mode
spec.gpsSetting = 1 -- 1: auto-mode, 2: gs-mode, 3: vca-mode, 4: vca-turn-left, 5: vca-turn-right, 6: ev-mode
spec.wasGPSAutomatic = false -- was headland automatic active on field?
spec.modGuidanceSteeringFound = false
spec.useGuidanceSteeringTrigger = false
spec.useGuidanceSteeringOffset = false
spec.guidanceSteeringOffset = 0
spec.setServerHeadlandActDistance = -1
spec.GSStatus = false
spec.modVCAFound = false
spec.vcaStatus = false
spec.vcaDirSwitch = true
spec.autoResume = false
spec.autoResumeOnTrigger = false
spec.modEVFound = false
spec.useEVTrigger = false
spec.modSpeedControlFound = false -- does mod 'FS22_zzzSpeedControl' exist?
spec.useModSpeedControl = false -- use mod 'FS22_xxxSpeedControl'
spec.modECCFound = false -- does mod 'FS22_extendedCruiseControl' exist?
spec.useModECC = false
spec.useDiffLock = true
spec.diffStateF = false
spec.diffStateB = false
spec.contour = 0 -- contour state (0=off)
spec.contourLast = 0
spec.contourMultiMode = false -- more than one row
spec.contourNoSwap = false -- swap guiding side
spec.contourFrontActive = true -- front sensor state
spec.contourSetActive = false -- cg active
spec.contourTriggerMeasurement = false -- trigger measurement as soon as it is possible
spec.contourWidthAdaption = false -- adapt width in headland mode
spec.contourWidthMeasurement = true -- automatic mode state
spec.contourWidthManualMode = false -- manual width setting active
spec.contourWidthManualInput = 1 -- manual width input value
spec.triggerContourStateChange = false -- cg on standby (headland mode active)
spec.contourWidth = 0
spec.contourTrack = 0
spec.contourSteering = 0
spec.contourWorkedArea = false -- get contour of worked area (true) or of field border (false)
spec.contourShowLines = true
spec.workedArea = -1
spec.debugFlag = false -- shows green flag for triggerNode and red flag for vehicle's measure node
HeadlandManagement:loadContourSettings()
end
function HeadlandManagement:editParameter(sharpnessStr, smoothnessStr)
local vehicle = g_currentMission.controlledVehicle or nil
local spec = vehicle ~= nil and vehicle.spec_HeadlandManagement or nil
if spec ~= nil then
local sharpness = tonumber(sharpnessStr) or HeadlandManagement.contourSharpness
local smoothness = tonumber(smoothnessStr) or HeadlandManagement.contourSteeringSmoothness
local changed = sharpness ~= HeadlandManagement.contourSharpness and smoothness ~= HeadlandManagement.contourSteeringSmoothness
print("HLM Parameter: Sharpness = "..tostring(sharpness).." / SteeringSmoothness = "..tostring(smoothness))
HeadlandManagement.contourSharpness = sharpness
HeadlandManagement.contourSteeringSmoothness = smoothness
HeadlandManagement.contourParametersChanged = changed
end
end
addConsoleCommand("hlmParameter", "HLM: Change contour parameters", "editParameter", HeadlandManagement)
-- Detect outmost frontNode and outmost backNode by considering vehicle's attacherJoints and known workAreas
local function vehicleMeasurement(self, excludedImplement)
local frontNode, backNode, cFrontNode, cBackNode
local vehicleLength, vehicleWidth, maxTurningRadius = 0, 0, 0
local distFront, distBack, lastFront, lastBack = 0, 0, 0, 0
local frontExists, backExists
local lengthBackup, tmpLen = 0, 0
local allImplements = self:getRootVehicle():getChildVehicles()
dbgprint("vehicleMeasurement : #allImplements = "..tostring(#allImplements), 2)
-- the to-be-detached implement is still connected, so we have to exclude it and it's children from calculation of vehicle's length
local excludedChilds = {}
if excludedImplement ~= nil and excludedImplement.getFullName ~= nil then
dbgprint("vehicleMeasurement : excludedImplement: "..excludedImplement:getFullName(), 2)
if excludedImplement.getChildVehicles ~= nil then excludedChilds = excludedImplement:getChildVehicles() end
end
local vehicleWidthShop = 0
local vehicleWidthWA = 0
for _,implement in pairs(allImplements) do
if implement ~= nil then
local filtered = false
for _,filterName in pairs(HeadlandManagement.filterList) do
if implement.getName ~= nil and implement:getName() == filterName then filtered = true end
end
if implement == excludedImplement then filtered = true end
for _,excludedChild in pairs(excludedChilds) do
if implement == excludedChild then filtered = true end
end
local spec_at = implement.spec_attacherJoints
if implement.getName ~= nil then dbgprint("vehicleMeasurement : implement: "..implement:getName()) end
local implTurningRadius = implement.maxTurningRadius
if implTurningRadius ~= nil then maxTurningRadius = math.max(maxTurningRadius, implTurningRadius) end
dbgprint("vehicleMeasurement : maxTurningRadius: "..tostring(maxTurningRadius), 2)
if implement.size ~= nil then
dbgprint("vehicleMeasurement : width: "..tostring(implement.size.width))
dbgprint("vehicleMeasurement : length: "..tostring(implement.size.length))
lengthBackup = lengthBackup + implement.size.length
vehicleWidthShop = math.max(vehicleWidthShop, implement.size.width)
end
if not filtered and spec_at ~= nil then
for index,joint in pairs(spec_at.attacherJoints) do
local wx, wy, wz = getWorldTranslation(joint.jointTransform)
local lx, ly, lz = worldToLocal(self.rootNode, wx, wy, wz)
lastFront, lastBack = distFront, distBack
distFront, distBack = math.max(distFront, lz), math.min(distBack, lz)
if distFront ~= lastFront then
frontExists = true
frontNode = joint.jointTransform
dbgprint("vehicleMeasurement joint "..tostring(index)..": New frontNode set", 2)
end
if distBack ~= lastBack then
backExists = true
backNode = joint.jointTransform
dbgprint("vehicleMeasurement joint "..tostring(index)..": New backNode set", 2)
end
tmpLen = math.floor(math.abs(distFront) + math.abs(distBack) + 0.5)
dbgprint("vehicleMeasurement joint "..tostring(index)..": new distFront: "..tostring(distFront), 2)
dbgprint("vehicleMeasurement joint "..tostring(index)..": new distBack: "..tostring(distBack), 2)
dbgprint("vehicleMeasurement joint "..tostring(index)..": new vehicleLength: "..tostring(tmpLen), 2)
end
else
dbgprint("vehicleMeasurement: filtered or no attacherJoint", 2)
end
local spec_wa = implement.spec_workArea
if not filtered and spec_wa ~= nil and spec_wa.workAreas ~= nil then
for index, workArea in pairs(spec_wa.workAreas) do
local waWidth = 0
local maxX, minX = 0, 0
if workArea.functionName ~= "processRidgeMarkerArea" then
if workArea.start ~= nil then
local testNode = workArea.start
local widthNode = workArea.width
local wx, wy, wz = getWorldTranslation(testNode)
local lx, ly, lz = worldToLocal(self.rootNode, wx, wy, wz)
local wwx, wwy, wwz = getWorldTranslation(widthNode)
local lwx, lwy, lwz = worldToLocal(self.rootNode, wwx, wwy, wwz)
maxX = math.max(maxX, math.max(lwx, lx))
minX = math.min(minX, math.min(lwx, lx))
waWidth = math.abs(maxX - minX)
lastFront, lastBack = distFront, distBack
distFront, distBack = math.max(distFront, lz), math.min(distBack, lz)
if lastFront ~= distFront then
frontExists = true
frontNode = testNode;
dbgprint("vehicleMeasurement workArea "..tostring(index)..": New frontNode set", 2)
end
if lastBack ~= distBack then
backExists = true
backNode = testNode;
dbgprint("vehicleMeasurement workArea "..tostring(index)..": New backNode set", 2)
end
end
vehicleWidthWA = math.max(vehicleWidthWA, waWidth)
end
tmpLen = math.floor(math.abs(distFront) + math.abs(distBack) + 0.5)
dbgprint("vehicleMeasurement workArea "..tostring(index)..": function: "..tostring(workArea.functionName), 2)
dbgprint("vehicleMeasurement workArea "..tostring(index)..": new distFront: "..tostring(distFront), 2)
dbgprint("vehicleMeasurement workArea "..tostring(index)..": new distBack: "..tostring(distBack), 2)
dbgprint("vehicleMeasurement workArea "..tostring(index)..": new vehicleLength: "..tostring(tmpLen), 2)
dbgprint("vehicleMeasurement workArea "..tostring(index)..": new vehicleWidth: "..tostring(vehicleWidthWA), 2)
end
--vehicleWidth = vehicleWidthWA ~= 0 and vehicleWidthWA or vehicleWidth
dbgprint("vehicleMeasurement workArea: new vehicleWidth: "..tostring(vehicleWidth), 2)
else
dbgprint("vehicleMeasurement: filtered or no workArea", 2)
end
else
dbgprint("vehicleMeasurement: implement == nil", 2)
end
end
if frontExists and backExists then
vehicleLength = math.floor(math.abs(distFront) + math.abs(distBack) + 0.5)
else
vehicleLength = lengthBackup
end
vehicleWidth = vehicleWidthWA ~= 0 and vehicleWidthWA or vehicleWidthShop
local rwx, rwy, rwz, vz
if frontNode ~= nil then
dbgprint("frontNode center projection", 2)
-- center projection of frontNode
rwx, rwy, rwz = getWorldTranslation(frontNode)
_, _, vz = worldToLocal(self.rootNode, rwx, rwy, rwz)
cFrontNode = createTransformGroup("cFrontNode")
link(self.rootNode, cFrontNode)
setTranslation(cFrontNode, 0, 0, vz)
else
dbgprint("no frontNode center projection", 2)
cFrontNode = nil
end
if backNode ~= nil then
dbgprint("backNode center projection", 2)
-- center projection of backNode
rwx, rwy, rwz = getWorldTranslation(backNode)
_, _, vz = worldToLocal(self.rootNode, rwx, rwy, rwz)
cBackNode = createTransformGroup("cBackNode")
link(self.rootNode, cBackNode)
setTranslation(cBackNode, 0, 0, vz)
else
dbgprint("no backNode center projection", 2)
cBackNode = nil
end
dbgprint("vehicleMeasurement : distFront: "..tostring(distFront), 2)
dbgprint("vehicleMeasurement : distBack: "..tostring(distBack), 2)
dbgprint("vehicleMeasurement : frontNode: "..tostring(frontNode), 2)
dbgprint("vehicleMeasurement : backNode: "..tostring(backNode), 2)
dbgprint("vehicleMeasurement : cFrontNode: "..tostring(cFrontNode), 2)
dbgprint("vehicleMeasurement : cBackNode: "..tostring(cBackNode), 2)
dbgprint("vehicleMeasurement : vehicleLength: "..tostring(vehicleLength), 1)
dbgprint("vehicleMeasurement : vehicleWidth: "..tostring(vehicleWidth), 1)
return cFrontNode, cBackNode, vehicleLength, vehicleWidth, maxTurningRadius
end
function HeadlandManagement:onPostLoad(savegame)
dbgprint("onPostLoad: "..self:getFullName(), 2)
local spec = self.spec_HeadlandManagement
if spec == nil then return end
-- Check if vehicle supports CrabSteering
local csSpec = self.spec_crabSteering
spec.crabSteeringFound = csSpec ~= nil and csSpec.stateMax ~= nil and csSpec.stateMax > 0
dbgprint("onPostLoad : CrabSteering exists: "..tostring(spec.crabSteeringFound), 1)
-- Check if Mod SpeedControl exists
if FS22_SpeedControl ~= nil and FS22_SpeedControl.SpeedControl ~= nil and FS22_SpeedControl.SpeedControl.onInputAction ~= nil and not HeadlandManagement.kbSC then
spec.modSpeedControlFound = true
spec.useModSpeedControl = true
spec.turnSpeed = 1 --SpeedControl Mode 1
spec.normSpeed = 2 --SpeedControl Mode 2
end
-- Check if Mod FS22_extendedCruiseControl exists
if self.spec_extendedCruiseControl ~= nil and not HeadlandManagement.kbECC then
spec.modECCFound = true
spec.useModSpeedControl = true
spec.modSpeedControlFound = false -- Override SpeedControl if both mods are present
spec.turnSpeed = 1 --SpeedControl Mode 1
spec.normSpeed = 2 --SpeedControl Mode 2
end
-- Check if Mod GuidanceSteering exists
spec.modGuidanceSteeringFound = self.spec_globalPositioningSystem ~= nil and not HeadlandManagement.kbGS
-- Check if Mod VCA exists
spec.modVCAFound = self.vcaSetState ~= nil and not HeadlandManagement.kbVCA
-- Check if Mod EV exists
spec.modEVFound = FS22_EnhancedVehicle ~= nil and FS22_EnhancedVehicle.FS22_EnhancedVehicle ~= nil and FS22_EnhancedVehicle.FS22_EnhancedVehicle.onActionCall ~= nil and not HeadlandManagement.kbEV
dbgprint("modEVFound is "..tostring(spec.modEVFound).."("..tostring(modEVFound).."/"..tostring(modEVEnabled)..")")
-- HLM configured?
spec.exists = self.configurations["HeadlandManagement"] ~= nil and self.configurations["HeadlandManagement"] > 1
if savegame ~= nil then
dbgprint("onPostLoad : loading saved data", 2)
local xmlFile = savegame.xmlFile
local key = savegame.key .."."..HeadlandManagement.MOD_NAME..".HeadlandManagement"
local keyOld = savegame.key..".HeadlandManagement"
spec.exists = xmlFile:getValue(key.."#configured", spec.exists)
if not spec.exists then
-- Old savegame from version before 1.4.0.0? Load from old schema path!
spec.exists = xmlFile:getValue(keyOld.."#configured", spec.exists)
if spec.exists then key = keyOld end
end
if spec.exists then
spec.isOn = xmlFile:getValue(key.."#isOn", spec.isOn)
spec.beep = xmlFile:getValue(key.."#beep", spec.beep)
spec.beepVol = xmlFile:getValue(key.."#beepVol", spec.beepVol)
spec.turnSpeed = xmlFile:getValue(key.."#turnSpeed", spec.turnSpeed)
spec.useSpeedControl = xmlFile:getValue(key.."#useSpeedControl", spec.useSpeedControl)
spec.useModSpeedControl = xmlFile:getValue(key.."#useModSpeedControl", spec.useModSpeedControl)
spec.useCrabSteering = xmlFile:getValue(key.."#useCrabSteering", spec.useCrabSteering)
spec.useCrabSteeringTwoStep = xmlFile:getValue(key.."#useCrabSteeringTwoStep", spec.useCrabSteeringTwoStep)
spec.useRaiseImplementF = xmlFile:getValue(key.."#useRaiseImplementF", spec.useRaiseImplementF)
spec.useRaiseImplementB = xmlFile:getValue(key.."#useRaiseImplementB", spec.useRaiseImplementB)
spec.waitOnTrigger = xmlFile:getValue(key.."#waitOnTrigger", spec.waitOnTrigger)
spec.useStopPTOF = xmlFile:getValue(key.."#useStopPTOF", spec.useStopPTOF)
spec.useStopPTOB = xmlFile:getValue(key.."#useStopPTOB", spec.useStopPTOB)
spec.useTurnPlow = xmlFile:getValue(key.."#turnPlow", spec.useTurnPlow)
spec.useCenterPlow = xmlFile:getValue(key.."#centerPlow", spec.useCenterPlow)
spec.useRidgeMarker = xmlFile:getValue(key.."#switchRidge", spec.useRidgeMarker)
spec.useGPS = xmlFile:getValue(key.."#useGPS", spec.useGPS)
spec.gpsSetting = xmlFile:getValue(key.."#gpsSetting", spec.gpsSetting)
spec.useGuidanceSteeringTrigger = xmlFile:getValue(key.."#useGuidanceSteeringTrigger", spec.useGuidanceSteeringTrigger)
spec.useGuidanceSteeringOffset = xmlFile:getValue(key.."#useGuidanceSteeringOffset", spec.useGuidanceSteeringOffset)
spec.useEVTrigger = xmlFile:getValue(key.."#useEVTrigger", spec.useEVTrigger) and spec.modEVFound
spec.useHLMTriggerF = xmlFile:getValue(key.."#useHLMTriggerF", spec.useHLMTriggerF)
spec.useHLMTriggerB = xmlFile:getValue(key.."#useHLMTriggerB", spec.useHLMTriggerB)
spec.headlandDistance = xmlFile:getValue(key.."#headlandDistance", spec.headlandDistance)
spec.vcaDirSwitch = xmlFile:getValue(key.."#vcaDirSwitch", spec.vcaDirSwitch)
spec.autoResume = xmlFile:getValue(key.."#autoResume", spec.autoResume)
spec.useDiffLock = xmlFile:getValue(key.."#useDiffLock", spec.useDiffLock)
spec.contour = xmlFile:getValue(key.."#contour", spec.contour)
spec.contourMultiMode = xmlFile:getValue(key.."#contourMultiMode", spec.contourMultiMode)
spec.contourNoSwap = xmlFile:getValue(key.."#contourNoSwap", spec.contourNoSwap)
spec.contourFrontActive = xmlFile:getValue(key.."#contourFrontActive", spec.contourFrontActive)
spec.contourWidthAdaption = xmlFile:getValue(key.."#contourWidthAdaption", spec.contourWidthAdaption)
spec.contourWidthMeasurement = xmlFile:getValue(key.."#contourWidthMeasurement", spec.contourWidthMeasurement)
spec.contourWidthManualMode = xmlFile:getValue(key.."#contourWidthManualMode", spec.contourWidthManualMode)
spec.contourWidthManualInput = xmlFile:getValue(key.."#contourWidthManualInput", spec.contourWidthManualInput)
spec.contourWidth = xmlFile:getValue(key.."#contourWidth", spec.contourWidth)
spec.contourTrack = xmlFile:getValue(key.."#contourTrack", spec.contourTrack)
spec.contourWorkedArea = xmlFile:getValue(key.."#contourWorkedArea", spec.contourWorkedArea)
spec.contourShowLines = xmlFile:getValue(key.."#contourShowLines", spec.contourShowLines)
if spec.contourWidthManualMode then
spec.contourWidth = spec.contourWidthManualInput * spec.contourTrack
end
dbgprint("onPostLoad : Loaded whole data set using key "..key, 1)
end
dbgprint("onPostLoad : Loaded data for "..self:getName(), 1)
end
-- enable HLM in mission vehicles
spec.exists = spec.exists or (self.configurations["HeadlandManagement"] ~= nil and self.propertyState == Vehicle.PROPERTY_STATE_MISSION)
if spec.gpsSetting == 2 and not spec.modGuidanceSteeringFound then spec.gpsSetting = 1 end
if spec.gpsSetting > 2 and spec.gpsSetting < 6 and not spec.modVCAFound then spec.gpsSetting = 1 end
if spec.gpsSetting > 5 and not spec.modEVFound then spec.gpsSetting = 1 end
spec.autoResumeOnTrigger = spec.autoResume and (spec.useHLMTriggerF or spec.useHLMTriggerB)
if spec.exists then
-- Detect frontNode, backNode and calculate vehicle length and width
spec.frontNode, spec.backNode, spec.vehicleLength, spec.vehicleWidth, spec.maxTurningRadius = vehicleMeasurement(self)
spec.guidanceSteeringOffset = spec.vehicleLength
dbgprint("onPostLoad : length: "..tostring(spec.vehicleLength), 1)
dbgprint("onPostLoad : frontNode: "..tostring(spec.frontNode), 2)
dbgprint("onPostLoad : backNode: "..tostring(spec.backNode), 2)
end
-- Set HLM configuration if set by savegame
self.configurations["HeadlandManagement"] = spec.exists and 2 or 1
dbgprint("onPostLoad : HLM exists: "..tostring(spec.exists))
dbgprint_r(self.configurations, 4, 2)
end
function HeadlandManagement:saveToXMLFile(xmlFile, key, usedModNames)
dbgprint("saveToXMLFile", 2)
dbgprint("1:", 4)
dbgprint_r(self.configurations, 4, 2)
if HeadlandManagement.contourParametersChanged then
HeadlandManagement.contourParametersChanged = not HeadlandManagement:saveContourSettings()
end
local spec = self.spec_HeadlandManagement
spec.exists = self.configurations["HeadlandManagement"] == 2
dbgprint("saveToXMLFile : key: "..tostring(key), 2)
xmlFile:setValue(key.."#configured", spec.exists)
if spec.exists then
xmlFile:setValue(key.."#isOn", spec.isOn)
xmlFile:setValue(key.."#beep", spec.beep)
xmlFile:setValue(key.."#beepVol", spec.beepVol)
xmlFile:setValue(key.."#turnSpeed", spec.turnSpeed)
xmlFile:setValue(key.."#useSpeedControl", spec.useSpeedControl)
xmlFile:setValue(key.."#useModSpeedControl", spec.useModSpeedControl)
xmlFile:setValue(key.."#useCrabSteering", spec.useCrabSteering)
xmlFile:setValue(key.."#useCrabSteeringTwoStep", spec.useCrabSteeringTwoStep)
xmlFile:setValue(key.."#useRaiseImplementF", spec.useRaiseImplementF)
xmlFile:setValue(key.."#useRaiseImplementB", spec.useRaiseImplementB)
xmlFile:setValue(key.."#waitOnTrigger", spec.waitOnTrigger)
xmlFile:setValue(key.."#useStopPTOF", spec.useStopPTOF)
xmlFile:setValue(key.."#useStopPTOB", spec.useStopPTOB)
xmlFile:setValue(key.."#turnPlow", spec.useTurnPlow)
xmlFile:setValue(key.."#centerPlow", spec.useCenterPlow)
xmlFile:setValue(key.."#switchRidge", spec.useRidgeMarker)
xmlFile:setValue(key.."#useGPS", spec.useGPS)
xmlFile:setValue(key.."#gpsSetting", spec.gpsSetting)
xmlFile:setValue(key.."#useGuidanceSteeringTrigger", spec.useGuidanceSteeringTrigger)
xmlFile:setValue(key.."#useGuidanceSteeringOffset", spec.useGuidanceSteeringOffset)
xmlFile:setValue(key.."#useEVTrigger", spec.useEVTrigger)
xmlFile:setValue(key.."#useHLMTriggerF", spec.useHLMTriggerF)
xmlFile:setValue(key.."#useHLMTriggerB", spec.useHLMTriggerB)
xmlFile:setValue(key.."#headlandDistance", spec.headlandDistance)
xmlFile:setValue(key.."#vcaDirSwitch", spec.vcaDirSwitch)
xmlFile:setValue(key.."#autoResume", spec.autoResume)
xmlFile:setValue(key.."#useDiffLock", spec.useDiffLock)
xmlFile:setValue(key.."#contour", spec.contour)
xmlFile:setValue(key.."#contourMultiMode", spec.contourMultiMode)
xmlFile:setValue(key.."#contourNoSwap", spec.contourNoSwap)
xmlFile:setValue(key.."#contourFrontActive", spec.contourFrontActive)
xmlFile:setValue(key.."#contourWidthAdaption", spec.contourWidthAdaption)
xmlFile:setValue(key.."#contourWidthMeasurement", spec.contourWidthMeasurement)
xmlFile:setValue(key.."#contourWidthManualMode", spec.contourWidthManualMode)
xmlFile:setValue(key.."#contourWidthManualInput", spec.contourWidthManualInput)
xmlFile:setValue(key.."#contourWidth", spec.contourWidth)
xmlFile:setValue(key.."#contourTrack", math.floor(spec.contourTrack)) -- can be 1.5
xmlFile:setValue(key.."#contourWorkedArea", spec.contourWorkedArea)
xmlFile:setValue(key.."#contourShowLines", spec.contourShowLines)
dbgprint("saveToXMLFile : saving whole data", 2)
end
dbgprint("saveToXMLFile : saving data finished", 2)
end
function HeadlandManagement:onReadStream(streamId, connection)
dbgprint("onReadStream", 3)
local spec = self.spec_HeadlandManagement
spec.exists = streamReadBool(streamId, connection)
if spec.exists then
spec.isOn = streamReadBool(streamId)
spec.beep = streamReadBool(streamId)
spec.beepVol = streamReadInt8(streamId)
spec.turnSpeed = streamReadFloat32(streamId)
spec.useSpeedControl = streamReadBool(streamId)
spec.useModSpeedControl = streamReadBool(streamId)
spec.useCrabSteering = streamReadBool(streamId)
spec.useCrabSteeringTwoStep = streamReadBool(streamId)
spec.useRaiseImplementF = streamReadBool(streamId)
spec.useRaiseImplementB = streamReadBool(streamId)
spec.waitOnTrigger = streamReadBool(streamId)
spec.useStopPTOF = streamReadBool(streamId)
spec.useStopPTOB = streamReadBool(streamId)
spec.useTurnPlow = streamReadBool(streamId)
spec.useCenterPlow = streamReadBool(streamId)
spec.useRidgeMarker = streamReadBool(streamId)
spec.useGPS = streamReadBool(streamId)
spec.gpsSetting = streamReadInt8(streamId)
spec.useGuidanceSteeringTrigger = streamReadBool(streamId)
spec.useGuidanceSteeringOffset = streamReadBool(streamId)
spec.useEVTrigger = streamReadBool(streamId)
spec.useHLMTriggerF = streamReadBool(streamId)
spec.useHLMTriggerB = streamReadBool(streamId)
spec.headlandDistance = streamReadInt8(streamId)
spec.vcaDirSwitch = streamReadBool(streamId)
spec.autoResume = streamReadBool(streamId)
spec.autoResumeOnTrigger = streamReadBool(streamId)
spec.useDiffLock = streamReadBool(streamId)
spec.contour = streamReadInt8(streamId)
spec.contourMultiMode = streamReadBool(streamId)
spec.contourNoSwap = streamReadBool(streamId)
spec.contourFrontActive = streamReadBool(streamId)
spec.contourWidthAdaption = streamReadBool(streamId)
spec.contourWidthMeasurement = streamReadBool(streamId)
spec.contourWidthManualMode = streamReadBool(streamId)
spec.contourWidthManualInput = streamReadFloat32(streamId)
spec.contourWidth = streamReadFloat32(streamId)
spec.contourTrack = streamReadInt8(streamId) / 2 -- can be 1.5
spec.contourWorkedArea = streamReadBool(streamId)
spec.contourShowLines = streamReadBool(streamId)
end
end
function HeadlandManagement:onWriteStream(streamId, connection)
dbgprint("onWriteStream", 3)
local spec = self.spec_HeadlandManagement
streamWriteBool(streamId, spec.exists)
if spec.exists then
streamWriteBool(streamId, spec.isOn)
streamWriteBool(streamId, spec.beep)
streamWriteInt8(streamId, spec.beepVol)
streamWriteFloat32(streamId, spec.turnSpeed)
streamWriteBool(streamId, spec.useSpeedControl)
streamWriteBool(streamId, spec.useModSpeedControl)
streamWriteBool(streamId, spec.useCrabSteering)
streamWriteBool(streamId, spec.useCrabSteeringTwoStep)
streamWriteBool(streamId, spec.useRaiseImplementF)
streamWriteBool(streamId, spec.useRaiseImplementB)
streamWriteBool(streamId, spec.waitOnTrigger)
streamWriteBool(streamId, spec.useStopPTOF)
streamWriteBool(streamId, spec.useStopPTOB)
streamWriteBool(streamId, spec.useTurnPlow)
streamWriteBool(streamId, spec.useCenterPlow)
streamWriteBool(streamId, spec.useRidgeMarker)
streamWriteBool(streamId, spec.useGPS)
streamWriteInt8(streamId, spec.gpsSetting)
streamWriteBool(streamId, spec.useGuidanceSteeringTrigger)
streamWriteBool(streamId, spec.useGuidanceSteeringOffset)
streamWriteBool(streamId, spec.useEVTrigger)
streamWriteBool(streamId, spec.useHLMTriggerF)
streamWriteBool(streamId, spec.useHLMTriggerB)
streamWriteInt8(streamId, spec.headlandDistance)
streamWriteBool(streamId, spec.vcaDirSwitch)
streamWriteBool(streamId, spec.autoResume)
streamWriteBool(streamId, spec.autoResumeOnTrigger)
streamWriteBool(streamId, spec.useDiffLock)
streamWriteInt8(streamId, spec.contour)
streamWriteBool(streamId, spec.contourMultiMode)
streamWriteBool(streamId, spec.contourNoSwap)
streamWriteBool(streamId, spec.contourFrontActive)
streamWriteBool(streamId, spec.contourWidthAdaption)
streamWriteBool(streamId, spec.contourWidthMeasurement)
streamWriteBool(streamId, spec.contourWidthManualMode)
streamWriteFloat32(streamId, spec.contourWidthManualInput)
streamWriteFloat32(streamId, spec.contourWidth)
streamWriteInt8(streamId, spec.contourTrack * 2) -- can be 1.5
streamWriteBool(streamId, spec.contourWorkedArea)
streamWriteBool(streamId, spec.contourShowLines)
end
end
function HeadlandManagement:onReadUpdateStream(streamId, timestamp, connection)
if not connection:getIsServer() then
local spec = self.spec_HeadlandManagement
if streamReadBool(streamId) then
dbgprint("onReadUpdateStream: receiving data...", 4)
spec.exists = streamReadBool(streamId)
if spec.exists then
spec.isOn = streamReadBool(streamId)
spec.beep = streamReadBool(streamId)
spec.beepVol = streamReadInt8(streamId)
spec.turnSpeed = streamReadFloat32(streamId)
spec.useSpeedControl = streamReadBool(streamId)
spec.useModSpeedControl = streamReadBool(streamId)
spec.useCrabSteering = streamReadBool(streamId)
spec.useCrabSteeringTwoStep = streamReadBool(streamId)
spec.useRaiseImplementF = streamReadBool(streamId)
spec.useRaiseImplementB = streamReadBool(streamId)
spec.waitOnTrigger = streamReadBool(streamId)
spec.useStopPTOF = streamReadBool(streamId)
spec.useStopPTOB = streamReadBool(streamId)
spec.useTurnPlow = streamReadBool(streamId)
spec.useCenterPlow = streamReadBool(streamId)
spec.useRidgeMarker = streamReadBool(streamId)
spec.useGPS = streamReadBool(streamId)
spec.gpsSetting = streamReadInt8(streamId)
spec.useGuidanceSteeringTrigger = streamReadBool(streamId)
spec.useGuidanceSteeringOffset = streamReadBool(streamId)
spec.useEVTrigger = streamReadBool(streamId)
spec.useHLMTriggerF = streamReadBool(streamId)
spec.useHLMTriggerB = streamReadBool(streamId)
spec.headlandDistance = streamReadInt8(streamId)
spec.setServerHeadlandActDistance = streamReadFloat32(streamId)
spec.vcaDirSwitch = streamReadBool(streamId)
spec.autoResume = streamReadBool(streamId)
spec.autoResumeOnTrigger = streamReadBool(streamId)
spec.useDiffLock = streamReadBool(streamId)
spec.contour = streamReadInt8(streamId)
spec.contourMultiMode = streamReadBool(streamId)
spec.contourNoSwap = streamReadBool(streamId)
spec.contourFrontActive = streamReadBool(streamId)
spec.contourWidthAdaption = streamReadBool(streamId)
spec.contourWidthMeasurement = streamReadBool(streamId)
spec.contourWidthManualMode = streamReadBool(streamId)
spec.contourWidthManualInput = streamReadFloat32(streamId)
spec.contourWidth = streamReadFloat32(streamId)
spec.contourTrack = streamReadInt8(streamId) / 2
spec.contourWorkedArea = streamReadBool(streamId)
spec.contourShowLines = streamReadBool(streamId)
spec.workedArea = streamReadInt8(streamId)
end
end
end
end
function HeadlandManagement:onWriteUpdateStream(streamId, connection, dirtyMask)
if connection:getIsServer() then
local spec = self.spec_HeadlandManagement
if streamWriteBool(streamId, bitAND(dirtyMask, spec.dirtyFlag) ~= 0) then
dbgprint("onWriteUpdateStream: sending data...", 4)
streamWriteBool(streamId, spec.exists)
if spec.exists then
streamWriteBool(streamId, spec.isOn)
streamWriteBool(streamId, spec.beep)
streamWriteInt8(streamId, spec.beepVol)
streamWriteFloat32(streamId, spec.turnSpeed)
streamWriteBool(streamId, spec.useSpeedControl)
streamWriteBool(streamId, spec.useModSpeedControl)
streamWriteBool(streamId, spec.useCrabSteering)
streamWriteBool(streamId, spec.useCrabSteeringTwoStep)
streamWriteBool(streamId, spec.useRaiseImplementF)
streamWriteBool(streamId, spec.useRaiseImplementB)
streamWriteBool(streamId, spec.waitOnTrigger)
streamWriteBool(streamId, spec.useStopPTOF)
streamWriteBool(streamId, spec.useStopPTOB)
streamWriteBool(streamId, spec.useTurnPlow)
streamWriteBool(streamId, spec.useCenterPlow)
streamWriteBool(streamId, spec.useRidgeMarker)
streamWriteBool(streamId, spec.useGPS)
streamWriteInt8(streamId, spec.gpsSetting)
streamWriteBool(streamId, spec.useGuidanceSteeringTrigger)
streamWriteBool(streamId, spec.useGuidanceSteeringOffset)
streamWriteBool(streamId, spec.useEVTrigger)
streamWriteBool(streamId, spec.useHLMTriggerF)
streamWriteBool(streamId, spec.useHLMTriggerB)
streamWriteInt8(streamId, spec.headlandDistance)
streamWriteFloat32(streamId, spec.setServerHeadlandActDistance)
streamWriteBool(streamId, spec.vcaDirSwitch)
streamWriteBool(streamId, spec.autoResume)
streamWriteBool(streamId, spec.autoResumeOnTrigger)
streamWriteBool(streamId, spec.useDiffLock)
streamWriteInt8(streamId, spec.contour)
streamWriteBool(streamId, spec.contourMultiMode)
streamWriteBool(streamId, spec.contourNoSwap)
streamWriteBool(streamId, spec.contourFrontActive)
streamWriteBool(streamId, spec.contourWidthAdaption)
streamWriteBool(streamId, spec.contourWidthMeasurement)
streamWriteBool(streamId, spec.contourWidthManualMode)
streamWriteFloat32(streamId, spec.contourWidthManualInput)
streamWriteFloat32(streamId, spec.contourWidth)
streamWriteInt8(streamId, spec.contourTrack * 2)
streamWriteBool(streamId, spec.contourWorkedArea)
streamWriteBool(streamId, spec.contourShowLines)