Example #1
0
 public override void OnExit()
 {
     attackDone            = false;
     navObstacle.enabled   = false;
     navAgent.enabled      = true;
     currentPulseGenerator = null;
 }
Example #2
0
 public override void OnEnter()
 {
     currentPulseGenerator = null;
     navAgent.enabled      = false;
     navObstacle.enabled   = true;
     attackDone            = false;
     animator.SetInteger(Strings.ANIMATIONSTATE, (int)AnimationStates.Attack1);
     Attack();
 }
Example #3
0
        public Apu()
        {
            Pulse1   = new PulseGenerator(1);
            Pulse2   = new PulseGenerator(2);
            Triangle = new TriangleGenerator();
            Noise    = new NoiseGenerator();
            Dmc      = new DmcGenerator();

            filterChain = new FilterChain();
        }
Example #4
0
    private void Attack()
    {
        //Make sure the kamikaze is not stunned
        if (myStats.health <= myStats.skinnableHealth)
        {
            StopPulse();
            controller.UpdateState(EAIState.Stun);
            controller.DeActivateAI();
        }

        pulseGenerator = ObjectPool.Instance.GetObject(PoolObjectType.KamikazePulseGenerator);
        if (pulseGenerator)
        {
            pulseGenerator.transform.position = controller.transform.position;
            currentPulseGenerator             = pulseGenerator.GetComponent <PulseGenerator>();
            currentPulseGenerator.SetPulseGeneratorStats(properties.maxPulses, properties.pulseRate, properties.scaleRate, properties.maxScale, myStats.attack);
        }

        SFXManager.Instance.Play(SFXType.KamikazePulse, velBody.transform.position);
    }
        public void Separate(int index, bool bManual = false)
        {
            double      pos = GetStationPointDic()["剥料起始位"].pointY;
            double      posz = 0, posy = 0;
            WaranResult waranResult;

            Info(string.Format("{0} {1}次剥料", bManual?"手动":"自动", index));
            if (index > 6)
            {
                return;
            }

            switch (index)
            {
            case 0:
                #region  压
                ParamSetMgr.GetInstance().SetBoolParam("右剥料归位", false);
retry_pressup:
                IOMgr.GetInstace().WriteIoBit("右剥料后压紧气缸电磁阀", false);
                waranResult = CheckIobyName("右剥料后压紧气缸原位", true, "右剥料:Separate:右剥料后压紧气缸原位 到位失败", bManual);
                if (waranResult == WaranResult.Retry)
                {
                    goto retry_pressup;
                }

                //IOMgr.GetInstace().WriteIoBit("右剥料压紧气缸电磁阀", false);
                //waranResult = CheckIobyName("右剥料压紧气缸原位", true, "右剥料:Separate:右剥料压紧气缸原位 到位失败", bManual);
                //if (waranResult == WaranResult.Retry)
                //    goto retry_pressup;

                IOMgr.GetInstace().WriteIoBit("右剥料夹料气缸电磁阀", false);
                waranResult = CheckIobyName("右剥料夹料气缸原位", true, "右剥料:Separate:右剥料夹料气缸原位 到位失败", bManual);
                if (waranResult == WaranResult.Retry)
                {
                    goto retry_pressup;
                }


                IOMgr.GetInstace().WriteIoBit("右剥料气缸电磁阀", true);


                double xpos = GetStationPointDic()["剥料下压位"].pointX;
                double ypos = GetStationPointDic()["剥料下压位"].pointY;
                Info("右剥料:Y轴 去剥料下压位,RBZ轴 去剥料前压位");
                //MoveSigleAxisPosWaitInpos(AxisY, pos, MotionMgr.GetInstace().GetAxisMovePrm(AxisY).VelH, 20, bManual, this);
                MoveMulitAxisPosWaitInpos(new int[] { AxisX, AxisY }, new double[] { xpos, ypos }, new double[] { (double)SpeedType.High, (double)SpeedType.High }, 20, bManual, this, 60000);


retry_pressdown:
                IOMgr.GetInstace().WriteIoBit("右剥料后压紧气缸电磁阀", true);
                waranResult = CheckIobyName("右剥料后压紧气缸到位", true, "右剥料:Separate:右剥料后压紧气缸到位 到位失败", bManual);
                if (waranResult == WaranResult.Retry)
                {
                    goto retry_pressdown;
                }


#if false
                IOMgr.GetInstace().WriteIoBit("右剥料前推压紧气缸电磁阀", true);
                waranResult = CheckIobyName("右剥料前推压紧气缸到位", true, "右剥料:Separate:右剥料前推压紧气缸到位 到位失败", bManual);
                if (waranResult == WaranResult.Retry)
                {
                    goto retry_pressdown;
                }
#endif

                ypos = GetStationPointDic()["剥料前压位"].pointY;
                Info("去剥料前压位");
                MoveSigleAxisPosWaitInpos(AxisY, ypos, (double)SpeedType.High, 20, bManual, this);

retry_pushfront_:
                IOMgr.GetInstace().WriteIoBit("右剥料气缸电磁阀", true);
                waranResult = CheckIobyName("右剥料气缸到位", true, "右剥料:Separate:右剥料气缸到位 到位失败", bManual);
                if (waranResult == WaranResult.Retry)
                {
                    goto retry_pushfront_;
                }

#if false
retry_push:
                IOMgr.GetInstace().WriteIoBit("右剥料气缸电磁阀", true);
                waranResult = CheckIobyName("右剥料气缸到位", true, "右剥料:Separate:右剥料气缸到位 到位失败", bManual);
                if (waranResult == WaranResult.Retry)
                {
                    goto retry_push;
                }
#endif


                Info("右剥料 下拉");
                xpos = GetStationPointDic()["剥料前压位"].pointX;
                Info("去剥料前压位下压");
                MoveSigleAxisPosWaitInpos(AxisX, xpos, (double)SpeedType.High, 20, bManual, this);

                Info("右剥料 预剥料完成");

retry_camp:
                IOMgr.GetInstace().WriteIoBit("右剥料夹料气缸电磁阀", true);
                waranResult = CheckIobyName("右剥料夹料气缸到位", true, "右剥料:Separate:右剥料夹料气缸到位 到位失败", bManual);
                if (waranResult == WaranResult.Retry)
                {
                    goto retry_camp;
                }


                //IOMgr.GetInstace().WriteIoBit("右剥料压紧气缸电磁阀", true);
                //waranResult = CheckIobyName("右剥料压紧气缸到位", true, "右剥料:Separate:右剥料压紧气缸到位 到位失败", bManual);
                //if (waranResult == WaranResult.Retry)
                //    goto retry_pressdown;
                break;

                #endregion
            case 6:
                #region 弃料


                //retry_pressbackdown:
                //IOMgr.GetInstace().WriteIoBit("右剥料后压紧气缸电磁阀", true);
                //waranResult = CheckIobyName("右剥料后压紧气缸到位", true, "右剥料:Separate:右剥料后压紧气缸到位 到位失败", bManual);
                //if (waranResult == WaranResult.Retry)
                //    goto retry_pressbackdown;

                //retry_Spressup2:
                //IOMgr.GetInstace().WriteIoBit("右剥料夹料气缸电磁阀", true);
                //waranResult = CheckIobyName("右剥料夹料气缸到位", true, "右剥料:Separate:右剥料夹料气缸到位 到位失败", bManual);
                //if (waranResult == WaranResult.Retry)
                //    goto retry_Spressup2;
retry_pressbackup:
                IOMgr.GetInstace().WriteIoBit("右剥料后压紧气缸电磁阀", false);
                waranResult = CheckIobyName("右剥料后压紧气缸原位", true, "右剥料:Separate:右剥料后压紧气缸原位 到位失败", bManual);
                if (waranResult == WaranResult.Retry)
                {
                    goto retry_pressbackup;
                }

                posz = GetStationPointDic()["剥料弃料位"].pointX;
                // posy= GetStationPointDic()["剥料弃料位"].pointY;
                Info("右剥料:去弃料位");
                MoveSigleAxisPosWaitInpos(AxisX, posz, MotionMgr.GetInstace().GetAxisMovePrm(AxisX).VelH, 20, bManual, this);
                //  MoveLine2DWaitInpos("右剥料YZ", new double[] { posz, posy }, 20, bManual);



                IOMgr.GetInstace().WriteIoBit("右剥料上吹气电磁阀", true);
                IOMgr.GetInstace().WriteIoBit("右剥料下吹气电磁阀", true);

retry_SFront2:
                IOMgr.GetInstace().WriteIoBit("右剥料气缸电磁阀", false);
                waranResult = CheckIobyName("右剥料气缸原位", true, "右剥料:Separate:右剥料气缸原位 到位失败", bManual);
                if (waranResult == WaranResult.Retry)
                {
                    goto retry_SFront2;
                }
                PulseGenerator pulseGenerator = new PulseGenerator(200, 8, new Action <int>((nCount) => {
                    if (nCount % 2 == 0)
                    {
                        IOMgr.GetInstace().WriteIoBit("右剥料下吹气电磁阀", false);
                    }
                    else
                    {
                        IOMgr.GetInstace().WriteIoBit("右剥料下吹气电磁阀", true);
                    }
                }), new Action(() => {
                    IOMgr.GetInstace().WriteIoBit("右剥料下吹气电磁阀", false);
                }));

retry_Spressup3:
                IOMgr.GetInstace().WriteIoBit("右剥料夹料气缸电磁阀", false);
                waranResult = CheckIobyName("右剥料夹料气缸原位", true, "右剥料:Separate:右剥料夹料气缸原位 到位失败", bManual);
                if (waranResult == WaranResult.Retry)
                {
                    goto retry_Spressup3;
                }

                pulseGenerator.StartPulseGenerator();
                //retry_pressfrontpressup2:
                //IOMgr.GetInstace().WriteIoBit("右剥料压紧气缸电磁阀", false);
                //    waranResult = CheckIobyName("右剥料压紧气缸原位", true, "右剥料:Separate:右剥料前推压紧气缸到位 到位失败", bManual);
                //if (waranResult == WaranResult.Retry)
                //        goto retry_pressfrontpressup2;

                //retry_frontpush:
                //IOMgr.GetInstace().WriteIoBit("右剥料前推压紧气缸电磁阀", true);
                //waranResult = CheckIobyName("右剥料前推压紧气缸到位", true, "右剥料:Separate:右剥料前推压紧气缸到位 到位失败", bManual);
                //if (waranResult == WaranResult.Retry)
                //    goto retry_frontpush;

                //retry_pressbackdown2:
                //IOMgr.GetInstace().WriteIoBit("右剥料后压紧气缸电磁阀", true);
                //waranResult = CheckIobyName("右剥料后压紧气缸到位", true, "右剥料:Separate:右剥料后压紧气缸原位 到位失败", bManual);
                //if (waranResult == WaranResult.Retry)
                // goto retry_pressbackdown2;

                // retry_pressfrontup:
                //IOMgr.GetInstace().WriteIoBit("右剥料压紧气缸电磁阀", false);
                // waranResult = CheckIobyName("右剥料压紧气缸原位", true, "右剥料:Separate:右剥料压紧气缸原位 到位失败", bManual);
                //if (waranResult == WaranResult.Retry)
                //  goto retry_pressfrontup;


retry_pressbackup5:
                IOMgr.GetInstace().WriteIoBit("右剥料后压紧气缸电磁阀", false);
                waranResult = CheckIobyName("右剥料后压紧气缸原位", true, "右剥料:Separate:右剥料后压紧气缸原位 到位失败", bManual);
                if (waranResult == WaranResult.Retry)
                {
                    goto retry_pressbackup5;
                }

                pos = GetStationPointDic()["剥料准备位"].pointY;
                double posX = GetStationPointDic()["剥料准备位"].pointX;
                Info("右剥料:回剥料准备位");
                MoveMulitAxisPosWaitInpos(new int[] { AxisX, AxisY }, new double[] { posX, pos }, new double[] { (double)SpeedType.High, (double)SpeedType.High }, 20, bManual, this, 60000);
                IOMgr.GetInstace().WriteIoBit("右剥料上吹气电磁阀", false);
                IOMgr.GetInstace().WriteIoBit("右剥料下吹气电磁阀", false);

                ParamSetMgr.GetInstance().SetBoolParam("右剥料归位", true);
                PlaneMgr.GetInstance().PlaneArr[(int)PlaneType.rightStripPlane].planeState = PlaneState.None;
                break;

                #endregion
            default:
                #region 剥料(1 2 3 4 5)

                ParamSetMgr.GetInstance().SetBoolParam("右剥料归位", false);
#if false
retry_pressfrontpressup:
                IOMgr.GetInstace().WriteIoBit("右剥料压紧气缸电磁阀", true);
                waranResult = CheckIobyName("右剥料压紧气缸到位", true, "右剥料:Separate:右剥料压紧气缸到位 到位失败", bManual);
                if (waranResult == WaranResult.Retry)
                {
                    goto retry_pressfrontpressup;
                }

retry_pressfrontfront2:
                IOMgr.GetInstace().WriteIoBit("右剥料前推压紧气缸电磁阀", false);
                waranResult = CheckIobyName("右剥料前推压紧气缸原位", true, "右剥料:Separate:右剥料前推压紧气缸到位 到位失败", bManual);
                if (waranResult == WaranResult.Retry)
                {
                    goto retry_pressfrontfront2;
                }
#endif

#if true
retry_Sback:
                IOMgr.GetInstace().WriteIoBit("右剥料气缸电磁阀", true);
                waranResult = CheckIobyName("右剥料气缸到位", true, "右剥料:Separate:右剥料气缸到位 到位失败", bManual);
                if (waranResult == WaranResult.Retry)
                {
                    goto retry_Sback;
                }
#else
retry_push2:
                IOMgr.GetInstace().WriteIoBit("右剥料气缸电磁阀", false);
                waranResult = CheckIobyName("右剥料气缸原位", true, "右剥料:Separate:右剥料气缸电原位 到位失败", bManual);
                if (waranResult == WaranResult.Retry)
                {
                    goto retry_push2;
                }
#endif
                //retry_SFront:
                //IOMgr.GetInstace().WriteIoBit("右剥料气缸电磁阀", false);
                //waranResult = CheckIobyName("右剥料气缸原位", true, "右剥料:Separate:右剥料气缸原位 到位失败", bManual);
                //if (waranResult == WaranResult.Retry)
                //    goto retry_SFront;

retry_Spressup:
                IOMgr.GetInstace().WriteIoBit("右剥料夹料气缸电磁阀", true);
                waranResult = CheckIobyName("右剥料夹料气缸到位", true, "右剥料:Separate:右剥料夹料气缸到位 到位失败", bManual);
                if (waranResult == WaranResult.Retry)
                {
                    goto retry_Spressup;
                }

                pos = GetStationPointDic()["剥料起始位"].pointY;
                double lenstep = ParamSetMgr.GetInstance().GetDoubleParam("剥料步长");
                posy = pos - (int)((index - 1) * lenstep * nResolutionY);
                pos  = GetStationPointDic()["剥料起始位"].pointX;
                posz = pos - (int)((index - 1) * lenstep * nResolutionX);
                MoveLine2DWaitInpos("右剥料YZ", new double[] { posz, posy }, 10, bManual);

                //Info("去剥料起始位Y");
                //MoveSigleAxisPosWaitInpos(AxisY, pos, MotionMgr.GetInstace().GetAxisMovePrm(AxisY).VelH, 20, bManual,  this);

                //Info("去剥料起始位LZ");
                //MoveSigleAxisPosWaitInpos(AxisX, pos, MotionMgr.GetInstace().GetAxisMovePrm(AxisX).VelH, 20, bManual,  this);


                Info("压紧气缸下压");

retry_pressbackdownagain:
                IOMgr.GetInstace().WriteIoBit("右剥料后压紧气缸电磁阀", true);
                waranResult = CheckIobyName("右剥料后压紧气缸到位", true, "右剥料:Separate:右剥料后压紧气缸到位 到位失败", bManual);
                if (waranResult == WaranResult.Retry)
                {
                    goto retry_pressbackdownagain;
                }

                //retry_pressfrontfront:
                //    IOMgr.GetInstace().WriteIoBit("右剥料前推压紧气缸电磁阀", true);
                //    waranResult = CheckIobyName("右剥料前推压紧气缸到位", true, "右剥料:Separate:右剥料前推压紧气缸到位 到位失败", bManual);
                //    if (waranResult == WaranResult.Retry)
                //        goto retry_pressfrontfront;

                //retry_pressfrontpressdown:
                //IOMgr.GetInstace().WriteIoBit("右剥料压紧气缸电磁阀", true);
                //waranResult = CheckIobyName("右剥料压紧气缸到位", true, "右剥料:Separate: 右剥料压紧气缸到位 到位失败", bManual);
                //if (waranResult == WaranResult.Retry)
                //    goto retry_pressfrontpressdown;
                //retry_Spressdown:
                //IOMgr.GetInstace().WriteIoBit("右剥料夹料气缸电磁阀", true);
                //waranResult = CheckIobyName("右剥料夹料气缸到位", true, "右剥料:Separate:右剥料夹料气缸到位 到位失败", bManual);
                //if (waranResult == WaranResult.Retry)
                //    goto retry_Spressdown;

                //Thread.Sleep(ParamSetMgr.GetInstance().GetIntParam("下压延时"));
                //retry_Sback:
                //  IOMgr.GetInstace().WriteIoBit("右剥料气缸电磁阀", true);
                //  waranResult = CheckIobyName("右剥料气缸到位", true, "右剥料:Separate:右剥料气缸到位 到位失败", bManual);
                //  if (waranResult == WaranResult.Retry)
                //      goto retry_Sback;

                // Thread.Sleep(ParamSetMgr.GetInstance().GetIntParam("拨料延时"));
                //retry_pressfrontpressup3:
                //IOMgr.GetInstace().WriteIoBit("右剥料压紧气缸电磁阀", false);
                //waranResult = CheckIobyName("右剥料压紧气缸原位", true, "右剥料:Separate:右剥料压紧气缸原位 到位失败", bManual);
                //if (waranResult == WaranResult.Retry)
                //    goto retry_pressfrontpressup3;

                //retry_pressfrontback:
                //IOMgr.GetInstace().WriteIoBit("右剥料前推压紧气缸电磁阀", false);
                //waranResult = CheckIobyName("右剥料前推压紧气缸原位", true, "右剥料:Separate:右剥料前推压紧气缸原位 到位失败", bManual);
                //if (waranResult == WaranResult.Retry)
                //    goto retry_pressfrontback;

                double currentpos = MotionMgr.GetInstace().GetAxisPos(AxisX);
                MoveSigleAxisPosWaitInpos(AxisX, currentpos + ParamSetMgr.GetInstance().GetDoubleParam("剥料后拉距离") * nResolutionY, (double)SpeedType.High, 20, bManual, this, 60000);
                break;
                #endregion
            }

            ParamSetMgr.GetInstance().SetIntParam("右剥料次数", ++index);
        }
