Blowing.cs 26.7 KB
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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 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 104 105 106 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 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Collections.ObjectModel;
using System.IO;
using Newtonsoft.Json;

namespace FLY.Simulation.Blowing
{
    
    [JsonObject(MemberSerialization.OptIn)]
    public class Blowing:INotifyPropertyChanged
    {
        #region 参数
        #region 旋转架
        /// <summary>
        /// 360° 连续旋转
        /// </summary>
        [JsonProperty]
        public bool Is360 { get; set; }
        /// <summary>
        /// 正向旋转
        /// </summary>
        public bool IsForw { get; set; }

        /// <summary>
        /// 旋转架复位中
        /// </summary>
        public bool IsOrg { get; set; }

        /// <summary>
        /// 旋转架启动中
        /// </summary>
        public bool IsRotationOn { get; set; }

        /// <summary>
        /// 牵引启动中
        /// </summary>
        public bool IsTractionOn { get; set; }

        /// <summary>
        /// 1圈总脉冲
        /// </summary>
        [JsonProperty]
        public double PosOfR { get; set; }


        /// <summary>
        /// 两个限位间的角度范围  != 旋转的总角度,限位值 °
        /// </summary>
        [JsonProperty]
        public double AngleRange { get; set; }

        /// <summary>
        /// 复位信号角度范围°
        /// </summary>
        [JsonProperty]
        public double OrgAngleRange { get; set; }
        /// <summary>
        /// 旋转的速度, min/R 1R = 360°
        /// </summary>
        [JsonProperty]
        public double AngleVelocity { get; set; }


        /// <summary>
        /// 加速时间 单位 s
        /// </summary>
        [JsonProperty]
        public double AngleAccTime { get; set; }

        /// <summary>
        /// 减速时间 单位 s
        /// </summary>
        [JsonProperty]
        public double AngleDecTime { get; set; }

        /// <summary>
        /// 换方向冷却时间 单位s
        /// </summary>
        [JsonProperty]
        public double AngleCoolTime { get; set; }
        #endregion


        #region 

        /// <summary>
        /// 膜泡压扁后总宽度,单位 脉冲
        /// </summary>
        public double FilmWidth { get; set; }

        /// <summary>
        /// 膜走带速度, m/min
        /// </summary>
        [JsonProperty]
        public double FilmVelocity { get; set; }

        /// <summary>
        /// 人字架到测厚仪的距离 23m
        /// </summary>
        [JsonProperty]
        public double FilmDistance { get; set; }

        /// <summary>
        /// 辊轴承,单位mm
        /// </summary>
        [JsonProperty]
        public double RollPerimeter { get; set; }

        /// <summary>
        /// 测辊信号,信号长,单位mm
        /// </summary>
        [JsonProperty]
        public double RollSignLength { get; set; }
        #endregion

        #region 风环
        /// <summary>
        /// 加热棒数量
        /// </summary>
        [JsonProperty]
        public int ChannelCnt { get; set; }
        ///// <summary>
        ///// 加热功率, 1~100
        ///// </summary>
        //public int[] Heats;
        /// <summary>
        /// 第1根加热棒对应角度
        /// </summary>
        [JsonProperty]
        public double Channel1stAngle { get; set; }
        ///// <summary>
        ///// 温度影响厚度变化比例, 1厚度,对应多少加热
        ///// </summary>
        //public int Factor;//
        #endregion

        public bool IsShieldI9 { get; set; }


        #endregion
        #region 动态数据



        /// <summary>
        /// 当前人字架角度 °
        /// </summary>
        public double CurrAngle { get; private set; }
        /// <summary>
        /// 全局角度 °
        /// </summary>
        public double GlobalAngle { get; private set; }
        /// <summary>
        /// 当前速度,单位 °/s
        /// </summary>
        public double CurrAngleVelocity { get; private set; }
        /// <summary>
        /// 当前加速度, 单位 °/s^2
        /// </summary>
        public double CurrAngleAccV { get; private set; }


