|
|
using Rs.Camera;
|
|
|
using Rs.Framework;
|
|
|
using Rs.Motion.GugaoEcat;
|
|
|
using Rs.Motion.GugaoPulse;
|
|
|
using Rs.Motion;
|
|
|
using Rs.MotionPlat.Flow;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
using Rs.Motion.Base;
|
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement.ToolTip;
|
|
|
using Rs.Controls;
|
|
|
using System.Threading;
|
|
|
using System.Diagnostics;
|
|
|
using Rs.MotionPlat.AuxiliaryEquipment;
|
|
|
|
|
|
namespace Rs.MotionPlat.Commom
|
|
|
{
|
|
|
public class Ops
|
|
|
{
|
|
|
public static bool Pause { get; set; } = false;
|
|
|
public static void Init()
|
|
|
{
|
|
|
SysConfigParam.Init();
|
|
|
int errNum = 0;
|
|
|
//Task.Run(() => {
|
|
|
if(!GlobalVar.VirtualAxis)
|
|
|
{
|
|
|
#region 初始化固高卡
|
|
|
ErrorCode errCode = GugaoPulseCardManager.Instance.Init();
|
|
|
if (errCode > ErrorCode.Ok)
|
|
|
{
|
|
|
errNum++;
|
|
|
MessageQueue.Instance.Warn($"Gugao motion card load fail {errCode}");
|
|
|
LogHelper.Debug($"Gugao motion card load fail {errCode}");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
MessageQueue.Instance.Insert("Gugao motion card load success");
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 初始化ztm卡
|
|
|
errCode = ZtmCardManager.Instance.Init();
|
|
|
if (errCode > ErrorCode.Ok)
|
|
|
{
|
|
|
errNum++;
|
|
|
MessageQueue.Instance.Warn($"rs motion card load fail {errCode}"); return;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
MessageQueue.Instance.Insert("rs motion card load ok");
|
|
|
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 初始化IO
|
|
|
IoManager.Instance.Init();
|
|
|
#endregion
|
|
|
|
|
|
#region 链接相机
|
|
|
//链接相机
|
|
|
ECameraErrorCode ceCode = HikCamera.Instance.Init();
|
|
|
if (ceCode > ECameraErrorCode.Ok)
|
|
|
{
|
|
|
errNum++;
|
|
|
MessageQueue.Instance.Warn(ceCode.ToString());
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
MessageQueue.Instance.Insert("Camera load ok!");
|
|
|
|
|
|
int ret = HikCamera.Instance.SetReverseX("upCamera", EDir.Y, false);
|
|
|
ret += HikCamera.Instance.SetReverseX("upCamera", EDir.X, false);
|
|
|
if (ret != 0)
|
|
|
{
|
|
|
MessageQueue.Instance.Warn("Camera init error");
|
|
|
}
|
|
|
ret = 0;
|
|
|
ret = HikCamera.Instance.SetReverseX("downCamera", EDir.X, true);
|
|
|
ret += HikCamera.Instance.SetReverseX("downCamera", EDir.Y, false);
|
|
|
if (ret != 0)
|
|
|
{
|
|
|
MessageQueue.Instance.Warn("Camera init error");
|
|
|
}
|
|
|
|
|
|
ret = HikCamera.Instance.StartGrab("upCamera");
|
|
|
if (ret != 0)
|
|
|
{
|
|
|
MessageQueue.Instance.Warn("Camera init error");
|
|
|
}
|
|
|
ret = HikCamera.Instance.StartGrab("locationCamera");
|
|
|
if (ret != 0)
|
|
|
{
|
|
|
MessageQueue.Instance.Warn("Camera init error");
|
|
|
}
|
|
|
|
|
|
ret = HikCamera.Instance.StartGrab("scanCamera");
|
|
|
if (ret != 0)
|
|
|
{
|
|
|
MessageQueue.Instance.Warn("Camera init error");
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
//使能所有轴卡
|
|
|
AxisControl.AllEnable();
|
|
|
SafeControl.Instance.Init();
|
|
|
|
|
|
AxisControl.AllStop();
|
|
|
if (errNum == 0)
|
|
|
{
|
|
|
MessageQueue.Instance.Insert("Init finished");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
MessageQueue.Instance.Insert("Init fail");
|
|
|
}
|
|
|
Ops.On("上下气缸电磁阀原位");
|
|
|
Ops.Off("上下气缸电磁阀动位");
|
|
|
Ops.Off("下左相机光源触发");
|
|
|
Ops.Off("下右相机光源触发");
|
|
|
Ops.Off("上相机光源触发");
|
|
|
Ops.Off("夹爪气缸电磁阀");
|
|
|
}
|
|
|
NozzleManager.Init();
|
|
|
TrayPointManager.LoadPoint();
|
|
|
TurnoverSlotOffset.Init();
|
|
|
MonitorSystemButton.Instance.Start();
|
|
|
TestCenter.Instance.Init();
|
|
|
DeviceFactory.Init();
|
|
|
QifuManager.Instance.Init();
|
|
|
QifuManager.Instance.Write(SysConfigParam.GetValue<float>("QifuValue"));
|
|
|
}
|
|
|
|
|
|
|
|
|
public static void Start()
|
|
|
{
|
|
|
Task.Run(() => {
|
|
|
if(MachineManage.Instance.MachineStatus== EMachineStatus.Homed || MachineManage.Instance.MachineStatus== EMachineStatus.Stop)
|
|
|
{
|
|
|
WorkEnvironment.Instance.Ready();
|
|
|
WorkEnvironment.Instance.EnvReadyOkEvent.WaitOne();
|
|
|
DischargeFlow.Instance.Start();
|
|
|
TurnoverFlow.Instance.Start();
|
|
|
MachineManage.Instance.SetCenterMachineStatus(ERunStatus.Started);
|
|
|
if (DischargeFlow.Instance.GetCurStep() == "等待任务" && TurnoverFlow.Instance.GetStep() == "等待任务")
|
|
|
{
|
|
|
MachineManage.Instance.SetLoadUnloadStatus(ERunState.Waiting);
|
|
|
}
|
|
|
MachineManage.Instance.SetLocalMachineStatus(EMachineStatus.Working);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
public static void Stop()
|
|
|
{
|
|
|
if(MachineManage.Instance.MachineStatus== EMachineStatus.Working)
|
|
|
{
|
|
|
DischargeFlow.Instance.Stop();
|
|
|
TurnoverFlow.Instance.Stop();
|
|
|
MachineManage.Instance.SetCenterMachineStatus(ERunStatus.Stopped);
|
|
|
//MachineManage.Instance.SetLoadUnloadStatus(ERunState.Interrupt);
|
|
|
MachineManage.Instance.MachineStatus = EMachineStatus.Stop;
|
|
|
}
|
|
|
else if(MachineManage.Instance.MachineStatus== EMachineStatus.Homing)
|
|
|
{
|
|
|
foreach (IAxis axis in AxisControl.GetAllAxis())
|
|
|
{
|
|
|
axis.Abort_Go_Home();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public static void GoHome()
|
|
|
{
|
|
|
if (MachineManage.Instance.MachineStatus == EMachineStatus.Homed
|
|
|
|| MachineManage.Instance.MachineStatus == EMachineStatus.NotInit
|
|
|
|| MachineManage.Instance.MachineStatus == EMachineStatus.NotHomed
|
|
|
|| MachineManage.Instance.MachineStatus == EMachineStatus.Stop
|
|
|
)
|
|
|
{
|
|
|
HomeFlow.Instance.StartGoHome();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
MessageQueue.Instance.Warn($"device state {MachineManage.Instance.MachineStatus} cann't home!");
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 检测轴是否报警
|
|
|
/// </summary>
|
|
|
/// <param name="axis"></param>
|
|
|
/// <returns></returns>
|
|
|
public static List<IAxis> AxiesAlarm(params IAxis[] axies)
|
|
|
{
|
|
|
ErrorCode errCode = ErrorCode.Ok;
|
|
|
bool bAlarm = false;
|
|
|
List<IAxis> axes= new List<IAxis>();
|
|
|
foreach (IAxis axis in axies)
|
|
|
{
|
|
|
errCode = axis.GetAlarmStatus(out bAlarm);
|
|
|
if (errCode == ErrorCode.Ok)
|
|
|
{
|
|
|
if(bAlarm)
|
|
|
axes.Add(axis);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
axes.Add(axis);
|
|
|
}
|
|
|
}
|
|
|
return axes;
|
|
|
}
|
|
|
public static bool IsStop(params string[] axies)
|
|
|
{
|
|
|
foreach (var axisname in axies)
|
|
|
{
|
|
|
if (!IsStop(AxisControl.GetAxis(axisname)))
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
public static bool IsStop(params IAxis[] axies)
|
|
|
{
|
|
|
foreach (var axis in axies)
|
|
|
{
|
|
|
axis.IsStop(out bool bStop);
|
|
|
if (!bStop)
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
//public static MoveResult IsStop( IAxis axis)
|
|
|
//{
|
|
|
// ErrorCode errCode = ErrorCode.Ok;
|
|
|
// MoveResult mr = new MoveResult();
|
|
|
// errCode = axis.GetAlarmStatus(out bool bAlarm);
|
|
|
// if (errCode == ErrorCode.Ok)
|
|
|
// {
|
|
|
// mr.IsAlarm= bAlarm;
|
|
|
// errCode = axis.IsStop(out bool bStop);
|
|
|
// if(errCode== ErrorCode.Ok)
|
|
|
// {
|
|
|
// mr.IsStop= bStop;
|
|
|
// }
|
|
|
// }
|
|
|
// mr.Result = errCode;
|
|
|
// return mr ;
|
|
|
//}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 轴是否运动到位
|
|
|
/// </summary>
|
|
|
/// <param name="axies"></param>
|
|
|
/// <returns></returns>
|
|
|
public static bool IsArrived(params string[] axies)
|
|
|
{
|
|
|
ErrorCode errCode = ErrorCode.Ok;
|
|
|
foreach (var axisname in axies)
|
|
|
{
|
|
|
errCode = AxisControl.GetAxis(axisname).IsArrived(out bool isArrived);
|
|
|
if(errCode > ErrorCode.Ok)
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
else if(!isArrived)
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 轴是否运动到位
|
|
|
/// </summary>
|
|
|
/// <param name="axies"></param>
|
|
|
/// <returns></returns>
|
|
|
public static bool IsArrived(params IAxis[] axies)
|
|
|
{
|
|
|
ErrorCode errCode = ErrorCode.Ok;
|
|
|
foreach (var axis in axies)
|
|
|
{
|
|
|
errCode = axis.IsArrived(out bool isArrived);
|
|
|
if (errCode > ErrorCode.Ok)
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
else if (!isArrived)
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
public static bool IsHomed(params string[] axies)
|
|
|
{
|
|
|
foreach (var axisname in axies)
|
|
|
{
|
|
|
if (!IsHomed(AxisControl.GetAxis(axisname)))
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
public static bool IsHomed(params IAxis[] axies)
|
|
|
{
|
|
|
foreach (var axis in axies)
|
|
|
{
|
|
|
if (axis.HomeStatus != EHomeStatus.Finished)
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
public static void On(string ioName)
|
|
|
{
|
|
|
IoManager.Instance.WriteOut(ioName, 1);
|
|
|
}
|
|
|
|
|
|
public static void Off(string ioName)
|
|
|
{
|
|
|
IoManager.Instance.WriteOut(ioName, 0);
|
|
|
}
|
|
|
|
|
|
public static bool IsOn(string ioName)
|
|
|
{
|
|
|
return IoManager.Instance.ReadIn(ioName) == 1;
|
|
|
}
|
|
|
|
|
|
public static bool IsOff(string ioName)
|
|
|
{
|
|
|
return IoManager.Instance.ReadIn(ioName) == 0;
|
|
|
}
|
|
|
|
|
|
public static bool IsOutOn(string ioName)
|
|
|
{
|
|
|
return IoManager.Instance.ReadOut(ioName) == 1;
|
|
|
}
|
|
|
|
|
|
public static bool IsOutOff(string ioName)
|
|
|
{
|
|
|
return IoManager.Instance.ReadOut(ioName) == 0;
|
|
|
}
|
|
|
|
|
|
public static void Quit()
|
|
|
{
|
|
|
AxisControl.AllDisable();
|
|
|
HikCamera.Instance.Deinit();
|
|
|
}
|
|
|
|
|
|
public static bool AllZHomed()
|
|
|
{
|
|
|
if(AxisControl.NozzleZ1.HomeStatus!= EHomeStatus.Finished) return false;
|
|
|
if (AxisControl.NozzleZ2.HomeStatus != EHomeStatus.Finished) return false;
|
|
|
if (AxisControl.NozzleZ3.HomeStatus != EHomeStatus.Finished) return false;
|
|
|
if (AxisControl.NozzleZ4.HomeStatus != EHomeStatus.Finished) return false;
|
|
|
if (AxisControl.NozzleZ5.HomeStatus != EHomeStatus.Finished) return false;
|
|
|
if (AxisControl.NozzleZ6.HomeStatus != EHomeStatus.Finished) return false;
|
|
|
if (AxisControl.NozzleZ7.HomeStatus != EHomeStatus.Finished) return false;
|
|
|
if (AxisControl.NozzleZ8.HomeStatus != EHomeStatus.Finished) return false;
|
|
|
if (AxisControl.NozzleZ9.HomeStatus != EHomeStatus.Finished) return false;
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
public static bool AllZStoped()
|
|
|
{
|
|
|
if (!IsStop(AxisControl.NozzleZ1)) return false;
|
|
|
if (!IsStop(AxisControl.NozzleZ2)) return false;
|
|
|
if (!IsStop(AxisControl.NozzleZ3)) return false;
|
|
|
if (!IsStop(AxisControl.NozzleZ4)) return false;
|
|
|
if (!IsStop(AxisControl.NozzleZ5)) return false;
|
|
|
if (!IsStop(AxisControl.NozzleZ6)) return false;
|
|
|
if (!IsStop(AxisControl.NozzleZ7)) return false;
|
|
|
if (!IsStop(AxisControl.NozzleZ8)) return false;
|
|
|
if (!IsStop(AxisControl.NozzleZ9)) return false;
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
public static bool AllRStoped()
|
|
|
{
|
|
|
if (!IsStop(AxisControl.NozzleR1)) return false;
|
|
|
if (!IsStop(AxisControl.NozzleR2)) return false;
|
|
|
if (!IsStop(AxisControl.NozzleR3)) return false;
|
|
|
if (!IsStop(AxisControl.NozzleR4)) return false;
|
|
|
if (!IsStop(AxisControl.NozzleR5)) return false;
|
|
|
if (!IsStop(AxisControl.NozzleR6)) return false;
|
|
|
if (!IsStop(AxisControl.NozzleR7)) return false;
|
|
|
if (!IsStop(AxisControl.NozzleR8)) return false;
|
|
|
if (!IsStop(AxisControl.NozzleR9)) return false;
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
public static bool AllRHomed()
|
|
|
{
|
|
|
if (AxisControl.NozzleR1.HomeStatus != EHomeStatus.Finished) return false;
|
|
|
if (AxisControl.NozzleR2.HomeStatus != EHomeStatus.Finished) return false;
|
|
|
if (AxisControl.NozzleR3.HomeStatus != EHomeStatus.Finished) return false;
|
|
|
if (AxisControl.NozzleR4.HomeStatus != EHomeStatus.Finished) return false;
|
|
|
if (AxisControl.NozzleR5.HomeStatus != EHomeStatus.Finished) return false;
|
|
|
if (AxisControl.NozzleR6.HomeStatus != EHomeStatus.Finished) return false;
|
|
|
if (AxisControl.NozzleR7.HomeStatus != EHomeStatus.Finished) return false;
|
|
|
if (AxisControl.NozzleR8.HomeStatus != EHomeStatus.Finished) return false;
|
|
|
if (AxisControl.NozzleR9.HomeStatus != EHomeStatus.Finished) return false;
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 检查有没有轴报警
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public static bool CheckHasAlarm()
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
|
|
|
public static double GetCurPosition(string axisName)
|
|
|
{
|
|
|
IAxis axis=AxisControl.GetAxis(axisName);
|
|
|
return GetCurPosition(axis);
|
|
|
}
|
|
|
|
|
|
public static double GetCurPosition(IAxis axis)
|
|
|
{
|
|
|
double pos = 0.0;
|
|
|
if (axis == null) return 0;
|
|
|
if (axis.Config.EnableEncoder == 1)
|
|
|
{
|
|
|
if (axis.Config.AxisName.IndexOf("Nozzle") >= 0)
|
|
|
{
|
|
|
axis.GetPrfPosition(out pos);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
axis.GetEncoderPosition(out pos);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
axis.GetPrfPosition(out pos);
|
|
|
}
|
|
|
return pos;
|
|
|
}
|
|
|
|
|
|
public static void HomeAndGoStartPos(string axisName)
|
|
|
{
|
|
|
Task.Run(() => {
|
|
|
IAxis axis = AxisControl.GetAxis(axisName);
|
|
|
axis.Home();
|
|
|
MessageQueue.Instance.Insert("stat home");
|
|
|
Thread.Sleep(10);
|
|
|
Stopwatch timeout = new Stopwatch();
|
|
|
timeout.Restart();
|
|
|
while (axis.HomeStatus != EHomeStatus.Finished)
|
|
|
{
|
|
|
MessageQueue.Instance.Insert("homing");
|
|
|
Thread.Sleep(10);
|
|
|
}
|
|
|
|
|
|
timeout.Stop();
|
|
|
if (axis.HomeStatus == EHomeStatus.Finished)
|
|
|
{
|
|
|
MessageQueue.Instance.Insert("go to start pos");
|
|
|
Thread.Sleep(100);
|
|
|
timeout.Restart();
|
|
|
ErrorCode errCode = axis.MovePos(SysConfigParam.GetValue<double>($"{axisName}StartPos"), GlobalVar.WholeSpeed);
|
|
|
while (!Ops.IsStop(axisName) && timeout.ElapsedMilliseconds < 5000)
|
|
|
{
|
|
|
Thread.Sleep(10);
|
|
|
}
|
|
|
}
|
|
|
timeout.Stop();
|
|
|
});
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 是否已回原并在起始位
|
|
|
/// </summary>
|
|
|
/// <param name="axisName"></param>
|
|
|
public static bool IsHomedAndNearStartPos(string axisName)
|
|
|
{
|
|
|
IAxis axis = AxisControl.GetAxis(axisName);
|
|
|
if(axis.HomeStatus==EHomeStatus.Finished)
|
|
|
{
|
|
|
double curPos = GetCurPosition(axisName);
|
|
|
double startPos = SysConfigParam.GetValue<double>($"{axisName}StartPos");
|
|
|
if (Math.Abs(curPos - startPos) <= 0.02)
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
public static bool Go(string axisName,double targetPos, int speedPercent = 0) {
|
|
|
return Go(AxisControl.GetAxis(axisName),targetPos, speedPercent);
|
|
|
}
|
|
|
|
|
|
public static bool Go(IAxis axis, double targetPos,int speedPercent = 0)
|
|
|
{
|
|
|
ErrorCode errCode = ErrorCode.Ok;
|
|
|
if(speedPercent==0)
|
|
|
speedPercent=GlobalVar.WholeSpeed;
|
|
|
errCode = axis.MovePos(targetPos,speedPercent);
|
|
|
if(errCode == ErrorCode.Ok || GlobalVar.VirtualAxis)
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
Msg.ShowError($"轴{axis.Config.AxisName}运动异常,ret={errCode}");
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|