Browse Source

整理代码。

增加机械臂上下左右控制。
增加设置机械臂当前位置。
样式分支
yahaha 2 years ago
parent
commit
2ccddb56c2
3 changed files with 257 additions and 54 deletions
  1. +183
    -51
      BPASmartClient.MorkF/Control_MorkF.cs
  2. +20
    -2
      BPASmartClient.MorkF/View/DebugView.xaml
  3. +54
    -1
      BPASmartClient.MorkF/ViewModel/DebugViewModel.cs

+ 183
- 51
BPASmartClient.MorkF/Control_MorkF.cs View File

@@ -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;


+ 20
- 2
BPASmartClient.MorkF/View/DebugView.xaml View File

@@ -22,7 +22,7 @@
<Grid.RowDefinitions>
<RowDefinition Height="81" ></RowDefinition>
<RowDefinition Height="81" ></RowDefinition>
<RowDefinition Height="285"></RowDefinition>
<RowDefinition Height="325"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<GroupBox Header="设备控制" FontSize="15" Foreground="Aqua" VerticalAlignment="Center" >
@@ -65,6 +65,8 @@
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<WrapPanel Orientation="Horizontal" >
<TextBlock Text="取料手臂实时位置" Margin="0,0,10,0"/>
@@ -94,13 +96,29 @@
<Button Content="感应器3测距" Margin="5,0" Command="{Binding GetDistance_3}"/>
<TextBox Text="{Binding SensingDistance_3}" Margin="5,0" Width="60" IsReadOnly="True"/>
</WrapPanel>
<WrapPanel Grid.Row="2" Orientation="Horizontal" >
<WrapPanel Grid.Row="2" Orientation="Horizontal" >
<TextBlock Text="设定手臂当前位置" Margin="0,0,10,0"/>
<TextBlock Text="X:" Margin="5,0"/>
<TextBox Text="{Binding SettingNowX}" Width="70" Margin="5,0" VerticalAlignment="Center" />
<TextBlock Text="Y:" Margin="5,0"/>
<TextBox Text="{Binding SettingNowY}" Width="70" Margin="5,0" VerticalAlignment="Center" />
<Button Content="设置" Margin="10,0,5,0" Command="{Binding SetNowPosition}"/>
</WrapPanel>
<WrapPanel Grid.Row="3" Orientation="Horizontal" >
<Button Content="夹爪正转" Command="{Binding PawTurnFront}" Margin="5,0" Cursor="Hand"/>
<Button Content="夹爪反转" Command="{Binding PawTurnBack}" Margin="5,0" Cursor="Hand"/>
<RadioButton Content="位置1" Margin="5,0" IsEnabled="True" IsChecked="{Binding PawPositon1}" Command="{Binding GetDistance_1}" GroupName="PawTurn"/>
<RadioButton Content="位置2" Margin="5,0" IsEnabled="True" IsChecked="{Binding PawPositon2}" Command="{Binding GetDistance_2}" GroupName="PawTurn"/>
<RadioButton Content="位置3" Margin="5,0 " IsEnabled="True" IsChecked="{Binding PawPositon3}" Command="{Binding GetDistance_3}" GroupName="PawTurn"/>
</WrapPanel>
<WrapPanel Grid.Row="4" Orientation="Horizontal" >
<RadioButton Content="上" Margin="5,0" IsEnabled="{Binding ArmRunEnable}" IsChecked="{Binding ArmRunUp}" Command="{Binding GetDistance_1}" GroupName="ArmRun"/>
<RadioButton Content="下" Margin="5,0" IsEnabled="{Binding ArmRunEnable}" IsChecked="{Binding ArmRunDown}" Command="{Binding GetDistance_2}" GroupName="ArmRun"/>
<RadioButton Content="左" Margin="5,0 " IsEnabled="{Binding ArmRunEnable}" IsChecked="{Binding ArmRunLeft}" Command="{Binding GetDistance_3}" GroupName="ArmRun"/>
<RadioButton Content="右" Margin="5,0 " IsEnabled="{Binding ArmRunEnable}" IsChecked="{Binding ArmRunRight}" Command="{Binding GetDistance_3}" GroupName="ArmRun"/>
<Button Content="{Binding ArmButtonName}" Command="{Binding ArmRun}" Margin="5,0" Cursor="Hand">
</Button>
</WrapPanel>
</Grid>

</GroupBox>


+ 54
- 1
BPASmartClient.MorkF/ViewModel/DebugViewModel.cs View File

@@ -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<string> PassageWays { get; set; } = new List<string>()
@@ -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<int> { SettingX, SettingY }); });//设定机械臂位置
SetNowPosition = new RelayCommand(() => { ActionManage.GetInstance.Send("SetNowPosition", new List<int> { 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 配料仓控制


Loading…
Cancel
Save