GageAD.cs 3.78 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 21 22 23
        public int TotalLength { get; set; } = 3000;

        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 38 39 40
        /// </summary>
        public int SenserWidth;

        public int[] AirDatas;

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

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

49 50 51 52
            FilmWidth = (int)mBlowing.FilmWidth;
            FilmBegin = 300;
            SenserWidth = 30;
            AirDatas = new int[TotalLength];
潘栩锋's avatar
潘栩锋 committed
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
            NewAirDatas();
        }
        void NewAirDatas() 
        {
            int a = 20;
            Random r = new Random();
            for (int i = 0; i < AirDatas.Count(); i++)
            {
                AirDatas[i] = r.Next(a) - a/2;
            }
        }
        public void OnPoll(DateTime now) 
        {
            //NewAirDatas();
            mBlowing.OnPoll(now);

        }
70
        public int GetAD(int mm) 
潘栩锋's avatar
潘栩锋 committed
71
        {
72
            return GetAD_1(mm);
潘栩锋's avatar
潘栩锋 committed
73 74
            //return GetAD_2(pos);
        }
75 76
        int GetAD_1(int mm) 
        {                
潘栩锋's avatar
潘栩锋 committed
77 78 79
                Random r = new Random();
                int data = r.Next(50) - 25;

80
                if ((mm >= FilmBegin) && (mm<(FilmBegin+FilmWidth))) 
潘栩锋's avatar
潘栩锋 committed
81
                {
82 83
                    int position = mm-FilmBegin;
                    double pos_m = position / 1000.0;
84
                    FilmData fd = mBlowing.GetData(pos_m);
潘栩锋's avatar
潘栩锋 committed
85 86 87 88 89
                    if (fd != null)
                    {
                        data += fd.data1 + fd.data2;
                    }
                }
90

潘栩锋's avatar
潘栩锋 committed
91
            //求平均值
92 93
            double thick = data / 100.0;
            return curve.Value2Ad(thick, AD2ValueFlag.NoRevised);
潘栩锋's avatar
潘栩锋 committed
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
        }
        int GetAD_2(int pos)
        {
            int[] datas = new int[SenserWidth];

            for (int i = 0; i < SenserWidth; i++)
            {
                datas[i] = GetAD_1(pos - SenserWidth / 2 + i);
            }
            //求平均值
            return (int)datas.Average();
        }
        /// <summary>
        /// 获取输入口
        /// </summary>
        /// <returns></returns>
        public UInt16 GetInput() 
        {
            UInt16 istatus = 0x0fff;
            if (!mBlowing.IsShieldI9)
            {
                if (mBlowing.CheckLimit0())
116
                    Misc.MyBase.CLEARBIT(ref istatus, IODefinition.IN_RENZIJIA_0);
潘栩锋's avatar
潘栩锋 committed
117
            }
118

潘栩锋's avatar
潘栩锋 committed
119
            if (mBlowing.CheckLimit1())
120
                Misc.MyBase.CLEARBIT(ref istatus, IODefinition.IN_RENZIJIA_1);
121 122 123


            if (mBlowing.CheckOrg())
124
                Misc.MyBase.CLEARBIT(ref istatus, IODefinition.IN_RENZIJIA_ORG);
125

潘栩锋's avatar
潘栩锋 committed
126 127

            if (mBlowing.CheckRoll())
128
                Misc.MyBase.CLEARBIT(ref istatus, IODefinition.IN_RSENSOR);
潘栩锋's avatar
潘栩锋 committed
129 130 131 132 133 134 135

            return istatus;
        }


        public int GetPosition2()
        {
136 137
            double p = mBlowing.GlobalAngle / 360;
            return (int)(mBlowing.PosOfR * p);
潘栩锋's avatar
潘栩锋 committed
138 139 140
        }
        public int GetSpeed2() 
        {
141
            return (int)(mBlowing.PosOfR * mBlowing.CurrAngleVelocity / 360);
潘栩锋's avatar
潘栩锋 committed
142
        }
143 144 145 146 147

        public void SetOutput(ushort output)
        {
            
        }
潘栩锋's avatar
潘栩锋 committed
148 149 150 151
    }
}