Common.cs
65.3 KB
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
using BLL;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Threading;
using System.Web.UI.WebControls;
using System.Windows.Forms;
namespace AGVControl
{
public static class SettingString
{
public const int AGVCNT = 6;
public const string Move = "Move";
//任务名称
public const string Standby = "Standby";
public const string CheckShelf = "CheckShelf";
public const string DoorDToC = "DoorDToC";
public const string DoorCToD = "DoorCToD";
public const string DoorAirIn = "DoorAirIn";
public const string DoorAirOut = "DoorAirOut";
public const string DoubleLine_Name_Prefix = "A";
public const string Wait = "Wait";
public const string Done = "Done";
public const string Aborted = "Aborted";
public const string Invalid = "Invalid";
public const string AutoCharge = "AutoCharge";
public const string Executing = "Executing";
public const string RandomCharge_IP1 = "10.85.199.80";
public const string RandomCharge_IP2 = "10.85.199.81";
public const string RandomCharge_IP3 = "10.85.199.71";
public const string RandomCharge_IP4 = "10.85.199.74";
public const string FileName_AGV = "AgvName.csv";
public const string FileName_AgvMission = "AgvMission.csv";
public const string FileName_AgvProductionLine = "AgvProductionLine.csv";
public const string FileName_tempData = "tempData.ini";
public const string IsUse = "IsUse";
public const string RFID = "RFID";
public const string EmptyShelfCnt = "EmptyShelfCnt";
public const string EmptyShelfRFIDs = "EmptyShelfRFIDs";
/// <summary>
/// 去4C的3辆车IP
/// </summary>
public const string C4_AGV_IPs = "C4_AGV_IPs";
public const string C4_STANDBY1 = "C4_STANDBY1";
public const string C4_STANDBY2 = "C4_STANDBY2";
public const string C4FeederIn = "C21";
public const string D4FeederIn = "D21";
public const string C4FeederOut = "C22";
public const string D4FeederOut = "D22";
/// <summary>
/// 上料区
/// </summary>
public const string A6 = "A6";
/// <summary>
/// 下料区
/// </summary>
public const string A5 = "A5";
public const string D4_Name_Prefix = "D";
public const string C4_Name_Prefix = "C";
public const string IP_4D_Light = "IP_4D_Light";
public const string IP_4C_Light = "IP_4C_Light";
public const string IgnoreLightLines = "IgnoreLightLines";
public const string Lines_In_Air_Door = "C8,C9,C14,C15";
}
/// <summary>
/// 公共参数
/// </summary>
public static class Common
{
/// <summary>
/// 节点信息
/// </summary>
public static List<ClientNode> nodeInfo;
/// <summary>
/// 小车信息
/// </summary>
public static List<Agv_Info> agvInfo;
public static System.Windows.Forms.TextBox logTextBox;
public static System.Windows.Forms.DataGridView missionView;
public static AgvServer server;
public static BLL.Control control;
public static MiR_API mir;
public static WebService web;
public static ChargeStatus chargeStatus;
public static string itsHttp;
public static log4net.ILog log;
public static Dictionary<string, string> agvMission;
public static Dictionary<string, string> showNameMissionName;
//public static Dictionary<string, string> agvProductionLine;
public static System.Configuration.Configuration appConfig;
public static UnlockMissionManager missionManager;
public static StandbyStation StandbyStation = new StandbyStation() { C4_Station1 = "", C4_Station2 = "" };
private static List<string> msg = new List<string>();
private static string preLog = "";
public static readonly string CONFIG_PATH = AppDomain.CurrentDomain.BaseDirectory + "Config\\";
public static string C4_AGV_IPs = ConfigAppSettings.GetValue(SettingString.C4_AGV_IPs);
#region 任务日志
static log4net.ILog runLog = log4net.LogManager.GetLogger("RunLog");
static Dictionary<string, RunInfo> runInfoMap = new Dictionary<string, RunInfo>();
static List<string> IgnoreLightLines = ConfigAppSettings.GetValue(SettingString.IgnoreLightLines).Split(',').ToList();
public static void RunLogInfo(RunInfo info)
{
if (runInfoMap == null)
return;
if (runInfoMap.Keys.Contains(info.AGVNum))
{
if (!runInfoMap[info.AGVNum].Equals(info))
{
runLog.Info(info.ToString());
}
}
else
{
runInfoMap.Add(info.AGVNum, info);
runLog.Info(info.ToString());
}
}
public static void ErrorLogRecord(ErrorInfo errorInfo)
{
runLog.Info(errorInfo.ToString());
}
#endregion
public static string ReadIni(string section, string key)
{
return IniHelper.ReadValue(section, key, CONFIG_PATH + SettingString.FileName_tempData);
}
public static void WriteIni(string section, string key, string value)
{
IniHelper.WriteValue(section, key, value, CONFIG_PATH + SettingString.FileName_tempData);
}
public static bool GetNodeNameByLineName(string lineName, out string nodeName)
{
nodeName = "";
int id = nodeInfo.FindIndex(s => s.LineName.Equals(lineName));
if (id > -1)
{
nodeName = nodeInfo[id].Name;
return true;
}
else
{
return false;
}
}
public static bool GetLineNameByNodeName(string nodeName, out string lineName)
{
lineName = "";
int id = nodeInfo.FindIndex(s => s.Name.Equals(nodeName));
if (id > -1)
{
lineName = nodeInfo[id].LineName;
return true;
}
else
{
return false;
}
}
/// <summary>
/// 查找节点是否存在以及是否调用
/// </summary>
/// <param name="nodeName">节点名称</param>
/// <returns></returns>
public static int FindNode(string nodeName)
{
int idx = Common.nodeInfo.FindIndex(s => s.Name.Equals(nodeName) && s.IsUse);
return idx;
}
/// <summary>
/// 移动到节点位置
/// </summary>
/// <param name="agv"></param>
/// <param name="nodeName"></param>
/// <returns></returns>
public static bool MoveToNode(Agv_Info agv, string nodeName)
{
string log;
//清除目的地
agv.Place = "";
//执行下一个任务
bool rtn = Common.mir.Add_Mission_Fleet(agv, Common.agvMission[SettingString.Move + nodeName]);
if (rtn)
{
agv.Place = nodeName;
log = string.Format("{0} {1} To Node {2}", agv.Name, SettingString.Move, nodeName);
Common.LogInfo(log);
Common.mir.State_Ready(agv);
}
else
{
log = string.Format("{0} {1} To Node {2} 失败", agv.Name, SettingString.Move, nodeName);
Common.LogInfo(log);
}
return rtn;
}
/// <summary>
/// 查看A5、A6需要料架的状况
/// </summary>
/// <param name="agv"></param>
/// <param name="node"></param>
public static bool CheckA5A6State(Agv_Info agv, eShelfType shelfType, out string nodeName)
{
bool rtn = false;
string place = agv.Place;
nodeName = "";
if (shelfType.Equals(eShelfType.SmallShelf))
{
int tarIdx = Common.nodeInfo.FindIndex(s => s.Name == SettingString.A5
&& (s.StateEquals(eNodeStatus.NeedD) || s.StateEquals(eNodeStatus.NeedEnter)) && s.IsUse);
if (tarIdx == -1)
{
Common.log.Debug(string.Format("{0} {1}不需要小料架", agv.Name, SettingString.A5));
}
else
{
tarIdx = Common.agvInfo.FindIndex(s => !s.IP.Equals(agv.IP) && s.CurJob != null && s.CurJob is EmptyShelfBackJob
&& ((((EmptyShelfBackJob)s.CurJob).EmptyShelfTargetPlace) != null) && ((EmptyShelfBackJob)s.CurJob).EmptyShelfTargetPlace.Equals(SettingString.A5));
if (tarIdx == -1)
{
nodeName = SettingString.A5;
Common.log.Debug(string.Format("{0} {1}需要小料架", agv.Name, SettingString.A5));
return true;
}
}
tarIdx = Common.nodeInfo.FindIndex(s => s.Name == SettingString.A6 &&
(s.StateEquals(eNodeStatus.NeedEnter) || s.StateEquals(eNodeStatus.NeedEnterLeave)) && s.IsUse);
if (tarIdx == -1)
{
Common.log.Debug(string.Format("{0} {1}不需要小料架", agv.Name, SettingString.A6));
//rtn = Common.mir.Add_Mission_Fleet(agv, Common.agvMission[SettingString.MoveStandby]);
//if (rtn)
//{
// agv.NextPlace = "";
// agv.TaskSend = rtn ? SettingString.MoveStandby : "";
// agv.Msg = string.Format("{0} 在{1}已装载小料架,送往{2}", agv.Name, place, SettingString.MoveStandby);
// Common.LogInfo(string.Format("{0} 在{1}已装载小料架,送往{2}", agv.Name, place, SettingString.MoveStandby));
//}
}
else
{
tarIdx = Common.agvInfo.FindIndex(s => !s.IP.Equals(agv.IP) && s.CurJob != null && s.CurJob is EmptyShelfBackJob
&& ((((EmptyShelfBackJob)s.CurJob).EmptyShelfTargetPlace) != null) && ((EmptyShelfBackJob)s.CurJob).EmptyShelfTargetPlace.Equals(SettingString.A6));
if (tarIdx == -1)
{
nodeName = SettingString.A6;
Common.log.Debug(string.Format("{0} {1}需要小料架", agv.Name, SettingString.A6));
return true;
}
//rtn = Common.mir.Add_Mission_Fleet(agv, Common.agvMission[SettingString.Move + SettingString.A6]);
//if (rtn)
//{
// agv.NextPlace = "";
// tarNodeName = SettingString.A6;
// Common.nodeInfo[tarIdx].AgvName = agv.Name;
// agv.TaskSend = rtn ? SettingString.Move + SettingString.A6 : "";
// agv.Msg = string.Format("{0} 在{1}已装载小料架,送往{2}", agv.Name, place, SettingString.A6);
// Common.LogInfo(string.Format("{0} 在{1}已装载小料架,送往{2}", agv.Name, place, SettingString.A6));
// return true;
//}
}
}
else if (shelfType.Equals(eShelfType.BigShelf))
{
int tarIdx = Common.nodeInfo.FindIndex(s => s.Name == SettingString.A5
&& (s.StateEquals(eNodeStatus.NeedC) || s.StateEquals(eNodeStatus.NeedEnter)) && s.IsUse);
if (tarIdx == -1)
{
Common.log.Debug(string.Format("{0} {1}不需要大料架", agv.Name, SettingString.A5));
}
else
{
tarIdx = Common.agvInfo.FindIndex(s => !s.IP.Equals(agv.IP) && s.CurJob != null && s.CurJob is EmptyShelfBackJob
&& ((((EmptyShelfBackJob)s.CurJob).EmptyShelfTargetPlace) != null) && ((EmptyShelfBackJob)s.CurJob).EmptyShelfTargetPlace.Equals(SettingString.A5));
if (tarIdx == -1)
{
nodeName = SettingString.A5;
Common.log.Debug(string.Format("{0} {1}需要大料架", agv.Name, SettingString.A5));
return true;
}
}
tarIdx = Common.nodeInfo.FindIndex(s => s.Name == SettingString.A6 &&
(s.StateEquals(eNodeStatus.NeedEnter) || s.StateEquals(eNodeStatus.NeedEnterLeave)) && s.IsUse);
if (tarIdx == -1)
{
Common.log.Debug(string.Format("{0} {1}不需要大料架", agv.Name, SettingString.A6));
//rtn = Common.mir.Add_Mission_Fleet(agv, Common.agvMission[SettingString.MoveStandby]);
//if (rtn)
//{
// agv.NextPlace = "";
// agv.TaskSend = rtn ? SettingString.MoveStandby : "";
// agv.Msg = string.Format("{0} 在{1}已装载大料架,送往{2}", agv.Name, place, SettingString.MoveStandby);
// Common.LogInfo(string.Format("{0} 在{1}已装载大料架,送往{2}", agv.Name, place, SettingString.MoveStandby));
//}
}
else
{
tarIdx = Common.agvInfo.FindIndex(s => !s.IP.Equals(agv.IP) && s.CurJob != null && s.CurJob is EmptyShelfBackJob
&& ((((EmptyShelfBackJob)s.CurJob).EmptyShelfTargetPlace) != null) && ((EmptyShelfBackJob)s.CurJob).EmptyShelfTargetPlace.Equals(SettingString.A6));
if (tarIdx == -1)
{
nodeName = SettingString.A6;
Common.log.Debug(string.Format("{0} {1}需要大料架", agv.Name, SettingString.A6));
return true;
}
//rtn = Common.mir.Add_Mission_Fleet(agv, Common.agvMission[SettingString.Move + SettingString.A6]);
//if (rtn)
//{
// agv.NextPlace = "";
// tarNodeName = SettingString.A6;
// Common.nodeInfo[tarIdx].AgvName = agv.Name;
// agv.TaskSend = rtn ? SettingString.Move + SettingString.A6 : "";
// agv.Msg = string.Format("{0} 在{1}已装载大料架,送往{2}", agv.Name, place, SettingString.A6);
// Common.LogInfo(string.Format("{0} 在{1}已装载大料架,送往{2}", agv.Name, place, SettingString.A6));
// return true;
//}
}
}
return false;
}
/// <summary>
/// 查看A5料架的状况(A5当前料架小于2个)
/// </summary>
/// <param name="agv"></param>
/// <param name="node"></param>
public static bool CheckA5State(Agv_Info agv, eShelfType shelfType, out string nodeName)
{
bool rtn = false;
string place = agv.Place;
nodeName = "";
if (shelfType.Equals(eShelfType.SmallShelf))
{
int tarIdx = Common.nodeInfo.FindIndex(s => s.Name == SettingString.A5 && s.ClientLevel.Equals(ClientLevel.High)
&& (s.StateEquals(eNodeStatus.NeedD) || s.StateEquals(eNodeStatus.NeedEnter)) && s.IsUse);
if (tarIdx == -1)
{
Common.log.Debug(string.Format("{0} {1}不需要小料架", agv.Name, SettingString.A5));
}
else
{
nodeName = SettingString.A5;
Common.log.Debug(string.Format("{0} {1}需要小料架", agv.Name, SettingString.A5));
return true;
}
}
else if (shelfType.Equals(eShelfType.BigShelf))
{
int tarIdx = Common.nodeInfo.FindIndex(s => s.Name == SettingString.A5
&& (s.StateEquals(eNodeStatus.NeedC) || s.StateEquals(eNodeStatus.NeedEnter)) && s.IsUse);
if (tarIdx == -1)
{
Common.log.Debug(string.Format("{0} {1}不需要大料架", agv.Name, SettingString.A5));
}
else
{
nodeName = SettingString.A5;
Common.log.Debug(string.Format("{0} {1}需要大料架", agv.Name, SettingString.A5));
return true;
}
}
return false;
}
/// <summary>
/// 查看A6料架的状况(A6主要用于Feeder)
/// </summary>
/// <param name="agv"></param>
/// <param name="node"></param>
public static bool CheckA6State(Agv_Info agv, eShelfType shelfType, out string nodeName)
{
bool rtn = false;
string place = agv.Place;
nodeName = "";
if (shelfType.Equals(eShelfType.SmallShelf))
{
//int tarIdx = Common.nodeInfo.FindIndex(s => s.Name == SettingString.A5 && s.ClientLevel.Equals(ClientLevel.High)
// && (s.StateEquals(eNodeStatus.NeedD) || s.StateEquals(eNodeStatus.NeedEnter)) && s.IsUse);
//if (tarIdx == -1)
//{
// Common.log.Debug(string.Format("{0} {1}不需要小料架", agv.Name, SettingString.A5));
//}
//else
//{
// nodeName = SettingString.A5;
// Common.log.Debug(string.Format("{0} {1}需要小料架", agv.Name, SettingString.A5));
// return true;
//}
int tarIdx = Common.nodeInfo.FindIndex(s => s.Name == SettingString.A6 &&
(s.StateEquals(eNodeStatus.NeedEnter) || s.StateEquals(eNodeStatus.NeedEnterLeave)) && s.IsUse);
if (tarIdx == -1)
{
Common.log.Debug(string.Format("{0} {1}不需要小料架", agv.Name, SettingString.A6));
//rtn = Common.mir.Add_Mission_Fleet(agv, Common.agvMission[SettingString.MoveStandby]);
//if (rtn)
//{
// agv.NextPlace = "";
// agv.TaskSend = rtn ? SettingString.MoveStandby : "";
// agv.Msg = string.Format("{0} 在{1}已装载小料架,送往{2}", agv.Name, place, SettingString.MoveStandby);
// Common.LogInfo(string.Format("{0} 在{1}已装载小料架,送往{2}", agv.Name, place, SettingString.MoveStandby));
//}
}
else
{
nodeName = SettingString.A6;
Common.log.Debug(string.Format("{0} {1}需要小料架", agv.Name, SettingString.A6));
return true;
//rtn = Common.mir.Add_Mission_Fleet(agv, Common.agvMission[SettingString.Move + SettingString.A6]);
//if (rtn)
//{
// agv.NextPlace = "";
// tarNodeName = SettingString.A6;
// Common.nodeInfo[tarIdx].AgvName = agv.Name;
// agv.TaskSend = rtn ? SettingString.Move + SettingString.A6 : "";
// agv.Msg = string.Format("{0} 在{1}已装载小料架,送往{2}", agv.Name, place, SettingString.A6);
// Common.LogInfo(string.Format("{0} 在{1}已装载小料架,送往{2}", agv.Name, place, SettingString.A6));
// return true;
//}
}
}
else if (shelfType.Equals(eShelfType.BigShelf))
{
int tarIdx = Common.nodeInfo.FindIndex(s => s.Name == SettingString.A5
&& (s.StateEquals(eNodeStatus.NeedC) || s.StateEquals(eNodeStatus.NeedEnter)) && s.IsUse);
if (tarIdx == -1)
{
Common.log.Debug(string.Format("{0} {1}不需要大料架", agv.Name, SettingString.A5));
}
else
{
nodeName = SettingString.A5;
Common.log.Debug(string.Format("{0} {1}需要大料架", agv.Name, SettingString.A5));
return true;
}
tarIdx = Common.nodeInfo.FindIndex(s => s.Name == SettingString.A6 &&
(s.StateEquals(eNodeStatus.NeedEnter) || s.StateEquals(eNodeStatus.NeedEnterLeave)) && s.IsUse);
if (tarIdx == -1)
{
Common.log.Debug(string.Format("{0} {1}不需要料架", agv.Name, SettingString.A6));
}
else
{
nodeName = SettingString.A6;
Common.log.Debug(string.Format("{0} {1}需要料架", agv.Name, SettingString.A6));
return true;
}
}
return false;
}
/// <summary>
/// 检查AGV是否有负载
/// </summary>
/// <returns></returns>
public static bool CheckLoad(Agv_Info agv)
{
return Common.mir.Add_Mission_Fleet(agv, Common.agvMission["CheckShelf"]);
}
public static bool DoorMission(Agv_Info agv, string doorName)
{
agv.Place = doorName;
return Common.mir.Add_Mission_Fleet(agv, Common.agvMission[SettingString.Move + doorName]);
}
/// <summary>
/// 检查是否在4C风淋门内
/// </summary>
/// <param name="nodeName"></param>
/// <returns></returns>
public static bool CheckIsInAirDoor(string nodeName)
{
return SettingString.Lines_In_Air_Door.Split(',').Contains(nodeName);
}
/// <summary>
/// 检查当前任务是否结束
/// </summary>
/// <param name="taskName">任务名称</param>
/// <param name="taskGUID">任务GUID</param>
/// <returns></returns>
public static bool CheckTaskFinished(Agv_Info agv, string nodeName, string curTaskState)
{
string tmp = $"{agv.Name},{SettingString.Move + nodeName},{agv.CurTaskID},{curTaskState}";
if (curTaskState.Equals(SettingString.Done) && !taskFiStr.Equals(tmp))
{
taskFiStr = tmp;
log.Info(taskFiStr);
}
return Common.agvMission[SettingString.Move + nodeName].Equals(agv.CurTaskGUID) && curTaskState.Equals(SettingString.Done);
}
static string taskFiStr = "";
/// <summary>
/// 检查充电任务是否分配完成
/// </summary>
/// <param name="taskName"></param>
/// <returns></returns>
public static bool CheckTaskFinished(Agv_Info agv, string taskName)
{
return taskName.Contains(SettingString.AutoCharge) && agv.CurTaskState.Equals(SettingString.Executing);
}
static string elStr = "";
public static bool CheckEnterOrLeaveFinished(Agv_Info agv, string actionName, string curTaskState)
{
string tmp = $"{agv.Name},{actionName},{agv.CurTaskID},{curTaskState}";
if (curTaskState.Equals(SettingString.Done) && !elStr.Equals(tmp))
{
elStr = tmp;
log.Info(elStr);
}
return Common.agvMission[actionName].Equals(agv.CurTaskGUID) && curTaskState.Equals(SettingString.Done);
}
//双层线工单信息
public static string doubleLine_WO = "";
public static string warnMsg = "";
/// <summary>
/// 查找空架任务
/// </summary>
/// <param name="curPlace">为空表示待机位</param>
/// <param name="nodeName">出空料架的节点名</param>
/// <param name="emptyAGVbACK">agv空车返回,带一个料架</param>
/// <returns></returns>
public static bool FindEmptyShelfNode(Agv_Info agv, out string nodeName, bool emptyAGVbACK = false)
{
nodeName = "";
if (!Common.CheckCanExecuteMission(agv))
return false;
///双层线出口检查
int idx = nodeInfo.FindIndex(s => s.Name.Equals(SettingString.A6)
&& (s.StateEquals(eNodeStatus.NeedEnterLeave) || (s.StateEquals(eNodeStatus.NeedLeave))) && !s.RFID.Equals(""));
if (idx > -1)
{
if (AGVManager.FindFullShelfTarget(Common.nodeInfo[idx].RFID, out AGVManager.BoxDestInfo FullShelfDestInfo))
{
idx = nodeInfo.FindIndex(s => s.Name.Equals(FullShelfDestInfo.location) && s.EmptyShelfCnt > 0);
if (idx > -1)
{
if (FullShelfDestInfo.location.StartsWith(SettingString.C4_Name_Prefix) && C4_AGV_IPs.Contains(agv.IP))
{
nodeName = FullShelfDestInfo.location;
Common.GetLineNameByNodeName(nodeName, out string line);
Common.log.Info("A6出满料架的产线有空料架,优先处理 " + FullShelfDestInfo.ShowInfo(line));
return true;
}
else if (FullShelfDestInfo.location.StartsWith(SettingString.D4_Name_Prefix) && !C4_AGV_IPs.Contains(agv.IP))
{
nodeName = FullShelfDestInfo.location;
Common.GetLineNameByNodeName(nodeName, out string line);
Common.log.Info("A6出满料架的产线有空料架,优先处理 " + FullShelfDestInfo.ShowInfo(line));
return true;
}
}
}
else
{
if (FullShelfDestInfo != null)
{
Common.log.Error("A6的出料信息不正确,请检查:" + FullShelfDestInfo.ShowInfo("ERROR"));
//return false;
}
}
}
//查询双层线正在出的工单料
if (AGVManager.FindCurSO(out AGVManager.WOData woData))
{
if (Common.GetNodeNameByLineName(woData.line, out string loc))
{
nodeName = loc;
doubleLine_WO = woData.ToTxt(loc);
Common.log.Debug(doubleLine_WO);
idx = nodeInfo.FindIndex(s => s.Name.Equals(loc) && s.EmptyShelfCnt > 0);
if (idx > -1)
{
if (loc.StartsWith(SettingString.C4_Name_Prefix) && C4_AGV_IPs.Contains(agv.IP))
{
nodeName = loc;
Common.log.Info("双层线正在出的工单目标产线有空料架,优先处4C-" + loc);
return true;
}
else if (loc.StartsWith(SettingString.D4_Name_Prefix) && !C4_AGV_IPs.Contains(agv.IP))
{
nodeName = loc;
Common.log.Info("双层线正在出的工单目标产线有空料架,优先处理4D-" + loc);
return true;
}
}
}
}
///AGV出满料带回一个料架
if (emptyAGVbACK)
{
//双层线是否需要小料架
if (CheckA5A6State(agv, eShelfType.SmallShelf, out string lineNodeName))
{
//4C车间寻找
if (SettingString.C4_AGV_IPs.Contains(agv.IP))
{
List<Agv_Info> agvs = Common.agvInfo.FindAll(s => C4_AGV_IPs.Contains(s.IP) && (s.CurJob is EmptyShelfBackJob || s.CurJob is GoEmptyShelfLineJob));
if (agvs != null && agvs.Count >= 1)
return false;
string nearNodeName = CalculateNearNode(agv, SettingString.C4_Name_Prefix);
if (nearNodeName.Equals(""))
{
return false;
}
nodeName = nearNodeName;
Common.log.Info(agv.Name + " 双层线需要小料架,准备去4C-" + nearNodeName);
return true;
}
//4D车间寻找
if (!C4_AGV_IPs.Contains(agv.IP))
{
List<Agv_Info> agvs = Common.agvInfo.FindAll(s => !C4_AGV_IPs.Contains(s.IP) && (s.CurJob is EmptyShelfBackJob || s.CurJob is GoEmptyShelfLineJob));
if (agvs != null && agvs.Count >= 1)
return false;
string nearNodeName = CalculateNearNode(agv, SettingString.D4_Name_Prefix);
if (nearNodeName.Equals(""))
{
return false;
}
nodeName = nearNodeName;
Common.log.Info(agv.Name + " 双层线需要小料架,准备去4D-" + nearNodeName);
return true;
}
}
}
else//主动拉料架
{
//双层线是否需要小料架
if (CheckA5State(agv, eShelfType.SmallShelf, out string lineNodeName2))
{
//4C车间寻找
if (C4_AGV_IPs.Contains(agv.IP))
{
idx = nodeInfo.FindIndex(s => s.EmptyShelfCnt > 0 && s.Name.Equals(SettingString.C4FeederOut) && s.RFID.StartsWith("D") && s.IsUse);
if (idx > -1)
{
int idx1 = agvInfo.FindIndex(s => s.CurJob is EnterLeaveShelfJob && ((EnterLeaveShelfJob)s.CurJob).LineName.Equals(SettingString.C4FeederOut));
if (idx1 == -1)
{
nodeName = nodeInfo[idx].Name;
Common.log.Info(agv.Name + " 双层线左侧需要小料架,准备去4C-" + nodeName);
return true;
}
}
//string nearNodeName = CalculateNearNode(agv, SettingString.C4_Name_Prefix);
//if (!nearNodeName.Equals(""))
//{
// nodeName = nearNodeName;
// Common.log.Debug(agv.Name + " 双层线需要小料架,准备去4C-" + nearNodeName);
// return true;
//}
}
//4D车间寻找
if (!C4_AGV_IPs.Contains(agv.IP))
{
idx = nodeInfo.FindIndex(s => s.EmptyShelfCnt > 0 && s.Name.Equals(SettingString.D4FeederOut) && s.RFID.StartsWith("D") && s.IsUse);
if (idx > -1)
{
nodeName = nodeInfo[idx].Name;
Common.log.Info(agv.Name + " 双层线左侧需要小料架,准备去4D-" + nodeName);
return true;
}
//string nearNodeName = CalculateNearNode(agv, SettingString.D4_Name_Prefix);
//if (!nearNodeName.Equals(""))
//{
// nodeName = nearNodeName;
// Common.log.Debug(agv.Name + " 双层线需要小料架,准备去4D-" + nearNodeName);
// return true;
//}
}
}
else if (CheckA5State(agv, eShelfType.BigShelf, out string lineNodeName3))
{
//4C车间寻找
if (C4_AGV_IPs.Contains(agv.IP))
{
idx = nodeInfo.FindIndex(s => s.EmptyShelfCnt > 0 && s.Name.Equals(SettingString.C4FeederOut) && s.RFID.StartsWith("C") && s.IsUse);
if (idx > -1)
{
int idx1 = agvInfo.FindIndex(s => s.CurJob is EnterLeaveShelfJob && ((EnterLeaveShelfJob)s.CurJob).LineName.Equals(SettingString.C4FeederOut));
if (idx1 == -1)
{
nodeName = nodeInfo[idx].Name;
Common.log.Info(agv.Name + " 双层线左侧需要大料架,准备去4C-" + nodeName);
return true;
}
}
}
//4D车间寻找
if (!C4_AGV_IPs.Contains(agv.IP))
{
idx = nodeInfo.FindIndex(s => s.EmptyShelfCnt > 0 && s.Name.Equals(SettingString.D4FeederOut) && s.RFID.StartsWith("C") && s.IsUse);
if (idx > -1)
{
nodeName = nodeInfo[idx].Name;
Common.log.Info(agv.Name + " 双层线左侧需要小料架,准备去4D-" + nodeName);
return true;
}
}
}
if (CheckA6State(agv, eShelfType.BigShelf, out string lineNodeName1))
{
//4C车间备料区寻找
if (C4_AGV_IPs.Contains(agv.IP))
{
idx = nodeInfo.FindIndex(s => s.EmptyShelfCnt > 0 && s.Name.Equals(SettingString.C4FeederOut) && !s.RFID.StartsWith("0") && s.IsUse);
if (idx > -1)
{
int idx1 = agvInfo.FindIndex(s => s.CurJob is EnterLeaveShelfJob && ((EnterLeaveShelfJob)s.CurJob).LineName.Equals(SettingString.C4FeederOut));
if (idx1 == -1)
{
nodeName = nodeInfo[idx].Name;
Common.log.Info(agv.Name + " 双层线右侧需要料架,准备去4C-" + nodeName);
return true;
}
}
//string nearNodeName = CalculateNearNode(agv, SettingString.C4_Name_Prefix);
//if (!nearNodeName.Equals(""))
//{
// nodeName = nearNodeName;
// Common.log.Debug(agv.Name + " 双层线右侧需要料架,准备去4C-" + nearNodeName);
// return true;
//}
}
//4D车间寻找
if (!C4_AGV_IPs.Contains(agv.IP))
{
idx = nodeInfo.FindIndex(s => s.EmptyShelfCnt > 0 && s.Name.Equals(SettingString.D4FeederOut) && !s.RFID.StartsWith("0") && s.IsUse);
if (idx > -1)
{
nodeName = nodeInfo[idx].Name;
Common.log.Info(agv.Name + " 双层线右侧需要料架,准备去4D-" + nodeName);
return true;
}
//string nearNodeName = CalculateNearNode(agv, SettingString.D4_Name_Prefix);
//if (!nearNodeName.Equals(""))
//{
// nodeName = nearNodeName;
// Common.log.Debug(agv.Name + " 双层线右侧需要料架,准备去4D-" + nearNodeName);
// return true;
//}
}
}
}
return false;
}
/// <summary>
/// 查找出满料架任务
/// </summary>
/// <returns></returns>
public static bool FindFullShelfTask(Agv_Info agv)
{
if (!Common.CheckCanExecuteMission(agv))
return false;
int idx = nodeInfo.FindIndex(s => s.Name.Equals(SettingString.A6)
&& (s.StateEquals(eNodeStatus.NeedEnterLeave) || (s.StateEquals(eNodeStatus.NeedLeave))) && !s.RFID.Equals(""));
if (idx > -1)
{
if (AGVManager.FindFullShelfTarget(Common.nodeInfo[idx].RFID, out AGVManager.BoxDestInfo FullShelfDestInfo))
{
if (FullShelfDestInfo.location.StartsWith(SettingString.C4_Name_Prefix) && C4_AGV_IPs.Contains(agv.IP))
{
int i = Common.agvInfo.FindIndex(s => s.CurJob is GoFullShelfStationJob && !s.IP.Equals(agv.IP));
if (i == -1)
return true;
}
else if (FullShelfDestInfo.location.StartsWith(SettingString.D4_Name_Prefix) && !C4_AGV_IPs.Contains(agv.IP))
{
int i = Common.agvInfo.FindIndex(s => s.CurJob is SendFullShelfToLineJob && !s.IP.Equals(agv.IP)
&& ((SendFullShelfToLineJob)s.CurJob).FullShelfPlace.Equals(FullShelfDestInfo.location));
if (i > -1)
return false;
i = Common.agvInfo.FindIndex(s => s.CurJob is GoFullShelfStationJob && !s.IP.Equals(agv.IP));
if (i == -1)
return true;
}
}
else
{
if (FullShelfDestInfo != null)
{
Common.log.Error("A6的出料信息不正确,请检查:" + FullShelfDestInfo.ShowInfo("ERROR"));
}
}
}
return false;
}
/// <summary>
/// 查找当前出料工单的产线是否有空料架
/// </summary>
/// <param name="agv"></param>
/// <returns></returns>
public static bool FindEmptyShelfBeforeSendFullShelf(out string nodeName)
{
nodeName = "";
int idx = nodeInfo.FindIndex(s => s.Name.Equals(SettingString.A6)
&& (s.StateEquals(eNodeStatus.NeedEnterLeave) || (s.StateEquals(eNodeStatus.NeedLeave))) && !s.RFID.Equals("") && s.IsUse);
if (idx > -1)
{
if (AGVManager.FindFullShelfTarget(Common.nodeInfo[idx].RFID, out AGVManager.BoxDestInfo FullShelfDestInfo))
{
idx = nodeInfo.FindIndex(s => s.Name.Equals(FullShelfDestInfo.location) && s.EmptyShelfCnt > 0 && s.IsUse);
if (idx > -1)
{
nodeName = FullShelfDestInfo.location;
Common.GetLineNameByNodeName(nodeName, out string line);
Common.log.Debug("A6出满料架的产线有空料架,优先处理 " + FullShelfDestInfo.ShowInfo(line));
return true;
}
}
else
{
if (FullShelfDestInfo != null)
{
Common.log.Error("A6的出料信息不正确,请检查:" + FullShelfDestInfo.ShowInfo("ERROR"));
}
}
}
return false;
}
/// <summary>
/// 检查接驳台状态
/// </summary>
/// <returns></returns>
public static bool CheckStationState(ClientNode clientNode, out string rfid)
{
rfid = "";
if(IgnoreLightLines.Contains(clientNode.Name)&&Common.missionManager.GetUnlockCnt(clientNode.Name)>0)
{
rfid = Common.missionManager.GetUnlockRfids(clientNode.Name)[0];
warnMsg = "";
return true;
}
if (!Common.missionManager.GetUnlockRfids(clientNode.Name).Contains(clientNode.RFID))
{
if (clientNode.Name.Equals(SettingString.C4FeederOut) || clientNode.Name.Equals(SettingString.D4FeederOut))
{
warnMsg = string.Format("佳世达线体[{0}]外侧料架[{1}]未解绑,已解绑料架:{2}", clientNode.AliceName, clientNode.RFID, string.Join(",", Common.missionManager.GetUnlockRfids(clientNode.Name).ToArray()));
Common.log.Debug(warnMsg);
}
else
{
string res = AGVManager.GetRFIDs(clientNode.Name);
warnMsg = string.Format("佳世达线体[{0}]外侧料架[{1}]未解绑,已解绑料架:{2}", clientNode.AliceName, clientNode.RFID, string.Join(",", Common.missionManager.GetUnlockRfids(clientNode.Name).ToArray()));
Common.log.Debug(warnMsg);
}
return false;
}
rfid = clientNode.RFID;
warnMsg = "";
return true;
}
/// <summary>
/// 上报接驳台状态
/// </summary>
/// <param name="clientNode"></param>
/// <returns>true:表示正常</returns>
public static bool UpdateStationState(ClientNode clientNode)
{
if(IgnoreLightLines.Contains(clientNode.Name))
{
clientNode.WarnMsg = "";
return true;
}
if (Common.missionManager.GetUnlockCnt(clientNode.Name) > 0 && !Common.missionManager.GetUnlockRfids(clientNode.Name).Contains(clientNode.RFID))
{
if (clientNode.Name.Equals(SettingString.C4FeederOut) || clientNode.Name.Equals(SettingString.D4FeederOut))
{
// 外侧料架[D34]未解绑,已解绑料架:Dxx,Dxx,Dxx
clientNode.WarnMsg = string.Format("佳世达外侧料架[{0}]未解绑,已解绑料架:{1}", clientNode.RFID, string.Join(",", Common.missionManager.GetUnlockRfids(clientNode.Name).ToArray()));
return false;
}
else
{
clientNode.WarnMsg = string.Format("佳世达外侧料架[{0}]未解绑,已解绑料架:{1}", clientNode.RFID, string.Join(",", Common.missionManager.GetUnlockRfids(clientNode.Name).ToArray()));
return false;
}
}
clientNode.WarnMsg = "";
return true;
}
/// <summary>
/// 出料前检查接驳台状态
/// </summary>
/// <returns></returns>
public static bool CheckStationState(ClientNode clientNode)
{
if (Common.missionManager.GetUnlockCnt(clientNode.Name) > 0)
{
// if (warnMsg.Equals(""))
{
warnMsg = string.Format("接驳台[{1}]有空料架未回收完,无法出满料", clientNode.RFID, clientNode.Name);
//Common.LogInfo(warnMsg);
}
return false;
}
return true;
}
/// <summary>
/// 计算当前小车距离最近的任务点(只针对产线)
/// </summary>
/// <param name="agv"></param>
/// <returns>节点名称</returns>
public static string CalculateNearNode(Agv_Info agv, string RoomProfix)
{
double minDis = Double.MaxValue;
string nodeName = "";
List<ClientNode> clientNodes = nodeInfo.FindAll(s => s.EmptyShelfCnt > 0 && s.Name.Substring(0, 1).Equals(RoomProfix) && s.IsUse);
try
{
if (clientNodes.Count.Equals(0))
return nodeName;
foreach (var item in clientNodes)
{
double dis = Math.Sqrt(Math.Pow((agv.Position.x - item.position.X), 2) + Math.Pow((agv.Position.y - item.position.Y), 2));
Common.log.Debug(string.Format("{0} 距离{1}={2}", agv.Name, item.Name, dis.ToString("f2")));
if (dis < minDis && CheckStationState(item, out string rfid))
{
minDis = dis;
nodeName = item.Name;
}
}
Common.log.Debug(string.Format("{0} 准备运动到产线 {1} 回收空料架", agv.Name, nodeName));
return nodeName;
}
catch (Exception e)
{
Common.log.Error("CalculateNearNode " + e.ToString());
}
return nodeName;
}
/// <summary>
/// 充电
/// </summary>
/// <param name="agv"></param>
/// <returns>充电任务结果</returns>
public static bool StatusCharge(Agv_Info agv, bool isRemovePreMission = false)
{
bool rtn;
string log;
agv.Place = "";
#region 指定充电位置
if (agv.IP == "10.85.199.72")//1764
{
rtn = Common.mir.Add_Mission_Fleet(agv, Common.agvMission["AutoCharge4"], isRemovePreMission);
if (rtn)
{
//agv.TaskSend = "AutoCharge5";
agv.Place = SettingString.AutoCharge;
Common.chargeStatus.charge4 = agv.Name;
Common.chargeStatus.chargeInterval = DateTime.Now.Ticks;
log = string.Format("{0} AutoCharge4", agv.Name);
agv.Msg = log;
Common.LogInfo(log);
Common.mir.State_Ready(agv);
}
else
{
log = string.Format("{0} AutoCharge4 失败", agv.Name);
//防止上一个任务已执行但返回失败时,删除任务
//Common.mir.Del_Mission(agv);
Common.LogInfo(log);
}
return rtn;
}
else if (agv.IP == "10.85.199.73")//1767
{
rtn = Common.mir.Add_Mission_Fleet(agv, Common.agvMission["AutoCharge5"], isRemovePreMission);
if (rtn)
{
//agv.TaskSend = "AutoCharge6";
agv.Place = SettingString.AutoCharge;
Common.chargeStatus.charge5 = agv.Name;
Common.chargeStatus.chargeInterval = DateTime.Now.Ticks;
log = string.Format("{0} AutoCharge5", agv.Name);
agv.Msg = log;
Common.LogInfo(log);
Common.mir.State_Ready(agv);
}
else
{
log = string.Format("{0} AutoCharge5 失败", agv.Name);
//防止上一个任务已执行但返回失败时,删除任务
//Common.mir.Del_Mission(agv);
Common.LogInfo(log);
}
return rtn;
}
//随机充电
if (Common.chargeStatus.charge3 == "")//1763 agv.IP == "10.85.199.71"
{
rtn = Common.mir.Add_Mission_Fleet(agv, Common.agvMission["AutoCharge3"], isRemovePreMission);
if (rtn)
{
//agv.TaskSend = "AutoCharge3";
agv.Place = SettingString.AutoCharge;
Common.chargeStatus.charge3 = agv.Name;
Common.chargeStatus.chargeInterval = DateTime.Now.Ticks;
log = string.Format("{0} AutoCharge3", agv.Name);
agv.Msg = log;
Common.LogInfo(log);
Common.mir.State_Ready(agv);
}
else
{
log = string.Format("{0} AutoCharge3 失败", agv.Name);
//防止上一个任务已执行但返回失败时,删除任务
Common.mir.Del_Mission(agv);
Common.LogInfo(log);
}
return rtn;
}
else if (Common.chargeStatus.charge6 == "")//1764 agv.IP == "10.85.199.72"
{
rtn = Common.mir.Add_Mission_Fleet(agv, Common.agvMission["AutoCharge6"], isRemovePreMission);
if (rtn)
{
//agv.TaskSend = "AutoCharge4";
agv.Place = SettingString.AutoCharge;
Common.chargeStatus.charge6 = agv.Name;
Common.chargeStatus.chargeInterval = DateTime.Now.Ticks;
log = string.Format("{0} AutoCharge6", agv.Name);
agv.Msg = log;
Common.LogInfo(log);
Common.mir.State_Ready(agv);
}
else
{
log = string.Format("{0} AutoCharge6 失败", agv.Name);
//防止上一个任务已执行但返回失败时,删除任务
Common.mir.Del_Mission(agv);
Common.LogInfo(log);
}
return rtn;
}
else
{
return false;
}
#endregion
}
/// <summary>
/// 判断电量是否够执行任务
/// </summary>
/// <param name="agv"></param>
/// <returns></returns>
public static bool CheckCanExecuteMission(Agv_Info agv)
{
if (agv.Battery <= Common.chargeStatus.chargeMin)
{
Common.log.Debug(agv.Name + " 电量小于20%,不执行任务");
return false;
}
return true;
}
/// <summary>
/// 判断小车是否空闲
/// </summary>
/// <param name="agv"></param>
/// <returns></returns>
public static bool CheckAGVStatusNone(Agv_Info agv)
{
if ((agv.CurJob is ChargeJob || agv.CurJob == null) && !agv.IsExistShelf)
return true;
else
return false;
}
public static void LogInfo(string text, bool isShow = true)
{
if (logTextBox == null) return;
if (logTextBox.InvokeRequired)
{
logTextBox.Invoke(new Action(() => LogInfo(text, isShow)));
return;
}
if (preLog.Equals(text))//连续重复的日志只打印一次
return;
preLog = text;
if (msg.Count > 255)
{
msg.RemoveRange(0, 10);
}
log.Info(text);
string tmpStr = "";
if (isShow)
{
msg.Add(string.Format("[{0}] {1}\r\n", DateTime.Now.ToString("HH:mm:ss"), text));
msg.ForEach(s => tmpStr += s);
logTextBox.Text = tmpStr;
//logTextBox.AppendText(string.Format("[{0}] {1}\r\n", DateTime.Now.ToString("HH:mm:ss"), text));
//logTextBox.ScrollToCaret();
}
}
/// <summary>
/// 读取料架解绑信息
/// </summary>
public static void ReadUnlockLineInfo()
{
if (!System.IO.File.Exists(Common.CONFIG_PATH + "UnlockInfo.json"))
{
File.Create(Common.CONFIG_PATH + "UnlockInfo.json");
missionManager = new UnlockMissionManager(nodeInfo);
return;
}
string s = File.ReadAllText(Common.CONFIG_PATH + "UnlockInfo.json");
missionManager = JsonHelper.DeserializeJsonToObject<UnlockMissionManager>(s);
if (missionManager == null)
missionManager = new UnlockMissionManager(nodeInfo);
missionManager.Init();
}
public static void GetNodesPosition()
{
Agv_Info agv = agvInfo[0];
foreach (ClientNode clientNode in nodeInfo)
{
bool rtn = Common.mir.Get_Node_Pos(agv, clientNode, out MirPosition mirPosition);
Thread.Sleep(50);
if (rtn)
{
clientNode.position.X = mirPosition.pos_x;
clientNode.position.Y = mirPosition.pos_y;
Common.log.Debug(string.Format("软件开启:{0} 获取节点位置({1},{2})", clientNode.Name, clientNode.position.X, clientNode.position.Y));
}
else
{
Common.log.Error(clientNode.Name + " GetNodesPosition 获取节点位置失败");
}
}
}
/// <summary>
/// 检查该目的地是否有车占用
/// </summary>
/// <param name="nodeName"></param>
/// <returns>false:未被占用</returns>
public static bool Check4CTarget(Agv_Info agv, string nodeName)
{
List<Agv_Info> agvs = agvInfo.FindAll(s => !s.IP.Equals(agv.IP) && (s.CurJob is GoEmptyShelfLineJob || s.CurJob is SendFullShelfToLineJob)
); //&& !s.Name.Equals(StandbyStation.C4_Station1) && !s.Name.Equals(StandbyStation.C4_Station2)
if (agvs.Count.Equals(0))
return false;
else if (agvs.Count > 0)
{
foreach (Agv_Info item in agvs)
{
if (item.CurJob is GoEmptyShelfLineJob)
{
if (((GoEmptyShelfLineJob)item.CurJob).EmptyShelfPlace.Equals(nodeName) && item.CurTaskName.Equals(SettingString.Move + nodeName))
{
log.Debug(item.Name + " 在目的地:" + ((GoEmptyShelfLineJob)item.CurJob).EmptyShelfPlace + " " + agv.Name + "暂不去" + nodeName);
return true;
}
}
else if (item.CurJob is SendFullShelfToLineJob)
{
if (((SendFullShelfToLineJob)item.CurJob).FullShelfPlace.Equals(nodeName) && item.CurTaskName.Equals(SettingString.Move + nodeName))
{
log.Debug(item.Name + " 在目的地:" + ((SendFullShelfToLineJob)item.CurJob).FullShelfPlace + " " + agv.Name + "暂不去" + nodeName);
return true;
}
}
}
}
ClientNode clientNode = nodeInfo.Find(s => s.Name.Equals(nodeName));
if (clientNode == null)
return false;
if (clientNode.IsOccupied())
return true;
return false;
}
public static void ClearNodeBuff(string agvname)
{
foreach (var item in nodeInfo)
{
item.ClearOccupied(agvname);
}
}
public static void SetNodeOccupied(string nodename,string agvname)
{
ClearNodeBuff(agvname);
ClientNode clientNode = nodeInfo.Find(s => s.Name.Equals(nodename));
if(clientNode!=null)
{
clientNode.SetOccupy(agvname);
}
}
/// <summary>
/// 移动到4C待机位
/// </summary>
/// <param name="agv"></param>
public static void MoveTo4CStandy(Agv_Info agv)
{
if (StandbyStation.C4_Station1.Equals(""))
{
StandbyStation.C4_Station1 = agv.Name;
Common.MoveToNode(agv, SettingString.C4_STANDBY1);
}
else if (StandbyStation.C4_Station2.Equals(""))
{
StandbyStation.C4_Station2 = agv.Name;
Common.MoveToNode(agv, SettingString.C4_STANDBY2);
}
}
/// <summary>
/// 清除该小车在待机位的信息
/// </summary>
public static void DeleteStandyInfo(Agv_Info agv)
{
if (StandbyStation.C4_Station1.Equals(agv.Name))
{
StandbyStation.C4_Station1 = "";
}
else if (StandbyStation.C4_Station2.Equals(agv.Name))
{
StandbyStation.C4_Station2 = "";
}
}
/// <summary>
/// 获取Job任务状态
/// </summary>
/// <param name="CurTaskID"></param>
/// <returns></returns>
public static string GetTakJobState(long CurTaskID)
{
if (!CurTaskID.Equals(-1) && Common.mir.Get_Task_State(CurTaskID, out string st))
return st;
return SettingString.Wait;
}
}
public class RunInfo
{
/// <summary>
/// AGV编号
/// </summary>
public string AGVNum { get; set; } = "";
public string DeviceName { get; set; } = "";
/// <summary>
/// 任务名称
/// </summary>
public string TaskName { get; set; } = "";
/// <summary>
/// 目的地
/// </summary>
public string TargetPlace { get; set; } = "";
/// <summary>
/// 任务步骤
/// </summary>
public string TaskStep { get; set; } = "";
/// <summary>
/// 任务内容
/// </summary>
public string MissionInfo { get; set; } = "";
/// <summary>
/// 开始时间
/// </summary>
public string DateTime { get; set; } = "";
/// <summary>
/// 结束时间
/// </summary>
public string EndDateTime { get; set; } = "";
/// <summary>
/// 任务运行时长
/// </summary>
public string TaskRunTime { get; set; } = "";
/// <summary>
/// 类型
/// </summary>
public string Type { get; set; } = "Task";
public RunInfo(string AGVNum, string taskName, string targetPlace, string taskStep, string missionInfo, DateTime startTime)
{
//开始时间 2006-01-02 15:04:05
DateTime = startTime.ToString("yyyy-MM-dd HH:mm:ss");
EndDateTime = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
this.AGVNum = AGVNum;
MissionInfo = missionInfo;
TaskName = taskName;
TaskRunTime = (System.DateTime.Now - startTime).TotalMinutes.ToString("f2");
TargetPlace = targetPlace;
TaskStep = taskStep;
}
public RunInfo() { }
public override bool Equals(object obj)
{
if (obj is RunInfo)
{
RunInfo info = (RunInfo)obj;
if (this.MissionInfo.Equals(info.MissionInfo))
return true;
this.MissionInfo = info.MissionInfo;
}
return false;
}
public override string ToString()
{
return JsonHelper.SerializeObject(this);
}
}
public class ErrorInfo
{
/// <summary>
/// AGV编号
/// </summary>
public string AGVNum
{
get { return agvname; }
set
{
agvname = value.PadLeft(4, '0');
}
}
private string agvname = "";
public string DeviceName { get; set; } = "";
/// <summary>
/// 开始时间
/// </summary>
public string DateTime { get; set; } = "";
/// <summary>
/// 结束时间
/// </summary>
public string EndDateTime { get; set; } = "";
/// <summary>
/// 异常信息
/// </summary>
public string ErrorMsg { get; set; } = "";
public string ErrorLastTime { get; set; } = "";
/// <summary>
/// 任务名称
/// </summary>
public string TaskName { get; set; } = "";
/// <summary>
/// AGV的当前任务
/// </summary>
public string AGVMissionName { get; set; } = "";
public string MissionInfo { get; set; } = "";
/// <summary>
/// 目的地
/// </summary>
public string TargetPlace { get; set; } = "";
/// <summary>
/// 类型
/// </summary>
public string Type { get; set; } = "Error";
public ErrorInfo(Agv_Info agv)
{
DateTime = agv.errStartTime.ToString("yyyy-MM-dd HH:mm:ss");
AGVNum = agv.Name;
EndDateTime = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
ErrorMsg = agv.ErrorMsg;
ErrorLastTime = (System.DateTime.Now - agv.errStartTime).TotalMinutes.ToString("f2");
if (agv.CurJob != null)
{
TaskName = agv.CurJob.JobName;
MissionInfo = agv.CurJob.runInfo;
}
AGVMissionName = agv.CurTaskName;
TargetPlace = agv.Place;
}
public override string ToString()
{
return JsonHelper.SerializeObject(this);
}
}
public static class API
{
[DllImport("user32.dll", EntryPoint = "ShowWindow", CharSet = CharSet.Auto)]
public static extern int ShowWindow(IntPtr hwnd, int nCmdShow);
[DllImport("user32.dll ", SetLastError = true)]
public static extern void SwitchToThisWindow(IntPtr hWnd, bool fAltTab);
public const int SW_RESTORE = 9;
}
/// <summary>
/// 客户端
/// </summary>
public class Client
{
/// <summary>
/// 循环
/// </summary>
public bool Loop;
/// <summary>
/// IP地址
/// </summary>
public string IP;
/// <summary>
/// 是否连接
/// </summary>
public bool IsConn;
/// <summary>
/// 节点名称集合
/// </summary>
public List<string> nodeName;
/// <summary>
/// 套接字
/// </summary>
public Socket Socket;
/// <summary>
/// 接收数据线程
/// </summary>
public Thread ListenNet;
}
/// <summary>
/// 地点状态
/// </summary>
public enum ePlaceState
{
/// <summary>
/// 没有任务
/// </summary>
None = 0,
/// <summary>
/// 小车移动任务
/// </summary>
Move = 1,
/// <summary>
/// 小车移动任务完成
/// </summary>
MoveFinish = 2,
/// <summary>
/// 小车Enter任务
/// </summary>
Enter = 3,
/// <summary>
/// 小车Enter任务完成
/// </summary>
EnterFinish = 4,
/// <summary>
/// 小车Leave任务
/// </summary>
Leave = 5,
/// <summary>
/// 小车Leave任务完成
/// </summary>
LeaveFinish = 6,
/// <summary>
/// 出错
/// </summary>
Error = 9
}
public struct PositionStru
{
public double X;
public double Y;
}
public class ChargeStatus
{
/// <summary>
/// 1号充电桩的AGV名称
/// </summary>
public string charge3 = "";
/// <summary>
/// 1号充电桩的AGV名称
/// </summary>
public string charge4 = "";
/// <summary>
/// 1号充电桩的AGV名称
/// </summary>
public string charge5 = "";
/// <summary>
/// 1号充电桩的AGV名称
/// </summary>
public string charge6 = "";
/// <summary>
/// 1号充电桩的AGV名称
/// </summary>
public string charge7 = "";
/// <summary>
/// 充电最大电量,小于该值等待指定时间去充电
/// </summary>
public int chargeMax;
/// <summary>
/// 充电最小电量,小于该值直接去充电
/// </summary>
public int chargeMin;
/// <summary>
/// 两车充电间隔时间(ms)
/// </summary>
public long chargeInterval;
private bool _autoCharge;
public bool AutoCharge
{
set
{
_autoCharge = value;
Common.appConfig.AppSettings.Settings["AutoCharge"].Value = value.ToString();
Common.appConfig.Save();
}
get
{
return _autoCharge;
}
}
public ChargeStatus()
{
_autoCharge = Convert.ToBoolean(Common.appConfig.AppSettings.Settings["AutoCharge"].Value);
string s = Common.appConfig.AppSettings.Settings["ChargeThreshold"].Value;
string[] arr = s.Split(',');
chargeMin = Convert.ToInt32(arr[0]);
chargeMax = Convert.ToInt32(arr[1]);
chargeInterval = 0;
}
public void ClearRandomChargeInfo(Agv_Info agv)
{
if (Common.chargeStatus.charge3.Equals(agv.Name))
{
Common.chargeStatus.charge3 = "";
}
if (Common.chargeStatus.charge6.Equals(agv.Name))
{
Common.chargeStatus.charge6 = "";
}
}
}
/// <summary>
/// 4C待机位
/// </summary>
public struct StandbyStation
{
public string C4_Station1;
public string C4_Station2;
}
}