|
@@ -1,6 +1,9 @@
|
|
|
using Aitex.Common.Util;
|
|
|
+using Aitex.Core.RT.Device;
|
|
|
using Aitex.Core.RT.Log;
|
|
|
+using Aitex.Core.RT.Routine;
|
|
|
using Aitex.Core.Util;
|
|
|
+using CyberX8_Core;
|
|
|
using MECF.Framework.Common.Beckhoff.AxisProvider;
|
|
|
using MECF.Framework.Common.Beckhoff.Station;
|
|
|
using MECF.Framework.Common.Device.Galil;
|
|
@@ -8,6 +11,7 @@ using MECF.Framework.Common.Equipment;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.IO;
|
|
|
+using System.Runtime.InteropServices.ComTypes;
|
|
|
|
|
|
namespace MECF.Framework.Common.Simulator
|
|
|
{
|
|
@@ -29,6 +33,8 @@ namespace MECF.Framework.Common.Simulator
|
|
|
private const string HOMING_SIGNAL = "HomingSignal";
|
|
|
private const string MOTION_SIGNAL = "MotionSignal";
|
|
|
private const string STOP_SIGNAL = "StopSignal";
|
|
|
+ private const string FESTO_DATABUFFER_TRANSPORT1_LOCK = "ProcessTransporterLock";
|
|
|
+ private const string FESTO_DATABUFFER_TRANSPORT2_LOCK = "LoaderTransporterLock";
|
|
|
/// <summary>
|
|
|
/// 定时器间隔(ms)
|
|
|
/// </summary>
|
|
@@ -52,6 +58,22 @@ namespace MECF.Framework.Common.Simulator
|
|
|
/// Key:moduleName, Value:minStep
|
|
|
/// </summary>
|
|
|
private Dictionary<string, int> _motorNameMinStepDic = new Dictionary<string, int>();
|
|
|
+ /// <summary>
|
|
|
+ /// Key:stationName, Value:position
|
|
|
+ /// </summary>
|
|
|
+ private Dictionary<string, double> _stationPositionDic = new Dictionary<string, double>();
|
|
|
+ /// <summary>
|
|
|
+ /// Key:stationName, Value:Tolerance
|
|
|
+ /// </summary>
|
|
|
+ private Dictionary<string, double> _toleranceDic = new Dictionary<string, double>();
|
|
|
+ /// <summary>
|
|
|
+ /// Key:stationName, Value:BeckhoffProviderAxis
|
|
|
+ /// </summary>
|
|
|
+ private Dictionary<string, BeckhoffProviderAxis> _axisDataDic = new Dictionary<string, BeckhoffProviderAxis>();
|
|
|
+ /// <summary>
|
|
|
+ /// 其他模块数据
|
|
|
+ /// </summary>
|
|
|
+ private Dictionary<string, bool> _otherModuleDataDic = new Dictionary<string, bool>();
|
|
|
#endregion
|
|
|
|
|
|
#region 属性
|
|
@@ -60,14 +82,19 @@ namespace MECF.Framework.Common.Simulator
|
|
|
|
|
|
//delegate
|
|
|
#region Delegate
|
|
|
- public delegate void UpdateVariableValueChanged(Dictionary<string, SimulatorMotionData> datasDic);
|
|
|
+ public delegate void UpdateVariableValueMotionDatasChanged(Dictionary<string, SimulatorMotionData> datasDic);
|
|
|
+ public delegate void UpdateVariableValueInputDatasChanged(string module, string VariableName, bool value);
|
|
|
#endregion
|
|
|
|
|
|
#region 事件
|
|
|
/// <summary>
|
|
|
- /// 变量变更事件
|
|
|
+ /// MotionDatas变更事件
|
|
|
+ /// </summary>
|
|
|
+ public event UpdateVariableValueMotionDatasChanged OnUpdateMotionDatasChanged;
|
|
|
+ /// <summary>
|
|
|
+ /// InputDatas变更事件
|
|
|
/// </summary>
|
|
|
- public event UpdateVariableValueChanged OnUpdateVariableValueChanged;
|
|
|
+ public event UpdateVariableValueInputDatasChanged OnUpdateInputDatasChanged;
|
|
|
#endregion
|
|
|
/// <summary>
|
|
|
/// 初始化
|
|
@@ -82,6 +109,8 @@ namespace MECF.Framework.Common.Simulator
|
|
|
/// </summary>
|
|
|
private void Init()
|
|
|
{
|
|
|
+ SimulatorCommManager.Instance.OnUpdateVariableValueChanged += UpdataDataCausedByOtherModule;
|
|
|
+ InitOtherModuleDatas();
|
|
|
//加载对应配置文件 GalilControllerCfg-Simulator.xml,初始化数据字典
|
|
|
try
|
|
|
{
|
|
@@ -100,6 +129,7 @@ namespace MECF.Framework.Common.Simulator
|
|
|
_motorNameDataDic[$"{config.Module}.{item.Name}"].NegativeTorqueLimit = item.NegativeTorqueLimit;
|
|
|
_motorNameDataDic[$"{config.Module}.{item.Name}"].PositiveTorqueLimit = item.PositiveTorqueLimit;
|
|
|
_motorNameDataDic[$"{config.Module}.{item.Name}"].SwitchSignal = true;
|
|
|
+ _motorNameDataDic[$"{config.Module}.{item.Name}"].ModuleName = config.Module;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -120,6 +150,7 @@ namespace MECF.Framework.Common.Simulator
|
|
|
foreach (BeckhoffProviderAxis item in axisProviderCfg.Axes)
|
|
|
{
|
|
|
double value = item.ScaleFactor / 30;
|
|
|
+ _axisDataDic[item.Name] = item;
|
|
|
_motorNameMinStepDic[item.Name] = (int)((value < 100) ? 100 : value);
|
|
|
}
|
|
|
}
|
|
@@ -132,35 +163,39 @@ namespace MECF.Framework.Common.Simulator
|
|
|
try
|
|
|
{
|
|
|
string oldXmlPath = PathManager.GetCfgDir();
|
|
|
- string newXmlPath = oldXmlPath.Replace("CyberX8_Simulator", "CyberX8_RT") + "Devices\\StationPositionsCfg_Simulator.xml";
|
|
|
+ string newXmlPath = oldXmlPath.Replace("CyberX8_Simulator", "CyberX8_RT") + "Station\\StationPositionsCfg_Simulator.xml";
|
|
|
StationPositionCfg cfg = CustomXmlSerializer.Deserialize<StationPositionCfg>(new FileInfo(newXmlPath));
|
|
|
if (cfg != null)
|
|
|
{
|
|
|
- //foreach (BeckhoffStationModule config in cfg.Module)
|
|
|
- //{
|
|
|
- // if (config.Name == ModuleName.Transporter1.ToString())
|
|
|
- // {
|
|
|
- // foreach (BeckhoffStationAxis item in config.Axises)
|
|
|
- // {
|
|
|
- // ;
|
|
|
- // }
|
|
|
- // }
|
|
|
- // else if(config.Name == ModuleName.Transporter2.ToString())
|
|
|
- // {
|
|
|
- // foreach (BeckhoffStationAxis item in config.Axises)
|
|
|
- // {
|
|
|
- // ;
|
|
|
- // }
|
|
|
- // }
|
|
|
-
|
|
|
- //}
|
|
|
+ foreach (BeckhoffStationModule config in cfg.Module)
|
|
|
+ {
|
|
|
+ if (config.Name.Contains("Transporter"))
|
|
|
+ {
|
|
|
+ foreach (BeckhoffStationAxis item in config.Axises)
|
|
|
+ {
|
|
|
+ _toleranceDic[item.Name] = item.ToleranceDefault;
|
|
|
+ if (item.Name.Contains("Elevator"))
|
|
|
+ {
|
|
|
+ foreach(var subItem in item.Stations)
|
|
|
+ {
|
|
|
+ _stationPositionDic[subItem.Name.ToLower()] = double.Parse(subItem.Position);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
catch
|
|
|
{
|
|
|
- LOG.WriteLog(eEvent.ERR_GALIL, "Galil", "Load galil GalilControllerCfg-Simulator.xml failed");
|
|
|
+ LOG.WriteLog(eEvent.ERR_GALIL, "StationPosition", "Load StationPositionCfg-Simulator.xml failed");
|
|
|
}
|
|
|
}
|
|
|
+ private void InitOtherModuleDatas()
|
|
|
+ {
|
|
|
+ _otherModuleDataDic[FESTO_DATABUFFER_TRANSPORT1_LOCK] = false;
|
|
|
+ _otherModuleDataDic[FESTO_DATABUFFER_TRANSPORT2_LOCK] = false;
|
|
|
+ }
|
|
|
/// <summary>
|
|
|
/// 定时器执行
|
|
|
/// </summary>
|
|
@@ -173,23 +208,38 @@ namespace MECF.Framework.Common.Simulator
|
|
|
//对应电机进行模拟
|
|
|
MotorMotionSimulator(motorItem);
|
|
|
//实时更新电机数据
|
|
|
- UpdateVariableValue(_motorNameDataDic);
|
|
|
+ UpdateMotionDatas(_motorNameDataDic);
|
|
|
+ //更新InputDatas
|
|
|
+ UpdateInputDatas(motorItem);
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
/// <summary>
|
|
|
- /// 通知Galil模块数据变化
|
|
|
+ /// 通知Galil模块motion数据变化
|
|
|
/// </summary>
|
|
|
/// <param name="data"></param>
|
|
|
- private void UpdateVariableValue(Dictionary<string, SimulatorMotionData> datasDic)
|
|
|
+ private void UpdateMotionDatas(Dictionary<string, SimulatorMotionData> datasDic)
|
|
|
{
|
|
|
- if (OnUpdateVariableValueChanged != null)
|
|
|
+ if (OnUpdateMotionDatasChanged != null)
|
|
|
{
|
|
|
- OnUpdateVariableValueChanged(datasDic);
|
|
|
+ OnUpdateMotionDatasChanged(datasDic);
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
+ /// 通知Galil模块Input数据变化
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="module"></param>
|
|
|
+ /// <param name="value"></param>
|
|
|
+ private void UpdateInputDatas(KeyValuePair<string, SimulatorMotionData> motorItem)
|
|
|
+ {
|
|
|
+ if (OnUpdateInputDatasChanged != null && CheckMotionData(motorItem, out string VariableName, out bool value))
|
|
|
+ {
|
|
|
+ OnUpdateInputDatasChanged(motorItem.Value.ModuleName, VariableName, value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
/// 设置电机数据
|
|
|
/// </summary>
|
|
|
/// <param name="axisName"></param>
|
|
@@ -357,6 +407,52 @@ namespace MECF.Framework.Common.Simulator
|
|
|
}
|
|
|
return speed;
|
|
|
}
|
|
|
-
|
|
|
+ /// <summary>
|
|
|
+ /// 检查电机数据
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ private bool CheckMotionData(KeyValuePair<string, SimulatorMotionData> motor, out string name,out bool value)
|
|
|
+ {
|
|
|
+ bool result = false;
|
|
|
+ value = false;
|
|
|
+ name = "";
|
|
|
+ switch (motor.Key)
|
|
|
+ {
|
|
|
+ case "Transporter1.Elevator":
|
|
|
+ name = "r_TRANSPORT1_WS_HOLD_PRESENT";
|
|
|
+ value = _otherModuleDataDic[FESTO_DATABUFFER_TRANSPORT1_LOCK] && CheckAtStation(motor.Key, motor.Value, "up") ? true : false;
|
|
|
+ result = true;
|
|
|
+ break;
|
|
|
+ case "Transporter2.Elevator":
|
|
|
+ name = "r_TRANSPORT2_WS_HOLD_PRESENT";
|
|
|
+ value = _otherModuleDataDic[FESTO_DATABUFFER_TRANSPORT2_LOCK] && CheckAtStation(motor.Key, motor.Value, "up") ? true : false;
|
|
|
+ result = true;
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 更新其他模块数据
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="name"></param>
|
|
|
+ /// <param name="value"></param>
|
|
|
+ private void UpdataDataCausedByOtherModule(string name, bool value)
|
|
|
+ {
|
|
|
+ if (_otherModuleDataDic.ContainsKey(name))
|
|
|
+ {
|
|
|
+ _otherModuleDataDic[name] = value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private bool CheckAtStation(string name, SimulatorMotionData data, string stationName)
|
|
|
+ {
|
|
|
+ double diff = Math.Abs(data.ActualPosition - _stationPositionDic[$"{name.ToLower()}.{stationName.ToLower()}"] * _axisDataDic[name].ScaleFactor);
|
|
|
+ if (diff <= _toleranceDic[name] * _axisDataDic[name].ScaleFactor)
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
}
|