forked from P33a/SimTwo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParams.pas
1688 lines (1485 loc) · 50.8 KB
/
Params.pas
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
unit Params;
{$MODE Delphi}
interface
uses
LCLIntf, Windows, SysUtils, Variants, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls, ComCtrls, ExtCtrls, GLLCLViewer, GLcontext, Math,
ODERobots, OdeImport, Grids, GLCadencer, SdpofpSerial, Sockets,
GLShadowVolume, GLScene, Buttons, IniPropStorage, enum_serial,
GLVectorGeometry, GLTexture, modbusTCP, lNetComponents, lNet;
type
{
TShutdownThread = class(TThread)
protected
procedure Execute; override;
end;
}
{ TFParams }
TFParams = class(TForm)
BCloseComPort: TButton;
BOpenComPort: TButton;
CBComPort: TComboBox;
CBComBaudrate: TComboBox;
CBDTR: TCheckBox;
CBRTS: TCheckBox;
IniPropStorage: TIniPropStorage;
Label65: TLabel;
TCPModBus: TLTCPComponent;
UDPGeneric: TLUDPComponent;
UDPServer_alt: TLUDPComponent;
PageControl: TPageControl;
SerialCom: TSdpofpSerial;
TabControl: TTabSheet;
RGControlBlock: TRadioGroup;
TabGraphics: TTabSheet;
CBShadows: TCheckBox;
TabDebug: TTabSheet;
EditDEbug2: TEdit;
CBVsync: TCheckBox;
CBAntiAliasing: TCheckBox;
CBGrid: TCheckBox;
CBAxis: TCheckBox;
CBGroundTexture: TCheckBox;
CBSkyDome: TCheckBox;
CBHotCPU: TCheckBox;
Label24: TLabel;
EditTargetFPS: TEdit;
BSetFPS: TButton;
BEditScript: TButton;
BTest: TButton;
RGCamera: TRadioGroup;
EditCamX: TEdit;
EditCamY: TEdit;
EditCamZ: TEdit;
Label9: TLabel;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
EditDebug3: TEdit;
MemoDebug: TMemo;
LBRobots: TListBox;
PGRobots: TPageControl;
TabRobot: TTabSheet;
TabAxis: TTabSheet;
Label6: TLabel;
Label19: TLabel;
Label20: TLabel;
Label21: TLabel;
Label18: TLabel;
Label14: TLabel;
Label15: TLabel;
Label16: TLabel;
Label17: TLabel;
Label22: TLabel;
Label23: TLabel;
Label25: TLabel;
Label26: TLabel;
Label2: TLabel;
Label3: TLabel;
Label5: TLabel;
Label7: TLabel;
Label30: TLabel;
Label31: TLabel;
Label32: TLabel;
Label33: TLabel;
Label34: TLabel;
CBIO1: TCheckBox;
CBIO2: TCheckBox;
CBIO3: TCheckBox;
CBIO4: TCheckBox;
CBIO5: TCheckBox;
CBIO6: TCheckBox;
CBIO7: TCheckBox;
CBIO8: TCheckBox;
EditU0: TEdit;
EditOdo0: TEdit;
EditOdo1: TEdit;
EditU1: TEdit;
EditI0: TEdit;
EditI1: TEdit;
EditU2: TEdit;
EditOdo2: TEdit;
EditI2: TEdit;
EditI3: TEdit;
EditOdo3: TEdit;
EditU3: TEdit;
CBPIDsActive: TCheckBox;
EditIR0: TEdit;
EditIR1: TEdit;
EditIR2: TEdit;
EditIR3: TEdit;
EditIR4: TEdit;
EditIR5: TEdit;
EditIR6: TEdit;
EditIR7: TEdit;
EditDebug: TEdit;
SGJoints: TStringGrid;
EditJointTeta: TEdit;
Label38: TLabel;
EditJointTetaRef: TEdit;
BSetJointTetaRef: TButton;
BFreeze: TButton;
BStep: TButton;
CBIRNoise: TCheckBox;
EditLoadJointPoints: TEdit;
BLoadJointWayPoints: TButton;
CBFreeze: TCheckBox;
TabPhysics: TTabSheet;
Label40: TLabel;
EditDefaultFriction: TEdit;
BPhysicsSet: TButton;
Label28: TLabel;
BSetPosition: TButton;
EditRobotX: TEdit;
Label27: TLabel;
Label35: TLabel;
EditRobotSetX: TEdit;
EditRobotSetY: TEdit;
Label36: TLabel;
EditRobotY: TEdit;
Label29: TLabel;
Label13: TLabel;
EditRobotTeta: TEdit;
Label39: TLabel;
EditRobotSetZ: TEdit;
EditRobotSetTeta: TEdit;
Label37: TLabel;
BSetAll: TButton;
BSetJointWayPointTeta: TButton;
Label41: TLabel;
ComboWayPointName: TComboBox;
BJointWayPointsSave: TButton;
BWayPointEdit: TButton;
Label42: TLabel;
EditOde_dt: TEdit;
Label43: TLabel;
Label44: TLabel;
EditTimeSpeed: TEdit;
SGConf: TStringGrid;
EditGridX: TEdit;
EditGridY: TEdit;
EditGridZ: TEdit;
BSGConfSet: TButton;
TabIO: TTabSheet;
Panel1: TPanel;
Label45: TLabel;
BComWrite: TButton;
EditComWrite: TEdit;
Panel2: TPanel;
EditUDPPort: TEdit;
Label46: TLabel;
CBUDPConnect: TCheckBox;
Label47: TLabel;
EditODE_CFM: TEdit;
Label48: TLabel;
EditODE_ERP: TEdit;
TabGlobal: TTabSheet;
Label1: TLabel;
EditScriptPeriod: TEdit;
BGlobalSet: TButton;
CBWorldQuickStep: TCheckBox;
Label4: TLabel;
EditQuickStepIterations: TEdit;
EditRobotZ: TEdit;
Label49: TLabel;
Label50: TLabel;
EditCamLookX: TEdit;
EditCamLookY: TEdit;
EditCamLookZ: TEdit;
EditSetCamX: TEdit;
EditSetCamY: TEdit;
Label51: TLabel;
Label52: TLabel;
EditSetCamZ: TEdit;
BSetCamPars: TButton;
Label53: TLabel;
EditSetCamLookX: TEdit;
EditSetCamLookY: TEdit;
EditSetCamLookZ: TEdit;
BGetCamPos: TButton;
Button1: TButton;
Label54: TLabel;
EditTrailsCount: TEdit;
Label55: TLabel;
EditTrailSize: TEdit;
BSetTrailPars: TButton;
RGGLObjects: TRadioGroup;
SGGlobalSensors: TStringGrid;
BExportTrack: TButton;
CBTags: TCheckBox;
LBSelectedTags: TListBox;
LBAllTags: TListBox;
BitBtnAddTags: TBitBtn;
BitBtnRemoveTags: TBitBtn;
BitBtnAddAll: TBitBtn;
RGSensorGL: TRadioGroup;
BSGConfGet: TButton;
CBFog: TCheckBox;
ShapeSelColor: TShape;
ColorDialog: TColorDialog;
ComboGroundTextures: TComboBox;
EditRemoteIP: TEdit;
Label8: TLabel;
Edit3DProjection: TEdit;
Label56: TLabel;
EditModBusPort: TEdit;
BModBusConnect: TButton;
BModBusDisconnect: TButton;
ShapeModBusState: TShape;
MemoModBus: TMemo;
BModbusTest: TButton;
Label57: TLabel;
Label58: TLabel;
ShapeInput0: TShape;
ShapeOutput0: TShape;
Label59: TLabel;
EditModBusInputOffset: TEdit;
Label60: TLabel;
EditModBusOutputOffset: TEdit;
CBModBusInputOverride: TCheckBox;
CBModBusOutputOverride: TCheckBox;
ShapeInput1: TShape;
ShapeInput2: TShape;
ShapeInput3: TShape;
ShapeInput4: TShape;
ShapeInput5: TShape;
ShapeInput6: TShape;
ShapeInput7: TShape;
ShapeOutput1: TShape;
ShapeOutput2: TShape;
ShapeOutput3: TShape;
ShapeOutput4: TShape;
ShapeOutput5: TShape;
ShapeOutput6: TShape;
ShapeOutput7: TShape;
LabelInBit0: TLabel;
BModbusOffsetSet: TButton;
LabelInBit1: TLabel;
LabelInBit2: TLabel;
LabelInBit3: TLabel;
LabelInBit4: TLabel;
LabelInBit5: TLabel;
LabelInBit6: TLabel;
LabelInBit7: TLabel;
LabelOutBit0: TLabel;
LabelOutBit1: TLabel;
LabelOutBit2: TLabel;
LabelOutBit3: TLabel;
LabelOutBit4: TLabel;
LabelOutBit5: TLabel;
LabelOutBit6: TLabel;
LabelOutBit7: TLabel;
ProgressBarModBus: TProgressBar;
Timer: TTimer;
CBEndlessWorld: TCheckBox;
Label61: TLabel;
Label62: TLabel;
EditWindSpeedX: TEdit;
EditWindSpeedY: TEdit;
Label63: TLabel;
Label64: TLabel;
EditWindSpeedZ: TEdit;
procedure BCloseComPortClick(Sender: TObject);
procedure BOpenComPortClick(Sender: TObject);
procedure CBComPortDropDown(Sender: TObject);
procedure CBDTRChange(Sender: TObject);
procedure CBRTSChange(Sender: TObject);
procedure CBShadowsClick(Sender: TObject);
procedure CBVsyncClick(Sender: TObject);
procedure BSetFPSClick(Sender: TObject);
procedure CBAntiAliasingClick(Sender: TObject);
procedure CBGridClick(Sender: TObject);
procedure CBAxisClick(Sender: TObject);
procedure CBGroundTextureClick(Sender: TObject);
procedure CBSkyDomeClick(Sender: TObject);
procedure BEditScriptClick(Sender: TObject);
procedure EditRemoteIPChange(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
procedure TCPModBusAccept(aSocket: TLSocket);
procedure TCPModBusDisconnect(aSocket: TLSocket);
procedure TCPModBusError(const msg: string; aSocket: TLSocket);
procedure BTestClick(Sender: TObject);
procedure SetComState(newState: boolean);
procedure SerialComRxData(Sender: TObject);
procedure CBPIDsActiveClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure BSetPositionClick(Sender: TObject);
procedure BSetJointTetaRefClick(Sender: TObject);
procedure LBRobotsClick(Sender: TObject);
procedure BFreezeClick(Sender: TObject);
procedure BStepClick(Sender: TObject);
procedure CBIRNoiseClick(Sender: TObject);
procedure BLoadJointWayPointsClick(Sender: TObject);
procedure CBHotCPUClick(Sender: TObject);
procedure CBFreezeClick(Sender: TObject);
procedure BPhysicsSetClick(Sender: TObject);
procedure BSetJointWayPointTetaClick(Sender: TObject);
procedure BSetAllClick(Sender: TObject);
procedure BJointWayPointsSaveClick(Sender: TObject);
procedure BWayPointEditClick(Sender: TObject);
procedure BSGConfSetClick(Sender: TObject);
procedure SGConfDblClick(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure EditGridKeyPress(Sender: TObject; var Key: Char);
procedure BComConfClick(Sender: TObject);
procedure BComWriteClick(Sender: TObject);
procedure CBUDPConnectClick(Sender: TObject);
procedure BGlobalSetClick(Sender: TObject);
procedure BSetCamParsClick(Sender: TObject);
procedure BGetCamPosClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure BSetTrailParsClick(Sender: TObject);
procedure RGGLObjectsClick(Sender: TObject);
procedure BExportTrackClick(Sender: TObject);
procedure BitBtnAddTagsClick(Sender: TObject);
procedure BitBtnRemoveTagsClick(Sender: TObject);
procedure BitBtnAddAllClick(Sender: TObject);
procedure RGSensorGLClick(Sender: TObject);
procedure BSGConfGetClick(Sender: TObject);
procedure ShapeSelColorMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure CBFogClick(Sender: TObject);
procedure ComboGroundTexturesClick(Sender: TObject);
procedure BModBusConnectClick(Sender: TObject);
procedure BModBusDisconnectClick(Sender: TObject);
procedure BModbusOffsetSetClick(Sender: TObject);
procedure ModbusRefreshLEDs;
procedure ShapeOutputMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure ShapeInputMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure TCPModBusReceive(aSocket: TLSocket);
procedure TimerTimer(Sender: TObject);
procedure UDPGenericError(const msg: string; aSocket: TLSocket);
procedure UDPGenericReceive(aSocket: TLSocket);
procedure UDPServer_altError(const msg: string; aSocket: TLSocket);
procedure UDPServer_altReceive(aSocket: TLSocket);
private
procedure FillEditArray(ProtoName: string;
var EditArray: array of TEdit);
procedure SGConfRowToVar(SGRow: longword);
procedure VarToSGConfRow(SGRow: longword);
procedure FillSGConf;
procedure FillSGConfRow(varname: string);
procedure FillLabelArray(ParentControl: TTabSheet; ProtoName: string; var LabelArray: array of TLabel);
procedure FillLEDArray(ParentControl: TTabSheet; ProtoName: string; var LEDArray: array of TShape);
//procedure TCPModBusDisconnectAndWait;
{ Private declarations }
public
EditsU, EditsI, EditsOdo : array[0..3] of TEdit;
EditsIR: array[0..7] of TEdit;
UDPGenData: TMemoryStream;
UDPGenPackets: TStringList;
SerialData: string;
ModbusData: TModbusData;
ModbusServer: TModbusServer;
ModBusDisconnected, ModBusWantsToDisconnected: boolean;
ModBusInLEDs, ModBusOutLEDs: array[0..7] of TShape;
ModBusInLabels, ModBusOutLabels: array[0..7] of TLabel;
ModBusInputsOffset, ModBusOutputsOffset: integer;
procedure ModBusEvent(command: byte);
procedure FillLBRobots(LB: TListBox);
procedure FillLBLinks(LB: TListBox; r: integer);
procedure ShowRobotState;
procedure ShowRobotPosition(r: integer);
procedure ComboWayPointNameUpdate(robot: TRobot);
procedure ShowGlobalState;
procedure ShowCameraConfig(GLCamera: TGLCamera);
procedure ShowParsedScene;
// procedure ShowIRValues;
end;
var
FParams: TFParams;
dt: double;
function getModbusInput(bit_addr: integer): boolean;
procedure setModbusInput(bit_addr: integer; new_state: boolean);
function getModbusCoil(bit_addr: integer): boolean;
procedure setModbusCoil(bit_addr: integer; new_state: boolean);
implementation
{$R *.lfm}
uses GLFile3DS, Viewer, Editor, FastChart, ODERobotsPublished, WayPointsEdit, ProjConfig, utils,
cameras;
procedure TFParams.SetComState(newState: boolean);
var comColor: TColor;
i: integer;
begin
try try
if newState then begin
SerialCom.Device := CBComPort.Text;
SerialCom.BaudRate := br115200;
i := CBComBaudrate.ItemIndex;
if i >= 0 then begin
SerialCom.BaudRate := TBaudRate(i);
end;
SerialCom.Open;
end else begin
SerialCom.Close;
end;
except
on E: Exception do
Showmessage(E.Message);
end;
finally
if SerialCom.Active then comColor := clGreen
else comColor := clRed;
CBComPort.Color := comColor;
end;
end;
procedure TFParams.BSetFPSClick(Sender: TObject);
var fps: integer;
begin
fps:=strtointdef(EditTargetFPS.text,25);
if fps>0 then begin
FViewer.GLCadencer.FixedDeltaTime := 1/fps;
//FViewer.GLCadencer.MinDeltaTime := FViewer.GLCadencer.FixedDeltaTime;
//FViewer.GLCadencer.MaxDeltaTime := FViewer.GLCadencer.FixedDeltaTime;
end;
end;
procedure TFParams.CBVsyncClick(Sender: TObject);
begin
FViewer.GLCadencer.Enabled := false;
if CBVsync.checked then begin
FViewer.GLSceneViewer.VSync := vsmSync;
//FCameras.GLSceneViewer.VSync := vsmSync;
end else begin
FViewer.GLSceneViewer.VSync := vsmNoSync;
//FCameras.GLSceneViewer.VSync := vsmNoSync;
end;
FViewer.GLCadencer.Enabled := true;
end;
procedure TFParams.CBAntiAliasingClick(Sender: TObject);
begin
if not assigned(FViewer) then exit;
if not assigned(FCameras) then exit;
if CBAntiAliasing.checked then begin
FViewer.GLSceneViewer.Buffer.AntiAliasing := aa2x;
//FCameras.GLSceneViewer.Buffer.AntiAliasing := aa2x;
end else begin
//FViewer.GLSceneViewer.Buffer.AntiAliasing := TGLAntiAliasing.aaNone;
FViewer.GLSceneViewer.Buffer.AntiAliasing := TGLAntiAliasing.aaDefault;
//FCameras.GLSceneViewer.Buffer.AntiAliasing := TGLAntiAliasing.aaNone;
end;
end;
procedure TFParams.CBShadowsClick(Sender: TObject);
begin
FViewer.GLShadowVolume.Active := CBShadows.Checked;
end;
procedure TFParams.BOpenComPortClick(Sender: TObject);
begin
SetComState(true);
end;
procedure TFParams.CBComPortDropDown(Sender: TObject);
begin
ListComPorts(CBComPort.Items);
end;
procedure TFParams.CBDTRChange(Sender: TObject);
begin
//SerialCom.SetDTR(CBDTR.Checked);
end;
procedure TFParams.CBRTSChange(Sender: TObject);
begin
//SerialCom.SetRTS(CBRTS.Checked);
end;
procedure TFParams.BCloseComPortClick(Sender: TObject);
begin
SetComState(false);
end;
procedure TFParams.CBGridClick(Sender: TObject);
begin
FViewer.GLXYZGrid.Visible:= CBGrid.Checked;
end;
procedure TFParams.CBAxisClick(Sender: TObject);
begin
FViewer.GLDummyCubeAxis.Visible:= CBAxis.Checked;
end;
procedure TFParams.CBGroundTextureClick(Sender: TObject);
begin
FViewer.GLPlaneFloor.Material.Texture.Disabled:=not CBGroundTexture.Checked;
// FViewer.GLMaterialLibrary.Materials.
// FViewer.GLPlaneFloor.Material.LibMaterialName
end;
procedure TFParams.CBSkyDomeClick(Sender: TObject);
begin
FViewer.GLEarthSkyDome.Visible:= CBSkyDome.Checked;
end;
procedure TFParams.BEditScriptClick(Sender: TObject);
begin
FEditor.show;
end;
procedure TFParams.EditRemoteIPChange(Sender: TObject);
begin
RGControlBlock.ItemIndex := 0;
end;
procedure TFParams.FormCloseQuery(Sender: TObject; var CanClose: boolean);
begin
TCPModBus.Disconnect(true);
end;
procedure TFParams.TCPModBusAccept(aSocket: TLSocket);
begin
ShapeModBusState.Brush.Color := clGreen;
end;
procedure TFParams.TCPModBusDisconnect(aSocket: TLSocket);
begin
ModBusDisconnected := true;
ShapeModBusState.Brush.Color := clRed;
end;
procedure TFParams.TCPModBusError(const msg: string; aSocket: TLSocket);
begin
MemoModBus.Lines.Add('Error:' + msg);
TCPModBus.Disconnect(true);
ShapeModBusState.Brush.Color := clRed;
end;
procedure TFParams.BTestClick(Sender: TObject);
var prs: string;
i: integer;
begin
// UDPServer.Send(EditRemoteIP.Text, 9801, 'test');
// FRemoteControl.show;
// FChart.AddSample(0, WorldODE.physTime);
// FViewer.GLCadencer.Progress;
prs := '';
for i := 1 to ParamCount do begin
prs := ' ' + ParamStr(i);
end;
FViewer.Close;
OpenDocument(pchar(Application.ExeName)); { *Converted from ShellExecute* }
end;
procedure TFParams.SerialComRxData(Sender: TObject);
var s: string;
ls: integer;
begin
//if not SdpoSerial.Active then exit;
s := SerialCom.ReadData;
if s = '' then exit;
//FEditor.writeLn(s);
ls := Length(s);
if Length(SerialData) + ls > 65535 then begin
SerialData := copy(SerialData, 32768, MaxInt);
end;
SerialData := SerialData + s;
end;
function GetListValue(L: TStrings; QName: string): string;
var i: integer;
trim_name: string;
begin
result := '';
trim_name := AnsiLowerCase(trim(QName));
if trim_name = '' then exit;
for i:=0 to L.Count-1 do begin
if trim_name = AnsiLowerCase(trim(L.Names[i])) then begin
result := trim(L.ValueFromIndex[i]);
exit;
end;
end;
end;
procedure TFParams.UDPServer_altReceive(aSocket: TLSocket);
var str: string;
begin
UDPServer_alt.GetMessage(str);
end;
procedure TFParams.ShowRobotState;
var i, idx, wp_idx: integer;
//str: string;
theta: double;
begin
idx := LBRobots.ItemIndex;
if (idx < 0) or (idx >= WorldODE.Robots.Count) then exit;
wp_idx := ComboWayPointName.ItemIndex;
{ TODO
for i := low(EditsU) to high(EditsU) do begin
if WorldODE.Robots[idx].Links.Count > i then begin
//if not CBPIDsActive.Checked then
// EditsU[i].Text := format('%5.1f',[WorldODE.Robots[idx].Links[i].Axis.ref.volts])
//else
// EditsU[i].Text := format('%5.1f',[WorldODE.Robots[idx].Links[i].Axis.ref.w]);
EditsU[i].Text := format('%5.1f',[WorldODE.Robots[idx].Links[i].Axis[0].Motor.voltage]);
end else begin
EditsU[i].Text := '';
end;
end;
for i := low(EditsI) to high(EditsI) do begin
if WorldODE.Robots[idx].Links.Count > i then begin
EditsI[i].Text := format('%f',[WorldODE.Robots[idx].Links[i].Axis[0].Motor.Im]);
end else begin
EditsI[i].Text := '';
end;
end;
for i := low(EditsOdo) to high(EditsOdo) do begin
if WorldODE.Robots[idx].Wheels.Count > i then begin
EditsOdo[i].Text := format('%d',[WorldODE.Robots[idx].Wheels[i].Axle.Axis[0].Odo.Value]);
//EditsOdo[i].Text := format('%d',[WorldODE.Robots[idx].Links[i].Axis.Odo.Value]);
end else begin
EditsOdo[i].Text := '';
end;
end;
for i := low(EditsIR) to high(EditsIR) do begin
if (WorldODE.Robots[idx].Sensors.Count > i) and
WorldODE.Robots[idx].Sensors[i].Measures[0].has_measure then begin
EditsIR[i].Text := format('%.2f',[WorldODE.Robots[idx].Sensors[i].Measures[0].value]);
end else begin
EditsIR[i].Text := '';
end;
end;
}
theta := 0;
with WorldODE.Robots[idx] do begin
for i := 0 to Axes.Count -1 do begin
SGJoints.Cells[0,i+1] := Axes[i].ParentLink.ID;
SGJoints.Cells[4,i+1] := Axes[i].ParentLink.description;
if (dJointGetType(Axes[i].ParentLink.joint) = ord(dJointTypeHinge)) or
(dJointGetType(Axes[i].ParentLink.joint) = ord(dJointTypeUniversal)) then begin
theta := radtodeg(Axes[i].GetPos);
SGJoints.Cells[2,i+1] := format('%.2f',[radtodeg(Axes[i].ref.theta)]);
end else if dJointGetType(Axes[i].ParentLink.joint) = ord(dJointTypeSlider) then begin
theta := Axes[i].GetPos;
SGJoints.Cells[2,i+1] := format('%.2f',[Axes[i].ref.theta]);
end;
SGJoints.Cells[1,i+1] := format('%.2f',[theta]);
//if wp_idx >= 0 then
// SGJoints.Cells[3,i+1] := format('%.2f',[radtodeg(Axes[i].WayPoints[wp_idx].pos)]);
SGJoints.Cells[3, i + 1] := format('%.2f',[Axes[i].Motor.voltage]);
if i+1 = SGJoints.Selection.Top then begin
EditJointTeta.Text := SGJoints.Cells[1,i+1];
end;
end;
end;
end;
procedure TFParams.ShowRobotPosition(r: integer);
var x, y, z, teta: double;
begin
if r <> LBRobots.ItemIndex then exit;
WorldODE.Robots[r].GetXYZTeta(x, y, z, teta);
EditRobotX.text := format('%.3f',[x]);
EditRobotY.text := format('%.3f',[y]);
EditRobotZ.text := format('%.3f',[z]);
EditRobotTeta.text := format('%.3f',[radToDeg(teta)]);
end;
procedure TFParams.CBPIDsActiveClick(Sender: TObject);
var i, idx: integer;
begin
idx := LBRobots.ItemIndex;
if (idx < 0) or (idx >= WorldODE.Robots.Count) then exit;
//for i := 0 to WorldODE.Robots[idx].Wheels.Count - 1 do begin
// WorldODE.Robots[idx].Wheels[i].Axle.Axis[0].Motor.Controller.active := CBPIDsActive.Checked;
//end;
for i := 0 to WorldODE.Robots[idx].Axes.Count - 1 do begin
WorldODE.Robots[idx].Axes[i].Motor.Controller.active := CBPIDsActive.Checked;
end;
end;
procedure TFParams.FormCreate(Sender: TObject);
var i: integer;
begin
IniPropStorage.IniFileName := GetIniFineName(copy(name, 2, MaxInt));
ModbusData := TModbusData.Create;
ModbusServer := TModbusServer.Create(ModbusData, ModBusEvent);
SGJoints.Cells[0,0] := 'ID';
SGJoints.Cells[1,0] := 'Pos';
SGJoints.Cells[2,0] := 'Ref';
SGJoints.Cells[3,0] := 'WP';
SGJoints.Cells[4,0] := 'Description';
SGGlobalSensors.Cells[0,0] := 'Sensor ID';
SGGlobalSensors.Cells[1,0] := 'Value';
SGGlobalSensors.Cells[2,0] := 'Kind';
UDPGenData := TMemoryStream.Create;
UDPGenPackets:= TStringList.Create;
//for i := 0 to FViewer.GLMaterialLibrary.Materials.Count - 1 do begin
// ComboGroundTextures.Items.Add(FViewer.GLMaterialLibrary.Materials.Items[i].Name);
//end;
ListComPorts(CBComPort.Items);
end;
procedure TFParams.FormShow(Sender: TObject);
var i: integer;
begin
FillLBRobots(LBRobots);
if LBRobots.Count>0 then LBRobots.ItemIndex := 0;
FillEditArray('EditU', EditsU);
FillEditArray('EditI', EditsI);
FillEditArray('EditOdo', EditsOdo);
FillEditArray('EditIR', EditsIR);
FillLabelArray(TabIO, 'LabelInBit', ModBusInLabels);
FillLabelArray(TabIO, 'LabelOutBit', ModBusOutLabels);
FillLEDArray(TabIO, 'ShapeInput', ModBusInLEDs);
FillLEDArray(TabIO, 'ShapeOutput', ModBusOutLEDs);
BModbusOffsetSetClick(Sender);
ComboGroundTexturesClick(Sender);
CBIRNoiseClick(Sender);
BPhysicsSetClick(Sender);
RGGLObjectsClick(Sender);
BGlobalSetClick(Sender);
CBFogClick(Sender);
FViewer.GLSceneViewer.Buffer.FogEnvironment.FogColor.AsWinColor := ShapeSelColor.Brush.Color;
FCameras.GLSceneViewer.Buffer.FogEnvironment.FogColor.AsWinColor := ShapeSelColor.Brush.Color;
CBUDPConnectClick(Sender);
try
if FileExists('params.cfg') then begin
LoadGridFromfile(SGConf, 'params.cfg');
end;
FillSGConf;
except
on E: Exception do
Showmessage(E.Message);
end;
for i := 1 to SGConf.RowCount-1 do begin
SGConfRowToVar(i);
VarToSGConfRow(i);
end;
// Vista hack?
if PageControl.Height + PageControl.Top > ClientHeight - (EditDebug.Height + 8) then begin
PageControl.Height := - PageControl.Top + ClientHeight - (EditDebug.Height + 8);
EditDebug.Top := ClientHeight - (EditDebug.Height + 4);
//EditDebug.Anchors := EditDebug.Anchors - [akbottom];
//EditDebug.Anchors := EditDebug.Anchors + [akbottom];
end;
LBAllTags.Clear;
WorldODE.getGLPolygonsTags(LBAllTags.Items);
try
BSetCamParsClick(Sender);
except
on E: Exception do
Showmessage(E.Message);
end;
end;
procedure TFParams.FillEditArray(ProtoName: string; var EditArray: array of TEdit);
var i, cnt: integer;
begin
cnt := low(EditArray);
for i := 0 to TabRobot.ControlCount-1 do begin
if cnt > high(EditArray) then exit;
if LowerCase(TabRobot.Controls[i].Name) = LowerCase(ProtoName + inttostr(cnt)) then begin
EditArray[cnt] := TEdit(TabRobot.Controls[i]);
inc(cnt);
end;
end;
end;
procedure TFParams.FillLabelArray(ParentControl: TTabSheet; ProtoName: string; var LabelArray: array of TLabel);
var i, cnt: integer;
begin
cnt := low(LabelArray);
for i := 0 to ParentControl.ControlCount-1 do begin
if cnt > high(LabelArray) then exit;
if LowerCase(ParentControl.Controls[i].Name) = LowerCase(ProtoName + inttostr(cnt)) then begin
LabelArray[cnt] := TLabel(ParentControl.Controls[i]);
inc(cnt);
end;
end;
end;
procedure TFParams.FillLEDArray(ParentControl: TTabSheet; ProtoName: string; var LEDArray: array of TShape);
var i, cnt: integer;
begin
cnt := low(LEDArray);
for i := 0 to ParentControl.ControlCount-1 do begin
if cnt > high(LEDArray) then exit;
if LowerCase(ParentControl.Controls[i].Name) = LowerCase(ProtoName + inttostr(cnt)) then begin
LEDArray[cnt] := TShape(ParentControl.Controls[i]);
inc(cnt);
end;
end;
end;
procedure TFParams.ModBusEvent(command: byte);
begin
//MemoModBus.Lines.Add(IntToStr(command));
end;
procedure TFParams.FillLBRobots(LB: TListBox);
var i: integer;
begin
for i:=0 to WorldODE.Robots.Count-1 do begin
with WorldODE.Robots[i] do begin
LB.Items.Add(format('%s',[id]));
end;
end;
end;
procedure TFParams.ShowParsedScene;
var r, i: integer;
begin
MemoDebug.Lines.Add(format('Robots: %d',[WorldODE.Robots.Count]));
for r:=0 to WorldODE.Robots.Count-1 do begin
MemoDebug.Lines.Add(format('Robot[%d]',[r]));
MemoDebug.Lines.Add(format(' axes: %d',[WorldODE.Robots[r].Axes.Count]));
for i:=0 to WorldODE.Robots[r].Axes.Count-1 do begin
with WorldODE.Robots[r].Axes[i] do begin
MemoDebug.Lines.Add(format(' axis[%d]: %s',[i, ParentLink.ID]));
with Motor.Controller do begin
MemoDebug.Lines.Add(format(' Mode: %s, Active: %d, Period: %g ms',[ControlModeNames[ControlMode], ord(active), 1000*ControlPeriod]));
MemoDebug.Lines.Add(format(' kp: %g, ki: %g, kd: %g, kf: %g',[Kp, Ki, Kd, Kf]));
end;
with Motor do begin
MemoDebug.Lines.Add(format(' Ri: %g, Li: %g, K: %g Active: %d',[Ri, Li, Ki, ord(active)]));
MemoDebug.Lines.Add(format(' Gear: %g, Vmax: %g, Imax: %g',[GearRatio, Vmax, Imax]));
end;
end;
end;
end;
end;
procedure TFParams.FillLBLinks(LB: TListBox; r: integer);
var i: integer;
begin
if (r < 0) or (r >= WorldODE.Robots.Count) then exit;
with WorldODE.Robots[r] do begin
for i := 0 to Links.Count -1 do begin
//LB.Items.Add(inttostr(Links[i].ID) + ': ' + Links[i].description);
LB.Items.Add(Links[i].description);
end;
end;
end;
procedure TFParams.BSetPositionClick(Sender: TObject);
var r: integer;
dx, dy, dz, dteta: double;
begin
r := LBRobots.ItemIndex;
if (r < 0) or (r >= WorldODE.Robots.Count) then exit;
dx := StrToFloatDef(EditRobotSetX.Text, 0);
dy := StrToFloatDef(EditRobotSetY.Text, 0);
dz := StrToFloatDef(EditRobotSetZ.Text, 0);
dteta := degtorad(StrToFloatDef(EditRobotSetTeta.Text, 0));
WorldODE.Robots[r].SetXYZTeta(dx, dy, dz, dteta);
end;
procedure TFParams.BSetJointTetaRefClick(Sender: TObject);
var r, i: integer;
begin
r := LBRobots.ItemIndex;
if (r < 0) or (r >= WorldODE.Robots.Count) then exit;
i := SGJoints.Selection.Top - 1;
if (i < 0) or (i >= WorldODE.Robots[r].Axes.Count) then exit;
with WorldODE.Robots[r].Axes[i] do begin
if (dJointGetType(ParentLink.joint) = ord(dJointTypeHinge)) or
(dJointGetType(ParentLink.joint) = ord(dJointTypeUniversal)) then begin
ref.theta := degtorad(strtofloatdef(EditJointTetaRef.Text, 0));
end else if dJointGetType(ParentLink.joint) = ord(dJointTypeSlider) then begin
ref.theta := strtofloatdef(EditJointTetaRef.Text, 0);
end;
end;
end;
procedure TFParams.LBRobotsClick(Sender: TObject);
var r, i, c: integer;
begin
r := LBRobots.ItemIndex;
if (r < 0) or (r >= WorldODE.Robots.Count) then exit;
// Set the new Camera Target
WorldODE.SetCameraTarget(r);
// Fill the Joints names and IDs
for i := 0 to SGJoints.RowCount - 2 do begin
for c := 0 to SGJoints.ColCount -1 do begin
SGJoints.Cells[c,i+1] := '';
end;
end;
with WorldODE.Robots[r] do begin
for i := 0 to Axes.Count -1 do begin
SGJoints.Cells[0,i+1] := Axes[i].ParentLink.ID;
SGJoints.Cells[1,i+1] := Axes[i].ParentLink.description;
end;
end;
// Update Robot Tab
end;
procedure TFParams.BFreezeClick(Sender: TObject);
begin
// FViewer.GLCadencer.Enabled := not FViewer.GLCadencer.Enabled;
if FViewer.GLCadencer.Mode = cmApplicationIdle then begin
FViewer.GLCadencer.Mode := cmManual;
end else if FViewer.GLCadencer.Mode = cmManual then begin
FViewer.GLCadencer.Mode := cmApplicationIdle;
end;
end;
procedure TFParams.BStepClick(Sender: TObject);
begin
FViewer.GLCadencer.MaxDeltaTime := FViewer.GLCadencer.FixedDeltaTime;
FViewer.GLCadencer.Progress;
FViewer.GLCadencer.MaxDeltaTime := 0;
end;
procedure TFParams.CBIRNoiseClick(Sender: TObject);
var i, r: integer;
begin
r := LBRobots.ItemIndex;
if (r < 0) or (r >= WorldODE.Robots.Count) then exit;