|
|
using Rs.Framework;
|
|
|
using Rs.Motion;
|
|
|
using Rs.MotionPlat.Commom;
|
|
|
using Rs.MotionPlat.Entitys;
|
|
|
using Rs.MotionPlat.Module;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Diagnostics;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading;
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
namespace Rs.MotionPlat.Flow.NormalFlow
|
|
|
{
|
|
|
|
|
|
public enum EStockStatus
|
|
|
{
|
|
|
Ready,
|
|
|
UnReady
|
|
|
}
|
|
|
enum EOutStockFlowStep
|
|
|
{
|
|
|
松开定位销,
|
|
|
等待松开定位销完成,
|
|
|
到出仓位,
|
|
|
等待到出仓位,
|
|
|
打开抽屉锁,
|
|
|
等待打开抽屉锁完成,
|
|
|
出仓,
|
|
|
等待出仓完成
|
|
|
}
|
|
|
|
|
|
enum EInStockFlowStep
|
|
|
{
|
|
|
松开定位销,
|
|
|
等待松开定位销完成,
|
|
|
等待进仓信号,
|
|
|
进仓,
|
|
|
等待进仓完成,
|
|
|
关闭开抽屉锁,
|
|
|
等待关闭抽屉锁完成,
|
|
|
到起始位,
|
|
|
等待到起始位
|
|
|
}
|
|
|
|
|
|
public class StockFlowBase
|
|
|
{
|
|
|
public EStockStatus Status { get; set; } = EStockStatus.UnReady;
|
|
|
/// <summary>
|
|
|
/// 料盘的高度
|
|
|
/// </summary>
|
|
|
public double TrayHeight
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return GlobalVar.TwentyTrayHeight / 20;
|
|
|
}
|
|
|
}
|
|
|
public int CurrentLayer { get; set; } = 20;
|
|
|
public int StockIndex { get; set; }
|
|
|
//protected ManualResetEvent actionFinished = new ManualResetEvent(false);
|
|
|
public bool UpFinished { get; set; }
|
|
|
public bool DownFinished { get; set; }
|
|
|
EOutStockFlowStep outStockStep = EOutStockFlowStep.松开定位销;
|
|
|
EInStockFlowStep inStockStep = EInStockFlowStep.松开定位销;
|
|
|
bool outStockFinished = true;
|
|
|
bool inStockFinished = true;
|
|
|
Stopwatch stopwatch = new Stopwatch();
|
|
|
TargetPosition targetPosition = new TargetPosition();
|
|
|
ErrorCode errCode = ErrorCode.Ok;
|
|
|
string logInfo = string.Empty;
|
|
|
bool canFlash = false;
|
|
|
/// <summary>
|
|
|
/// 等待事件完成
|
|
|
/// </summary>
|
|
|
public bool WaitFinished()
|
|
|
{
|
|
|
return UpFinished;
|
|
|
}
|
|
|
|
|
|
public virtual string GetClassName()
|
|
|
{
|
|
|
return string.Empty;
|
|
|
}
|
|
|
|
|
|
public void OutStock()
|
|
|
{
|
|
|
if (outStockFinished)
|
|
|
{
|
|
|
outStockFinished = false;
|
|
|
outStockStep = EOutStockFlowStep.松开定位销;
|
|
|
}
|
|
|
else
|
|
|
return;
|
|
|
while (!outStockFinished)
|
|
|
{
|
|
|
switch (outStockStep)
|
|
|
{
|
|
|
case EOutStockFlowStep.松开定位销:
|
|
|
//StockModule.ClampTrayCylinder(EIoOperate.Open, StockIndex,GetClassName());
|
|
|
StockManager.OpenTray(StockIndex);
|
|
|
stopwatch.Restart();
|
|
|
outStockStep = EOutStockFlowStep.等待松开定位销完成;
|
|
|
break;
|
|
|
case EOutStockFlowStep.等待松开定位销完成:
|
|
|
if (Ops.IsOn($"料仓夹磁气缸{StockIndex}原位"))
|
|
|
{
|
|
|
outStockStep = EOutStockFlowStep.到出仓位;
|
|
|
}
|
|
|
else if (stopwatch.ElapsedMilliseconds > 5000)
|
|
|
{
|
|
|
Msgbox.ShowTipDialog(EButtonType.Retry, "抽屉锁原位异常,请处理后点击重试", "error", true);
|
|
|
}
|
|
|
break;
|
|
|
case EOutStockFlowStep.到出仓位:
|
|
|
if (StockIndex == 1)
|
|
|
{
|
|
|
targetPosition.StockZ = GlobalVar.StockZ1OutStock;
|
|
|
}
|
|
|
else if (StockIndex == 2)
|
|
|
{
|
|
|
targetPosition.StockZ = GlobalVar.StockZ2OutStock;
|
|
|
}
|
|
|
else if (StockIndex == 3)
|
|
|
{
|
|
|
targetPosition.StockZ = GlobalVar.StockZ3OutStock;
|
|
|
}
|
|
|
errCode = AxisControl.GetAxis($"StockZ{StockIndex}").MovePos(targetPosition.StockZ, GlobalVar.WholeSpeed);
|
|
|
if (errCode == ErrorCode.Ok)
|
|
|
{
|
|
|
logInfo = GetClassName() + $"到出仓位,tz1:{targetPosition.StockZ}";
|
|
|
MessageQueue.Instance.Insert(logInfo);
|
|
|
outStockStep = EOutStockFlowStep.等待到出仓位;
|
|
|
}
|
|
|
break;
|
|
|
case EOutStockFlowStep.等待到出仓位:
|
|
|
if (Ops.IsStop($"StockZ{StockIndex}"))
|
|
|
{
|
|
|
logInfo = GetClassName() + $"已运动到出仓位";
|
|
|
MessageQueue.Instance.Insert(logInfo);
|
|
|
outStockStep = EOutStockFlowStep.打开抽屉锁;
|
|
|
}
|
|
|
break;
|
|
|
case EOutStockFlowStep.打开抽屉锁:
|
|
|
StockModule.DrawerLock(EIoOperate.Open, StockIndex);
|
|
|
stopwatch.Restart();
|
|
|
outStockStep = EOutStockFlowStep.等待打开抽屉锁完成;
|
|
|
break;
|
|
|
case EOutStockFlowStep.等待打开抽屉锁完成:
|
|
|
if (Ops.IsOn($"抽屉锁{StockIndex}原位"))
|
|
|
{
|
|
|
outStockStep = EOutStockFlowStep.出仓;
|
|
|
}
|
|
|
else if (stopwatch.ElapsedMilliseconds > 20000)
|
|
|
{
|
|
|
Msg.ShowError(AlarmCollection.Get(AlarmConstID.抽屉锁原位异常报警).Transform(StockIndex).CN);
|
|
|
outStockStep = EOutStockFlowStep.打开抽屉锁;
|
|
|
}
|
|
|
break;
|
|
|
case EOutStockFlowStep.出仓:
|
|
|
StockModule.DrawerPullCylinder(EIoOperate.Open, StockIndex);
|
|
|
stopwatch.Restart();
|
|
|
outStockStep = EOutStockFlowStep.等待出仓完成;
|
|
|
break;
|
|
|
case EOutStockFlowStep.等待出仓完成:
|
|
|
if (Ops.IsOn($"抽屉拉伸气缸{StockIndex}动位"))
|
|
|
{
|
|
|
FlashLight();
|
|
|
outStockFinished = true;
|
|
|
}
|
|
|
else if (stopwatch.ElapsedMilliseconds > 30000)
|
|
|
{
|
|
|
Msg.ShowError(AlarmCollection.Get(AlarmConstID.抽屉拉伸气缸动位异常).Transform(StockIndex).CN);
|
|
|
outStockStep = EOutStockFlowStep.出仓;
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 进仓
|
|
|
/// </summary>
|
|
|
public void InStock(bool gotoStartPos = true)
|
|
|
{
|
|
|
if (inStockFinished)
|
|
|
{
|
|
|
inStockFinished = false;
|
|
|
inStockStep = EInStockFlowStep.松开定位销;
|
|
|
}
|
|
|
else
|
|
|
return;
|
|
|
while (!inStockFinished)
|
|
|
{
|
|
|
switch (inStockStep)
|
|
|
{
|
|
|
case EInStockFlowStep.松开定位销:
|
|
|
//StockModule.ClampTrayCylinder(EIoOperate.Open, StockIndex, GetClassName());
|
|
|
StockManager.OpenTray(StockIndex);
|
|
|
stopwatch.Restart();
|
|
|
inStockStep = EInStockFlowStep.等待松开定位销完成;
|
|
|
break;
|
|
|
case EInStockFlowStep.等待松开定位销完成:
|
|
|
if (Ops.IsOn($"料仓夹磁气缸{StockIndex}原位"))
|
|
|
{
|
|
|
inStockStep = EInStockFlowStep.等待进仓信号;
|
|
|
}
|
|
|
else if (stopwatch.ElapsedMilliseconds > 20000)
|
|
|
{
|
|
|
Msgbox.ShowTipDialog(EButtonType.Retry, "抽屉锁原位异常,请处理后点击重试", "error", true);
|
|
|
}
|
|
|
break;
|
|
|
case EInStockFlowStep.等待进仓信号:
|
|
|
if (Ops.IsOn($"抽屉锁{StockIndex}按钮"))
|
|
|
{
|
|
|
inStockStep = EInStockFlowStep.进仓;
|
|
|
}
|
|
|
break;
|
|
|
case EInStockFlowStep.进仓:
|
|
|
StockModule.DrawerPullCylinder(EIoOperate.Close, StockIndex);
|
|
|
stopwatch.Restart();
|
|
|
inStockStep = EInStockFlowStep.等待进仓完成;
|
|
|
break;
|
|
|
case EInStockFlowStep.等待进仓完成:
|
|
|
if (Ops.IsOn($"抽屉拉伸气缸{StockIndex}原位"))
|
|
|
{
|
|
|
Thread.Sleep(1000);
|
|
|
inStockStep = EInStockFlowStep.关闭开抽屉锁;
|
|
|
}
|
|
|
else if (stopwatch.ElapsedMilliseconds > 10000)
|
|
|
{
|
|
|
AlarmEntity alarmEntity = AlarmCollection.Get(AlarmConstID.抽屉拉伸气缸原位异常).Transform(StockIndex);
|
|
|
Msgbox.ShowDialog(alarmEntity, EButtonType.Recheck, true);
|
|
|
inStockStep = EInStockFlowStep.进仓;
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
case EInStockFlowStep.关闭开抽屉锁:
|
|
|
StockModule.DrawerLock(EIoOperate.Close, StockIndex);
|
|
|
stopwatch.Restart();
|
|
|
inStockStep = EInStockFlowStep.等待关闭抽屉锁完成;
|
|
|
break;
|
|
|
case EInStockFlowStep.等待关闭抽屉锁完成:
|
|
|
if (Ops.IsOn($"抽屉锁{StockIndex}动位"))
|
|
|
{
|
|
|
ResetLayer();
|
|
|
if (gotoStartPos)
|
|
|
{
|
|
|
inStockStep = EInStockFlowStep.到起始位;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
CloseFlashLight();
|
|
|
inStockFinished = true;
|
|
|
}
|
|
|
}
|
|
|
else if (stopwatch.ElapsedMilliseconds > 30000)
|
|
|
{
|
|
|
Msg.ShowError(AlarmCollection.Get(AlarmConstID.抽屉锁动位异常报警).Transform(StockIndex).CN);
|
|
|
inStockStep = EInStockFlowStep.关闭开抽屉锁;
|
|
|
}
|
|
|
break;
|
|
|
case EInStockFlowStep.到起始位:
|
|
|
Up();
|
|
|
inStockStep = EInStockFlowStep.等待到起始位;
|
|
|
break;
|
|
|
case EInStockFlowStep.等待到起始位:
|
|
|
CloseFlashLight();
|
|
|
inStockFinished = true;
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void ResetLayer()
|
|
|
{
|
|
|
CurrentLayer = 20;
|
|
|
}
|
|
|
|
|
|
public void Up()
|
|
|
{
|
|
|
if (CurrentLayer == 0)
|
|
|
{
|
|
|
logInfo = $"{GetClassName()} 料仓{StockIndex}已处于第{CurrentLayer}层,不能再上升";
|
|
|
MessageQueue.Instance.Warn(logInfo);
|
|
|
return;
|
|
|
}
|
|
|
if (Ops.IsOn($"料仓夹磁气缸{StockIndex}动位"))
|
|
|
{
|
|
|
ReleaseTray();
|
|
|
}
|
|
|
CurrentLayer--;
|
|
|
targetPosition.StockZ = GetStockZPosByLayer(CurrentLayer);
|
|
|
|
|
|
errCode = AxisControl.GetAxis($"StockZ{StockIndex}").MovePos(targetPosition.StockZ, GlobalVar.WholeSpeed);
|
|
|
if (errCode == ErrorCode.Ok)
|
|
|
{
|
|
|
logInfo = $"{GetClassName()} 料仓{StockIndex}运动到{CurrentLayer}层,tz:{targetPosition.StockZ}";
|
|
|
MessageQueue.Instance.Insert(logInfo);
|
|
|
stopwatch.Restart();
|
|
|
while (true)
|
|
|
{
|
|
|
if (Ops.IsStop($"StockZ{StockIndex}"))
|
|
|
{
|
|
|
Thread.Sleep(500);
|
|
|
logInfo = $"{GetClassName()} 料仓{StockIndex}已运动到{CurrentLayer}层,cz:{Ops.GetCurPosition($"StockZ{StockIndex}")}";
|
|
|
MessageQueue.Instance.Insert(logInfo);
|
|
|
//if (HasTray())
|
|
|
//{
|
|
|
// ClampTray();
|
|
|
// Thread.Sleep(GlobalVar.StepMotorMoveDelayTime);
|
|
|
//}
|
|
|
break;
|
|
|
}
|
|
|
else if (stopwatch.ElapsedMilliseconds > 5000)
|
|
|
{
|
|
|
//运动异常报警
|
|
|
errCode = AxisControl.GetAxis($"StockZ{StockIndex}").MovePos(targetPosition.StockZ, GlobalVar.WholeSpeed);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void Down()
|
|
|
{
|
|
|
if (CurrentLayer == 20)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
//下降之前松开料盘
|
|
|
ReleaseTray();
|
|
|
CurrentLayer++;
|
|
|
targetPosition.StockZ = GetStockZPosByLayer(CurrentLayer);
|
|
|
errCode = AxisControl.GetAxis($"StockZ{StockIndex}").MovePos(targetPosition.StockZ, GlobalVar.WholeSpeed);
|
|
|
if (errCode == ErrorCode.Ok)
|
|
|
{
|
|
|
stopwatch.Restart();
|
|
|
while (true)
|
|
|
{
|
|
|
if (Ops.IsStop($"StockZ{StockIndex}"))
|
|
|
{
|
|
|
Thread.Sleep(GlobalVar.StepMotorMoveDelayTime);
|
|
|
break;
|
|
|
}
|
|
|
else if (stopwatch.ElapsedMilliseconds > 30000)
|
|
|
{
|
|
|
//运动异常报警
|
|
|
errCode = AxisControl.GetAxis($"StockZ{StockIndex}").MovePos(targetPosition.StockZ, GlobalVar.WholeSpeed);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 松开料盘
|
|
|
/// </summary>
|
|
|
public void ReleaseTray()
|
|
|
{
|
|
|
StockModule.ClampTrayCylinder(EIoOperate.Open, StockIndex, GetClassName());
|
|
|
stopwatch.Restart();
|
|
|
while (true)
|
|
|
{
|
|
|
if (Ops.IsOn($"料仓夹磁气缸{StockIndex}原位"))
|
|
|
{
|
|
|
Thread.Sleep(1000);
|
|
|
break;
|
|
|
}
|
|
|
else if (stopwatch.ElapsedMilliseconds > 30000)
|
|
|
{
|
|
|
AlarmEntity alarmEntity = AlarmCollection.Get($"料仓{StockIndex}夹磁气缸原位异常");
|
|
|
if (alarmEntity != null)
|
|
|
{
|
|
|
Msgbox.ShowDialog(alarmEntity, EButtonType.Retry, true);
|
|
|
StockModule.ClampTrayCylinder(EIoOperate.Open, StockIndex, GetClassName());
|
|
|
stopwatch.Restart();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
Msg.ShowError($"翻译文件中未找到 料仓{StockIndex}夹磁气缸原位异常");
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 抓紧料盘
|
|
|
/// </summary>
|
|
|
public void ClampTray()
|
|
|
{
|
|
|
StockModule.ClampTrayCylinder(EIoOperate.Close, StockIndex, GetClassName());
|
|
|
stopwatch.Restart();
|
|
|
while (true)
|
|
|
{
|
|
|
if (Ops.IsOn($"料仓夹磁气缸{StockIndex}动位") || GlobalVar.RunSpace)
|
|
|
{
|
|
|
logInfo = $"{GetClassName()} 检测到料仓夹磁气缸{StockIndex}动位 OK";
|
|
|
MessageQueue.Instance.Insert(logInfo);
|
|
|
Thread.Sleep(1000);
|
|
|
return;
|
|
|
}
|
|
|
else if (stopwatch.ElapsedMilliseconds > 30000)
|
|
|
{
|
|
|
AlarmEntity alarmEntity = AlarmCollection.Get($"料仓{StockIndex}夹磁气缸动位异常");
|
|
|
if (alarmEntity != null)
|
|
|
{
|
|
|
Msgbox.ShowDialog(alarmEntity, EButtonType.Retry, true);
|
|
|
StockModule.ClampTrayCylinder(EIoOperate.Close, StockIndex, GetClassName());
|
|
|
stopwatch.Restart();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
Msg.ShowError($"翻译文件中未找到 料仓{StockIndex}夹磁气缸动位异常");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 闪烁料仓灯
|
|
|
/// </summary>
|
|
|
public void FlashLight()
|
|
|
{
|
|
|
if (canFlash)
|
|
|
return;
|
|
|
else
|
|
|
canFlash = true;
|
|
|
Task.Run(() => {
|
|
|
while (canFlash)
|
|
|
{
|
|
|
Ops.On($"料仓{StockIndex}状态灯");
|
|
|
Thread.Sleep(200);
|
|
|
Ops.Off($"料仓{StockIndex}状态灯");
|
|
|
Thread.Sleep(200);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
public void CloseFlashLight()
|
|
|
{
|
|
|
canFlash = false;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 根据层数获取料仓Z的高度
|
|
|
/// </summary>
|
|
|
/// <param name="layer"></param>
|
|
|
/// <returns></returns>
|
|
|
private double GetStockZPosByLayer(int layer)
|
|
|
{
|
|
|
return (GetFirstLayerPos() - ((CurrentLayer - 1) * TrayHeight));
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取料仓首层的位置
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public double GetFirstLayerPos()
|
|
|
{
|
|
|
switch (StockIndex)
|
|
|
{
|
|
|
case 1:
|
|
|
return GlobalVar.StockZ1FirstTray;
|
|
|
case 2:
|
|
|
return GlobalVar.StockZ2FirstTray;
|
|
|
case 3:
|
|
|
return GlobalVar.StockZ3FirstTray;
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取当前层数
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public int GetCurrentLayer()
|
|
|
{
|
|
|
return CurrentLayer;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 是否有料盘
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public bool HasTray()
|
|
|
{
|
|
|
return Ops.IsOn($"满料{StockIndex}对射光电");
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 工作完成收料
|
|
|
/// </summary>
|
|
|
public void DischargeFinish()
|
|
|
{
|
|
|
Status = EStockStatus.UnReady;
|
|
|
EDischargeFinishStep finishStep = EDischargeFinishStep.等待出仓信号;
|
|
|
while (true)
|
|
|
{
|
|
|
switch (finishStep)
|
|
|
{
|
|
|
case EDischargeFinishStep.等待出仓信号:
|
|
|
FlashLight();
|
|
|
if (Ops.IsOn($"抽屉锁{StockIndex}按钮"))
|
|
|
{
|
|
|
finishStep = EDischargeFinishStep.出仓;
|
|
|
}
|
|
|
break;
|
|
|
case EDischargeFinishStep.出仓:
|
|
|
OutStock();
|
|
|
finishStep = EDischargeFinishStep.进仓;
|
|
|
break;
|
|
|
case EDischargeFinishStep.进仓:
|
|
|
InStock(false);
|
|
|
Status = EStockStatus.Ready;
|
|
|
return;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
public void Reset()
|
|
|
{
|
|
|
Status = EStockStatus.UnReady;
|
|
|
}
|
|
|
}
|
|
|
}
|