        /// <summary>
        /// 当前已经走到长度, 通过编码器获取 单位 m
        /// </summary>
        public double CurrFilmLength { get; private set; }

        #endregion
        public HMI mHMI;
        public int Avg { get; set; }
        /// <summary>
        /// 原始数据
        /// </summary>
        public ObservableCollection<int> BeforeDatas = new ObservableCollection<int>();
        /// <summary>
        /// 系统扰动后 数据
        /// </summary>
        public ObservableCollection<int> BeforeDatas2 = new ObservableCollection<int>();
        /// <summary>
        /// 系统扰动后 再 加热数据
        /// </summary>
        public ObservableCollection<int> AfterDatas = new ObservableCollection<int>();




        class PositionAngleInfo
        {
            public DateTime dt;
            public double position;
            public double angle;
        }



        /// <summary>
        /// 10ms 1个记录点
        /// </summary>
        List<PositionAngleInfo> mPositionAngleList = new List<PositionAngleInfo>();

        int ListCap = 30000;//300s

        public Blowing()
        {

            //撞了限位后,限位信号一直在。。。。
            PosOfR = 50000;
            OrgAngleRange = 5;//复位信号角度°
            AngleRange = 350;//两个限位间的角度范围350°
            AngleVelocity = 6;//出限位 到 撞另一个限位的时间 8min/ 360°
            AngleAccTime = 1;//加速时间1s
            AngleDecTime = 5;//减速时间5s
            AngleCoolTime = 5;//正反转延迟时间5s 
            
            FilmWidth = 2.3;//膜宽2.3m
    
            FilmVelocity = 20;//线速度m/min
            FilmDistance = 26;//膜距离m


            RollPerimeter = 314;//辊周长mm
            RollSignLength = 30;//辊信号长度mm


            ChannelCnt = 88;//加热棒数量
            Channel1stAngle = 100;//第1根加热棒对应角度

            if (!Load())
                Save();

            //整个膜片1000个数据
            int[] datas = OrgData.GetData(1000);
            for(int i=0;i<1000;i++)
            {
                BeforeDatas.Add(datas[i]);//原始数据
                BeforeDatas2.Add(datas[i]);//系统扰动后数据
                AfterDatas.Add(datas[i]);//系统扰动后 再 加热数据
            }

            mAirRing = new AirRing(ChannelCnt);//88支加热棒
            mAirRing.Init(BeforeDatas, BeforeDatas2, 0);


            mAirRing2 = new AirRing(ChannelCnt);//88支加热棒;
            mAirRing2.Init(BeforeDatas2, AfterDatas, (int)(1000*Channel1stAngle/360));//加热偏移了 

            mAirRing2.AfterDatasUpdateEvent += new Action<ObservableCollection<int>>(mAirRing2_AfterDatasUpdateEvent);
            Avg = (int)(BeforeDatas.Average());//原始平均值

            TestPos = 500;
            UpdateTestHeat();

            //AfterDatas.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(AfterDatas_CollectionChanged);
            PropertyChanged += new PropertyChangedEventHandler(Blowing_PropertyChanged);

            mHMI = new HMI();
            mHMI.mAirRing = mAirRing2;



            Is360 = false;

            IsForw = true;
            IsOrg = false;
            IsRotationOn = true;
            IsTractionOn = true;
        }

        void mAirRing2_AfterDatasUpdateEvent(ObservableCollection<int> obj)
        {
            NotifyPropertyChanged(nameof(AfterDatas));
        }
        

        public int TestPos { get; set; }

        public int TestHeat { get; set; }

        public void Test()
        {
            int idx = mAirRing.ChannelCnt * TestPos / BeforeDatas.Count();

            int offset = TestHeat - mAirRing.Heats[idx];

            mAirRing.Test(idx, offset);

            mAirRing2.HeatApply();
        }
        
