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#

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