You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
223 lines
8.7 KiB
C#
223 lines
8.7 KiB
C#
using Newtonsoft.Json;
|
|
using Rs.Framework;
|
|
using Rs.Motion;
|
|
using Rs.MotionPlat.AuxiliaryEquipment;
|
|
using Rs.MotionPlat.Commom;
|
|
using Rs.MotionPlat.Flow.NgFlow;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Rs.MotionPlat.Flow.SubFlow
|
|
{
|
|
enum ELaserFlowStep
|
|
{
|
|
到测高穴位上方,
|
|
等待运动到测高穴位上方,
|
|
开始测高,
|
|
测高完成
|
|
}
|
|
/// <summary>
|
|
/// 镭射头到穴位上方
|
|
/// </summary>
|
|
public class LaserFlow
|
|
{
|
|
private ELaserFlowStep step;
|
|
string logInfo = string.Empty;
|
|
string alarmInfo = string.Empty;
|
|
bool finished = false;
|
|
ErrorCode errCode = ErrorCode.Ok;
|
|
/// <summary>
|
|
/// 测量点位
|
|
/// </summary>
|
|
int testPoint = 1;
|
|
TestHeightResult result = new TestHeightResult();
|
|
private LaserFlow() { }
|
|
private static LaserFlow instance;
|
|
public static LaserFlow Instance
|
|
{
|
|
get
|
|
{
|
|
if(instance==null)
|
|
instance = new LaserFlow();
|
|
return instance;
|
|
}
|
|
}
|
|
|
|
private void ResetResult()
|
|
{
|
|
result = new TestHeightResult();
|
|
result.HasProduct = false;
|
|
result.TestHeight2 = 0.0;
|
|
result.TestHeight1 = 0.0;
|
|
}
|
|
/// <summary>
|
|
/// 到测高位测高
|
|
/// </summary>
|
|
/// <param name="trayType"></param>
|
|
/// <param name="slotIndex"></param>
|
|
public TestHeightResult HasProduct(ETrayType trayType,int slotIndex)
|
|
{
|
|
ResetResult();
|
|
SlotPoint targetSlot = new SlotPoint();
|
|
finished = false;
|
|
step = ELaserFlowStep.到测高穴位上方;
|
|
while (!finished)
|
|
{
|
|
if (MachineManage.Instance.MachineStatus == EMachineStatus.Stop)
|
|
{
|
|
Thread.Sleep(10);
|
|
continue;
|
|
}
|
|
switch (step)
|
|
{
|
|
case ELaserFlowStep.到测高穴位上方:
|
|
if(trayType== ETrayType.Turnover)
|
|
{
|
|
targetSlot = TrayPointManager.GetTurnoverTrayCheckHeighPoint(slotIndex);
|
|
}
|
|
else if(trayType== ETrayType.Test)
|
|
{
|
|
targetSlot = TrayPointManager.GetTestFixtureTrayCheckHeighPoint(slotIndex);
|
|
}
|
|
|
|
if (targetSlot != null)
|
|
{
|
|
if(testPoint==1)
|
|
{
|
|
errCode = AxisControl.TurnoverX.MovePos(targetSlot.X, GlobalVar.WholeSpeed);
|
|
}
|
|
else
|
|
{
|
|
if(trayType== ETrayType.Test)
|
|
{
|
|
errCode = AxisControl.TurnoverX.MovePos(targetSlot.X - GlobalVar.TestFixtureTrayTestHeightOffsetX, GlobalVar.WholeSpeed);
|
|
}
|
|
else if(trayType== ETrayType.Turnover)
|
|
{
|
|
errCode = AxisControl.TurnoverX.MovePos(targetSlot.X +GlobalVar.TurnoverTrayTestHeightOffsetX, GlobalVar.WholeSpeed);
|
|
}
|
|
}
|
|
if(errCode== ErrorCode.Ok || GlobalVar.VirtualAxis)
|
|
{
|
|
errCode = AxisControl.TurnoverY.MovePos(targetSlot.Y, GlobalVar.WholeSpeed);
|
|
if(errCode== ErrorCode.Ok || GlobalVar.VirtualAxis)
|
|
{
|
|
logInfo = GetClassName() + $"到{trayType}盘{slotIndex}号穴位的上方";
|
|
MessageQueue.Instance.Insert(logInfo);
|
|
step = ELaserFlowStep.等待运动到测高穴位上方;
|
|
}
|
|
else
|
|
{
|
|
MsgBox.ShowAxisAlarmDialog(AxisControl.TurnoverY, errCode);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
MsgBox.ShowAxisAlarmDialog(AxisControl.TurnoverX, errCode);
|
|
}
|
|
}
|
|
break;
|
|
case ELaserFlowStep.等待运动到测高穴位上方:
|
|
if (Ops.IsStop(AxisAlias.TurnoverX, AxisAlias.TurnoverY) || GlobalVar.VirtualAxis)
|
|
{
|
|
Thread.Sleep(500);
|
|
if (Ops.IsArrived(AxisAlias.TurnoverX) || GlobalVar.VirtualAxis)
|
|
{
|
|
if (Ops.IsArrived(AxisAlias.TurnoverY) || GlobalVar.VirtualAxis)
|
|
{
|
|
logInfo = GetClassName() + $"已运动到{trayType}盘{slotIndex}号穴位的上方";
|
|
MessageQueue.Instance.Insert(logInfo);
|
|
step = ELaserFlowStep.开始测高;
|
|
}
|
|
else
|
|
{
|
|
Msg.ShowQuestion($"{AxisAlias.TurnoverY}轴没有运动到位");
|
|
step = ELaserFlowStep.到测高穴位上方;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Msg.ShowQuestion($"{AxisAlias.TurnoverX}轴没有运动到位");
|
|
step = ELaserFlowStep.到测高穴位上方;
|
|
}
|
|
}
|
|
break;
|
|
|
|
case ELaserFlowStep.开始测高:
|
|
double heightVal = DeviceFactory.checkHeightDev.Read();
|
|
logInfo = GetClassName() + $"start test height:point{testPoint}:{heightVal}";
|
|
MessageQueue.Instance.Insert(logInfo);
|
|
if(testPoint==1)
|
|
{
|
|
result.TestHeight1 = heightVal;
|
|
testPoint++;
|
|
step = ELaserFlowStep.到测高穴位上方;
|
|
}
|
|
else
|
|
{
|
|
result.TestHeight2 = heightVal;
|
|
step = ELaserFlowStep.测高完成;
|
|
}
|
|
|
|
break;
|
|
case ELaserFlowStep.测高完成:
|
|
testPoint = 1;
|
|
result.CalcResult(trayType);
|
|
logInfo= GetClassName()+ JsonConvert.SerializeObject(result);
|
|
LogHelper.Debug(logInfo);
|
|
MessageQueue.Instance.Insert(GetClassName() + " Test Height Finished!");
|
|
finished = true;
|
|
break;
|
|
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
private string GetClassName()
|
|
{
|
|
return "LaserFlow-";
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 测高结果
|
|
/// </summary>
|
|
public class TestHeightResult
|
|
{
|
|
/// <summary>
|
|
/// 是否有产品
|
|
/// </summary>
|
|
public bool HasProduct { get; set; }
|
|
/// <summary>
|
|
/// 测量高度1
|
|
/// </summary>
|
|
public double TestHeight1 { get; set; }
|
|
/// <summary>
|
|
/// 测量高度2
|
|
/// </summary>
|
|
public double TestHeight2 { get; set;}
|
|
|
|
/// <summary>
|
|
/// 计算测高结果
|
|
/// </summary>
|
|
public void CalcResult(ETrayType trayType)
|
|
{
|
|
if (trayType == ETrayType.Test)
|
|
{
|
|
//HasProduct = Math.Abs(Math.Abs(TestHeight1 - TestHeight2) - GlobalVar.TestFixtureTrayOffsetHeight)>0.6;
|
|
HasProduct = TestHeight1 - TestHeight2 < GlobalVar.TestFixtureTrayOffsetHeight - 0.3;
|
|
}
|
|
else if (trayType == ETrayType.Turnover)
|
|
{
|
|
//HasProduct = Math.Abs((Math.Abs(TestHeight1 - TestHeight2) - GlobalVar.TurnoverTrayOffsetHeight))>0.6;
|
|
HasProduct = TestHeight1 - TestHeight2 < GlobalVar.TurnoverTrayOffsetHeight - 0.3;
|
|
}
|
|
}
|
|
}
|
|
}
|