Beispiel #1
0
    /// <summary>
    /// 复位到点方法
    /// </summary>
    /// <param name="Pos">复位点位置</param>
    /// <param name="Speed">机器移动速度</param>
    /// <param name="Deviation">机器移动误差</param>
    /// <returns></returns>
    public static IEnumerator WaitForResetting(Vector2 Pos, int Speed, int Deviation)
    {
        Debug.Log("开始复位点");
        //发送复位命令
        DynaLinkHS.CmdServoOn();
        DynaLinkHS.CmdLinePassive((int)Pos.x, (int)Pos.y, Speed);
        //等待复位
        float waittime = 0;

        do
        {
            //复位中超过三秒不动重新发点
            if (waittime >= ResendTime)
            {
                DynaLinkHS.CmdServoOn();
                DynaLinkHS.CmdLinePassive((int)Pos.x, (int)Pos.y, Speed);
                waittime = 0;
            }
            yield return(new WaitForSeconds(0.5f));

            //根据MotionInProcess来判断是否在运动
            if (!DiagnosticStatus.MotStatus.MotionInProcess)
            {
                waittime += 0.5f;
            }
            else
            {
                waittime = 0;
            }
        } while ((Mathf.Abs(DynaLinkHS.StatusMotRT.PosDataJ1 - Pos.x) > Deviation || Mathf.Abs(DynaLinkHS.StatusMotRT.PosDataJ2 - Pos.y) > Deviation || DiagnosticStatus.MotStatus.MotionInProcess) && !IsEmrgencyStop && IsConnected && !IsCaution && !IsHalt && !IsPause && !IsFault);
        Debug.Log("Enter");
        yield return("ResettingFinished");
    }
        private void Awake()
        {
            // 初始化窗体属性
            base.CurrentUIType.UIForms_Type       = UIFormType.PopUp;
            base.CurrentUIType.UIForms_ShowMode   = UIFormShow.ReverseChange;
            base.CurrentUIType.UIForm_LucencyType = UIFormLucenyType.ImPenetrable;
            //base.Initialize();
            // 注册按钮事件

            RigisterButtonObjectEvent("CountDown_Pause",
                                      p =>
            {
                OpenUIForm("HOGUIPause");
                GlobalApplication.IsPause = true;
                DynaLinkHS.CmdServoOn();
                SendMessage(HiddenObjectMessage.MsgStopGame, "", "True");
            }
                                      );
        }
