MainMachine.cs
7.7 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
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace DeviceLibrary
{
public partial class MainMachine : IRobot
{
public string Name { get; set; } = "移载";
public bool canRunning { get; set; } = false;
public bool isBusy { get; set; } = false;
public bool isAlarm { get; set; } = false;
public RunStatus runStatus { get; set; } = RunStatus.Stop;
public Robot_Config config { get; set; }
public MoveInfo MoveInfo;
public AxisBean Take_Middle_Axis;
public AxisBean Take_UpDown_Axis;
public AxisBean Left_Batch_Axis;
public AxisBean Right_Batch_Axis;
public AxisBean Label_X_Axis;
public AxisBean Label_Y_Axis;
public AxisBean Label_Z_Axis;
public AxisBean Label_R_Axis;
/// <summary>
/// 开始运行的时间
/// </summary>
public DateTime StartTime { get; set; }
/// <summary>
/// 是否在急停中
/// </summary>
public bool isInSuddenDown = false;
public MainMachine(Robot_Config _config) {
config = _config;
Take_Middle_Axis = new AxisBean(config.Take_Middle_Axis, Name);
Take_UpDown_Axis = new AxisBean(config.Take_UpDown_Axis, Name);
Left_Batch_Axis = new AxisBean(config.Left_Batch_Axis, Name);
Right_Batch_Axis = new AxisBean(config.Right_Batch_Axis, Name);
Label_X_Axis = new AxisBean(config.Label_X_Axis, Name);
Label_Y_Axis = new AxisBean(config.Label_Y_Axis, Name);
Label_Z_Axis = new AxisBean(config.Label_Z_Axis, Name);
Label_R_Axis = new AxisBean(config.Label_R_Axis, Name);
}
public void Run() {
while (true) {
canRunning = DeviceCheck();
if (canRunning)
canRunning = SafeCheck();
Thread.Sleep(50);
if (!canRunning)
continue;
if (runStatus == RunStatus.Running)
{
WorkProcess();
}
else if (runStatus == RunStatus.HomeReset)
{
HomeReset();
}
}
}
public void BeginHomeReset() {
StopMove();
Thread.Sleep(500);
OpenAllServo();
alarmType = AlarmType.None;
runStatus = RunStatus.HomeReset;
MoveInfo.NextMoveStep(MoveStep.H01_HomeReset);
LogInfo(MoveInfo.MoveType + ": 开始回原 ");
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
}
void HomeReset()
{
if (CheckWait())
return;
switch (MoveInfo.MoveStep)
{
case MoveStep.H01_HomeReset:
MoveInfo.NextMoveStep(MoveStep.H02_HomeReset);
//MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
LogInfo(MoveInfo.MoveType + ":正在回原");
Take_Middle_Axis.HomeMove(MoveInfo);
Take_UpDown_Axis.HomeMove(MoveInfo);
Left_Batch_Axis.HomeMove(MoveInfo);
Right_Batch_Axis.HomeMove(MoveInfo);
break;
case MoveStep.H02_HomeReset:
MoveInfo.NextMoveStep(MoveStep.H03_HomeReset);
LogInfo(MoveInfo.moveStep + ":正在回原");
Label_Z_Axis.HomeMove(MoveInfo);
Take_Middle_Axis.AbsMove(MoveInfo, config.Take_Middle_P1, config.Take_Middle_P1_speed);
Take_UpDown_Axis.AbsMove(MoveInfo, config.Take_UpDown_P1, config.Take_UpDown_P1_speed);
Right_Batch_Axis.AbsMove(MoveInfo, config.Right_Batch_P1, config.Right_Batch_P1_speed);
Left_Batch_Axis.AbsMove(MoveInfo, config.Left_Batch_P1, config.Left_Batch_P1_speed);
break;
case MoveStep.H03_HomeReset:
MoveInfo.NextMoveStep(MoveStep.H04_HomeReset);
LogInfo(MoveInfo.moveStep + ":正在回原");
Label_Z_Axis.HomeMove(MoveInfo);
Label_X_Axis.HomeMove(MoveInfo);
Label_Y_Axis.HomeMove(MoveInfo);
Label_R_Axis.HomeMove(MoveInfo);
break;
case MoveStep.H04_HomeReset:
MoveInfo.NextMoveStep(MoveStep.H05_HomeReset);
LogInfo(MoveInfo.moveStep + ":正在回原");
Label_Z_Axis.AbsMove(MoveInfo, config.Label_Z_P1, config.Label_Z_P1_speed);
Label_X_Axis.AbsMove(MoveInfo, config.Label_X_P1, config.Label_X_P1_speed);
Label_Y_Axis.AbsMove(MoveInfo, config.Label_Y_P1, config.Label_Y_P1_speed);
Label_R_Axis.AbsMove(MoveInfo, config.Label_R_P1, config.Label_R_P1_speed);
break;
case MoveStep.H05_HomeReset:
MoveInfo.NextMoveStep(MoveStep.HEND_HomeReset);
LogInfo(MoveInfo.moveStep + ":正在回原 阻挡气缸判断");
if (IOManager.IOValue(IO_Type.LeftEnd_Check) == IO_VALUE.LOW)
{
CylinderMove(MoveInfo, IO_Type.LeftStopUP, IO_Type.LeftStopDown);
}
if (IOManager.IOValue(IO_Type.RightEnd_Check) == IO_VALUE.LOW)
{
CylinderMove(MoveInfo, IO_Type.RightStopUP, IO_Type.RightStopDown);
}
break;
case MoveStep.HEND_HomeReset:
LogInfo(MoveInfo.moveStep + ": 完成");
MoveEndProcess();
break;
}
}
bool SafeCheck() {
List<string> msglist = new List<string>();
if (IOValue(IO_Type.GratingSignal_Check).Equals(IO_VALUE.LOW))
{
msglist.Add("安全光栅被遮挡");
}
if (IOValue(IO_Type.HasNgBox).Equals(IO_VALUE.LOW))
{
msglist.Add("没有检测到NG料箱");
}
if (IOValue(IO_Type.HasPrinter).Equals(IO_VALUE.LOW))
{
msglist.Add("没有检测到NG料箱");
}
if (IOValue(IO_Type.LeftBackDoor_Check).Equals(IO_VALUE.LOW))
{
msglist.Add("左后门没有关闭");
}
if (IOValue(IO_Type.RightBackDoor_Check).Equals(IO_VALUE.LOW))
{
msglist.Add("右后门没有关闭");
}
return (msglist.Count == 0);
}
/// <summary>
/// 最后一次气压检测变为0的时间
/// </summary>
DateTime lastAirCloseTime = DateTime.MinValue;
bool DeviceCheck() {
List<string> msglist = new List<string>();
if (IOValue(IO_Type.SuddenStop_BTN).Equals(IO_VALUE.LOW))
{
msglist.Add("急停中");
}
if (IOValue(IO_Type.Airpressure_Check).Equals(IO_VALUE.LOW))
{
if (lastAirCloseTime == DateTime.MinValue)
lastAirCloseTime = DateTime.Now;
TimeSpan span = DateTime.Now - lastAirCloseTime;
if (span.TotalSeconds > RobotManage.Config.AirCheckSeconds)
{
msglist.Add("急停中");
}
}
else {
lastAirCloseTime = DateTime.MinValue;
}
return (msglist.Count == 0);
}
}
}