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.
181 lines
6.8 KiB
C#
181 lines
6.8 KiB
C#
using HalconDotNet;
|
|
using Rs.Controls;
|
|
using Rs.Framework;
|
|
using Rs.Motion;
|
|
using Rs.MotionPlat.Commom;
|
|
using Rs.MotionPlat.Entitys;
|
|
using Rs.MotionPlat.Flow.Camera;
|
|
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 EUpCameraCheckFlowStep
|
|
{
|
|
到拍照位上方,
|
|
等待运动到拍照位上方
|
|
}
|
|
|
|
public enum ECheckType
|
|
{
|
|
/// <summary>
|
|
/// 定位检测
|
|
/// </summary>
|
|
Location,
|
|
/// <summary>
|
|
/// 有无判断
|
|
/// </summary>
|
|
HaveOrNot
|
|
}
|
|
/// <summary>
|
|
/// 上相机检测流程
|
|
/// </summary>
|
|
public class UpCameraCheckFlow
|
|
{
|
|
|
|
public event Action<SlotProductHasOrNotResult> OnStockTrayHasOrNotResult;
|
|
public event Action<SlotProductHasOrNotResult> OnTurnTrayHasOrNotResult;
|
|
|
|
string logInfo = string.Empty;
|
|
bool finished = false;
|
|
EUpCameraCheckFlowStep step = EUpCameraCheckFlowStep.到拍照位上方;
|
|
TraySlot slot = new TraySlot();
|
|
SlotPoint curSlotPoint = new SlotPoint();
|
|
ErrorCode errCode = ErrorCode.Ok;
|
|
private UpCameraCheckFlow() { }
|
|
private static UpCameraCheckFlow instance;
|
|
public static UpCameraCheckFlow Instance
|
|
{
|
|
get
|
|
{
|
|
if(instance==null)
|
|
instance = new UpCameraCheckFlow();
|
|
return instance;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 检测周转盘的产品是否放好
|
|
/// </summary>
|
|
/// <param name="slotIndex"></param>
|
|
/// <returns></returns>
|
|
public bool CheckTurnoverTrayDumpOK(int slotIndex=0,bool isNeedMove=false)
|
|
{
|
|
if(isNeedMove)
|
|
{
|
|
Go(ETrayType.Turnover, slotIndex);
|
|
}
|
|
int result = 0;// VisionManager.TurnoverTrayDumpProductOK();
|
|
if (result == 1)
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 检测周转盘是否有产品
|
|
/// </summary>
|
|
/// <param name="slotIndex"></param>
|
|
/// <returns></returns>
|
|
public SlotProductHasOrNotResult CheckTurnoverTrayHasProduct(Action<HObject> checkFinishedEvent,int slotIndex=1,bool needGo=true)
|
|
{
|
|
if (needGo)
|
|
Go(ETrayType.Turnover, slotIndex);
|
|
SlotProductHasOrNotResult result= VisionManager.TurnoverTrayHasProduct(checkFinishedEvent);
|
|
OnTurnTrayHasOrNotResult?.Invoke(result);
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 检测料仓料盘是否有产品
|
|
/// </summary>
|
|
/// <param name="slotIndex"></param>
|
|
/// <returns></returns>
|
|
public SlotProductHasOrNotResult CheckStockTrayHasProduct(ETrayType trayType= ETrayType.Input1,int slotIndex=0,bool isNeedMove=false)
|
|
{
|
|
if(isNeedMove)
|
|
Go(trayType, slotIndex);
|
|
SlotProductHasOrNotResult result = VisionManager.StockTrayHasProduct();
|
|
OnStockTrayHasOrNotResult?.Invoke(result);
|
|
return result;
|
|
}
|
|
|
|
|
|
public void Go(ETrayType trayType,int slotIndex)
|
|
{
|
|
TargetPosition targetPosition = new TargetPosition();
|
|
AlarmEntity alarmEntity = null;
|
|
step = EUpCameraCheckFlowStep.到拍照位上方;
|
|
bool moving = true;
|
|
while (moving)
|
|
{
|
|
if (MachineManage.Instance.MachineStatus == EMachineStatus.Stop)
|
|
{
|
|
Thread.Sleep(10);
|
|
continue;
|
|
}
|
|
switch (step)
|
|
{
|
|
case EUpCameraCheckFlowStep.到拍照位上方:
|
|
curSlotPoint = TrayPointManager.GetSlotPoint(trayType, slotIndex);
|
|
if (curSlotPoint != null)
|
|
{
|
|
targetPosition.X=curSlotPoint.X;
|
|
targetPosition.Y = curSlotPoint.Y;
|
|
errCode = AxisControl.LoadX.MovePos(targetPosition.X, GlobalVar.WholeSpeed);
|
|
if (errCode == ErrorCode.Ok || GlobalVar.VirtualAxis)
|
|
{
|
|
errCode = AxisControl.LoadY.MovePos(targetPosition.Y, (int)(GlobalVar.WholeSpeed));
|
|
if (errCode == ErrorCode.Ok || GlobalVar.VirtualAxis)
|
|
{
|
|
logInfo = GetClassName() + $"到{trayType}盘{slotIndex}穴位拍照位上方";
|
|
MessageQueue.Instance.Insert(logInfo);
|
|
step = EUpCameraCheckFlowStep.等待运动到拍照位上方;
|
|
}
|
|
else
|
|
{
|
|
//PromptMessageBox.ShowAxisAlarmDialog(AxisControl.LoadY, errCode);
|
|
alarmEntity = AlarmCollection.Get(AlarmConstID.LoadY运动异常).Transform(errCode.ToString());
|
|
AlarmMessageBox.ShowDialog(alarmEntity, ETipButton.Ok, null);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//PromptMessageBox.ShowAxisAlarmDialog(AxisControl.LoadX, errCode);
|
|
alarmEntity = AlarmCollection.Get(AlarmConstID.LoadX运动异常).Transform(errCode.ToString());
|
|
AlarmMessageBox.ShowDialog(alarmEntity, ETipButton.Ok, null);
|
|
}
|
|
}
|
|
|
|
break;
|
|
case EUpCameraCheckFlowStep.等待运动到拍照位上方:
|
|
if (Ops.IsStop(AxisAlias.LoadX, AxisAlias.LoadY) || GlobalVar.VirtualAxis)
|
|
{
|
|
if(AxisArrived.LoadXYIsArrived(targetPosition.X,targetPosition.Y))
|
|
{
|
|
logInfo = GetClassName() + $"已运动到{trayType}盘{slotIndex}穴位拍照位上方";
|
|
MessageQueue.Instance.Insert(logInfo);
|
|
moving = false;
|
|
}
|
|
else
|
|
{
|
|
step = EUpCameraCheckFlowStep.到拍照位上方;
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
public string GetClassName()
|
|
{
|
|
return "UpCameraCheckFlow-";
|
|
}
|
|
}
|
|
}
|