Beispiel #3
0
        void Awake()
        {
            base.CurrentUIType.UIForms_Type       = UIFormType.Normal;
            base.CurrentUIType.UIForms_ShowMode   = UIFormShow.Normal;
            base.CurrentUIType.UIForm_LucencyType = UIFormLucenyType.Lucency;

            //注册按钮事件
            RigisterButtonObjectEvent("Btn_Music",
                                      p =>
            {
                // print("音乐按钮");
                GlobalApplication.IsPause = true;
                OpenUIForm(HiddenObjectPage.MusicConsole);
                DynaLinkHS.CmdServoOn();
                SendMessage(HiddenObjectMessage.MsgStopGame, "", "True");
            }
                                      );

            RigisterButtonObjectEvent("Btn_Pause",
                                      p =>
            {
                GlobalApplication.IsPause = true;
                OpenUIForm("HOGUIPause");
                DynaLinkHS.CmdServoOn();
                SendMessage(HiddenObjectMessage.MsgStopGame, "", "True");
            }
                                      );

            RigisterButtonObjectEvent("Btn_Next",
                                      p =>
            {
                print("下一步按钮");
                //CloseUIForm("Task");
                OnClickNext();
            }
                                      );
        }
        /// <summary>
        /// Called on Update
        /// </summary>
        void MonitorMachineStatus()
        {
            if (DiagnosticStatus.MotStatus.Caution && !_isbool)
            {
                OpenUIForm("Spasm");
                _isCaution = true;
                //CommandFunctions.SpasmRecover(new Vector2(81500, 35600), 150000, 300, 3, 60);
                Vector2 rePoint = new Vector2();
                if (_canStartGame)
                {
                    rePoint.x = Mathf.CeilToInt(_lastPos.x / MachinePara.WidthScale);
                    rePoint.y = Mathf.CeilToInt(_lastPos.y / MachinePara.HeightScale);
                }
                else
                {
                    rePoint = MachinePara.ResetVect;
                }
                CommandFunctions.SpasmRecover(rePoint, 150000, 300, 3, 60);
                _isbool = true;
            }

            if (CommandFunctions.IsSpasmFinished)
            {
                Debug.LogWarning("<color=orange>" + CommandFunctions.IsInReset + "</color>");
                if (CommandFunctions.IsInReset)
                {
                    CommandFunctions.RestartReset();
                }
                //else
                //{
                //    if (GlobalApplication.CanRecord)
                //        SendMachineCmd();
                //}
                CommandFunctions.IsSpasmFinished = false;
                _isbool    = false;
                _isCaution = false;
            }

            //if (CommandFunctions.IsSpasmAgain)
            //{
            //    Debug.Log("二次痉挛");
            //    CommandFunctions.SpasmAgainRecover();
            //    CommandFunctions.IsSpasmAgain = false;
            //}


            if (!CommandFunctions.IsConnected || DynaLinkHS.EMstop || _isCaution)
            {
                GlobalApplication.IsPause = true;
                _canSendCmd = true;
            }
            else
            {
                if (!_isGameStop)
                {
                    GlobalApplication.IsPause = false;
                }
            }

            if (_canSendCmd && _canStartGame && !_isCaution && CommandFunctions.IsConnected && !DynaLinkHS.EMstop)
            {
                if (_isGameStop)
                {
                    DynaLinkHS.CmdServoOn();
                }
                else
                {
                    SendMachineCmd();
                }
                _canSendCmd = false;
            }
        }
    void Update()
    {
        //出现断开连接或者急停或者痉挛,不执行痉挛/复位的任何操作
        if (CommandFunctions.IsEmrgencyStop || !CommandFunctions.IsConnected)
        {
            return;
        }
        //获得Caution标志位
        DetectionManage.Instance.Caution = DiagnosticStatus.MotStatus.Caution;
        DetectionManage.Instance.Fault   = DiagnosticStatus.MotStatus.Fault;
        //痉挛流程处理
        switch (CommandFunctions.spasmState)
        {
        //痉挛等待阶段,等待X秒后开始清除痉挛
        case CommandFunctions.SpasmState.RecoveryWaiting:
            //等待时间到
            if (CommandFunctions.SpasmWaitingTime <= 0)
            {
                Debug.Log("等待完毕");
                //等待时间到,切换痉挛状态为清除痉挛
                CommandFunctions.spasmState = CommandFunctions.SpasmState.Recovering;
            }
            else
            {
                CommandFunctions.SpasmWaitingTime -= Time.deltaTime;
            }
            break;

        //清除痉挛阶段
        case CommandFunctions.SpasmState.Recovering:
            //首先判断是在复位中还是游戏中
            //如果在复位中继续复位
            if (CommandFunctions.IsInReset)
            {
                Debug.Log("IsInReset");
                ControlSpasmAgain = false;
                //清除痉挛
                DynaLinkHS.CmdClearAlm();
                DynaLinkHS.CmdServoOff();
                DynaLinkHS.CmdServoOn();
                //改变痉挛完成标志位
                //CommandFunctions.IsSpasmFinished = true;
                CommandFunctions.spasmState = CommandFunctions.SpasmState.NoSpasm;
            }
            else
            {
                //在游戏中,改变痉挛状态为等待复位中
                Debug.Log("IsInGame");
                CommandFunctions.spasmState = CommandFunctions.SpasmState.ResettingWaiting;
                //开始复位到上一个点
                StartCoroutine(WaitForSpasmReset(CommandFunctions.SpasmPostion, CommandFunctions.ResetSpeed, CommandFunctions.ResetDeviation));
            }
            break;

        //等待不做任何事
        case CommandFunctions.SpasmState.ResettingWaiting:

            break;

        //二次痉挛
        case CommandFunctions.SpasmState.SpasmAgain:
            Debug.Log("二次痉挛");
            //停止所有协程
            StopAllCoroutines();
            //等待清除痉挛标志位
            WaitforCaution = true;
            //延迟0.5秒清除痉挛
            Invoke("DelayClearAlm", 0.5f);
            CommandFunctions.spasmState = CommandFunctions.SpasmState.ResettingWaiting;
            break;

        //跳过痉挛
        case CommandFunctions.SpasmState.SkipSpasm:
            Debug.Log("跳过痉挛");
            CommandFunctions.spasmState = CommandFunctions.SpasmState.ResettingWaiting;
            //停止现在所有协程
            StopAllCoroutines();
            if (Ienumerator != null)
            {
                StopCoroutine(Ienumerator);
            }
            DynaLinkHS.CmdServoOn();
            CommandFunctions.SpasmWaitingTraining = 0;
            //如果还有痉挛清除痉挛
            if (CommandFunctions.IsCaution)
            {
                WaitforCaution = true;
                DynaLinkHS.CmdClearAlm();
                DynaLinkHS.CmdServoOn();
            }
            else
            {
                //痉挛已清除,直接改变痉挛过程完成标志位
                ControlSpasmAgain = false;
                //CommandFunctions.IsSpasmFinished = true;
                //设置痉挛状态为无痉挛
                CommandFunctions.spasmState = CommandFunctions.SpasmState.NoSpasm;
            }
            break;
        }
        //复位流程处理
        if (CommandFunctions.resettingState != CommandFunctions.ResettingState.ResetFinshed && CommandFunctions.IsCanReset && !CommandFunctions.IsCaution && !CommandFunctions.IsPause && DiagnosticStatus.MotStatus.SysCalPass)
        {
            switch (CommandFunctions.resettingState)
            {
            //游戏开始前复位
            case CommandFunctions.ResettingState.Resetting:
                CommandFunctions.resettingState = CommandFunctions.ResettingState.ResetWaiting;
                //开始复位到游戏开始点
                StartCoroutine(WaitForReset(CommandFunctions.ResetPostion, CommandFunctions.ResetSpeed, CommandFunctions.ResetDeviation));
                break;

            //等待阶段什么都不做
            case CommandFunctions.ResettingState.ResetWaiting:
                break;

            //游戏结束后复位
            case CommandFunctions.ResettingState.EndResetting:
                CommandFunctions.resettingState = CommandFunctions.ResettingState.ResetWaiting;
                //开始复位到游戏结束点
                StartCoroutine(WaitForEndReset(CommandFunctions.ResetPostion, CommandFunctions.ResetSpeed, CommandFunctions.ResetDeviation));
                break;
            }
        }
    }