|
|
@@ -32,6 +32,17 @@ namespace BPASmartClient.MorkF |
|
|
|
/// </summary> |
|
|
|
private int count = 2; |
|
|
|
|
|
|
|
// |
|
|
|
private const int materialHigh = 40000; |
|
|
|
|
|
|
|
//炒锅1倒菜的xy坐标 |
|
|
|
private const int materialPutPositionXFry1 = -30000; |
|
|
|
private const int materialPutPositionYFry1 = -20000; |
|
|
|
|
|
|
|
//炒锅2倒菜的xy坐标 |
|
|
|
private const int materialPutPositionXFry2 = -30000; |
|
|
|
private const int materialPutPositionYFry2 = -20000; |
|
|
|
|
|
|
|
//当前炒锅,默认为1号炒锅 |
|
|
|
private int fryIndex = 0; |
|
|
|
|
|
|
@@ -170,6 +181,47 @@ namespace BPASmartClient.MorkF |
|
|
|
} |
|
|
|
}), "SetArmPosition"); |
|
|
|
}), "SetArmPosition"); |
|
|
|
ActionManage.GetInstance.Register(new Action<object>((list) => |
|
|
|
{ |
|
|
|
if (list is bool startOrStop) |
|
|
|
{ |
|
|
|
ArmRunUp(startOrStop); |
|
|
|
} |
|
|
|
}), "ArmRunUp"); |
|
|
|
ActionManage.GetInstance.Register(new Action<object>((list) => |
|
|
|
{ |
|
|
|
if (list is bool startOrStop) |
|
|
|
{ |
|
|
|
ArmRunDown(startOrStop); |
|
|
|
} |
|
|
|
}), "ArmRunDown"); |
|
|
|
ActionManage.GetInstance.Register(new Action<object>((list) => |
|
|
|
{ |
|
|
|
if (list is bool startOrStop) |
|
|
|
{ |
|
|
|
ArmRunLeft(startOrStop); |
|
|
|
} |
|
|
|
}), "ArmRunLeft"); |
|
|
|
ActionManage.GetInstance.Register(new Action<object>((list) => |
|
|
|
{ |
|
|
|
if (list is bool startOrStop) |
|
|
|
{ |
|
|
|
ArmRunRight(startOrStop); |
|
|
|
} |
|
|
|
}), "ArmRunRight"); |
|
|
|
ActionManage.GetInstance.Register(new Action<object>((list) => |
|
|
|
{ |
|
|
|
ThreadManage.GetInstance().Start(new Action(() => |
|
|
|
{ |
|
|
|
if (list is List<int> list_int) |
|
|
|
{ |
|
|
|
if (list_int.Count == 2) |
|
|
|
{ |
|
|
|
SetNowPosition(list_int[0], list_int[1]); |
|
|
|
} |
|
|
|
} |
|
|
|
}), "SetNowPosition"); |
|
|
|
}), "SetNowPosition"); |
|
|
|
#endregion |
|
|
|
//ActionManage.GetInstance.Register(PLCInite, "InitCommand"); |
|
|
|
#region 配料控制 |
|
|
@@ -622,33 +674,33 @@ namespace BPASmartClient.MorkF |
|
|
|
/// </summary> |
|
|
|
/// <param name="address"></param> |
|
|
|
/// <param name="value"></param> |
|
|
|
private void MaterailLibrary_Write(string address, object value,int num) |
|
|
|
private void MaterailLibrary_Write(string address, object value,int num = 2) |
|
|
|
{ |
|
|
|
WriteControlExact(address, value, num); |
|
|
|
} |
|
|
|
/// <summary> |
|
|
|
/// 菜品库初始化 |
|
|
|
/// </summary> |
|
|
|
public void FoodLibInit(int num = 2) |
|
|
|
public void FoodLibInit() |
|
|
|
{ |
|
|
|
MaterailLibrary_Write("M0.2", true, num); |
|
|
|
MaterailLibrary_Write("M0.2", true); |
|
|
|
} |
|
|
|
/// <summary> |
|
|
|
/// 电磁阀启停 |
|
|
|
/// </summary> |
|
|
|
/// <param name="o">电磁阀启停:true:启动。false:停止。</param> |
|
|
|
public void Electromagnetism(object o,int num = 2) |
|
|
|
public void Electromagnetism(object o) |
|
|
|
{ |
|
|
|
if (o == null) return; |
|
|
|
if (o is List<bool> bs && bs.Count == 1) |
|
|
|
{ |
|
|
|
MaterailLibrary_Write("M1.3", bs[0],num); |
|
|
|
MaterailLibrary_Write("M1.3", bs[0]); |
|
|
|
} |
|
|
|
} |
|
|
|
public bool GetDistance_1(int num = 2) |
|
|
|
public bool GetDistance_1() |
|
|
|
{ |
|
|
|
MessageLog.GetInstance.Show("爪子去到1号位"); |
|
|
|
MaterailLibrary_Write("M1.0", true, num); |
|
|
|
MaterailLibrary_Write("M1.0", true); |
|
|
|
for (int i = 0; i < sleepCount && !ml_morkf.PawArrivePortOne; i++) |
|
|
|
{ |
|
|
|
Thread.Sleep(sleepTime); |
|
|
@@ -658,13 +710,16 @@ namespace BPASmartClient.MorkF |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
Thread.Sleep(300); |
|
|
|
|
|
|
|
MessageLog.GetInstance.Show("爪子去到1号位完成"); |
|
|
|
return true; |
|
|
|
} |
|
|
|
public bool GetDistance_2(int num = 2) |
|
|
|
public bool GetDistance_2() |
|
|
|
{ |
|
|
|
MessageLog.GetInstance.Show("爪子去到2号位"); |
|
|
|
MaterailLibrary_Write("M1.1", true, num); |
|
|
|
MaterailLibrary_Write("M1.1", true); |
|
|
|
for (int i = 0; i < sleepCount && !ml_morkf.PawArrivePortTwo; i++) |
|
|
|
{ |
|
|
|
Thread.Sleep(sleepTime); |
|
|
@@ -674,13 +729,16 @@ namespace BPASmartClient.MorkF |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
Thread.Sleep(300); |
|
|
|
|
|
|
|
MessageLog.GetInstance.Show("爪子去到2号位完成"); |
|
|
|
return true; |
|
|
|
} |
|
|
|
public bool GetDistance_3(int num = 2) |
|
|
|
public bool GetDistance_3() |
|
|
|
{ |
|
|
|
MessageLog.GetInstance.Show("爪子去到3号位"); |
|
|
|
MaterailLibrary_Write("M1.2", true,num); |
|
|
|
MaterailLibrary_Write("M1.2", true); |
|
|
|
for (int i = 0; i < sleepCount && !ml_morkf.PawArrivePortThree; i++) |
|
|
|
{ |
|
|
|
Thread.Sleep(sleepTime); |
|
|
@@ -690,16 +748,19 @@ namespace BPASmartClient.MorkF |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
Thread.Sleep(300); |
|
|
|
|
|
|
|
MessageLog.GetInstance.Show("爪子去到3号位完成"); |
|
|
|
return true; |
|
|
|
} |
|
|
|
public void PawTurnFront(int num = 2) |
|
|
|
public void PawTurnFront() |
|
|
|
{ |
|
|
|
MaterailLibrary_Write("", true, num); |
|
|
|
MaterailLibrary_Write("", true); |
|
|
|
} |
|
|
|
public void PawTurnBack(int num = 2) |
|
|
|
public void PawTurnBack() |
|
|
|
{ |
|
|
|
MaterailLibrary_Write("", true, num); |
|
|
|
MaterailLibrary_Write("", true); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
@@ -707,20 +768,20 @@ namespace BPASmartClient.MorkF |
|
|
|
/// </summary> |
|
|
|
/// <param name="x"></param> |
|
|
|
/// <param name="y"></param> |
|
|
|
public bool SetArmPosition(int x, int y, int num = 2) |
|
|
|
public bool SetArmPosition(int x, int y) |
|
|
|
{ |
|
|
|
//取反 |
|
|
|
x -= 2 * x; |
|
|
|
y -= 2 * y; |
|
|
|
MaterailLibrary_Write("VD836", x, num); |
|
|
|
MaterailLibrary_Write("VD836", x); |
|
|
|
Thread.Sleep(100); |
|
|
|
MaterailLibrary_Write("VD840", y, num); |
|
|
|
MaterailLibrary_Write("VD840", y); |
|
|
|
|
|
|
|
Thread.Sleep(200); |
|
|
|
|
|
|
|
MessageLog.GetInstance.Show($"机械臂移动到[{x},{y}]"); |
|
|
|
//定位启动 |
|
|
|
MaterailLibrary_Write("M0.0", true, num); |
|
|
|
MaterailLibrary_Write("M0.0", true); |
|
|
|
|
|
|
|
for (int i = 0; i < sleepCount && !ml_morkf.ArriveComplete; i++) |
|
|
|
{ |
|
|
@@ -739,15 +800,73 @@ namespace BPASmartClient.MorkF |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// 设定机械臂的当前坐标 |
|
|
|
/// </summary> |
|
|
|
/// <param name="x"></param> |
|
|
|
/// <param name="y"></param> |
|
|
|
public void SetNowPosition(int x, int y) |
|
|
|
{ |
|
|
|
//取反 |
|
|
|
x -= 2 * x; |
|
|
|
y -= 2 * y; |
|
|
|
MessageLog.GetInstance.Show($"设置机械臂当前坐标为[{x},{y}]"); |
|
|
|
MaterailLibrary_Write("VD828", x); |
|
|
|
Thread.Sleep(200); |
|
|
|
MaterailLibrary_Write("VD832", y); |
|
|
|
Thread.Sleep(200); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// 机械臂向上移动开关 |
|
|
|
/// </summary> |
|
|
|
/// <param name="startOrStop">true:开启,false:关闭</param> |
|
|
|
public void ArmRunUp(bool startOrStop) |
|
|
|
{ |
|
|
|
MaterailLibrary_Write("M5.3", startOrStop); |
|
|
|
Thread.Sleep(200); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// 机械臂向下移动开关 |
|
|
|
/// </summary> |
|
|
|
/// <param name="startOrStop">true:开启,false:关闭</param> |
|
|
|
public void ArmRunDown(bool startOrStop) |
|
|
|
{ |
|
|
|
MaterailLibrary_Write("M5.4", startOrStop); |
|
|
|
Thread.Sleep(200); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// 机械臂向左移动开关 |
|
|
|
/// </summary> |
|
|
|
/// <param name="startOrStop">true:开启,false:关闭</param> |
|
|
|
public void ArmRunLeft(bool startOrStop) |
|
|
|
{ |
|
|
|
MaterailLibrary_Write("M5.5", startOrStop); |
|
|
|
Thread.Sleep(200); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// 机械臂向右移动开关 |
|
|
|
/// </summary> |
|
|
|
/// <param name="startOrStop">true:开启,false:关闭</param> |
|
|
|
public void ArmRunRight(bool startOrStop) |
|
|
|
{ |
|
|
|
MaterailLibrary_Write("M5.6", startOrStop); |
|
|
|
Thread.Sleep(200); |
|
|
|
} |
|
|
|
|
|
|
|
//菜品库锁 |
|
|
|
object lock_Materail = new object(); |
|
|
|
|
|
|
|
private const int up = 10000; |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// 获取菜品 |
|
|
|
/// 取菜操作 |
|
|
|
/// </summary> |
|
|
|
public void GetMaterail(int x,int y) |
|
|
|
/// <param name="x">取菜x轴坐标</param> |
|
|
|
/// <param name="y">取菜y轴坐标</param> |
|
|
|
/// <param name="fryNum"></param> |
|
|
|
public void GetMaterail(int x,int y,int fryNum = 0) |
|
|
|
{ |
|
|
|
//设置到抓菜处 |
|
|
|
if(!SetArmPosition(x, y)) |
|
|
@@ -755,36 +874,65 @@ namespace BPASmartClient.MorkF |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
//Thread.Sleep(2000); |
|
|
|
//获取传感器的距离 |
|
|
|
int laserHigh = ml_morkf.LaserDistance; |
|
|
|
|
|
|
|
//关闭电磁阀 |
|
|
|
Electromagnetism(new List<bool> { true }); |
|
|
|
Thread.Sleep(500); |
|
|
|
//设置到传感器感应的距离处 |
|
|
|
if(!SetArmPosition(x+ laserHigh, y )) |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
////关闭电磁阀 |
|
|
|
//Electromagnetism(new List<bool> { true }); |
|
|
|
//Thread.Sleep(500); |
|
|
|
|
|
|
|
//爪子去1号位抓菜 |
|
|
|
if (!GetDistance_1()) |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
Thread.Sleep(500); |
|
|
|
|
|
|
|
//移动前开启电磁阀 |
|
|
|
Electromagnetism(new List<bool> { false }); |
|
|
|
Thread.Sleep(500); |
|
|
|
//设置到该层菜品库最高处 |
|
|
|
if (!SetArmPosition(x + materialHigh, y)) |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
////移动前开启电磁阀 |
|
|
|
//Electromagnetism(new List<bool> { false }); |
|
|
|
//Thread.Sleep(500); |
|
|
|
|
|
|
|
//设置到出菜处,都在x轴-40000处出菜 |
|
|
|
if (!SetArmPosition(-40000, y)) |
|
|
|
//爪子去2号位放菜 |
|
|
|
if (!GetDistance_2()) |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
Thread.Sleep(500); |
|
|
|
//根据炒锅不同设置不同的出菜处 |
|
|
|
if (fryNum == 0) |
|
|
|
{ |
|
|
|
//设置到炒锅1出菜处 |
|
|
|
if (!SetArmPosition(materialPutPositionXFry1, materialPutPositionYFry1)) |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
//设置到炒锅2出菜处 |
|
|
|
if (!SetArmPosition(materialPutPositionXFry1, materialPutPositionYFry1)) |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//爪子去3号位放菜 |
|
|
|
if (!GetDistance_3()) |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
Thread.Sleep(500); |
|
|
|
|
|
|
|
////关闭电磁阀 |
|
|
|
//Electromagnetism(new List<bool> { false }); |
|
|
|
//Thread.Sleep(300); |
|
|
@@ -836,23 +984,9 @@ namespace BPASmartClient.MorkF |
|
|
|
{ |
|
|
|
ml_morkf.MaterailIsWorking = true; |
|
|
|
} |
|
|
|
//菜品库去指定位置 |
|
|
|
if (!SetArmPosition(x1, y)) |
|
|
|
{ |
|
|
|
MessageLog.GetInstance.Show("菜品库[机械臂操作失败]"); |
|
|
|
return; |
|
|
|
} |
|
|
|
//取菜操作 |
|
|
|
GetMaterail(x2,y); |
|
|
|
|
|
|
|
|
|
|
|
//机械臂去取菜放位 |
|
|
|
if (!SetArmPosition(-30000, -20000)) |
|
|
|
{ |
|
|
|
MessageLog.GetInstance.Show("菜品库[机械臂操作失败]"); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
//机械臂回原点 |
|
|
|
if (!SetArmPosition(0, 0)) |
|
|
|
{ |
|
|
@@ -876,7 +1010,6 @@ namespace BPASmartClient.MorkF |
|
|
|
} |
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
|
|
#region 炒锅PLC基本操作方法 |
|
|
|
/// <summary> |
|
|
|
/// 炒锅写寄存器方法,num为炒锅对应编号,从0开始 |
|
|
@@ -1178,7 +1311,6 @@ namespace BPASmartClient.MorkF |
|
|
|
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
|
|
bool isInitialArrive = false; |
|
|
|
|
|
|
|
bool isInitialPaw = false; |
|
|
|