        public class AirRing 
        {
            /// <summary>
            /// 加热通过
            /// </summary>
            public int ChannelCnt;
            /// <summary>
            /// 加热量, 数据量为 ChannelCnt
            /// </summary>
            public int[] Heats;
            /// <summary>
            /// 第1个加热棒,对应的 数据序号, 数据量为 1000, BeforeData.Count
            /// </summary>
            public int Channel1stIndex;
            /// <summary>
            /// 加热 对 厚度的影响
            /// </summary>
            public double Factor;

            //需要别人赋值
            /// <summary>
            /// 原始数据!! 数据量为1000
            /// </summary>
            public ObservableCollection<int> BeforeDatas;
            /// <summary>
            /// 加热后的数据!!!! 数据量为BeforeDatas.Count
            /// </summary>
            public ObservableCollection<int> AfterDatas;


            double[] p;// 一个凸起来的数组  0 1 4 9 16 9 4 1 0
            void p_init()
            {
                int size = ChannelCnt / 10;
                p = new double[size];
                for (int i = 0; i < size; i++)
                {
                    int index1 = i;
                    int index2 = size - 1 - i;
                    double d = i * i;
                    p[index1] = d;
                    p[index2] = d;
                    if (Math.Abs(index2-index1)<=1)
                        break;
                }
                double sum_p = p.Max();
                for (int i = 0; i < size; i++)
                {
                    p[i] = p[i] / sum_p;
                }
            }
            public AirRing(int channelcnt)
            {
                SetChannelCnt(channelcnt);
                p_init();
                Factor = 5;
            }
            public void Init(ObservableCollection<int> before_datas, ObservableCollection<int> after_datas, int channel1stIndex)
            {
                BeforeDatas = before_datas;
                AfterDatas = after_datas;
                Channel1stIndex = channel1stIndex;

            }
            public void SetChannelCnt(int channelcnt)
            {
                ChannelCnt = channelcnt;
                Heats = new int[ChannelCnt];
                Array.Clear(Heats, 0, ChannelCnt);
            }
            public event Action<ObservableCollection<int>> AfterDatasUpdateEvent;
            public void HeatApply() 
            {
                int boltcnt = BeforeDatas.Count();
                double b_c = (double)(boltcnt)/ChannelCnt;
                int b = Channel1stIndex;
                double beforeavg = BeforeDatas.Average();
                int[] datas = new int[boltcnt];
                for (int i = 0; i < ChannelCnt; i++) 
                {
                    int heat = Heats[i];
                    int e = (int)((i+1) * b_c)+ Channel1stIndex;

                    if (e >= boltcnt)
                        e -= boltcnt;
                    else if (e < 0)
                        e += boltcnt;
                        
                    int j=b;
                    while (j != e)
                    {
                        datas[j] = (int)(BeforeDatas[j] - beforeavg * heat / Factor/100);

                        j++;
                        if (j >= boltcnt)
                            j -= boltcnt;
                    }
                    b = e;
                }
                double afteravg = datas.Average();

                for (int j = 0; j < boltcnt; j++)
                {
                    AfterDatas[j] = (int)(beforeavg * datas[j] / afteravg);
                }
                if (AfterDatasUpdateEvent != null)
                {
                    AfterDatasUpdateEvent(AfterDatas);
                }
            }
            
            public void Test(int idx,int offset) 
            {
                idx -= p.Count() / 2;
                if (idx < 0)
                    idx += ChannelCnt;
                else if (idx >= ChannelCnt)
                    idx -= ChannelCnt;

                for (int i = 0; i < p.Count(); i++) 
                {
                    int index = idx+i;
                    
                    if (index < 0)
                        index += ChannelCnt;
                    else if (index>= ChannelCnt)
                        index -= ChannelCnt;


                    int heat = Heats[index] + (int)(offset * p[i]);
                    if (heat > 100)
                        heat = 100;
                    else if (heat < 0)
                        heat = 0;
                    Heats[index] = heat;
                }
                HeatApply();
            }
        }
        /// <summary>
        /// 1级加热, 模拟系统扰动
        /// </summary>
        private AirRing mAirRing;
        /// <summary>
        /// 2级加热, 通过HMI 控制的加热
        /// </summary>
        public AirRing mAirRing2;

