AgvControl.cs
7.0 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
using DeviceLibrary;
using DL.StandardRobot;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AutoScanAndLabel.UC
{
public partial class AgvControl : UserControl
{
public string serverIp = "";
public AgvControl()
{
InitializeComponent();
serverIp = ConfigAppSettings.GetValue(Setting_Init.STD_IP);
AGVManager.Connect(serverIp);
load();
groupBox2.Text = $"AGV状态[{serverIp}]";
AGVManager.Register(MissionStateChanged);
endit(false);
}
~AgvControl()
{
AGVManager.UnRegister(MissionStateChanged);
AGVManager.Close();
}
private void load()
{
txtEnterId.Text=ConfigAppSettings.GetValue(Setting_Init.ShelfInAGV);
txtLeaveId.Text = ConfigAppSettings.GetValue(Setting_Init.ShelfOutAGV);
txtMoveLSTId.Text = ConfigAppSettings.GetValue(Setting_Init.LStation);
txtMoveRSTId.Text = ConfigAppSettings.GetValue(Setting_Init.RStation);
}
private void save()
{
ConfigAppSettings.SaveValue(Setting_Init.ShelfInAGV, txtEnterId.Text);
ConfigAppSettings.SaveValue(Setting_Init.ShelfOutAGV, txtLeaveId.Text);
ConfigAppSettings.SaveValue(Setting_Init.LStation, $"{txtMoveLSTId.Text}");
ConfigAppSettings.SaveValue(Setting_Init.RStation, $"{txtMoveRSTId.Text}");
}
private void MissionStateChanged(MissionState state)
{
if (!this.IsHandleCreated) return;
this.Invoke(new Action(() =>
{
try
{
lblCurMissionId.Text = $"当前任务编号:{state.MissionId}";
lblCurRunMissionId.Text = $"运行任务编号:{state.RunMissionId}";
lblMissionRunstate.Text = $"任务运行状态:{state.MissionRunState}";
lblMissionResult.Text = $"任务运行结果:{state.MissionResult}";
}
catch
{
}
}));
}
private void button_rightneedempty_Click(object sender, EventArgs e)
{
if (!RobotManage.isRunning)
{
MessageBox.Show("机器尚未启动不能呼叫Agv");
return;
}
if (RobotManage.mainMachine.IOValue(IO_Type.RightEnd_Check).Equals(IO_VALUE.LOW))
{
//请求AGV代码放这里
//等待agv到位
RobotManage.mainMachine.RightMoveInfo.NewMove(MoveStep.R40_InShelf);//等待agv到位后执行,启动进入
Task.Run(() =>
{
while (RobotManage.mainMachine.RightMoveInfo.MoveStep >= MoveStep.R40_InShelf)
{
Task.Delay(1000).Wait();
}
//通知agv上料结束, 也可以把上料结束的代码放到 R40_InShelf的结束步骤里去
});
}
else
MessageBox.Show("当前有料串不能请求进入料串");
}
private void button_rightleavefull_Click(object sender, EventArgs e)
{
if (!RobotManage.isRunning)
{
MessageBox.Show("机器尚未启动不能呼叫Agv");
return;
}
if (RobotManage.mainMachine.IOValue(IO_Type.RightEnd_Check).Equals(IO_VALUE.HIGH))
{
//请求AGV代码放这里
//等待agv到位
RobotManage.mainMachine.RightMoveInfo.NewMove(MoveStep.R30_OutShelf);//等待agv到位后执行,启动料串离开
Task.Run(() =>
{
while (RobotManage.mainMachine.RightMoveInfo.MoveStep >= MoveStep.R30_OutShelf)
{
Task.Delay(1000).Wait();
}
//通知agv上料结束, 也可以把上料结束的代码放到R30_OutShelf的结束步骤里去
});
}
else
MessageBox.Show("当前没有料串不能请求取料串");
}
private void button_Leftleavefull_Click(object sender, EventArgs e)
{
if (!RobotManage.isRunning)
{
MessageBox.Show("机器尚未启动不能呼叫Agv");
return;
}
if (RobotManage.mainMachine.IOValue(IO_Type.LeftEnd_Check).Equals(IO_VALUE.HIGH))
{
//请求AGV代码放这里
//等待agv到位
RobotManage.mainMachine.LeftMoveInfo.NewMove(MoveStep.L50_OutShelf);//等待agv到位后执行,启动料串离开
Task.Run(() =>
{
while (RobotManage.mainMachine.LeftMoveInfo.MoveStep >= MoveStep.L50_OutShelf)
{
Task.Delay(1000).Wait();
}
//通知agv上料结束, 也可以把上料结束的代码放到L50_OutShelf的结束步骤里去
});
}
else
MessageBox.Show("当前没有料串不能请求取料串");
}
private void button_leftneedempty_Click(object sender, EventArgs e)
{
if (!RobotManage.isRunning)
{
MessageBox.Show("机器尚未启动不能呼叫Agv");
return;
}
if (RobotManage.mainMachine.IOValue(IO_Type.LeftEnd_Check).Equals(IO_VALUE.LOW))
{
//请求AGV代码放这里
//等待agv到位
RobotManage.mainMachine.LeftMoveInfo.NewMove(MoveStep.L60_InShelf);//等待agv到位后执行,启动进入
Task.Run(() =>
{
while (RobotManage.mainMachine.LeftMoveInfo.MoveStep >= MoveStep.L60_InShelf)
{
Task.Delay(1000).Wait();
}
//通知agv上料结束, 也可以把上料结束的代码放到 L60_InShelf的结束步骤里去
});
}
else
MessageBox.Show("当前有料串不能请求进入料串");
}
private void btnSave_Click(object sender, EventArgs e)
{
save();
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
endit(checkBox1.Checked);
}
void endit(bool maul)
{
groupBox3.Enabled = maul;
}
private void button1_Click(object sender, EventArgs e)
{
int.TryParse(txtMissionId.Text,out int val);
AGVManager.AddMission(val);
}
}
}