Ejemplo n.º 1
0
        //生成加样移动组合
        public void GenerateInjectActGroup(ref Sequence seque, ref int index, ref ActionPoint[] tager, ref int[] point, ref int[] width, ref bool is_ok, ActionBase move_x = null, Spawn move_zt = null)
        {
            if (index == 4)
            {
                is_ok = true;
                return;
            }
            else if (tager[index].y == point[index] || tager[index].y == -1)
            {
                if (tager[index].y == point[index])
                {
                    var action_point        = tager[index];
                    var move_act            = Sequence.create();
                    List <Enterclose> ents  = new List <Enterclose>();
                    int[]             injz  = IMask.Gen(-1);
                    int[]             injzl = IMask.Gen(-1);
                    int[]             injzd = IMask.Gen(-1);
                    ents.Add(Engine.getInstance().injectorDevice.Injector.Entercloses[index]);
                    move_act.AddAction(SkWaitForAction.create(move_x));
                    if (action_point.type == TestStepEnum.JXZT)
                    {
                        int[] absorbs   = IMask.Gen(-1);
                        var   injact_sp = Spawn.create();
                        injz[index]    = action_point.z;
                        absorbs[index] = (int)ents[0].PumpMotor.Maximum.SetValue;
                        injact_sp.AddAction(InjectMoveTo.create(3001, ents.ToArray(), -1, IMask.Gen(-1), injz, 2));
                        injact_sp.AddAction(InjectAbsorbMove.create(3001, ents.ToArray(), 100, absorbs));
                        move_act.AddAction(injact_sp);
                        injz[index] = action_point.zb;
                        move_act.AddAction(InjectMoveTo.create(3001, ents.ToArray(), -1, IMask.Gen(-1), injz));
                    }
                    else if (action_point.type == TestStepEnum.PutTip)
                    {
                        injz[index] = action_point.z;
                        var sequ = Sequence.create();
                        sequ.AddAction(InjectMoveTo.create(3001, ents.ToArray(), -1, IMask.Gen(-1), injz, 2));
                        sequ.AddAction(MoveTo.create(3001, action_point.puttip_x, -1, -1));
                        injz[index] = action_point.z - 1000;
                        sequ.AddAction(InjectMoveTo.create(3001, ents.ToArray(), -1, IMask.Gen(-1), injz, 100));
                        injz[index] = action_point.zb;
                        sequ.AddAction(InjectMoveTo.create(3001, ents.ToArray(), -1, IMask.Gen(-1), injz));
                        move_act.AddAction(sequ);
                    }
                    else if (action_point.type == TestStepEnum.AbsLiquid)
                    {
                        int[] absorbs = IMask.Gen(-1);
                        absorbs[index] = -(action_point.capacity);
                        move_act.AddAction(InjectMoveTo.create(3001, ents.ToArray(), -1, IMask.Gen(-1), injz, 0));
                        injz[index] = action_point.z + action_point.deep;
                        move_act.AddAction(InjectMoveTo.create(3001, ents.ToArray(), -1, IMask.Gen(-1), injz, action_point.deepspeed));
                        move_act.AddAction(InjectAbsorb.create(3001, ents.ToArray(), action_point.absbspeed, absorbs));
                        //回吸
                        var back_act = Spawn.create();
                        if (action_point.backcapacity != 0)
                        {
                            absorbs[index] = -(action_point.backcapacity);
                            back_act.AddAction(Sequence.create(SKSleep.create(500), InjectAbsorb.create(3001, ents.ToArray(), action_point.backspeed, absorbs)));
                        }
                        injz[index] = action_point.zb;
                        back_act.AddAction(InjectMoveTo.create(3001, ents.ToArray(), -1, IMask.Gen(-1), injz));
                        move_act.AddAction(back_act);
                    }
                    else if (action_point.type == TestStepEnum.FollowAbsLiquid)
                    {
                        int[] absorbs = IMask.Gen(-1);
                        injz[index]    = action_point.z;
                        injzl[index]   = action_point.z + action_point.detectordeep;
                        injzd[index]   = action_point.deep;
                        absorbs[index] = -(action_point.capacity);
                        move_act.AddAction(InjectDetector.create(3001, ents.ToArray(), injz, injzl, injzd, 2, 1));
                        move_act.AddAction(InjectAbsorb.create(3001, ents.ToArray(), action_point.absbspeed, absorbs));
                        //回吸
                        var back_act = Spawn.create();
                        if (action_point.backcapacity != 0)
                        {
                            absorbs[index] = -(action_point.backcapacity);
                            back_act.AddAction(Sequence.create(SKSleep.create(500), InjectAbsorb.create(3001, ents.ToArray(), action_point.backspeed, absorbs)));
                        }
                        injz[index] = action_point.zb;
                        back_act.AddAction(InjectMoveTo.create(3001, ents.ToArray(), -1, IMask.Gen(-1), injz));
                        move_act.AddAction(back_act);
                    }
                    else if (action_point.type == TestStepEnum.SpuLiquid)
                    {
                        int[] absorbs = IMask.Gen(-1);
                        injz[index]    = action_point.z;
                        absorbs[index] = action_point.spucapacity + action_point.backcapacity;
                        move_act.AddAction(InjectMoveTo.create(3001, ents.ToArray(), -1, IMask.Gen(-1), injz, 2));
                        move_act.AddAction(InjectAbsorb.create(3001, ents.ToArray(), action_point.spuspeed, absorbs));
                        //回吸
                        var back_act = Spawn.create();
                        if (action_point.backcapacity != 0)
                        {
                            absorbs[index] = -(action_point.backcapacity);
                            back_act.AddAction(Sequence.create(SKSleep.create(100), InjectAbsorb.create(3001, ents.ToArray(), action_point.backcapacity, absorbs)));
                        }
                        injz[index] = action_point.zb;
                        back_act.AddAction(InjectMoveTo.create(3001, ents.ToArray(), -1, IMask.Gen(-1), injz));
                        move_act.AddAction(back_act);
                    }
                    else if (action_point.type == TestStepEnum.MixLiquid)
                    {
                        int[] absorbs = IMask.Gen(-1);
                        injz[index] = action_point.z;
                        move_act.AddAction(InjectMoveTo.create(3001, ents.ToArray(), -1, IMask.Gen(-1), injz, 2));
                        absorbs[index] = action_point.capacity;
                        move_act.AddAction(InjectAbsorb.create(3001, ents.ToArray(), 100, absorbs));//把稀释液放进去
                        //混合操作
                        if (action_point.mixtimes != 0)
                        {
                            for (int i = 0; i < action_point.mixtimes * 2; i++)
                            {
                                int mixz = action_point.z - action_point.mixdeep;//混合高度
                                if (mixz <= 0)
                                {
                                    mixz = action_point.z;
                                }
                                absorbs[index] = i % 2 == 0 ? -action_point.capacity : action_point.capacity;
                                injz[index]    = i % 2 == 0 ? action_point.z: mixz;
                                move_act.AddAction(InjectMoveTo.create(3001, ents.ToArray(), -1, IMask.Gen(-1), injz, 2));
                                move_act.AddAction(InjectAbsorb.create(3001, ents.ToArray(), 100, absorbs));
                            }
                            injz[index] = action_point.z;
                            move_act.AddAction(InjectMoveTo.create(3001, ents.ToArray(), -1, IMask.Gen(-1), injz, 2));
                            absorbs[index] = (int)ents[0].PumpMotor.Maximum.SetValue;
                            move_act.AddAction(InjectAbsorbMove.create(3001, ents.ToArray(), 100, absorbs));
                            absorbs[index] = -(action_point.GetTubeList().Count *action_point.spucapacity);
                            move_act.AddAction(InjectAbsorb.create(3001, ents.ToArray(), 100, absorbs));
                        }
                        //回吸
                        if (action_point.backcapacity != 0)
                        {
                            injz[index] = action_point.z;
                            move_act.AddAction(InjectMoveTo.create(3001, ents.ToArray(), -1, IMask.Gen(-1), injz));
                            absorbs[index] = -(action_point.backcapacity);
                            move_act.AddAction(InjectAbsorb.create(3001, ents.ToArray(), action_point.backspeed, absorbs));
                        }
                        injz[index] = action_point.zb;
                        move_act.AddAction(InjectMoveTo.create(3001, ents.ToArray(), -1, IMask.Gen(-1), injz));
                    }
                    //查找前面的
                    if (move_zt != null)
                    {
                        move_zt.AddAction(move_act);
                    }
                    else
                    {
                        seque.AddAction(move_act);
                    }
                }
                index++;
                GenerateInjectActGroup(ref seque, ref index, ref tager, ref point, ref width, ref is_ok, move_x, move_zt);
            }
            else
            {
                List <int[]> node_list = new List <int[]>();
                for (int i = 0; i < 4; i++)
                {
                    for (int j = i; j < 4; j++)
                    {
                        for (int k = j; k < 4; k++)
                        {
                            for (int l = k; l < 4; l++)
                            {
                                int[] point_tem = { 0, 0, 0, 0 };
                                point_tem[i] = tager[i].y;
                                point_tem[j] = tager[j].y;
                                point_tem[k] = tager[k].y;
                                point_tem[l] = tager[l].y;
                                for (int n = 0; n < 4; n++)
                                {
                                    if (point_tem[n] < 0)
                                    {
                                        point_tem[n] = 0;
                                    }
                                }
                                bool ispass = true;
                                int  frist  = 0;
                                for (int n = 0; n < 4; n++)
                                {
                                    if (point_tem[n] != 0)
                                    {
                                        frist = n;
                                        break;
                                    }
                                }
                                for (int n = frist; n < 4; n++)
                                {
                                    if (point_tem[n] == 0 && n - 1 >= 0)
                                    {
                                        point_tem[n] = point_tem[n - 1] + width[n];
                                    }
                                }
                                for (int n = 0; n < frist; n++)
                                {
                                    if (point_tem[n] == 0 && n + 1 <= 3)
                                    {
                                        point_tem[n] = point_tem[frist] - width[n] * (frist - n);
                                    }
                                }
                                for (int n = 0; n < 4; n++)
                                {
                                    bool isforward = n - 1 >= 0 ? point_tem[n] >= point_tem[n - 1] + width[n - 1] : true;
                                    bool isback    = n + 1 <= 3 ? point_tem[n] + width[n] <= point_tem[n + 1] : true;

                                    ispass = isforward && isforward;
                                    if (!ispass)
                                    {
                                        break;
                                    }
                                }
                                if (ispass && point_tem[index] == tager[index].y)
                                {
                                    node_list.Add(point_tem);
                                }
                            }
                        }
                    }
                }
                int[] minnode = node_list[0];
                foreach (var node in node_list)
                {
                    if (GetLoss(tager, node) < GetLoss(tager, minnode))
                    {
                        minnode = node;
                    }
                }
                List <int> left  = new List <int>();
                List <int> right = new List <int>();
                for (int i = 0; i < 4; i++)
                {
                    if (point[i] - minnode[i] < 0)
                    {
                        left.Add(i);
                    }
                    else
                    {
                        right.Add(i);
                    }
                }
                left.Sort((a, b) => { return(a < b ? 1 : -1); });
                right.Sort((a, b) => { return(a > b ? 1 : -1); });
                var    movesp_act = Spawn.create();
                var    move_act   = Sequence.create();
                string msg        = "";

                int[]             yy   = { -1, -1, -1, -1 };
                int[]             zz   = { -1, -1, -1, -1 };
                List <Enterclose> ents = new List <Enterclose>();
                for (int i = 0; i < left.Count; i++)
                {
                    int indextem = left[i];
                    if (point[indextem] != minnode[indextem])
                    {
                        ents.Add(Engine.getInstance().injectorDevice.Injector.Entercloses[indextem]);
                        yy[indextem] = minnode[indextem];
                    }
                }
                movesp_act.AddAction(InjectMoveTo.create(3001, ents.ToArray(), -1, yy, zz));
                ents.Clear();
                for (int i = 0; i < right.Count; i++)
                {
                    int indextem = right[i];
                    if (point[indextem] != minnode[indextem])
                    {
                        ents.Add(Engine.getInstance().injectorDevice.Injector.Entercloses[indextem]);
                        yy[indextem] = minnode[indextem];
                    }
                }
                movesp_act.AddAction(InjectMoveTo.create(3001, ents.ToArray(), -1, yy, zz));
                for (int i = 0; i < 4; i++)
                {
                    point[i] = minnode[i];
                }
                move_act.AddAction(movesp_act);
                //同步Z动作
                var spawz_action = Spawn.create();
                move_act.AddAction(spawz_action);
                seque.AddAction(move_act);
                GenerateInjectActGroup(ref seque, ref index, ref tager, ref point, ref width, ref is_ok, move_x, spawz_action);
            }
        }