        void Blowing_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == nameof(Avg)) 
            {
                int avg = (int)(BeforeDatas.Average());
                int offset = Avg - avg;
                if (offset != 0)
                {
                    for (int i = 0; i < BeforeDatas.Count(); i++)
                    {
                        BeforeDatas[i] += offset;
                    }
                }
            }
            else if (e.PropertyName == nameof(TestPos))
            {
                UpdateTestHeat();
            }
        }
        void UpdateTestHeat() 
        {
            int idx = mAirRing.ChannelCnt * TestPos / BeforeDatas.Count();
                TestHeat = mAirRing.Heats[idx];
        }


        bool SearchAngleFromPositionList(double position, out double angle)
        {
            for (int i = 1; i < mPositionAngleList.Count; i++)
            {
                int idx1 = i;
                int idx2 = i - 1;
                if ((mPositionAngleList[idx1].position >= position))
                {

                    double percent = (position - mPositionAngleList[idx2].position) / (mPositionAngleList[idx1].position - mPositionAngleList[idx2].position);
                    if (percent < 0)
                    {
                        angle = 0;
                        return true;
                    }
                    //找到了
                    angle = (mPositionAngleList[idx1].angle - mPositionAngleList[idx2].angle) * percent + mPositionAngleList[idx2].angle;
                    return true;
                }
            }
            angle = 0;
            return true;
        }

        public FilmData GetData(double position)
        {
            double ago_filmlength = CurrFilmLength - FilmDistance;
            double angle;
            //从膜位置列表找时间
            if (!SearchAngleFromPositionList(ago_filmlength, out angle))
                return null;

            return GetData(position, angle);

        }
        double GetValidAngle(double a) {
            while (a >= 360)
                a -= 360;
            while (a < 0)
                a += 360;
            return a;
        }
        /// <summary>
        /// 获取膜泡数据
        /// </summary>
        /// <param name="position">相对于膜泡位置,横向</param>
        /// <param name="angle">人字架角度</param>
        /// <returns></returns>
        FilmData GetData(double position, double angle)
        {
            if ((position < 0) || (position > FilmWidth))
            {
                return null;
            }
            //与0°的偏移
            double a = position / FilmWidth * 180;
            //压扁对面的角度
            double a_other = 360 - a;

            a = GetValidAngle( a + angle );
            a_other = GetValidAngle(a_other + angle);

            int dat_idx1 = (int)(a / 360 * AfterDatas.Count());
            int dat_idx2 = (int)(a_other / 360 * AfterDatas.Count());

            FilmData fd = new FilmData()
            {
                angle1 = a,
                angle2 = a_other,
                data1 = AfterDatas[dat_idx1],
                data2 = AfterDatas[dat_idx2]
            };
            return fd;
        }

        /// <summary>
        /// 1.28ms 1次
        /// </summary>
        public void OnPoll(DateTime now)
        {
           
            UpdatePositionAndAngle(now);
        }


        enum STATE 
        {
            /// <summary>
            /// 加速
            /// </summary>
            Acc,
            /// <summary>
            /// 减速
            /// </summary>
            Dec,
            /// <summary>
            /// 恒速
            /// </summary>
            Constant,
            /// <summary>
            /// 方向交换,冷却期
            /// </summary>
            Wrap
        }
        STATE mState;
        DateTime mDTLast = DateTime.MinValue;
        /// <summary>
        /// 停下来的时间
        /// </summary>
        DateTime mDTWrap = DateTime.MinValue;


        /// <summary>
        /// 更新旋转
        /// </summary>
        /// <param name="now"></param>
        /// <param name="ts"></param>
        void UpdateAngleV(DateTime now, TimeSpan ts)
        {
            if (IsOrg) {
                IsRotationOn = false;

                UpdateAngleV_Org(now, ts);
                return;
            }

            if (IsRotationOn) {
                if (Is360)
                {
                    UpdateAngleV_360(now, ts);
                }
                else {
                    UpdateAngleV_ForwBackw(now, ts);
                }
            }
        }



        /// <summary>
        /// 正反向旋转
        /// </summary>
        /// <param name="now"></param>
        /// <param name="ts"></param>
        void UpdateAngleV_ForwBackw(DateTime now, TimeSpan ts) 
        {
            double angle = CurrAngle + CurrAngleVelocity * ts.TotalSeconds;

            switch (mState)
            {
                case STATE.Constant:
                    if (((CurrAngleVelocity > 0) && (angle >= AngleRange / 2)) ||
                        ((CurrAngleVelocity < 0) && (angle <= (-AngleRange / 2))))
                    {
                        mState = STATE.Dec;
                        double dv = 0 - CurrAngleVelocity;
                        CurrAngleAccV = dv / AngleDecTime;
                    } break;
                case STATE.Dec:
                    {
                        bool isForw = false;
                        if (CurrAngleVelocity > 0)
                            isForw = true;
                        CurrAngleVelocity += CurrAngleAccV * ts.TotalSeconds;
                        if (((isForw) && (CurrAngleVelocity < 0)) ||
                            ((!isForw) && (CurrAngleVelocity > 0)))
                        {
                            CurrAngleVelocity = 0;
                            mState = STATE.Wrap;
                            mDTWrap = now;
                        }
                    } break;
                case STATE.Wrap:
                    {
                        if ((now - mDTWrap).TotalSeconds >= AngleCoolTime)
                        {
                            //冷静完
                            mState = STATE.Acc;
                            double anglev = 360.0 / (AngleVelocity * 60);
                            if (angle >= AngleRange / 2)
                            {
                                //反转
                                anglev = -anglev;
                                IsForw = false;
                            }
                            else {
                                IsForw = true;
                            }
                            CurrAngleAccV = anglev / AngleAccTime;
                        }
                    } break;
                case STATE.Acc:
                    {
                        CurrAngleVelocity += CurrAngleAccV * ts.TotalSeconds;

                        double anglev = 360.0 / (AngleVelocity * 60);
                        if (CurrAngleAccV > 0)
                        {
                            if (CurrAngleVelocity >= anglev)
                            {
                                CurrAngleVelocity = anglev;
                                mState = STATE.Constant;
                            }
                        }
                        else
                        {
                            if (CurrAngleVelocity <= -anglev)
                            {
                                CurrAngleVelocity = -anglev;
                                mState = STATE.Constant;
                            }
                        }
                    } break;
            }
            double delta = angle - CurrAngle;
            GlobalAngle += delta;
            CurrAngle = angle;
        }


        /// <summary>
        /// 连续旋转
        /// </summary>
        /// <param name="now"></param>
        /// <param name="ts"></param>
        void UpdateAngleV_360(DateTime now, TimeSpan ts)
        {
            double anglev = 360.0 / (AngleVelocity * 60);
            if (IsForw)
                CurrAngleVelocity = anglev;
            else
                CurrAngleVelocity = -anglev;

            double angle = CurrAngle + CurrAngleVelocity * ts.TotalSeconds;
            double delta = angle - CurrAngle;
            GlobalAngle += delta;

            while (angle >= 360)
                angle -= 360;
            while (angle < 0)
                angle +=360;

            CurrAngle = angle;

        }

        /// <summary>
        /// 复位
        /// </summary>
        /// <param name="now"></param>
        /// <param name="ts"></param>
        void UpdateAngleV_Org(DateTime now, TimeSpan ts)
        {
            double anglev = 360.0 / (AngleVelocity * 60);

            if (CurrAngle > 0){
                CurrAngleVelocity = -anglev;
            }
            else if (CurrAngle < 0) 
            { 
                CurrAngleVelocity = anglev;
            }
            else {
                CurrAngleVelocity = 0;
                IsOrg = false;
                return;
            }

            double angle = CurrAngle + CurrAngleVelocity * ts.TotalSeconds;
            double delta = angle - CurrAngle;

            if (((CurrAngle > 0) && (angle <= 0))||
                ((CurrAngle < 0) && (angle >= 0)))
            {
                delta = 0 - CurrAngle;
                CurrAngle = 0;
                CurrAngleVelocity = 0;
                IsOrg = false;
                return;
            }
            GlobalAngle += delta;
            CurrAngle = angle;
        }
        
        
        
        /// <summary>
        /// 驱动器,根据时间,更新angle,
        /// </summary>
        /// <param name="now"></param>
        void UpdatePositionAndAngle(DateTime now)
        {
            if (mDTLast == DateTime.MinValue)
            {
                double position = FilmDistance;
                DateTime time = now;
                while (position > 0)
                {
                    mPositionAngleList.Insert(0,
                        new PositionAngleInfo()
                        {
                            dt = time,
                            position = position,
                            angle = 0
                        });
                    TimeSpan ts1 = TimeSpan.FromMilliseconds(10);
                    time -= ts1;
                    position -= FilmVelocity * ts1.TotalMinutes;
                }

                mDTLast = now;
                CurrFilmLength = FilmDistance;
                CurrAngle = 0;//在中间

                mState = STATE.Constant;
                double anglev = 360.0 / (AngleVelocity * 60);
                CurrAngleVelocity = anglev;


                return;
            }

            DateTime dt = now;

            TimeSpan ts = dt.Subtract(mDTLast);
            if (ts.TotalMilliseconds < 10)
                return;

            mDTLast = dt;
            //线速度。。。。



            if(IsTractionOn)//启动牵引
                CurrFilmLength += FilmVelocity * ts.TotalMinutes;

            UpdateAngleV(dt, ts);


            mPositionAngleList.Add(
                new PositionAngleInfo()
                {
                    dt = mDTLast,
                    angle = CurrAngle,
                    position = CurrFilmLength
                });

            if (mPositionAngleList.Count > ListCap)
                mPositionAngleList.RemoveAt(0);
        }
        public bool CheckOrg() 
        {
            if (CurrAngle <= OrgAngleRange / 2 && CurrAngle >= -OrgAngleRange / 2)
                return true;
            else
                return false;
        }
        public bool CheckLimit1() 
        {
            if (Is360)
            {
                if (CurrAngleVelocity < 0)
                    return true;
                else
                    return false;
            }
            else
            {
                if (CurrAngle >= AngleRange / 2)
                    return true;
                else
                    return false;
            }
        }
        public bool CheckLimit0()
        {
            if (Is360)
            {
                if (CurrAngleVelocity > 0)
                    return true;
                else
                    return false;
            }
            else
            {
                if (CurrAngle <= (-AngleRange / 2))
                    return true;
                else
                    return false;
            }
        }
        public bool CheckRoll() 
        {
            int rollcnt = (int)(CurrFilmLength*1000 / RollPerimeter);
            double p = CurrFilmLength*1000 - rollcnt * RollPerimeter;
            if (p <= RollSignLength)
                return true;
            else
                return false;
        }
        protected void NotifyPropertyChanged(string propertyname) 
        {
            if (PropertyChanged != null) 
            {
                PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyname));
            }
        }
        public event PropertyChangedEventHandler PropertyChanged;

        private string param_path = "simulation_blowing.json";
        public void Save() 
        {
            string json = Newtonsoft.Json.JsonConvert.SerializeObject(this, Formatting.Indented);
            File.WriteAllText(param_path, json);

        }
        bool Load() 
        {
            if (!File.Exists(param_path))
                return false;
            try
            {
                string json = File.ReadAllText(param_path);

                Newtonsoft.Json.JsonConvert.PopulateObject(json, this);
                return true;
            }
            catch {

                return false;
            }
        }
    }
    public class FilmData
    {
        public double angle1;
        public double angle2;
        public int data1;
        public int data2;
    }


}