Example #6
0
        //Methods
        public void Run()
        {
            //Filter test
            RealFeatureFilter rff = new RealFeatureFilter(new Interval(-1, 1));

            for (int i = 1; i <= 1500; i++)
            {
                rff.Update(_rand.NextDouble() * _rand.Next(0, 10000));
            }
            double featureValue = 0.5;
            double filterValue  = rff.ApplyFilter(featureValue);
            double reverseValue = rff.ApplyReverse(filterValue);

            Console.WriteLine($"Feature: {featureValue} Filter: {filterValue} Reverse: {reverseValue}");



            //Pulse generator test
            BasicStat sampleStat = new BasicStat();

            sampleStat.Reset();
            PulseGeneratorSettings modSettings = new PulseGeneratorSettings(1, 1.5, PulseGeneratorSettings.TimingMode.Poisson);
            IGenerator             generator   = new PulseGenerator(modSettings);

            int    steps  = 10000;
            double period = 0;

            for (int i = 0; i < steps; i++)
            {
                ++period;
                double sample = generator.Next();
                //Console.WriteLine(sample);
                if (sample != 0)
                {
                    sampleStat.AddSampleValue(period);
                    period = 0;
                }
            }
            Console.WriteLine($"Mean: {sampleStat.ArithAvg} StdDev: {sampleStat.StdDev} Min: {sampleStat.Min} Max: {sampleStat.Max}");
            Console.ReadLine();



            //Random distributions test
            BasicStat rStat = new BasicStat();

            for (int i = 0; i < 200; i++)
            {
                double r = _rand.NextFilterredGaussianDouble(0.5, 1, -0.5, 1);
                rStat.AddSampleValue(r);
                Console.WriteLine(r);
            }
            Console.WriteLine($"Mean: {rStat.ArithAvg} StdDev: {rStat.StdDev} Min: {rStat.Min} Max: {rStat.Max}");
            Console.ReadLine();



            //Activation tests
            double fadingSum = 0;

            for (int i = 0; i < 1000; i++)
            {
                fadingSum *= (1d - 0.1);
                fadingSum += 1d;
                Console.WriteLine(fadingSum);
            }

            Console.ReadLine();


            IActivationFunction testAF = ActivationFactory.Create(new SimpleIFSettings(refractoryPeriods: 0), new Random(0));

            TestActivation(testAF, 100, 3.5, 10, 70);

            SimpleIFSettings setup = new SimpleIFSettings();

            FindAFInputBorders(ActivationFactory.Create(setup, new Random(0)),
                               -0.1,
                               20
                               );



            //Linear algebra test
            double[] flatData =
            {
                0.2,      5,  17.3,   1.01,     54,     7,
                2.2,    5.5, 12.13,  11.57,   5.71,   -85,
                -70.1,   15, -18.3,    0.3,     42, -6.25,
                0.042,    1,  7.75, -81.01, -21.29,  5.44,
                0.1,      4,  -4.3,  18.01,   7.12, -3.14,
                -80.1, 24.4,   4.3,  12.03,  2.789, -13
            };
            Matrix testM = new Matrix(6, 6, flatData);

            /*
             * //Inversion test
             * Matrix resultM = new Matrix(testM);
             * resultM.SingleThreadInverse();
             */
            /*
             * //Transpose test
             * Matrix resultM = testM.Transpose();
             */

            /*
             * //Multiply test
             * Matrix resultM = Matrix.Multiply(testM, testM);
             * for (int i = 0; i < resultM.NumOfRows; i++)
             * {
             *  Console.WriteLine($"{resultM.Data[i][0]}; {resultM.Data[i][1]}; {resultM.Data[i][2]}; {resultM.Data[i][3]}; {resultM.Data[i][4]}; {resultM.Data[i][5]}");
             * }
             */



            ;



            int numOfweights = 3;
            int xIdx, dIdx = 0;

            double[][] data = new double[3][];
            data[dIdx]         = new double[numOfweights];
            xIdx               = -1;
            data[dIdx][++xIdx] = 2;
            data[dIdx][++xIdx] = 1;
            data[dIdx][++xIdx] = 3;
            ++dIdx;
            data[dIdx]         = new double[numOfweights];
            xIdx               = -1;
            data[dIdx][++xIdx] = 1;
            data[dIdx][++xIdx] = 3;
            data[dIdx][++xIdx] = -3;
            ++dIdx;
            data[dIdx]         = new double[numOfweights];
            xIdx               = -1;
            data[dIdx][++xIdx] = -2;
            data[dIdx][++xIdx] = 4;
            data[dIdx][++xIdx] = 4;

            //Matrix M = new Matrix(data, true);
            //Matrix I = M.Inverse(false);
            //Matrix identity = M * I; //Must lead to identity matrix


            Matrix I = new Matrix(3, 3);

            I.AddScalarToDiagonal(1);
            Matrix X = new Matrix(I);

            X.Multiply(0.1);

            Matrix XT = X.Transpose();
            Matrix R  = XT * X;


            Console.ReadLine();



            ///*
            SimpleIFSettings settings = new SimpleIFSettings(new RandomValueSettings(15, 15),
                                                             new RandomValueSettings(0.05, 0.05),
                                                             new RandomValueSettings(5, 5),
                                                             new RandomValueSettings(20, 20),
                                                             0
                                                             );
            IActivationFunction af = ActivationFactory.Create(settings, new Random(0));

            //*/
            TestActivation(af, 800, 0.15, 10, 600);
            return;
        }