using FLY.Thick.Base.Server; using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace FLY.Simulation.Battery.RayLaser { public class GageAd { #region 极片轮廓 /// /// 极片的横向视图, 精度1mm, /// um /// public List HorizontalView = new List(); /// /// 极片的一段涂布纵向视图,精度1mm, 第1个数据为 头部 /// um /// public List SegmentView = new List(); /// /// 箔材值, 当上面的视图 IsLight = true, 使用 FoilValue /// public double FoilValue { get; set; } = 27; #endregion #region 机架信息 /// /// 机架长度 mm /// public int TotalLength { get; set; } = 940; /// /// 托管左支架位置 mm /// public int HoldPosLeft { get; set; } = 57; /// /// 托管左支架位置 mm /// public int HoldPosRight { get; set; } = 885; /// /// 支架宽度 mm /// public int HoldWidth { get; set; } = 15; /// /// 射线样品值 /// public double SampleValueRay { get; set; } = 432; /// /// 激光样品值 /// public double SampleValueLaser { get; set; } = 654; /// /// 射线样品宽度 mm /// public double SampleWidthRay { get; set; } = 250; /// /// 激光样品宽度 mm /// public double SampleWidthLaser { get; set; } = 25; #endregion /// /// 纵向光纤与射线纵向距离 mm /// public double VSignOffsetRay { get; set; } = 207; /// /// 纵向光纤与激光纵向距离 mm /// public double VSignOffsetLaser { get; set; } = 610; /// /// 相对于机架 左起始位置 mm /// public int FilmBegin { get; set; } = 170; /// /// 极片速度 m/min /// public double FilmVelocity { get; set; } = 20; /// /// 当前极片位置 m /// public double FilmPosition { get; set; } = 0; /// /// 纵向光纤信号触发了 /// public bool IsVSignLight { get; set; } /// /// 同步信号触发了 /// public bool IsSyncLight { get; set; } public CurveCollection curve_laser; public CurveCollection curve_ray; public void Init() { curve_ray = new CurveCollection("curve_ray.json"); curve_laser = new CurveCollection("curve_laser.json"); Load(); } void Load() { Load_DataInfo(HorizontalView, "HorizontalView.csv"); Load_DataInfo(SegmentView, "SegmentView.csv"); } void Load_DataInfo(List dataInfos, string csvFilePath) { dataInfos.Clear(); using (StreamReader sr = new StreamReader(csvFilePath)) { string header = sr.ReadLine();//标题 , Thick, HSign while (!sr.EndOfStream) { string s = sr.ReadLine(); string[] ss = s.Split(','); double thk = double.Parse(ss[0]); int hsign = int.Parse(ss[1]); dataInfos.Add(new DataInfo() { Thick = thk, IsLight = hsign == 1 }); } sr.Close(); } } DateTime lastTime = DateTime.MinValue; public void OnPoll(DateTime now) { if (lastTime == DateTime.MinValue) { lastTime = now; return; } var ts = now - lastTime; double ms = 1.0 * ts.Ticks / TimeSpan.TicksPerMillisecond; double minute = ms / 1000 / 60; if (FilmVelocity != 0) { FilmPosition += minute * FilmVelocity; } int index = (int)(FilmPosition * 1000 % SegmentView.Count()); IsVSignLight = SegmentView[index].IsLight; lastTime = now; } public enum PosType { /// /// 空气 /// Air, /// /// 极片 /// Film, /// /// 托辊支架 /// Hold, /// /// 样品 /// Sample } /// /// /// /// 是射线? /// 相对于机架横向位置mm /// 相对于极片纵向位置mm /// 输出位置类型 /// public double GetValue(bool isRay, int mm, int mm_v, out PosType posType) { if (mm >= (HoldPosLeft - HoldWidth / 2) && mm <= (HoldPosLeft + HoldWidth / 2)) { posType = PosType.Hold; return 100000; } if (mm >= FilmBegin && mm < FilmBegin + HorizontalView.Count) { posType = PosType.Film; var dataInfoH = HorizontalView[mm - FilmBegin]; while (mm_v < 0) { mm_v += SegmentView.Count(); } var dataInfoV = SegmentView[mm_v % SegmentView.Count()]; if ((dataInfoV.IsLight) || (dataInfoH.IsLight)) { return FoilValue; } double vValue = dataInfoV.Thick; double hValue = dataInfoH.Thick; return (vValue + hValue) / 2; } if (mm >= (HoldPosRight - HoldWidth / 2) && mm <= (HoldPosRight + HoldWidth / 2)) { posType = PosType.Hold; return 100000; } if (isRay) { if (mm >= (HoldPosRight + HoldWidth / 2) && mm <= (HoldPosRight + HoldWidth / 2 + SampleWidthRay)) { posType = PosType.Sample; return SampleValueRay; } } else { if (mm >= (HoldPosRight + HoldWidth / 2) && mm <= (HoldPosRight + HoldWidth / 2 + SampleWidthLaser)) { posType = PosType.Sample; return SampleValueLaser; } } posType = PosType.Air; return 0; } } public class DataInfo { /// /// 上光纤是亮 /// public bool IsLight; /// /// 厚度值 /// public double Thick; } }