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.
263 lines
11 KiB
C#
263 lines
11 KiB
C#
using Newtonsoft.Json;
|
|
using Rs.Framework;
|
|
using Rs.Motion;
|
|
using Rs.MotionPlat.AuxiliaryEquipment;
|
|
using Rs.MotionPlat.Commom;
|
|
using Rs.MotionPlat.Entitys;
|
|
using Rs.MotionPlat.Flow.Common;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using static Rs.MotionPlat.Commom.SchedulingMessageBox;
|
|
|
|
namespace Rs.MotionPlat.Flow.SubFlow
|
|
{
|
|
enum ELaserFlowStep
|
|
{
|
|
到测高穴位上方1,
|
|
等待运动到测高穴位上方1,
|
|
开始测高1,
|
|
到测高穴位上方2,
|
|
等待运动到测高穴位上方2,
|
|
开始测高2,
|
|
测高完成
|
|
}
|
|
/// <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.到测高穴位上方1;
|
|
TargetPosition targetPosition= new TargetPosition();
|
|
AlarmEntity alarmEntity = null;
|
|
while (!finished)
|
|
{
|
|
if (MachineManage.Instance.MachineStatus == EMachineStatus.Stop)
|
|
{
|
|
Thread.Sleep(10);
|
|
continue;
|
|
}
|
|
switch (step)
|
|
{
|
|
case ELaserFlowStep.到测高穴位上方1:
|
|
if(trayType== ETrayType.Turnover)
|
|
{
|
|
targetSlot = TrayPointManager.GetTurnoverTrayCheckHeighPoint(slotIndex);
|
|
}
|
|
else if(trayType== ETrayType.Test)
|
|
{
|
|
targetSlot = TrayPointManager.GetTestFixtureTrayCheckHeighPoint(slotIndex);
|
|
}
|
|
|
|
if (targetSlot != null)
|
|
{
|
|
targetPosition.X=targetSlot.X;
|
|
targetPosition.Y=targetSlot.Y;
|
|
errCode = AxisControl.TurnoverY.MovePos(targetPosition.Y, GlobalVar.WholeSpeed);
|
|
if (errCode == ErrorCode.Ok || GlobalVar.VirtualAxis)
|
|
{
|
|
logInfo = GetClassName() + $"到{trayType}盘{slotIndex}号穴位的上方1";
|
|
MessageQueue.Instance.Insert(logInfo);
|
|
step = ELaserFlowStep.等待运动到测高穴位上方1;
|
|
}
|
|
else
|
|
{
|
|
//PromptMessageBox.ShowAxisAlarmDialog(AxisControl.TurnoverY, errCode);
|
|
alarmEntity = AlarmCollection.Get(AlarmConstID.TurnoverY运动异常).Transform(errCode.ToString());
|
|
AlarmMessageBox.ShowDialog(alarmEntity, ETipButton.Ok, null);
|
|
}
|
|
}
|
|
break;
|
|
case ELaserFlowStep.等待运动到测高穴位上方1:
|
|
if (Ops.IsStop(AxisAlias.TurnoverX, AxisAlias.TurnoverY) || GlobalVar.VirtualAxis)
|
|
{
|
|
if(AxisArrived.TurnoverYIsInTargetPos(targetPosition.Y) || GlobalVar.VirtualAxis)
|
|
{
|
|
logInfo = GetClassName() + $"已运动到{trayType}盘{slotIndex}号穴位的上方1";
|
|
MessageQueue.Instance.Insert(logInfo);
|
|
step = ELaserFlowStep.开始测高1;
|
|
}
|
|
else
|
|
{
|
|
step = ELaserFlowStep.到测高穴位上方1;
|
|
}
|
|
}
|
|
break;
|
|
|
|
case ELaserFlowStep.开始测高1:
|
|
result.TestHeight1 = DeviceFactory.checkHeightDev.Read();
|
|
logInfo = GetClassName() + $"start test height:point1:{result.TestHeight1}";
|
|
MessageQueue.Instance.Insert(logInfo);
|
|
step = ELaserFlowStep.到测高穴位上方2;
|
|
break;
|
|
case ELaserFlowStep.到测高穴位上方2:
|
|
if (trayType == ETrayType.Turnover)
|
|
{
|
|
targetSlot = TrayPointManager.GetTurnoverTrayCheckHeighPoint(slotIndex);
|
|
}
|
|
else if (trayType == ETrayType.Test)
|
|
{
|
|
targetSlot = TrayPointManager.GetTestFixtureTrayCheckHeighPoint(slotIndex);
|
|
}
|
|
|
|
if (targetSlot != null)
|
|
{
|
|
if (trayType == ETrayType.Test)
|
|
{
|
|
targetPosition.X = targetSlot.X - GlobalVar.TestFixtureTrayTestHeightOffsetX;
|
|
}
|
|
else if (trayType == ETrayType.Turnover)
|
|
{
|
|
targetPosition.X = targetSlot.X + GlobalVar.TurnoverTrayTestHeightOffsetX;
|
|
}
|
|
targetPosition.Y = targetSlot.Y;
|
|
errCode = AxisControl.TurnoverY.MovePos(targetPosition.Y, GlobalVar.WholeSpeed);
|
|
if (errCode == ErrorCode.Ok || GlobalVar.VirtualAxis)
|
|
{
|
|
logInfo = GetClassName() + $"到{trayType}盘{slotIndex}号穴位的上方2";
|
|
MessageQueue.Instance.Insert(logInfo);
|
|
step = ELaserFlowStep.等待运动到测高穴位上方2;
|
|
}
|
|
else
|
|
{
|
|
//PromptMessageBox.ShowAxisAlarmDialog(AxisControl.TurnoverY, errCode);
|
|
alarmEntity = AlarmCollection.Get(AlarmConstID.TurnoverY运动异常).Transform(errCode.ToString());
|
|
AlarmMessageBox.ShowDialog(alarmEntity, ETipButton.Ok, null);
|
|
}
|
|
}
|
|
break;
|
|
case ELaserFlowStep.等待运动到测高穴位上方2:
|
|
if (Ops.IsStop(AxisAlias.TurnoverX, AxisAlias.TurnoverY) || GlobalVar.VirtualAxis)
|
|
{
|
|
if(AxisArrived.TurnoverYIsInTargetPos(targetPosition.Y) || GlobalVar.VirtualAxis)
|
|
{
|
|
logInfo = GetClassName() + $"已运动到{trayType}盘{slotIndex}号穴位的上方2";
|
|
MessageQueue.Instance.Insert(logInfo);
|
|
step = ELaserFlowStep.开始测高2;
|
|
}
|
|
else
|
|
{
|
|
step = ELaserFlowStep.到测高穴位上方2;
|
|
}
|
|
}
|
|
break;
|
|
|
|
case ELaserFlowStep.开始测高2:
|
|
result.TestHeight2 = DeviceFactory.checkHeightDev.Read();
|
|
logInfo = GetClassName() + $"start test height:point2:{result.TestHeight2}";
|
|
MessageQueue.Instance.Insert(logInfo);
|
|
step = ELaserFlowStep.测高完成;
|
|
break;
|
|
case ELaserFlowStep.测高完成:
|
|
result.CalcResult(trayType);
|
|
logInfo= GetClassName()+ JsonConvert.SerializeObject(result);
|
|
//LogHelper.Debug(logInfo);
|
|
MessageQueue.Instance.Insert(GetClassName() + $"测高完成!{logInfo}");
|
|
finished = true;
|
|
break;
|
|
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
private string GetClassName()
|
|
{
|
|
return "LaserFlow-";
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 测高结果
|
|
/// </summary>
|
|
public class TestHeightResult
|
|
{
|
|
/// <summary>
|
|
/// 是否有产品
|
|
/// </summary>
|
|
public bool HasProduct { get; set; }
|
|
/// <summary>
|
|
/// 产品个数
|
|
/// </summary>
|
|
public int ProductCount { 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;
|
|
//HasProduct = (TestHeight1 - TestHeight2) > GlobalVar.SocketOneProductHeightMax;
|
|
//if(HasProduct)
|
|
//{
|
|
// ProductCount = ((TestHeight1 - TestHeight2) < GlobalVar.SocketOneProductHeightMin) ? 2 : 1;
|
|
//}
|
|
}
|
|
else if (trayType == ETrayType.Turnover)
|
|
{
|
|
//HasProduct = Math.Abs((Math.Abs(TestHeight1 - TestHeight2) - GlobalVar.TurnoverTrayOffsetHeight))>0.6;
|
|
HasProduct = TestHeight1 - TestHeight2 < GlobalVar.TurnoverTrayOffsetHeight - 0.3;
|
|
//HasProduct = (TestHeight1 - TestHeight2) > GlobalVar.TurnoverOneProductHeightMax;
|
|
//if (HasProduct)
|
|
//{
|
|
// ProductCount = ((TestHeight1 - TestHeight2) < GlobalVar.TurnoverTrayHaveOrNotGrayMin) ? 2 : 1;
|
|
//}
|
|
}
|
|
}
|
|
}
|
|
}
|