From 2ccddb56c26593e5fccf6bddb6e5bf87fe70acb3 Mon Sep 17 00:00:00 2001 From: yahaha Date: Fri, 11 Nov 2022 15:26:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81=E3=80=82?= =?UTF-8?q?=20=E5=A2=9E=E5=8A=A0=E6=9C=BA=E6=A2=B0=E8=87=82=E4=B8=8A?= =?UTF-8?q?=E4=B8=8B=E5=B7=A6=E5=8F=B3=E6=8E=A7=E5=88=B6=E3=80=82=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=AE=BE=E7=BD=AE=E6=9C=BA=E6=A2=B0=E8=87=82?= =?UTF-8?q?=E5=BD=93=E5=89=8D=E4=BD=8D=E7=BD=AE=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BPASmartClient.MorkF/Control_MorkF.cs | 234 ++++++++++++++---- BPASmartClient.MorkF/View/DebugView.xaml | 22 +- .../ViewModel/DebugViewModel.cs | 55 +++- 3 files changed, 257 insertions(+), 54 deletions(-) diff --git a/BPASmartClient.MorkF/Control_MorkF.cs b/BPASmartClient.MorkF/Control_MorkF.cs index 6bbdbbd5..ab657d51 100644 --- a/BPASmartClient.MorkF/Control_MorkF.cs +++ b/BPASmartClient.MorkF/Control_MorkF.cs @@ -32,6 +32,17 @@ namespace BPASmartClient.MorkF /// 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((list) => + { + if (list is bool startOrStop) + { + ArmRunUp(startOrStop); + } + }), "ArmRunUp"); + ActionManage.GetInstance.Register(new Action((list) => + { + if (list is bool startOrStop) + { + ArmRunDown(startOrStop); + } + }), "ArmRunDown"); + ActionManage.GetInstance.Register(new Action((list) => + { + if (list is bool startOrStop) + { + ArmRunLeft(startOrStop); + } + }), "ArmRunLeft"); + ActionManage.GetInstance.Register(new Action((list) => + { + if (list is bool startOrStop) + { + ArmRunRight(startOrStop); + } + }), "ArmRunRight"); + ActionManage.GetInstance.Register(new Action((list) => + { + ThreadManage.GetInstance().Start(new Action(() => + { + if (list is List 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 /// /// /// - 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); } /// /// 菜品库初始化 /// - public void FoodLibInit(int num = 2) + public void FoodLibInit() { - MaterailLibrary_Write("M0.2", true, num); + MaterailLibrary_Write("M0.2", true); } /// /// 电磁阀启停 /// /// 电磁阀启停:true:启动。false:停止。 - public void Electromagnetism(object o,int num = 2) + public void Electromagnetism(object o) { if (o == null) return; if (o is List 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); } /// @@ -707,20 +768,20 @@ namespace BPASmartClient.MorkF /// /// /// - 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; } + /// + /// 设定机械臂的当前坐标 + /// + /// + /// + 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); + } + + /// + /// 机械臂向上移动开关 + /// + /// true:开启,false:关闭 + public void ArmRunUp(bool startOrStop) + { + MaterailLibrary_Write("M5.3", startOrStop); + Thread.Sleep(200); + } + + /// + /// 机械臂向下移动开关 + /// + /// true:开启,false:关闭 + public void ArmRunDown(bool startOrStop) + { + MaterailLibrary_Write("M5.4", startOrStop); + Thread.Sleep(200); + } + + /// + /// 机械臂向左移动开关 + /// + /// true:开启,false:关闭 + public void ArmRunLeft(bool startOrStop) + { + MaterailLibrary_Write("M5.5", startOrStop); + Thread.Sleep(200); + } + + /// + /// 机械臂向右移动开关 + /// + /// true:开启,false:关闭 + public void ArmRunRight(bool startOrStop) + { + MaterailLibrary_Write("M5.6", startOrStop); + Thread.Sleep(200); + } + //菜品库锁 object lock_Materail = new object(); - private const int up = 10000; - /// - /// 获取菜品 + /// 取菜操作 /// - public void GetMaterail(int x,int y) + /// 取菜x轴坐标 + /// 取菜y轴坐标 + /// + 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 { true }); - Thread.Sleep(500); + //设置到传感器感应的距离处 + if(!SetArmPosition(x+ laserHigh, y )) + { + return; + } + + ////关闭电磁阀 + //Electromagnetism(new List { true }); + //Thread.Sleep(500); //爪子去1号位抓菜 if (!GetDistance_1()) { return; } - Thread.Sleep(500); - //移动前开启电磁阀 - Electromagnetism(new List { false }); - Thread.Sleep(500); + //设置到该层菜品库最高处 + if (!SetArmPosition(x + materialHigh, y)) + { + return; + } + + ////移动前开启电磁阀 + //Electromagnetism(new List { 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 { 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基本操作方法 /// /// 炒锅写寄存器方法,num为炒锅对应编号,从0开始 @@ -1178,7 +1311,6 @@ namespace BPASmartClient.MorkF #endregion - bool isInitialArrive = false; bool isInitialPaw = false; diff --git a/BPASmartClient.MorkF/View/DebugView.xaml b/BPASmartClient.MorkF/View/DebugView.xaml index 63e9fecd..63ad05c5 100644 --- a/BPASmartClient.MorkF/View/DebugView.xaml +++ b/BPASmartClient.MorkF/View/DebugView.xaml @@ -22,7 +22,7 @@ - + @@ -65,6 +65,8 @@ + + @@ -94,13 +96,29 @@ + diff --git a/BPASmartClient.MorkF/ViewModel/DebugViewModel.cs b/BPASmartClient.MorkF/ViewModel/DebugViewModel.cs index 7f44ff3b..091de4ac 100644 --- a/BPASmartClient.MorkF/ViewModel/DebugViewModel.cs +++ b/BPASmartClient.MorkF/ViewModel/DebugViewModel.cs @@ -50,6 +50,11 @@ namespace BPASmartClient.MorkF.ViewModel public int SettingY { get { return _settingY; } set { _settingY = value; OnPropertyChanged(); } } private int _settingY = 0; + public int SettingNowX { get { return _settingNowX; } set { _settingNowX = value; OnPropertyChanged(); } } + private int _settingNowX = 0; + public int SettingNowY { get { return _settingNowY; } set { _settingNowY = value; OnPropertyChanged(); } } + private int _settingNowY = 0; + public int MoveSpeed { get { return _moveSpeed; } set { _moveSpeed = value; OnPropertyChanged(); } } private int _moveSpeed; public string SensingDistance_1 { get { return _sensingDistance_1; } set { _sensingDistance_1 = value; OnPropertyChanged(); } } @@ -65,7 +70,21 @@ namespace BPASmartClient.MorkF.ViewModel public bool PawPositon3 { get { return _pawPositon3; } set { _pawPositon3 = value; OnPropertyChanged(); } } private bool _pawPositon3; + public bool ArmRunUp { get { return _armRunUp; } set { _armRunUp = value; OnPropertyChanged(); } } + private bool _armRunUp; + public bool ArmRunDown { get { return _armRunDown; } set { _armRunDown = value; OnPropertyChanged(); } } + private bool _armRunDown; + public bool ArmRunLeft { get { return _armRunLeft; } set { _armRunLeft = value; OnPropertyChanged(); } } + private bool _armRunLeft; + public bool ArmRunRight { get { return _armRunRight; } set { _armRunRight = value; OnPropertyChanged(); } } + private bool _armRunRight; + public bool ArmRunEnable { get { return _ArmRunEnable; } set { _ArmRunEnable = value; OnPropertyChanged(); } } + private bool _ArmRunEnable = true; + + public string ArmButtonName { get { return _ArmButtonName; } set { _ArmButtonName = value; OnPropertyChanged(); } } + private string _ArmButtonName = "启动"; + public RelayCommand SetNowPosition { get; set; }//设置机械臂当前坐标 public RelayCommand FoodLibInit { get; set; }//初始化 public RelayCommand StartElectromagnetism { get; set; }//电磁阀启动 public RelayCommand StopElectromagnetism { get; set; } @@ -76,9 +95,10 @@ namespace BPASmartClient.MorkF.ViewModel public RelayCommand PawTurnFront { get; set; }//夹爪正转 public RelayCommand PawTurnBack { get; set; }//夹爪反转 public RelayCommand SetArmPosition { get; set; }//机器臂位置设定 + public RelayCommand ArmRun { get; set; }//机械臂运动 #endregion - + #region 配料仓控制 public List PassageWays { get; set; } = new List() @@ -195,6 +215,39 @@ namespace BPASmartClient.MorkF.ViewModel PawTurnFront = new RelayCommand(() => { ActionManage.GetInstance.Send("PawTurnFront"); });//夹爪正转 PawTurnBack = new RelayCommand(() => { ActionManage.GetInstance.Send("PawTurnBack"); });//夹爪反转 SetArmPosition = new RelayCommand(() => { ActionManage.GetInstance.Send("SetArmPosition", new List { SettingX, SettingY }); });//设定机械臂位置 + SetNowPosition = new RelayCommand(() => { ActionManage.GetInstance.Send("SetNowPosition", new List { SettingX, SettingY }); });//设定机械臂当前位置 + ArmRun = new RelayCommand(() => { + //判断是否都未点击 + if(!ArmRunDown&&!ArmRunUp&&!ArmRunLeft&&!ArmRunRight) + { + return; + } + ArmRunEnable = !ArmRunEnable; + if(ArmRunEnable) + { + ArmButtonName = "启动"; + } + else + { + ArmButtonName = "停止"; + } + if(ArmRunUp) + { + ActionManage.GetInstance.Send("ArmRunUp", !ArmRunEnable); + } + else if(ArmRunDown) + { + ActionManage.GetInstance.Send("ArmRunDown", !ArmRunEnable); + } + else if (ArmRunLeft) + { + ActionManage.GetInstance.Send("ArmRunLeft", !ArmRunEnable); + } + else if(ArmRunRight) + { + ActionManage.GetInstance.Send("ArmRunRight", !ArmRunEnable); + } + });//设定机械臂位置 #endregion #region 配料仓控制