GageAD.cs 4.28 KB
Newer Older
潘栩锋's avatar
潘栩锋 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FLY.Simulation.Blowing
{
    public class GageAD:ISimulationGageAD
    {
        /// <summary>
        /// 1脉冲 = ? mm
        /// </summary>
        double mmpp = 0.1133;
        public double Mmpp
        {
            get { return mmpp; }
            set
            {
                mmpp = value;
            }
        }

        public Blowing mBlowing;
        /// <summary>
        /// 机架总长
        /// </summary>
        public int PosLen;
        /// <summary>
        /// 膜宽
        /// </summary>
        public int FilmWidth;
        /// <summary>
        /// 膜开始位置
        /// </summary>
        public int FilmBegin;

        /// <summary>
38
        /// 传感器直径,单位脉冲
潘栩锋's avatar
潘栩锋 committed
39 40 41 42 43 44
        /// </summary>
        public int SenserWidth;

        public int[] AirDatas;

        CurveCollection curve;
45 46
        
        double ppmm;
潘栩锋's avatar
潘栩锋 committed
47 48 49
        public GageAD() 
        {
            curve = new CurveCollection();
50 51 52 53 54 55

            mBlowing = new Blowing();
            double m_filmwidth = mBlowing.FilmWidth;//膜宽2.3m


            double m_gagelen = 3;//设备总长3m
潘栩锋's avatar
潘栩锋 committed
56 57 58 59
            double mm_senserwidth = 15;//传感器15mm
            double mm_filmbegin = 300;//mm

            PosLen = 8030;
60
            ppmm = PosLen / (m_gagelen*1000);
潘栩锋's avatar
潘栩锋 committed
61 62


63
            FilmWidth = (int)(m_filmwidth *1000 * ppmm);
潘栩锋's avatar
潘栩锋 committed
64 65
            FilmBegin = (int)(mm_filmbegin * ppmm);
            SenserWidth = (int)(mm_senserwidth * ppmm);
66

潘栩锋's avatar
潘栩锋 committed
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103

            AirDatas = new int[PosLen];
            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);

        }
        public int GetAD(int pos) 
        {
            return GetAD_1(pos);
            //return GetAD_2(pos);
        }
        int GetAD_1(int pos) 
        {
                int idx = pos;
                if(idx<0)
                    idx = 0;
                else if(idx>=PosLen)
                    idx = PosLen-1;
                
                Random r = new Random();
                int data = r.Next(50) - 25;

                if ((idx >= FilmBegin) && (idx<(FilmBegin+FilmWidth))) 
                {
104 105 106
                    int position = idx-FilmBegin;
                    double pos_m = position / ppmm / 1000.0;
                    FilmData fd = mBlowing.GetData(pos_m);
潘栩锋's avatar
潘栩锋 committed
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
                    if (fd != null)
                    {
                        data += fd.data1 + fd.data2;
                    }
                }
            
            //求平均值
            int thick = (int)data;
            return curve.Value2AD(thick, CurveCollection.AD2ValueFlag.NoRevised);
        }
        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())
                    Misc.MyBase.CLEARBIT(ref istatus, IODefinition.IN_RENZIJIA_0 - 1);
            }
140

潘栩锋's avatar
潘栩锋 committed
141
            if (mBlowing.CheckLimit1())
142 143 144 145 146 147
                Misc.MyBase.CLEARBIT(ref istatus, IODefinition.IN_RENZIJIA_1 - 1);


            if (mBlowing.CheckOrg())
                Misc.MyBase.CLEARBIT(ref istatus, IODefinition.IN_RENZIJIA_ORG - 1);

潘栩锋's avatar
潘栩锋 committed
148 149

            if (mBlowing.CheckRoll())
150
                Misc.MyBase.CLEARBIT(ref istatus, IODefinition.IN_RSENSOR - 1);
潘栩锋's avatar
潘栩锋 committed
151 152 153 154 155 156 157

            return istatus;
        }


        public int GetPosition2()
        {
158 159
            double p = mBlowing.GlobalAngle / 360;
            return (int)(mBlowing.PosOfR * p);
潘栩锋's avatar
潘栩锋 committed
160 161 162
        }
        public int GetSpeed2() 
        {
163
            return (int)(mBlowing.PosOfR * mBlowing.CurrAngleVelocity / 360);
潘栩锋's avatar
潘栩锋 committed
164 165 166 167 168
        }
    }
}