GageAD.cs 3.37 KB
Newer Older
1 2 3
using FLY.Thick.Base.Common;
using FLY.Thick.Base.Server;
using System;
潘栩锋's avatar
潘栩锋 committed
4 5 6 7 8 9 10 11 12 13 14
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FLY.Simulation.Blowing
{
    public class GageAD:ISimulationGageAD
    {
        /// <summary>
        /// 1脉冲 = ? mm
        /// </summary>
15
        public double Mmpp { get; set; } = 0.0943;
潘栩锋's avatar
潘栩锋 committed
16 17

        /// <summary>
18
        /// 机架总长 mm
潘栩锋's avatar
潘栩锋 committed
19
        /// </summary>
20
        public int TotalLength { get; set; } = 2440;
21 22 23

        public Blowing mBlowing;

潘栩锋's avatar
潘栩锋 committed
24
        /// <summary>
25
        /// 膜宽,mm
潘栩锋's avatar
潘栩锋 committed
26 27 28
        /// </summary>
        public int FilmWidth;
        /// <summary>
29
        /// 膜开始位置, mm
潘栩锋's avatar
潘栩锋 committed
30 31 32 33
        /// </summary>
        public int FilmBegin;

        /// <summary>
34
        /// 传感器直径,单位mm
潘栩锋's avatar
潘栩锋 committed
35 36 37
        /// </summary>
        public int SenserWidth;

38

潘栩锋's avatar
潘栩锋 committed
39 40

        CurveCollection curve;
41
        
潘栩锋's avatar
潘栩锋 committed
42 43 44
        public GageAD() 
        {
            curve = new CurveCollection();
45 46

            mBlowing = new Blowing();
潘栩锋's avatar
潘栩锋 committed
47

48 49 50
            FilmWidth = (int)mBlowing.FilmWidth;
            FilmBegin = 300;
            SenserWidth = 30;
潘栩锋's avatar
潘栩锋 committed
51
        }
52

潘栩锋's avatar
潘栩锋 committed
53 54 55 56 57 58
        public void OnPoll(DateTime now) 
        {
            //NewAirDatas();
            mBlowing.OnPoll(now);

        }
59
        public int GetAD(int mm) 
潘栩锋's avatar
潘栩锋 committed
60
        {
61
            return GetAD_1(mm);
62
            //return GetAD_2(mm);
潘栩锋's avatar
潘栩锋 committed
63
        }
64 65
        int GetAD_1(int mm) 
        {                
66 67
            Random r = new Random();
            int data = r.Next(30*2) - 30;// 单位 0.01um, ±0.3um波动
潘栩锋's avatar
潘栩锋 committed
68

69 70 71 72 73
            if ((mm >= FilmBegin) && (mm<(FilmBegin+FilmWidth))) 
            {
                int position_mm = mm-FilmBegin;
                FilmData fd = mBlowing.GetData(position_mm);
                if (fd != null)
潘栩锋's avatar
潘栩锋 committed
74
                {
75
                    data += fd.data1 + fd.data2;
潘栩锋's avatar
潘栩锋 committed
76
                }
77
            }
78

潘栩锋's avatar
潘栩锋 committed
79
            //求平均值
80 81
            double thick = data / 100.0;
            return curve.Value2Ad(thick, AD2ValueFlag.NoRevised);
潘栩锋's avatar
潘栩锋 committed
82
        }
83
        int GetAD_2(int mm)
潘栩锋's avatar
潘栩锋 committed
84 85 86
        {
            int[] datas = new int[SenserWidth];

87
            for (int i = 0; i < SenserWidth; i+=5)
潘栩锋's avatar
潘栩锋 committed
88
            {
89
                datas[i] = GetAD_1(mm - SenserWidth / 2 + i);
潘栩锋's avatar
潘栩锋 committed
90 91 92 93 94 95 96 97 98 99 100 101 102 103
            }
            //求平均值
            return (int)datas.Average();
        }
        /// <summary>
        /// 获取输入口
        /// </summary>
        /// <returns></returns>
        public UInt16 GetInput() 
        {
            UInt16 istatus = 0x0fff;
            if (!mBlowing.IsShieldI9)
            {
                if (mBlowing.CheckLimit0())
104
                    Misc.MyBase.CLEARBIT(ref istatus, IODefinition.IN_RENZIJIA_0);
潘栩锋's avatar
潘栩锋 committed
105
            }
106

潘栩锋's avatar
潘栩锋 committed
107
            if (mBlowing.CheckLimit1())
108
                Misc.MyBase.CLEARBIT(ref istatus, IODefinition.IN_RENZIJIA_1);
109 110 111


            if (mBlowing.CheckOrg())
112
                Misc.MyBase.CLEARBIT(ref istatus, IODefinition.IN_RENZIJIA_ORG);
113

潘栩锋's avatar
潘栩锋 committed
114 115

            if (mBlowing.CheckRoll())
116
                Misc.MyBase.CLEARBIT(ref istatus, IODefinition.IN_RSENSOR);
潘栩锋's avatar
潘栩锋 committed
117 118 119 120 121 122 123

            return istatus;
        }


        public int GetPosition2()
        {
124 125
            double p = mBlowing.GlobalAngle / 360;
            return (int)(mBlowing.PosOfR * p);
潘栩锋's avatar
潘栩锋 committed
126 127 128
        }
        public int GetSpeed2() 
        {
129
            return (int)(mBlowing.PosOfR * mBlowing.CurrAngleVelocity / 360);
潘栩锋's avatar
潘栩锋 committed
130
        }
131 132 133 134 135

        public void SetOutput(ushort output)
        {
            
        }
潘栩锋's avatar
潘栩锋 committed
136 137 138 139
    }
}