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.

146 lines
6.2 KiB
C#

11 months ago
using Rs.Controls;
using Rs.Framework;
using Rs.Motion.Base;
using Rs.MotionPlat.Commom;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Rs.MotionPlat.Flow
{
public class HomeFlow
{
ushort homeStep = 0;
private static HomeFlow instace;
private bool m_bCancle = false;
private bool m_bHomed = false;
private Stopwatch homeTime = new Stopwatch();
public static HomeFlow Instance
{
get
{
if (instace == null)
instace = new HomeFlow();
return instace;
}
}
public void CancleHome()
{
m_bCancle = true;
}
private HomeFlow() { }
public void StartGoHome()
{
MachineManage.Instance.InitializeState = EInitializeState.Initializing ;
homeStep = 0;
m_bHomed = false;
Task.Run(() =>
{
while (true && !m_bCancle && !m_bHomed)
{
if(GlobalVar.VirtualAxis)
{
MachineManage.Instance.SetCenterMachineStatus(Commom.ERunStatus.Stopped);
MessageQueue.Instance.Insert("Device home ok");
MachineManage.Instance.SetLocalMachineStatus(EMachineStatus.Homed);
MachineManage.Instance.InitializeState = EInitializeState.Initialized;
m_bHomed = true;
}
else
{
switch (homeStep)
{
case 0://所有的Z轴回原
string canGohome = CheckCanHome();
if (!string.IsNullOrEmpty(canGohome))
{
Msg.ShowError($"轴{canGohome}处于报警状态,不能回原");
MessageQueue.Instance.Warn($"轴{canGohome}处于报警状态,不能回原");
m_bCancle = true;
}
else
{
MessageQueue.Instance.Insert("Z轴开始回零");
homeTime.Restart();
MachineManage.Instance.MachineStatus = EMachineStatus.Homing;
AxisControl.GetAxis($"NozzleZ1").Home();
AxisControl.GetAxis($"NozzleZ2").Home();
AxisControl.GetAxis($"NozzleR1").Home();
AxisControl.GetAxis($"NozzleR2").Home();
homeStep++;
}
break;
case 1://等待所有Z轴回原完成
if (homeTime.ElapsedMilliseconds < 1000 * 60 * 2)//5分钟还未回零成功则返回回零超时
{
if (Ops.AllZHomed() && Ops.AllRHomed())
{
MessageQueue.Instance.Insert("ZR axis home finished!");
homeStep++;
}
}
else
{
AxisControl.GetAxis($"NozzleZ1").Abort_Go_Home();
AxisControl.GetAxis($"NozzleZ2").Abort_Go_Home();
MachineManage.Instance.MachineStatus = EMachineStatus.HomeFail;
MessageQueue.Instance.Insert("Device home fail");
CancleHome();
}
break;
case 2:
AxisControl.LoadX.MovePos(SysConfigParam.GetValue<double>("LoadXStartPos"), GlobalVar.WholeSpeed);
AxisControl.LoadY.MovePos(SysConfigParam.GetValue<double>("LoadYStartPos"), GlobalVar.WholeSpeed);
AxisControl.TurnoverY.MovePos(SysConfigParam.GetValue<double>("PressY"), GlobalVar.WholeSpeed);
AxisControl.TurnoverZ.MovePos(SysConfigParam.GetValue<double>("TurnoverSafeZ"), GlobalVar.WholeSpeed);
AxisControl.PressZ.MovePos(SysConfigParam.GetValue<double>("PressSafeZ"), GlobalVar.WholeSpeed);
11 months ago
homeStep++;
break;
case 3:
if (Ops.IsStop(AxisControl.LoadX, AxisControl.LoadY,AxisControl.TurnoverY,AxisControl.TurnoverZ,AxisControl.PressZ))
11 months ago
{
MachineManage.Instance.SetCenterMachineStatus(ERunStatus.Stopped);
MessageQueue.Instance.Insert("Device home ok");
MachineManage.Instance.MachineStatus = EMachineStatus.Homed;
m_bHomed = true;
MachineManage.Instance.InitializeState = EInitializeState.Initialized;
homeStep = 0;
}
break;
default:
break;
}
}
}
});
}
private string CheckCanHome()
{
return string.Empty;
List<string> list = new List<string>();
foreach(IAxis axis in AxisControl.GetAllAxis())
{
axis.GetAlarmStatus(out bool bAlarm);
if(bAlarm)
{
list.Add(axis.Config.AxisName);
}
}
return string.Join(",", list);
}
}
}